##// END OF EJS Templates
pyoxidizer: default to one-file binary on non-Windows platforms...
Augie Fackler -
r46435:f14c33b2 default
parent child Browse files
Show More
@@ -1,108 +1,112 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()
11 return default_python_distribution()
12
12
13 def make_distribution_windows():
13 def make_distribution_windows():
14 return default_python_distribution(flavor = "standalone_dynamic")
14 return default_python_distribution(flavor = "standalone_dynamic")
15
15
16 def resource_callback(policy, resource):
16 def resource_callback(policy, resource):
17 if not IS_WINDOWS:
18 resource.add_location = "in-memory"
19 return
17 # We use a custom resource routing policy to influence where things are loaded
20 # We use a custom resource routing policy to influence where things are loaded
18 # from.
21 # from.
19 #
22 #
20 # For Python modules and resources, we load from memory if they are in
23 # For Python modules and resources, we load from memory if they are in
21 # the standard library and from the filesystem if not. This is because
24 # the standard library and from the filesystem if not. This is because
22 # parts of Mercurial and some 3rd party packages aren't yet compatible
25 # parts of Mercurial and some 3rd party packages aren't yet compatible
23 # with memory loading.
26 # with memory loading.
24 #
27 #
25 # For Python extension modules, we load from the filesystem because
28 # For Python extension modules, we load from the filesystem because
26 # this yields greatest compatibility.
29 # this yields greatest compatibility.
27 if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"):
30 if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"):
28 if resource.is_stdlib:
31 if resource.is_stdlib:
29 resource.add_location = "in-memory"
32 resource.add_location = "in-memory"
30 else:
33 else:
31 resource.add_location = "filesystem-relative:lib"
34 resource.add_location = "filesystem-relative:lib"
32
35
33 elif type(resource) == "PythonExtensionModule":
36 elif type(resource) == "PythonExtensionModule":
34 resource.add_location = "filesystem-relative:lib"
37 resource.add_location = "filesystem-relative:lib"
35
38
36 def make_exe(dist):
39 def make_exe(dist):
37 """Builds a Rust-wrapped Mercurial binary."""
40 """Builds a Rust-wrapped Mercurial binary."""
38 packaging_policy = dist.make_python_packaging_policy()
41 packaging_policy = dist.make_python_packaging_policy()
39 # Extension may depend on any Python functionality. Include all
42 # Extension may depend on any Python functionality. Include all
40 # extensions.
43 # extensions.
41 packaging_policy.extension_module_filter = "all"
44 packaging_policy.extension_module_filter = "all"
42 packaging_policy.resources_location = "in-memory"
45 packaging_policy.resources_location = "in-memory"
43 packaging_policy.resources_location_fallback = "filesystem-relative:lib"
46 if IS_WINDOWS:
47 packaging_policy.resources_location_fallback = "filesystem-relative:lib"
44 packaging_policy.register_resource_callback(resource_callback)
48 packaging_policy.register_resource_callback(resource_callback)
45
49
46 config = dist.make_python_interpreter_config()
50 config = dist.make_python_interpreter_config()
47 config.raw_allocator = "system"
51 config.raw_allocator = "system"
48 config.run_mode = "eval:%s" % RUN_CODE
52 config.run_mode = "eval:%s" % RUN_CODE
49 # 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
50 config.filesystem_importer = True
54 config.filesystem_importer = True
51 # We need this to make resourceutil happy, since it looks for sys.frozen.
55 # We need this to make resourceutil happy, since it looks for sys.frozen.
52 config.sys_frozen = True
56 config.sys_frozen = True
53 config.legacy_windows_stdio = True
57 config.legacy_windows_stdio = True
54
58
55 exe = dist.to_python_executable(
59 exe = dist.to_python_executable(
56 name = "hg",
60 name = "hg",
57 packaging_policy = packaging_policy,
61 packaging_policy = packaging_policy,
58 config = config,
62 config = config,
59 )
63 )
60
64
61 # Add Mercurial to resources.
65 # Add Mercurial to resources.
62 exe.add_python_resources(exe.pip_install(["--verbose", ROOT]))
66 exe.add_python_resources(exe.pip_install(["--verbose", ROOT]))
63
67
64 # On Windows, we install extra packages for convenience.
68 # On Windows, we install extra packages for convenience.
65 if IS_WINDOWS:
69 if IS_WINDOWS:
66 exe.add_python_resources(
70 exe.add_python_resources(
67 exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py2.txt"]),
71 exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py2.txt"]),
68 )
72 )
69
73
70 return exe
74 return exe
71
75
72 def make_manifest(dist, exe):
76 def make_manifest(dist, exe):
73 m = FileManifest()
77 m = FileManifest()
74 m.add_python_resource(".", exe)
78 m.add_python_resource(".", exe)
75
79
76 return m
80 return m
77
81
78 def make_embedded_resources(exe):
82 def make_embedded_resources(exe):
79 return exe.to_embedded_resources()
83 return exe.to_embedded_resources()
80
84
81 register_target("distribution_posix", make_distribution)
85 register_target("distribution_posix", make_distribution)
82 register_target("distribution_windows", make_distribution_windows)
86 register_target("distribution_windows", make_distribution_windows)
83
87
84 register_target("exe_posix", make_exe, depends = ["distribution_posix"])
88 register_target("exe_posix", make_exe, depends = ["distribution_posix"])
85 register_target("exe_windows", make_exe, depends = ["distribution_windows"])
89 register_target("exe_windows", make_exe, depends = ["distribution_windows"])
86
90
87 register_target(
91 register_target(
88 "app_posix",
92 "app_posix",
89 make_manifest,
93 make_manifest,
90 depends = ["distribution_posix", "exe_posix"],
94 depends = ["distribution_posix", "exe_posix"],
91 default = "windows" not in BUILD_TARGET_TRIPLE,
95 default = "windows" not in BUILD_TARGET_TRIPLE,
92 )
96 )
93 register_target(
97 register_target(
94 "app_windows",
98 "app_windows",
95 make_manifest,
99 make_manifest,
96 depends = ["distribution_windows", "exe_windows"],
100 depends = ["distribution_windows", "exe_windows"],
97 default = "windows" in BUILD_TARGET_TRIPLE,
101 default = "windows" in BUILD_TARGET_TRIPLE,
98 )
102 )
99
103
100 resolve_targets()
104 resolve_targets()
101
105
102 # END OF COMMON USER-ADJUSTED SETTINGS.
106 # END OF COMMON USER-ADJUSTED SETTINGS.
103 #
107 #
104 # Everything below this is typically managed by PyOxidizer and doesn't need
108 # Everything below this is typically managed by PyOxidizer and doesn't need
105 # to be updated by people.
109 # to be updated by people.
106
110
107 PYOXIDIZER_VERSION = "0.9.0"
111 PYOXIDIZER_VERSION = "0.9.0"
108 PYOXIDIZER_COMMIT = "1fbc264cc004226cd76ee452e0a386ffca6ccfb1"
112 PYOXIDIZER_COMMIT = "1fbc264cc004226cd76ee452e0a386ffca6ccfb1"
General Comments 0
You need to be logged in to leave comments. Login now