32
32
add_env_common ,
33
33
add_licenses_to_extension_entry ,
34
34
clang_toolchain ,
35
+ create_tar_from_directory ,
35
36
download_entry ,
36
37
get_targets ,
37
38
get_target_settings ,
38
39
target_needs ,
39
40
validate_python_json ,
40
41
write_package_versions ,
42
+ write_cpython_version ,
41
43
write_target_settings ,
42
44
write_triples_makefiles ,
43
45
)
@@ -62,8 +64,7 @@ def install_sccache(build_env):
62
64
"""
63
65
candidates = [
64
66
# Prefer a binary in the project itself.
65
- ROOT
66
- / "sccache" ,
67
+ ROOT / "sccache" ,
67
68
]
68
69
69
70
# Look for sccache in $PATH, but only if the build environment
@@ -255,10 +256,9 @@ def simple_build(
255
256
build_env .copy_file (SUPPORT / ("build-%s.sh" % entry ))
256
257
257
258
env = {
258
- "%s_VERSION"
259
- % entry .upper ()
260
- .replace ("-" , "_" )
261
- .replace ("." , "_" ): DOWNLOADS [entry ]["version" ],
259
+ "%s_VERSION" % entry .upper ().replace ("-" , "_" ).replace ("." , "_" ): DOWNLOADS [
260
+ entry
261
+ ]["version" ],
262
262
}
263
263
264
264
add_target_env (env , host_platform , target_triple , build_env )
@@ -684,13 +684,23 @@ def build_cpython(
684
684
optimizations ,
685
685
dest_archive ,
686
686
version = None ,
687
+ python_source = None ,
687
688
):
688
689
"""Build CPython in a Docker image'"""
689
690
entry_name = "cpython-%s" % version
690
691
entry = DOWNLOADS [entry_name ]
691
- python_version = entry ["version" ]
692
+ if not python_source :
693
+ python_version = entry ["version" ]
694
+ python_archive = download_entry (entry_name , DOWNLOADS_PATH )
695
+ else :
696
+ python_version = os .environ ["PYBUILD_PYTHON_VERSION" ]
697
+ python_archive = DOWNLOADS_PATH / ("Python-%s.tar.xz" % python_version )
698
+ print ("Compressing %s to %s" % (python_source , python_archive ))
699
+ with python_archive .open ("wb" ) as fh :
700
+ create_tar_from_directory (
701
+ fh , python_source , path_prefix = "Python-%s" % python_version
702
+ )
692
703
693
- python_archive = download_entry (entry_name , DOWNLOADS_PATH )
694
704
setuptools_archive = download_entry ("setuptools" , DOWNLOADS_PATH )
695
705
pip_archive = download_entry ("pip" , DOWNLOADS_PATH )
696
706
@@ -726,7 +736,9 @@ def build_cpython(
726
736
for p in sorted (packages ):
727
737
build_env .install_artifact_archive (BUILD , p , target_triple , optimizations )
728
738
729
- build_env .install_toolchain_archive (BUILD , entry_name , host_platform )
739
+ build_env .install_toolchain_archive (
740
+ BUILD , entry_name , host_platform , version = python_version
741
+ )
730
742
731
743
for p in (
732
744
python_archive ,
@@ -762,8 +774,8 @@ def build_cpython(
762
774
763
775
env = {
764
776
"PIP_VERSION" : DOWNLOADS ["pip" ]["version" ],
765
- "PYTHON_VERSION" : entry [ "version" ] ,
766
- "PYTHON_MAJMIN_VERSION" : "." .join (entry [ "version" ] .split ("." )[0 :2 ]),
777
+ "PYTHON_VERSION" : python_version ,
778
+ "PYTHON_MAJMIN_VERSION" : "." .join (python_version .split ("." )[0 :2 ]),
767
779
"SETUPTOOLS_VERSION" : DOWNLOADS ["setuptools" ]["version" ],
768
780
"TOOLCHAIN" : "clang-%s" % host_platform ,
769
781
}
@@ -824,7 +836,7 @@ def build_cpython(
824
836
"target_triple" : target_triple ,
825
837
"optimizations" : optimizations ,
826
838
"python_tag" : entry ["python_tag" ],
827
- "python_version" : entry [ "version" ] ,
839
+ "python_version" : python_version ,
828
840
"python_stdlib_test_packages" : sorted (STDLIB_TEST_PACKAGES ),
829
841
"python_symbol_visibility" : python_symbol_visibility ,
830
842
"python_extension_module_loading" : extension_module_loading ,
@@ -924,6 +936,11 @@ def main():
924
936
"--dest-archive" , required = True , help = "Path to archive that we are producing"
925
937
)
926
938
parser .add_argument ("--docker-image" , help = "Docker image to use for building" )
939
+ parser .add_argument (
940
+ "--python-source" ,
941
+ default = None ,
942
+ help = "A custom path to CPython source files to use" ,
943
+ )
927
944
parser .add_argument ("action" )
928
945
929
946
args = parser .parse_args ()
@@ -933,6 +950,9 @@ def main():
933
950
target_triple = args .target_triple
934
951
host_platform = args .host_platform
935
952
optimizations = args .optimizations
953
+ python_source = (
954
+ pathlib .Path (args .python_source ) if args .python_source != "null" else None
955
+ )
936
956
dest_archive = pathlib .Path (args .dest_archive )
937
957
docker_image = args .docker_image
938
958
@@ -969,6 +989,12 @@ def main():
969
989
write_target_settings (targets , BUILD / "targets" )
970
990
write_package_versions (BUILD / "versions" )
971
991
992
+ # Override the DOWNLOADS package entry for CPython for the local build
993
+ if python_source :
994
+ write_cpython_version (
995
+ BUILD / "versions" , os .environ ["PYBUILD_PYTHON_VERSION" ]
996
+ )
997
+
972
998
elif action .startswith ("image-" ):
973
999
image_name = action [6 :]
974
1000
image_path = BUILD / ("%s.Dockerfile" % image_name )
@@ -1179,6 +1205,7 @@ def main():
1179
1205
optimizations = optimizations ,
1180
1206
dest_archive = dest_archive ,
1181
1207
version = action .split ("-" )[1 ],
1208
+ python_source = python_source ,
1182
1209
)
1183
1210
1184
1211
else :
0 commit comments