7
7
import concurrent .futures
8
8
import datetime
9
9
import json
10
+ import multiprocessing
10
11
import os
11
12
import pathlib
12
13
import re
@@ -802,11 +803,12 @@ def hack_project_files(
802
803
# Disable whole program optimization because it interferes with the format
803
804
# of object files and makes it so we can't easily consume their symbols.
804
805
# TODO this /might/ be OK once we figure out symbol exporting issues.
805
- static_replace_in_file (
806
- pyproject_props ,
807
- b"<WholeProgramOptimization>true</WholeProgramOptimization>" ,
808
- b"<WholeProgramOptimization>false</WholeProgramOptimization>" ,
809
- )
806
+ if static :
807
+ static_replace_in_file (
808
+ pyproject_props ,
809
+ b"<WholeProgramOptimization>true</WholeProgramOptimization>" ,
810
+ b"<WholeProgramOptimization>false</WholeProgramOptimization>" ,
811
+ )
810
812
811
813
# Make libpython a static library.
812
814
if static :
@@ -1294,7 +1296,12 @@ def find_additional_dependencies(project: pathlib.Path):
1294
1296
for obj in process_project ("pythoncore" , core_dir ):
1295
1297
res ["core" ]["objs" ].append ("build/core/%s" % obj )
1296
1298
1297
- for ext in ("lib" , "pdb" , "exp" ):
1299
+ if static :
1300
+ exts = ("lib" ,)
1301
+ else :
1302
+ exts = ("lib" , "pdb" , "exp" )
1303
+
1304
+ for ext in exts :
1298
1305
source = outputs_path / ("python37.%s" % ext )
1299
1306
dest = core_dir / ("python37.%s" % ext )
1300
1307
log ("copying %s" % source )
@@ -1431,6 +1438,9 @@ def find_additional_dependencies(project: pathlib.Path):
1431
1438
1432
1439
1433
1440
def build_cpython (arch : str , pgo = False , build_mode = "static" ):
1441
+ if pgo and build_mode == "static" :
1442
+ raise Exception ("PGO not supported for static build mode" )
1443
+
1434
1444
static = build_mode == "static"
1435
1445
1436
1446
msbuild = find_msbuild ()
@@ -1529,10 +1539,27 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
1529
1539
platform = build_platform ,
1530
1540
)
1531
1541
1542
+ # build-windows.py sets some environment variables which cause the
1543
+ # test harness to pick up the wrong `test` module. We unset these
1544
+ # so things work as expected.
1545
+ env = dict (os .environ )
1546
+ paths = [
1547
+ p for p in env ["PATH" ].split (";" ) if p != str (BUILD / "venv" / "bin" )
1548
+ ]
1549
+ env ["PATH" ] = ";" .join (paths )
1550
+ del env ["PYTHONPATH" ]
1551
+
1532
1552
exec_and_log (
1533
- [str (cpython_source_path / "python.bat" ), "-m" , "test" , "--pgo" ],
1553
+ [
1554
+ str (cpython_source_path / "python.bat" ),
1555
+ "-m" ,
1556
+ "test" ,
1557
+ "--pgo" ,
1558
+ "-j" ,
1559
+ "%d" % (multiprocessing .cpu_count () / 2 - 1 ),
1560
+ ],
1534
1561
str (pcbuild_path ),
1535
- os . environ ,
1562
+ env ,
1536
1563
exit_on_error = False ,
1537
1564
)
1538
1565
@@ -1675,7 +1702,16 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
1675
1702
with (out_dir / "python" / "PYTHON.json" ).open ("w" , encoding = "utf8" ) as fh :
1676
1703
json .dump (python_info , fh , sort_keys = True , indent = 4 )
1677
1704
1678
- dest_path = BUILD / ("cpython-windows-%s-%s.tar" % (arch , build_mode ))
1705
+ basename = "cpython-%s-windows-%s-%s" % (
1706
+ DOWNLOADS ["cpython-3.7" ]["version" ],
1707
+ arch ,
1708
+ build_mode ,
1709
+ )
1710
+ if pgo :
1711
+ basename += "-pgo"
1712
+ basename += ".tar"
1713
+
1714
+ dest_path = BUILD / basename
1679
1715
1680
1716
with dest_path .open ("wb" ) as fh :
1681
1717
create_tar_from_directory (fh , td / "out" )
@@ -1702,6 +1738,9 @@ def main():
1702
1738
default = "static" ,
1703
1739
help = "How to compile Python" ,
1704
1740
)
1741
+ parser .add_argument (
1742
+ "--pgo" , action = "store_true" , help = "Enable profile-guided optimization"
1743
+ )
1705
1744
1706
1745
args = parser .parse_args ()
1707
1746
@@ -1722,18 +1761,10 @@ def main():
1722
1761
build_openssl (perl_path , arch )
1723
1762
1724
1763
LOG_PREFIX [0 ] = "cpython"
1725
- tar_path = build_cpython (arch , build_mode = args .build_mode )
1764
+ tar_path = build_cpython (arch , build_mode = args .build_mode , pgo = args . pgo )
1726
1765
1727
1766
compress_python_archive (
1728
- tar_path ,
1729
- DIST ,
1730
- "cpython-%s-windows-%s-%s-%s"
1731
- % (
1732
- DOWNLOADS ["cpython-3.7" ]["version" ],
1733
- arch ,
1734
- args .build_mode ,
1735
- now .strftime ("%Y%m%dT%H%M" ),
1736
- ),
1767
+ tar_path , DIST , "%s-%s" % (tar_path .stem , now .strftime ("%Y%m%dT%H%M" )),
1737
1768
)
1738
1769
1739
1770
0 commit comments