Skip to content

Commit d249243

Browse files
committed
unix: move get_target_support_file() to utils
So we can use it as part of writing out Makefiles in a future commit.
1 parent 4e4a25a commit d249243

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

cpython-unix/build.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
download_entry,
3232
get_targets,
3333
get_target_settings,
34+
get_target_support_file,
3435
target_needs,
3536
validate_python_json,
3637
write_package_versions,
@@ -682,7 +683,7 @@ def process_setup_line(line, variant=None):
682683
)
683684

684685
with get_target_support_file(
685-
"required-extensions", version, platform, target_triple
686+
SUPPORT, "required-extensions", version, platform, target_triple
686687
).open("r") as fh:
687688
required_extensions = {l.strip() for l in fh if l.strip()}
688689

@@ -699,25 +700,6 @@ def process_setup_line(line, variant=None):
699700
return bi
700701

701702

702-
def get_target_support_file(prefix, python_version, host_platform, target_triple):
703-
candidates = [
704-
SUPPORT / ("%s.%s.%s" % (prefix, python_version, target_triple)),
705-
SUPPORT / ("%s.%s.%s" % (prefix, python_version, host_platform)),
706-
]
707-
708-
for path in candidates:
709-
if path.exists():
710-
return path
711-
712-
raise Exception(
713-
"Could not find support file %s for (%s, %s, %s)",
714-
prefix,
715-
python_version,
716-
host_platform,
717-
target_triple,
718-
)
719-
720-
721703
def build_cpython(
722704
settings,
723705
client,
@@ -738,12 +720,12 @@ def build_cpython(
738720
pip_archive = download_entry("pip", DOWNLOADS_PATH)
739721

740722
with get_target_support_file(
741-
"static-modules", version, host_platform, target_triple
723+
SUPPORT, "static-modules", version, host_platform, target_triple
742724
).open("rb") as fh:
743725
static_modules_lines = [l.rstrip() for l in fh if not l.startswith(b"#")]
744726

745727
with get_target_support_file(
746-
"disabled-static-modules", version, host_platform, target_triple
728+
SUPPORT, "disabled-static-modules", version, host_platform, target_triple
747729
).open("rb") as fh:
748730
disabled_static_modules = {
749731
l.strip() for l in fh if l.strip() and not l.strip().startswith(b"#")

pythonbuild/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ def hash_path(p: pathlib.Path):
9090
return h.hexdigest()
9191

9292

93+
def get_target_support_file(
94+
search_dir, prefix, python_version, host_platform, target_triple
95+
):
96+
candidates = [
97+
search_dir / ("%s.%s.%s" % (prefix, python_version, target_triple)),
98+
search_dir / ("%s.%s.%s" % (prefix, python_version, host_platform)),
99+
]
100+
101+
for path in candidates:
102+
if path.exists():
103+
return path
104+
105+
raise Exception(
106+
"Could not find support file %s for (%s, %s, %s)",
107+
prefix,
108+
python_version,
109+
host_platform,
110+
target_triple,
111+
)
112+
113+
93114
def write_if_different(p: pathlib.Path, data: bytes):
94115
"""Write a file if it is missing or its content is different."""
95116
if p.exists():

0 commit comments

Comments
 (0)