author | Augie Fackler <augie@google.com> |
Tue, 10 Nov 2020 12:44:15 -0500 | |
changeset 45832 | 867385f45559 |
parent 45831 | f14c33b2e497 |
child 45879 | 5d73d3053d92 |
permissions | -rw-r--r-- |
44639
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
1 |
ROOT = CWD + "/../.." |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
|
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
3 |
IS_WINDOWS = "windows" in BUILD_TARGET_TRIPLE |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
4 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
5 |
# Code to run in Python interpreter. |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
6 |
RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
7 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
8 |
set_build_path(ROOT + "/build/pyoxidizer") |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
9 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
10 |
def make_distribution(): |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
11 |
return default_python_distribution() |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
12 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
13 |
def make_distribution_windows(): |
44822
118f067f6bd1
pyoxidizer: formatting bazel definitions
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44763
diff
changeset
|
14 |
return default_python_distribution(flavor = "standalone_dynamic") |
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
15 |
|
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
16 |
def resource_callback(policy, resource): |
45831
f14c33b2e497
pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents:
45752
diff
changeset
|
17 |
if not IS_WINDOWS: |
f14c33b2e497
pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents:
45752
diff
changeset
|
18 |
resource.add_location = "in-memory" |
f14c33b2e497
pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents:
45752
diff
changeset
|
19 |
return |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
20 |
# We use a custom resource routing policy to influence where things are loaded |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
21 |
# from. |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
22 |
# |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
23 |
# For Python modules and resources, we load from memory if they are in |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
24 |
# the standard library and from the filesystem if not. This is because |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
25 |
# parts of Mercurial and some 3rd party packages aren't yet compatible |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
26 |
# with memory loading. |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
27 |
# |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
28 |
# For Python extension modules, we load from the filesystem because |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
29 |
# this yields greatest compatibility. |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
30 |
if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"): |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
31 |
if resource.is_stdlib: |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
32 |
resource.add_location = "in-memory" |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
33 |
else: |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
34 |
resource.add_location = "filesystem-relative:lib" |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
35 |
|
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
36 |
elif type(resource) == "PythonExtensionModule": |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
37 |
resource.add_location = "filesystem-relative:lib" |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
38 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
39 |
def make_exe(dist): |
44822
118f067f6bd1
pyoxidizer: formatting bazel definitions
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44763
diff
changeset
|
40 |
"""Builds a Rust-wrapped Mercurial binary.""" |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
41 |
packaging_policy = dist.make_python_packaging_policy() |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
42 |
# Extension may depend on any Python functionality. Include all |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
43 |
# extensions. |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
44 |
packaging_policy.extension_module_filter = "all" |
45749
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
45 |
packaging_policy.resources_location = "in-memory" |
45831
f14c33b2e497
pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents:
45752
diff
changeset
|
46 |
if IS_WINDOWS: |
f14c33b2e497
pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents:
45752
diff
changeset
|
47 |
packaging_policy.resources_location_fallback = "filesystem-relative:lib" |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
48 |
packaging_policy.register_resource_callback(resource_callback) |
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
49 |
|
45749
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
50 |
config = dist.make_python_interpreter_config() |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
51 |
config.raw_allocator = "system" |
45832
867385f45559
pyoxidizer: switch to modern config using run_command instead of run_mode
Augie Fackler <augie@google.com>
parents:
45831
diff
changeset
|
52 |
config.run_command = RUN_CODE |
45749
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
53 |
# We want to let the user load extensions from the file system |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
54 |
config.filesystem_importer = True |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
55 |
# We need this to make resourceutil happy, since it looks for sys.frozen. |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
56 |
config.sys_frozen = True |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
57 |
config.legacy_windows_stdio = True |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
|
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
exe = dist.to_python_executable( |
44639
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
60 |
name = "hg", |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
61 |
packaging_policy = packaging_policy, |
44639
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
62 |
config = config, |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
) |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
65 |
# Add Mercurial to resources. |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
66 |
exe.add_python_resources(exe.pip_install(["--verbose", ROOT])) |
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
67 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
68 |
# On Windows, we install extra packages for convenience. |
45685
57b5452a55d5
pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44822
diff
changeset
|
69 |
if IS_WINDOWS: |
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
70 |
exe.add_python_resources( |
45752
d270b9b797a7
contrib: split Windows requirements into multiple files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45749
diff
changeset
|
71 |
exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py2.txt"]), |
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
72 |
) |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
|
44639
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
74 |
return exe |
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
75 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
76 |
def make_manifest(dist, exe): |
44639
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
77 |
m = FileManifest() |
bc847878f4c0
hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44638
diff
changeset
|
78 |
m.add_python_resource(".", exe) |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
80 |
return m |
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
|
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
def make_embedded_resources(exe): |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
return exe.to_embedded_resources() |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
|
44763
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
85 |
register_target("distribution_posix", make_distribution) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
86 |
register_target("distribution_windows", make_distribution_windows) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
87 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
88 |
register_target("exe_posix", make_exe, depends = ["distribution_posix"]) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
89 |
register_target("exe_windows", make_exe, depends = ["distribution_windows"]) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
90 |
|
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
91 |
register_target( |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
92 |
"app_posix", |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
93 |
make_manifest, |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
94 |
depends = ["distribution_posix", "exe_posix"], |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
95 |
default = "windows" not in BUILD_TARGET_TRIPLE, |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
96 |
) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
97 |
register_target( |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
98 |
"app_windows", |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
99 |
make_manifest, |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
100 |
depends = ["distribution_windows", "exe_windows"], |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
101 |
default = "windows" in BUILD_TARGET_TRIPLE, |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
102 |
) |
94f4f2ec7dee
packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44639
diff
changeset
|
103 |
|
44638
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 |
resolve_targets() |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
|
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
# END OF COMMON USER-ADJUSTED SETTINGS. |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
# |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
# Everything below this is typically managed by PyOxidizer and doesn't need |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
# to be updated by people. |
af739894a4c1
hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
|
45749
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
111 |
PYOXIDIZER_VERSION = "0.9.0" |
f95b16796688
pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45685
diff
changeset
|
112 |
PYOXIDIZER_COMMIT = "1fbc264cc004226cd76ee452e0a386ffca6ccfb1" |