Show More
@@ -1,108 +1,87 b'' | |||||
1 | ROOT = CWD + "/../.." |
|
1 | ROOT = CWD + "/../.." | |
2 |
|
2 | |||
3 | IS_WINDOWS = "windows" in BUILD_TARGET_TRIPLE |
|
3 | IS_WINDOWS = "windows" in BUILD_TARGET_TRIPLE | |
4 |
|
4 | |||
5 | # Code to run in Python interpreter. |
|
5 | # Code to run in Python interpreter. | |
6 | RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" |
|
6 | RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" | |
7 |
|
7 | |||
8 | set_build_path(ROOT + "/build/pyoxidizer") |
|
8 | set_build_path(ROOT + "/build/pyoxidizer") | |
9 |
|
9 | |||
10 | def make_distribution(): |
|
10 | def make_distribution(): | |
11 | return default_python_distribution(python_version = "3.8") |
|
11 | return default_python_distribution(python_version = "3.8") | |
12 |
|
12 | |||
13 | def make_distribution_windows(): |
|
|||
14 | return default_python_distribution(flavor = "standalone_dynamic") |
|
|||
15 |
|
||||
16 | def resource_callback(policy, resource): |
|
13 | def resource_callback(policy, resource): | |
17 | if not IS_WINDOWS: |
|
14 | if not IS_WINDOWS: | |
18 | resource.add_location = "in-memory" |
|
15 | resource.add_location = "in-memory" | |
19 | return |
|
16 | return | |
20 |
|
17 | |||
21 | # We use a custom resource routing policy to influence where things are loaded |
|
18 | # We use a custom resource routing policy to influence where things are loaded | |
22 | # from. |
|
19 | # from. | |
23 | # |
|
20 | # | |
24 | # For Python modules and resources, we load from memory if they are in |
|
21 | # For Python modules and resources, we load from memory if they are in | |
25 | # the standard library and from the filesystem if not. This is because |
|
22 | # the standard library and from the filesystem if not. This is because | |
26 | # parts of Mercurial and some 3rd party packages aren't yet compatible |
|
23 | # parts of Mercurial and some 3rd party packages aren't yet compatible | |
27 | # with memory loading. |
|
24 | # with memory loading. | |
28 | # |
|
25 | # | |
29 | # For Python extension modules, we load from the filesystem because |
|
26 | # For Python extension modules, we load from the filesystem because | |
30 | # this yields greatest compatibility. |
|
27 | # this yields greatest compatibility. | |
31 | if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"): |
|
28 | if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"): | |
32 | if resource.is_stdlib: |
|
29 | if resource.is_stdlib: | |
33 | resource.add_location = "in-memory" |
|
30 | resource.add_location = "in-memory" | |
34 | else: |
|
31 | else: | |
35 | resource.add_location = "filesystem-relative:lib" |
|
32 | resource.add_location = "filesystem-relative:lib" | |
36 |
|
33 | |||
37 | elif type(resource) == "PythonExtensionModule": |
|
34 | elif type(resource) == "PythonExtensionModule": | |
38 | resource.add_location = "filesystem-relative:lib" |
|
35 | resource.add_location = "filesystem-relative:lib" | |
39 |
|
36 | |||
40 | def make_exe(dist): |
|
37 | def make_exe(dist): | |
41 | """Builds a Rust-wrapped Mercurial binary.""" |
|
38 | """Builds a Rust-wrapped Mercurial binary.""" | |
42 | packaging_policy = dist.make_python_packaging_policy() |
|
39 | packaging_policy = dist.make_python_packaging_policy() | |
43 |
|
40 | |||
44 | # Extension may depend on any Python functionality. Include all |
|
41 | # Extension may depend on any Python functionality. Include all | |
45 | # extensions. |
|
42 | # extensions. | |
46 | packaging_policy.extension_module_filter = "all" |
|
43 | packaging_policy.extension_module_filter = "all" | |
47 | packaging_policy.resources_location = "in-memory" |
|
44 | packaging_policy.resources_location = "in-memory" | |
48 | if IS_WINDOWS: |
|
45 | if IS_WINDOWS: | |
49 | packaging_policy.resources_location_fallback = "filesystem-relative:lib" |
|
46 | packaging_policy.resources_location_fallback = "filesystem-relative:lib" | |
50 | packaging_policy.register_resource_callback(resource_callback) |
|
47 | packaging_policy.register_resource_callback(resource_callback) | |
51 |
|
48 | |||
52 | config = dist.make_python_interpreter_config() |
|
49 | config = dist.make_python_interpreter_config() | |
53 | config.raw_allocator = "system" |
|
50 | config.raw_allocator = "system" | |
54 | config.run_command = RUN_CODE |
|
51 | config.run_command = RUN_CODE | |
55 |
|
52 | |||
56 | # We want to let the user load extensions from the file system |
|
53 | # We want to let the user load extensions from the file system | |
57 | config.filesystem_importer = True |
|
54 | config.filesystem_importer = True | |
58 |
|
55 | |||
59 | # We need this to make resourceutil happy, since it looks for sys.frozen. |
|
56 | # We need this to make resourceutil happy, since it looks for sys.frozen. | |
60 | config.sys_frozen = True |
|
57 | config.sys_frozen = True | |
61 | config.legacy_windows_stdio = True |
|
58 | config.legacy_windows_stdio = True | |
62 |
|
59 | |||
63 | exe = dist.to_python_executable( |
|
60 | exe = dist.to_python_executable( | |
64 | name = "hg", |
|
61 | name = "hg", | |
65 | packaging_policy = packaging_policy, |
|
62 | packaging_policy = packaging_policy, | |
66 | config = config, |
|
63 | config = config, | |
67 | ) |
|
64 | ) | |
68 |
|
65 | |||
69 | # Add Mercurial to resources. |
|
66 | # Add Mercurial to resources. | |
70 | exe.add_python_resources(exe.pip_install(["--verbose", ROOT])) |
|
67 | exe.add_python_resources(exe.pip_install(["--verbose", ROOT])) | |
71 |
|
68 | |||
72 | # On Windows, we install extra packages for convenience. |
|
69 | # On Windows, we install extra packages for convenience. | |
73 | if IS_WINDOWS: |
|
70 | if IS_WINDOWS: | |
74 | exe.add_python_resources( |
|
71 | exe.add_python_resources( | |
75 | exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py3.txt"]), |
|
72 | exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py3.txt"]), | |
76 | ) |
|
73 | ) | |
77 |
|
74 | |||
78 | return exe |
|
75 | return exe | |
79 |
|
76 | |||
80 | def make_manifest(dist, exe): |
|
77 | def make_manifest(dist, exe): | |
81 | m = FileManifest() |
|
78 | m = FileManifest() | |
82 | m.add_python_resource(".", exe) |
|
79 | m.add_python_resource(".", exe) | |
83 |
|
80 | |||
84 | return m |
|
81 | return m | |
85 |
|
82 | |||
86 | def make_embedded_resources(exe): |
|
83 | register_target("distribution", make_distribution) | |
87 | return exe.to_embedded_resources() |
|
84 | register_target("exe", make_exe, depends = ["distribution"]) | |
88 |
|
85 | register_target("app", make_manifest, depends = ["distribution", "exe"], default = True) | ||
89 | register_target("distribution_posix", make_distribution) |
|
|||
90 | register_target("distribution_windows", make_distribution_windows) |
|
|||
91 |
|
||||
92 | register_target("exe_posix", make_exe, depends = ["distribution_posix"]) |
|
|||
93 | register_target("exe_windows", make_exe, depends = ["distribution_windows"]) |
|
|||
94 |
|
||||
95 | register_target( |
|
|||
96 | "app_posix", |
|
|||
97 | make_manifest, |
|
|||
98 | depends = ["distribution_posix", "exe_posix"], |
|
|||
99 | default = "windows" not in BUILD_TARGET_TRIPLE, |
|
|||
100 | ) |
|
|||
101 | register_target( |
|
|||
102 | "app_windows", |
|
|||
103 | make_manifest, |
|
|||
104 | depends = ["distribution_windows", "exe_windows"], |
|
|||
105 | default = "windows" in BUILD_TARGET_TRIPLE, |
|
|||
106 | ) |
|
|||
107 |
|
86 | |||
108 | resolve_targets() |
|
87 | resolve_targets() |
General Comments 0
You need to be logged in to leave comments.
Login now