Skip to content

Commit 15d4d61

Browse files
committed
Refactor relenv.build.common into more understandable chunks
1 parent 1e746d9 commit 15d4d61

File tree

16 files changed

+2953
-2241
lines changed

16 files changed

+2953
-2241
lines changed

relenv/build/common.py

Lines changed: 0 additions & 2213 deletions
This file was deleted.

relenv/build/common/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2022-2025 Broadcom.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""
4+
Build process common methods.
5+
6+
This module has been split into focused submodules for better organization.
7+
All public APIs are re-exported here for backward compatibility.
8+
"""
9+
from __future__ import annotations
10+
11+
from .builders import (
12+
build_openssl,
13+
build_openssl_fips,
14+
build_sqlite,
15+
)
16+
17+
from .install import (
18+
update_ensurepip,
19+
install_runtime,
20+
finalize,
21+
create_archive,
22+
patch_file,
23+
)
24+
25+
from .builder import (
26+
Dirs,
27+
builds,
28+
get_dependency_version,
29+
)
30+
31+
32+
__all__ = [
33+
# Builder classes and instances
34+
"Dirs",
35+
"builds",
36+
# Dependency version management
37+
"get_dependency_version",
38+
# Install functions
39+
"finalize",
40+
"install_runtime",
41+
"create_archive",
42+
"update_ensurepip",
43+
"patch_file",
44+
# Builders (specific build functions)
45+
"build_openssl",
46+
"build_openssl_fips",
47+
"build_sqlite",
48+
]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2022-2025 Broadcom.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# mypy: ignore-errors
4+
# flake8: noqa
5+
"""
6+
Template for sysconfigdata module generated at build time.
7+
8+
This file is used as a template to generate the _sysconfigdata module
9+
that CPython uses at runtime. It is copied verbatim (after the header comments)
10+
into the generated sysconfigdata file.
11+
12+
The _build_time_vars dictionary is written before this content.
13+
14+
Note: mypy and flake8 errors are ignored for this template file as it contains
15+
code that is valid only in the context of the generated sysconfigdata module
16+
(e.g., _build_time_vars is injected, RelenvException is in generated context).
17+
"""
18+
19+
import pathlib
20+
import sys
21+
import platform
22+
import os
23+
import logging
24+
25+
log = logging.getLogger(__name__)
26+
27+
28+
def build_arch():
29+
machine = platform.machine()
30+
return machine.lower()
31+
32+
33+
def get_triplet(machine=None, plat=None):
34+
if not plat:
35+
plat = sys.platform
36+
if not machine:
37+
machine = build_arch()
38+
if plat == "darwin":
39+
return f"{machine}-macos"
40+
elif plat == "win32":
41+
return f"{machine}-win"
42+
elif plat == "linux":
43+
return f"{machine}-linux-gnu"
44+
else:
45+
raise RelenvException("Unknown platform {}".format(platform))
46+
47+
48+
pydir = pathlib.Path(__file__).resolve().parent
49+
if sys.platform == "win32":
50+
DEFAULT_DATA_DIR = pathlib.Path.home() / "AppData" / "Local" / "relenv"
51+
else:
52+
DEFAULT_DATA_DIR = pathlib.Path.home() / ".local" / "relenv"
53+
54+
if "RELENV_DATA" in os.environ:
55+
DATA_DIR = pathlib.Path(os.environ["RELENV_DATA"]).resolve()
56+
else:
57+
DATA_DIR = DEFAULT_DATA_DIR
58+
59+
buildroot = pydir.parent.parent
60+
61+
toolchain = DATA_DIR / "toolchain" / get_triplet()
62+
63+
build_time_vars = {}
64+
for key in _build_time_vars:
65+
val = _build_time_vars[key]
66+
orig = val
67+
if isinstance(val, str):
68+
val = val.format(
69+
BUILDROOT=buildroot,
70+
TOOLCHAIN=toolchain,
71+
)
72+
build_time_vars[key] = val

0 commit comments

Comments
 (0)