Skip to content

Commit 5580c25

Browse files
committed
Use keyword
1 parent ee2e4c3 commit 5580c25

File tree

4 files changed

+170
-84
lines changed

4 files changed

+170
-84
lines changed

cpython-unix/build.py

+89-42
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ def add_target_env(env, build_platform, target_triple, build_env):
214214
env["EXTRA_TARGET_LDFLAGS"] = " ".join(extra_target_ldflags)
215215

216216

217-
def toolchain_archive_path(package_name, host_platform, downloads):
217+
def toolchain_archive_path(package_name, host_platform, *, downloads: Downloads):
218218
entry = downloads[package_name]
219219

220220
basename = "%s-%s-%s.tar" % (package_name, entry["version"], host_platform)
221221

222222
return BUILD / basename
223223

224224

225-
def install_binutils(platform):
226-
return platform != "macos"
225+
def install_binutils(host_platform):
226+
return host_platform != "macos"
227227

228228

229229
def simple_build(
@@ -234,12 +234,13 @@ def simple_build(
234234
host_platform,
235235
target_triple,
236236
optimizations,
237-
downloads: Downloads,
238237
dest_archive,
239238
extra_archives=None,
240239
tools_path="deps",
240+
*,
241+
downloads: Downloads,
241242
):
242-
archive = download_entry(entry, DOWNLOADS_PATH, downloads)
243+
archive = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
243244

244245
with build_environment(client, image) as build_env:
245246
if settings.get("needs_toolchain"):
@@ -250,10 +251,13 @@ def simple_build(
250251
binutils=install_binutils(host_platform),
251252
clang=True,
252253
musl="musl" in target_triple,
254+
downloads=downloads,
253255
)
254256

255257
for a in extra_archives or []:
256-
build_env.install_artifact_archive(BUILD, a, target_triple, optimizations)
258+
build_env.install_artifact_archive(
259+
BUILD, a, target_triple, optimizations, downloads=downloads
260+
)
257261

258262
build_env.copy_file(archive)
259263
build_env.copy_file(SUPPORT / ("build-%s.sh" % entry))
@@ -275,9 +279,9 @@ def simple_build(
275279
build_env.get_tools_archive(dest_archive, tools_path)
276280

277281

278-
def build_binutils(client, image, host_platform, downloads):
282+
def build_binutils(client, image, host_platform, *, downloads: Downloads):
279283
"""Build binutils in the Docker image."""
280-
archive = download_entry("binutils", DOWNLOADS_PATH, downloads)
284+
archive = download_entry("binutils", DOWNLOADS_PATH, downloads=downloads)
281285

282286
with build_environment(client, image) as build_env:
283287
install_sccache(build_env)
@@ -295,13 +299,18 @@ def build_binutils(client, image, host_platform, downloads):
295299
)
296300

297301
build_env.get_tools_archive(
298-
toolchain_archive_path("binutils", host_platform, downloads), "host"
302+
toolchain_archive_path(
303+
"binutils",
304+
host_platform,
305+
downloads=downloads,
306+
),
307+
"host",
299308
)
300309

301310

302-
def materialize_clang(host_platform: str, target_triple: str, downloads):
311+
def materialize_clang(host_platform: str, target_triple: str, *, downloads: Downloads):
303312
entry = clang_toolchain(host_platform, target_triple)
304-
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads)
313+
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
305314
local_filename = "%s-%s-%s.tar" % (
306315
entry,
307316
downloads[entry]["version"],
@@ -315,12 +324,24 @@ def materialize_clang(host_platform: str, target_triple: str, downloads):
315324
dctx.copy_stream(ifh, ofh)
316325

317326

318-
def build_musl(client, image, host_platform: str, target_triple: str, downloads):
319-
musl_archive = download_entry("musl", DOWNLOADS_PATH, downloads)
327+
def build_musl(
328+
client,
329+
image,
330+
host_platform: str,
331+
target_triple: str,
332+
*,
333+
downloads: Downloads,
334+
):
335+
musl_archive = download_entry("musl", DOWNLOADS_PATH, downloads=downloads)
320336

321337
with build_environment(client, image) as build_env:
322338
build_env.install_toolchain(
323-
BUILD, host_platform, target_triple, binutils=True, clang=True
339+
BUILD,
340+
host_platform,
341+
target_triple,
342+
binutils=True,
343+
clang=True,
344+
downloads=downloads,
324345
)
325346
build_env.copy_file(musl_archive)
326347
build_env.copy_file(SUPPORT / "build-musl.sh")
@@ -333,7 +354,12 @@ def build_musl(client, image, host_platform: str, target_triple: str, downloads)
333354
build_env.run("build-musl.sh", environment=env)
334355

335356
build_env.get_tools_archive(
336-
toolchain_archive_path("musl", host_platform), "host"
357+
toolchain_archive_path(
358+
"musl",
359+
host_platform,
360+
downloads=downloads,
361+
),
362+
"host",
337363
)
338364

339365

@@ -345,9 +371,10 @@ def build_libedit(
345371
target_triple,
346372
optimizations,
347373
dest_archive,
374+
*,
348375
downloads: Downloads,
349376
):
350-
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads)
377+
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads=downloads)
351378

352379
with build_environment(client, image) as build_env:
353380
if settings.get("needs_toolchain"):
@@ -358,10 +385,11 @@ def build_libedit(
358385
binutils=install_binutils(host_platform),
359386
clang=True,
360387
musl="musl" in target_triple,
388+
downloads=downloads,
361389
)
362390

363391
build_env.install_artifact_archive(
364-
BUILD, "ncurses", target_triple, optimizations
392+
BUILD, "ncurses", target_triple, optimizations, downloads=downloads
365393
)
366394
build_env.copy_file(libedit_archive)
367395
build_env.copy_file(SUPPORT / "build-libedit.sh")
@@ -384,11 +412,12 @@ def build_tix(
384412
target_triple,
385413
optimizations,
386414
dest_archive,
415+
*,
387416
downloads: Downloads,
388417
):
389-
tcl_archive = download_entry("tcl", DOWNLOADS_PATH, downloads)
390-
tk_archive = download_entry("tk", DOWNLOADS_PATH, downloads)
391-
tix_archive = download_entry("tix", DOWNLOADS_PATH, downloads)
418+
tcl_archive = download_entry("tcl", DOWNLOADS_PATH, downloads=downloads)
419+
tk_archive = download_entry("tk", DOWNLOADS_PATH, downloads=downloads)
420+
tix_archive = download_entry("tix", DOWNLOADS_PATH, downloads=downloads)
392421

393422
with build_environment(client, image) as build_env:
394423
if settings.get("needs_toolchain"):
@@ -399,14 +428,17 @@ def build_tix(
399428
binutils=install_binutils(host_platform),
400429
clang=True,
401430
musl="musl" in target_triple,
431+
downloads=downloads,
402432
)
403433

404434
depends = {"tcl", "tk"}
405435
if host_platform != "macos":
406436
depends |= {"libX11", "xorgproto"}
407437

408438
for p in sorted(depends):
409-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
439+
build_env.install_artifact_archive(
440+
BUILD, p, target_triple, optimizations, downloads=downloads
441+
)
410442

411443
for p in (tcl_archive, tk_archive, tix_archive, SUPPORT / "build-tix.sh"):
412444
build_env.copy_file(p)
@@ -432,10 +464,11 @@ def build_cpython_host(
432464
target_triple: str,
433465
optimizations: str,
434466
dest_archive,
467+
*,
435468
downloads: Downloads,
436469
):
437470
"""Build binutils in the Docker image."""
438-
archive = download_entry(entry, DOWNLOADS_PATH, downloads)
471+
archive = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
439472

440473
with build_environment(client, image) as build_env:
441474
python_version = downloads[entry]["version"]
@@ -446,6 +479,7 @@ def build_cpython_host(
446479
target_triple,
447480
binutils=install_binutils(host_platform),
448481
clang=True,
482+
downloads=downloads,
449483
)
450484

451485
build_env.copy_file(archive)
@@ -463,7 +497,9 @@ def build_cpython_host(
463497
"m4",
464498
}
465499
for p in sorted(packages):
466-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
500+
build_env.install_artifact_archive(
501+
BUILD, p, target_triple, optimizations, downloads=downloads
502+
)
467503

468504
env = {
469505
"PYTHON_VERSION": python_version,
@@ -492,12 +528,13 @@ def build_cpython_host(
492528
def python_build_info(
493529
build_env,
494530
version,
495-
platform,
531+
host_platform,
496532
target_triple,
497533
musl,
498534
optimizations,
499535
extensions,
500536
extra_metadata,
537+
*,
501538
downloads: Downloads,
502539
):
503540
"""Obtain build metadata for the Python distribution."""
@@ -508,7 +545,7 @@ def python_build_info(
508545

509546
binary_suffix = ""
510547

511-
if platform == "linux64":
548+
if host_platform == "linux64":
512549
bi["core"]["static_lib"] = (
513550
"install/lib/python{version}/config-{version}{binary_suffix}-x86_64-linux-gnu/libpython{version}{binary_suffix}.a".format(
514551
version=version, binary_suffix=binary_suffix
@@ -522,7 +559,7 @@ def python_build_info(
522559
)
523560

524561
if optimizations in ("lto", "pgo+lto"):
525-
llvm_version = downloads[clang_toolchain(platform, target_triple)][
562+
llvm_version = downloads[clang_toolchain(host_platform, target_triple)][
526563
"version"
527564
]
528565
if "+" in llvm_version:
@@ -531,7 +568,7 @@ def python_build_info(
531568
object_file_format = f"llvm-bitcode:%{llvm_version}"
532569
else:
533570
object_file_format = "elf"
534-
elif platform == "macos":
571+
elif host_platform == "macos":
535572
bi["core"]["static_lib"] = (
536573
"install/lib/python{version}/config-{version}{binary_suffix}-darwin/libpython{version}{binary_suffix}.a".format(
537574
version=version, binary_suffix=binary_suffix
@@ -549,7 +586,7 @@ def python_build_info(
549586
else:
550587
object_file_format = "mach-o"
551588
else:
552-
raise Exception("unsupported platform: %s" % platform)
589+
raise Exception("unsupported platform: %s" % host_platform)
553590

554591
bi["object_file_format"] = object_file_format
555592

@@ -564,9 +601,9 @@ def python_build_info(
564601
if lib.startswith("-l"):
565602
lib = lib[2:]
566603

567-
if platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
604+
if host_platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
568605
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
569-
elif platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
606+
elif host_platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
570607
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
571608

572609
log("adding core system link library: %s" % lib)
@@ -681,7 +718,7 @@ def python_build_info(
681718
extension_suffix = extra_metadata["python_config_vars"]["EXT_SUFFIX"]
682719
entry["shared_lib"] = "%s/%s%s" % (shared_dir, extension, extension_suffix)
683720

684-
add_licenses_to_extension_entry(entry)
721+
add_licenses_to_extension_entry(entry, downloads=downloads)
685722

686723
bi["extensions"].setdefault(extension, []).append(entry)
687724

@@ -701,17 +738,18 @@ def build_cpython(
701738
host_platform,
702739
target_triple,
703740
optimizations,
704-
downloads: Downloads,
705741
dest_archive,
706742
version=None,
707743
python_source=None,
744+
*,
745+
downloads: Downloads,
708746
):
709747
"""Build CPython in a Docker image'"""
710748
entry_name = "cpython-%s" % version
711749
entry = downloads[entry_name]
712750
if not python_source:
713751
python_version = entry["version"]
714-
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads)
752+
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads=downloads)
715753
else:
716754
python_version = os.environ["PYBUILD_PYTHON_VERSION"]
717755
python_archive = DOWNLOADS_PATH / ("Python-%s.tar.xz" % python_version)
@@ -721,8 +759,10 @@ def build_cpython(
721759
fh, python_source, path_prefix="Python-%s" % python_version
722760
)
723761

724-
setuptools_archive = download_entry("setuptools", DOWNLOADS_PATH, downloads)
725-
pip_archive = download_entry("pip", DOWNLOADS_PATH, downloads)
762+
setuptools_archive = download_entry(
763+
"setuptools", DOWNLOADS_PATH, downloads=downloads
764+
)
765+
pip_archive = download_entry("pip", DOWNLOADS_PATH, downloads=downloads)
726766

727767
ems = extension_modules_config(EXTENSION_MODULES)
728768

@@ -746,6 +786,7 @@ def build_cpython(
746786
binutils=install_binutils(host_platform),
747787
clang=True,
748788
musl="musl" in target_triple,
789+
downloads=downloads,
749790
)
750791

751792
packages = target_needs(TARGETS_CONFIG, target_triple, python_version)
@@ -754,10 +795,16 @@ def build_cpython(
754795
packages.discard("musl")
755796

756797
for p in sorted(packages):
757-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
798+
build_env.install_artifact_archive(
799+
BUILD, p, target_triple, optimizations, downloads=downloads
800+
)
758801

759802
build_env.install_toolchain_archive(
760-
BUILD, entry_name, host_platform, version=python_version
803+
BUILD,
804+
entry_name,
805+
host_platform,
806+
version=python_version,
807+
downloads=downloads,
761808
)
762809

763810
for p in (
@@ -1008,9 +1055,9 @@ def main():
10081055
write_dockerfiles(SUPPORT, BUILD)
10091056
elif action == "makefiles":
10101057
targets = get_targets(TARGETS_CONFIG)
1011-
write_triples_makefiles(targets, BUILD, SUPPORT)
1058+
write_triples_makefiles(targets, BUILD, SUPPORT, downloads=downloads)
10121059
write_target_settings(targets, BUILD / "targets")
1013-
write_package_versions(BUILD / "versions")
1060+
write_package_versions(BUILD / "versions", downloads=downloads)
10141061

10151062
# Override the DOWNLOADS package entry for CPython for the local build
10161063
if python_source:
@@ -1056,9 +1103,9 @@ def main():
10561103
target_triple=target_triple,
10571104
optimizations=optimizations,
10581105
dest_archive=dest_archive,
1059-
downloads=downloads,
10601106
tools_path="host",
10611107
extra_archives=["m4"],
1108+
downloads=downloads,
10621109
)
10631110

10641111
elif action == "libedit":
@@ -1110,8 +1157,8 @@ def main():
11101157
target_triple=target_triple,
11111158
optimizations=optimizations,
11121159
dest_archive=dest_archive,
1113-
downloads=downloads,
11141160
tools_path=tools_path,
1161+
downloads=downloads,
11151162
)
11161163

11171164
elif action == "libX11":
@@ -1243,9 +1290,9 @@ def main():
12431290
target_triple=target_triple,
12441291
optimizations=optimizations,
12451292
dest_archive=dest_archive,
1246-
downloads=downloads,
12471293
version=action.split("-")[1],
12481294
python_source=python_source,
1295+
downloads=downloads,
12491296
)
12501297

12511298
else:

0 commit comments

Comments
 (0)