annotate rust/hgcli/pyoxidizer.bzl @ 45920:1441f4d57083

dispatch: pass root path in ui.readconfig() as root of main repo Since we are reading main (shared-source) repository config options, we should pass root as that repository root only. Differential Revision: https://phab.mercurial-scm.org/D9359
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 20 Nov 2020 14:34:15 +0530
parents 5d73d3053d92
children 926c7ed47ab0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
45879
5d73d3053d92 pyoxidizer: run buildifier
Augie Fackler <augie@google.com>
parents: 45832
diff changeset
20
45685
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
21 # 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
22 # from.
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
23 #
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
24 # 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
25 # 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
26 # 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
27 # with memory loading.
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
28 #
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
29 # 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
30 # this yields greatest compatibility.
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
31 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
32 if resource.is_stdlib:
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
33 resource.add_location = "in-memory"
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
34 else:
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
35 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
36
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
37 elif type(resource) == "PythonExtensionModule":
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
38 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
39
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
40 def make_exe(dist):
44822
118f067f6bd1 pyoxidizer: formatting bazel definitions
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44763
diff changeset
41 """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
42 packaging_policy = dist.make_python_packaging_policy()
45879
5d73d3053d92 pyoxidizer: run buildifier
Augie Fackler <augie@google.com>
parents: 45832
diff changeset
43
45685
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
44 # 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
45 # extensions.
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
46 packaging_policy.extension_module_filter = "all"
45749
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
47 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
48 if IS_WINDOWS:
f14c33b2e497 pyoxidizer: default to one-file binary on non-Windows platforms
Augie Fackler <augie@google.com>
parents: 45752
diff changeset
49 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
50 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
51
45749
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
52 config = dist.make_python_interpreter_config()
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
53 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
54 config.run_command = RUN_CODE
45879
5d73d3053d92 pyoxidizer: run buildifier
Augie Fackler <augie@google.com>
parents: 45832
diff changeset
55
45749
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
56 # 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
57 config.filesystem_importer = True
45879
5d73d3053d92 pyoxidizer: run buildifier
Augie Fackler <augie@google.com>
parents: 45832
diff changeset
58
45749
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
59 # 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
60 config.sys_frozen = True
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
61 config.legacy_windows_stdio = True
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63 exe = dist.to_python_executable(
44639
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
64 name = "hg",
45685
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
65 packaging_policy = packaging_policy,
44639
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
66 config = config,
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
67 )
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
68
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
69 # Add Mercurial to resources.
45685
57b5452a55d5 pyoxidizer: produce working Python 3 Windows installers (issue6366)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44822
diff changeset
70 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
71
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
72 # 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
73 if IS_WINDOWS:
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
74 exe.add_python_resources(
45752
d270b9b797a7 contrib: split Windows requirements into multiple files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45749
diff changeset
75 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
76 )
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77
44639
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
78 return exe
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
79
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
80 def make_manifest(dist, exe):
44639
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
81 m = FileManifest()
bc847878f4c0 hgcli: customize for Mercurial
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44638
diff changeset
82 m.add_python_resource(".", exe)
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
84 return m
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 def make_embedded_resources(exe):
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87 return exe.to_embedded_resources()
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
89 register_target("distribution_posix", make_distribution)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
90 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
91
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
92 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
93 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
94
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
95 register_target(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
96 "app_posix",
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
97 make_manifest,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
98 depends = ["distribution_posix", "exe_posix"],
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
99 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
100 )
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
101 register_target(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
102 "app_windows",
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
103 make_manifest,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
104 depends = ["distribution_windows", "exe_windows"],
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
105 default = "windows" in BUILD_TARGET_TRIPLE,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
106 )
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44639
diff changeset
107
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
108 resolve_targets()
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
109
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
110 # END OF COMMON USER-ADJUSTED SETTINGS.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
111 #
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
112 # 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
113 # to be updated by people.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
114
45749
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
115 PYOXIDIZER_VERSION = "0.9.0"
f95b16796688 pyoxidizer: update to PyOxidizer 0.9
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45685
diff changeset
116 PYOXIDIZER_COMMIT = "1fbc264cc004226cd76ee452e0a386ffca6ccfb1"