##// END OF EJS Templates
packaging: move documentation HTML building to own function...
Gregory Szorc -
r47978:41be7698 default
parent child Browse files
Show More
@@ -1,144 +1,152 b''
1 # pyoxidizer.py - Packaging support for PyOxidizer
1 # pyoxidizer.py - Packaging support for PyOxidizer
2 #
2 #
3 # Copyright 2020 Gregory Szorc <gregory.szorc@gmail.com>
3 # Copyright 2020 Gregory Szorc <gregory.szorc@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 # no-check-code because Python 3 native.
8 # no-check-code because Python 3 native.
9
9
10 import os
10 import os
11 import pathlib
11 import pathlib
12 import shutil
12 import shutil
13 import subprocess
13 import subprocess
14 import sys
14 import sys
15
15
16 from .downloads import download_entry
16 from .downloads import download_entry
17 from .util import (
17 from .util import (
18 extract_zip_to_directory,
18 extract_zip_to_directory,
19 process_install_rules,
19 process_install_rules,
20 find_vc_runtime_dll,
20 find_vc_runtime_dll,
21 )
21 )
22
22
23
23
24 STAGING_RULES_WINDOWS = [
24 STAGING_RULES_WINDOWS = [
25 ('contrib/bash_completion', 'contrib/'),
25 ('contrib/bash_completion', 'contrib/'),
26 ('contrib/hgk', 'contrib/hgk.tcl'),
26 ('contrib/hgk', 'contrib/hgk.tcl'),
27 ('contrib/hgweb.fcgi', 'contrib/'),
27 ('contrib/hgweb.fcgi', 'contrib/'),
28 ('contrib/hgweb.wsgi', 'contrib/'),
28 ('contrib/hgweb.wsgi', 'contrib/'),
29 ('contrib/logo-droplets.svg', 'contrib/'),
29 ('contrib/logo-droplets.svg', 'contrib/'),
30 ('contrib/mercurial.el', 'contrib/'),
30 ('contrib/mercurial.el', 'contrib/'),
31 ('contrib/mq.el', 'contrib/'),
31 ('contrib/mq.el', 'contrib/'),
32 ('contrib/tcsh_completion', 'contrib/'),
32 ('contrib/tcsh_completion', 'contrib/'),
33 ('contrib/tcsh_completion_build.sh', 'contrib/'),
33 ('contrib/tcsh_completion_build.sh', 'contrib/'),
34 ('contrib/vim/*', 'contrib/vim/'),
34 ('contrib/vim/*', 'contrib/vim/'),
35 ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
35 ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
36 ('contrib/win32/ReadMe.html', 'ReadMe.html'),
36 ('contrib/win32/ReadMe.html', 'ReadMe.html'),
37 ('contrib/xml.rnc', 'contrib/'),
37 ('contrib/xml.rnc', 'contrib/'),
38 ('contrib/zsh_completion', 'contrib/'),
38 ('contrib/zsh_completion', 'contrib/'),
39 ('doc/*.html', 'doc/'),
39 ('doc/*.html', 'doc/'),
40 ('doc/style.css', 'doc/'),
40 ('doc/style.css', 'doc/'),
41 ('COPYING', 'Copying.txt'),
41 ('COPYING', 'Copying.txt'),
42 ]
42 ]
43
43
44 STAGING_RULES_APP = [
44 STAGING_RULES_APP = [
45 ('lib/mercurial/helptext/**/*.txt', 'helptext/'),
45 ('lib/mercurial/helptext/**/*.txt', 'helptext/'),
46 ('lib/mercurial/defaultrc/*.rc', 'defaultrc/'),
46 ('lib/mercurial/defaultrc/*.rc', 'defaultrc/'),
47 ('lib/mercurial/locale/**/*', 'locale/'),
47 ('lib/mercurial/locale/**/*', 'locale/'),
48 ('lib/mercurial/templates/**/*', 'templates/'),
48 ('lib/mercurial/templates/**/*', 'templates/'),
49 ]
49 ]
50
50
51 STAGING_EXCLUDES_WINDOWS = [
51 STAGING_EXCLUDES_WINDOWS = [
52 "doc/hg-ssh.8.html",
52 "doc/hg-ssh.8.html",
53 ]
53 ]
54
54
55
55
56 def build_docs_html(source_dir: pathlib.Path):
57 """Ensures HTML documentation is built.
58
59 This will fail if docutils isn't available.
60
61 (The HTML docs aren't built as part of `pip install` so we need to build them
62 out of band.)
63 """
64 subprocess.run(
65 [sys.executable, str(source_dir / "setup.py"), "build_doc", "--html"],
66 cwd=str(source_dir),
67 check=True,
68 )
69
70
56 def run_pyoxidizer(
71 def run_pyoxidizer(
57 source_dir: pathlib.Path,
72 source_dir: pathlib.Path,
58 build_dir: pathlib.Path,
73 build_dir: pathlib.Path,
59 out_dir: pathlib.Path,
74 out_dir: pathlib.Path,
60 target_triple: str,
75 target_triple: str,
61 ):
76 ):
62 """Build Mercurial with PyOxidizer and copy additional files into place.
77 """Build Mercurial with PyOxidizer and copy additional files into place.
63
78
64 After successful completion, ``out_dir`` contains files constituting a
79 After successful completion, ``out_dir`` contains files constituting a
65 Mercurial install.
80 Mercurial install.
66 """
81 """
67 # We need to make gettext binaries available for compiling i18n files.
82 # We need to make gettext binaries available for compiling i18n files.
68 gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
83 gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
69 gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
84 gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
70
85
71 gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version'])
86 gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version'])
72
87
73 if not gettext_root.exists():
88 if not gettext_root.exists():
74 extract_zip_to_directory(gettext_pkg, gettext_root)
89 extract_zip_to_directory(gettext_pkg, gettext_root)
75 extract_zip_to_directory(gettext_dep_pkg, gettext_root)
90 extract_zip_to_directory(gettext_dep_pkg, gettext_root)
76
91
77 env = dict(os.environ)
92 env = dict(os.environ)
78 env["PATH"] = "%s%s%s" % (
93 env["PATH"] = "%s%s%s" % (
79 env["PATH"],
94 env["PATH"],
80 os.pathsep,
95 os.pathsep,
81 str(gettext_root / "bin"),
96 str(gettext_root / "bin"),
82 )
97 )
83
98
84 args = [
99 args = [
85 "pyoxidizer",
100 "pyoxidizer",
86 "build",
101 "build",
87 "--path",
102 "--path",
88 str(source_dir / "rust" / "hgcli"),
103 str(source_dir / "rust" / "hgcli"),
89 "--release",
104 "--release",
90 "--target-triple",
105 "--target-triple",
91 target_triple,
106 target_triple,
92 ]
107 ]
93
108
94 subprocess.run(args, env=env, check=True)
109 subprocess.run(args, env=env, check=True)
95
110
96 if "windows" in target_triple:
111 if "windows" in target_triple:
97 target = "app_windows"
112 target = "app_windows"
98 else:
113 else:
99 target = "app_posix"
114 target = "app_posix"
100
115
101 build_dir = (
116 build_dir = (
102 source_dir / "build" / "pyoxidizer" / target_triple / "release" / target
117 source_dir / "build" / "pyoxidizer" / target_triple / "release" / target
103 )
118 )
104
119
105 if out_dir.exists():
120 if out_dir.exists():
106 print("purging %s" % out_dir)
121 print("purging %s" % out_dir)
107 shutil.rmtree(out_dir)
122 shutil.rmtree(out_dir)
108
123
109 # Now assemble all the files from PyOxidizer into the staging directory.
124 # Now assemble all the files from PyOxidizer into the staging directory.
110 shutil.copytree(build_dir, out_dir)
125 shutil.copytree(build_dir, out_dir)
111
126
112 # Move some of those files around. We can get rid of this once Mercurial
127 # Move some of those files around. We can get rid of this once Mercurial
113 # is taught to use the importlib APIs for reading resources.
128 # is taught to use the importlib APIs for reading resources.
114 process_install_rules(STAGING_RULES_APP, build_dir, out_dir)
129 process_install_rules(STAGING_RULES_APP, build_dir, out_dir)
115
130
116 # We also need to run setup.py build_doc to produce html files,
131 build_docs_html(source_dir)
117 # as they aren't built as part of ``pip install``.
118 # This will fail if docutils isn't installed.
119 subprocess.run(
120 [sys.executable, str(source_dir / "setup.py"), "build_doc", "--html"],
121 cwd=str(source_dir),
122 check=True,
123 )
124
132
125 if "windows" in target_triple:
133 if "windows" in target_triple:
126 process_install_rules(STAGING_RULES_WINDOWS, source_dir, out_dir)
134 process_install_rules(STAGING_RULES_WINDOWS, source_dir, out_dir)
127
135
128 # Write out a default editor.rc file to configure notepad as the
136 # Write out a default editor.rc file to configure notepad as the
129 # default editor.
137 # default editor.
130 os.makedirs(out_dir / "defaultrc", exist_ok=True)
138 os.makedirs(out_dir / "defaultrc", exist_ok=True)
131 with (out_dir / "defaultrc" / "editor.rc").open(
139 with (out_dir / "defaultrc" / "editor.rc").open(
132 "w", encoding="utf-8"
140 "w", encoding="utf-8"
133 ) as fh:
141 ) as fh:
134 fh.write("[ui]\neditor = notepad\n")
142 fh.write("[ui]\neditor = notepad\n")
135
143
136 for f in STAGING_EXCLUDES_WINDOWS:
144 for f in STAGING_EXCLUDES_WINDOWS:
137 p = out_dir / f
145 p = out_dir / f
138 if p.exists():
146 if p.exists():
139 print("removing %s" % p)
147 print("removing %s" % p)
140 p.unlink()
148 p.unlink()
141
149
142 # Add vcruntimeXXX.dll next to executable.
150 # Add vcruntimeXXX.dll next to executable.
143 vc_runtime_dll = find_vc_runtime_dll(x64="x86_64" in target_triple)
151 vc_runtime_dll = find_vc_runtime_dll(x64="x86_64" in target_triple)
144 shutil.copy(vc_runtime_dll, out_dir / vc_runtime_dll.name)
152 shutil.copy(vc_runtime_dll, out_dir / vc_runtime_dll.name)
General Comments 0
You need to be logged in to leave comments. Login now