Show More
@@ -1,245 +1,245 b'' | |||
|
1 | 1 | # py2exe.py - Functionality for performing py2exe builds. |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | # no-check-code because Python 3 native. |
|
9 | 9 | |
|
10 | 10 | import os |
|
11 | 11 | import pathlib |
|
12 | 12 | import subprocess |
|
13 | 13 | |
|
14 | 14 | from .downloads import download_entry |
|
15 | 15 | from .util import ( |
|
16 | 16 | extract_tar_to_directory, |
|
17 | 17 | extract_zip_to_directory, |
|
18 | 18 | process_install_rules, |
|
19 | 19 | python_exe_info, |
|
20 | 20 | ) |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | STAGING_RULES = [ |
|
24 | 24 | ('contrib/bash_completion', 'Contrib/'), |
|
25 | 25 | ('contrib/hgk', 'Contrib/hgk.tcl'), |
|
26 | 26 | ('contrib/hgweb.fcgi', 'Contrib/'), |
|
27 | 27 | ('contrib/hgweb.wsgi', 'Contrib/'), |
|
28 | 28 | ('contrib/logo-droplets.svg', 'Contrib/'), |
|
29 | 29 | ('contrib/mercurial.el', 'Contrib/'), |
|
30 | 30 | ('contrib/mq.el', 'Contrib/'), |
|
31 | 31 | ('contrib/tcsh_completion', 'Contrib/'), |
|
32 | 32 | ('contrib/tcsh_completion_build.sh', 'Contrib/'), |
|
33 | 33 | ('contrib/vim/*', 'Contrib/Vim/'), |
|
34 | 34 | ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'), |
|
35 | 35 | ('contrib/win32/ReadMe.html', 'ReadMe.html'), |
|
36 | 36 | ('contrib/xml.rnc', 'Contrib/'), |
|
37 | 37 | ('contrib/zsh_completion', 'Contrib/'), |
|
38 | 38 | ('dist/hg.exe', './'), |
|
39 | 39 | ('dist/lib/*.dll', 'lib/'), |
|
40 | 40 | ('dist/lib/*.pyd', 'lib/'), |
|
41 | 41 | ('dist/lib/library.zip', 'lib/'), |
|
42 | 42 | ('dist/Microsoft.VC*.CRT.manifest', './'), |
|
43 | 43 | ('dist/msvc*.dll', './'), |
|
44 | 44 | ('dist/python*.dll', './'), |
|
45 | 45 | ('doc/*.html', 'doc/'), |
|
46 | 46 | ('doc/style.css', 'doc/'), |
|
47 | 47 | ('mercurial/helptext/**/*.txt', 'helptext/'), |
|
48 |
('mercurial/default |
|
|
48 | ('mercurial/defaultrc/*.rc', 'hgrc.d/'), | |
|
49 | 49 | ('mercurial/locale/**/*', 'locale/'), |
|
50 | 50 | ('mercurial/templates/**/*', 'Templates/'), |
|
51 | 51 | ('COPYING', 'Copying.txt'), |
|
52 | 52 | ] |
|
53 | 53 | |
|
54 | 54 | # List of paths to exclude from the staging area. |
|
55 | 55 | STAGING_EXCLUDES = [ |
|
56 | 56 | 'doc/hg-ssh.8.html', |
|
57 | 57 | ] |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | def build_py2exe( |
|
61 | 61 | source_dir: pathlib.Path, |
|
62 | 62 | build_dir: pathlib.Path, |
|
63 | 63 | python_exe: pathlib.Path, |
|
64 | 64 | build_name: str, |
|
65 | 65 | venv_requirements_txt: pathlib.Path, |
|
66 | 66 | extra_packages=None, |
|
67 | 67 | extra_excludes=None, |
|
68 | 68 | extra_dll_excludes=None, |
|
69 | 69 | extra_packages_script=None, |
|
70 | 70 | ): |
|
71 | 71 | """Build Mercurial with py2exe. |
|
72 | 72 | |
|
73 | 73 | Build files will be placed in ``build_dir``. |
|
74 | 74 | |
|
75 | 75 | py2exe's setup.py doesn't use setuptools. It doesn't have modern logic |
|
76 | 76 | for finding the Python 2.7 toolchain. So, we require the environment |
|
77 | 77 | to already be configured with an active toolchain. |
|
78 | 78 | """ |
|
79 | 79 | if 'VCINSTALLDIR' not in os.environ: |
|
80 | 80 | raise Exception( |
|
81 | 81 | 'not running from a Visual C++ build environment; ' |
|
82 | 82 | 'execute the "Visual C++ <version> Command Prompt" ' |
|
83 | 83 | 'application shortcut or a vcsvarsall.bat file' |
|
84 | 84 | ) |
|
85 | 85 | |
|
86 | 86 | # Identity x86/x64 and validate the environment matches the Python |
|
87 | 87 | # architecture. |
|
88 | 88 | vc_x64 = r'\x64' in os.environ['LIB'] |
|
89 | 89 | |
|
90 | 90 | py_info = python_exe_info(python_exe) |
|
91 | 91 | |
|
92 | 92 | if vc_x64: |
|
93 | 93 | if py_info['arch'] != '64bit': |
|
94 | 94 | raise Exception( |
|
95 | 95 | 'architecture mismatch: Visual C++ environment ' |
|
96 | 96 | 'is configured for 64-bit but Python is 32-bit' |
|
97 | 97 | ) |
|
98 | 98 | else: |
|
99 | 99 | if py_info['arch'] != '32bit': |
|
100 | 100 | raise Exception( |
|
101 | 101 | 'architecture mismatch: Visual C++ environment ' |
|
102 | 102 | 'is configured for 32-bit but Python is 64-bit' |
|
103 | 103 | ) |
|
104 | 104 | |
|
105 | 105 | if py_info['py3']: |
|
106 | 106 | raise Exception('Only Python 2 is currently supported') |
|
107 | 107 | |
|
108 | 108 | build_dir.mkdir(exist_ok=True) |
|
109 | 109 | |
|
110 | 110 | gettext_pkg, gettext_entry = download_entry('gettext', build_dir) |
|
111 | 111 | gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0] |
|
112 | 112 | virtualenv_pkg, virtualenv_entry = download_entry('virtualenv', build_dir) |
|
113 | 113 | py2exe_pkg, py2exe_entry = download_entry('py2exe', build_dir) |
|
114 | 114 | |
|
115 | 115 | venv_path = build_dir / ( |
|
116 | 116 | 'venv-%s-%s' % (build_name, 'x64' if vc_x64 else 'x86') |
|
117 | 117 | ) |
|
118 | 118 | |
|
119 | 119 | gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version']) |
|
120 | 120 | |
|
121 | 121 | if not gettext_root.exists(): |
|
122 | 122 | extract_zip_to_directory(gettext_pkg, gettext_root) |
|
123 | 123 | extract_zip_to_directory(gettext_dep_pkg, gettext_root) |
|
124 | 124 | |
|
125 | 125 | # This assumes Python 2. We don't need virtualenv on Python 3. |
|
126 | 126 | virtualenv_src_path = build_dir / ( |
|
127 | 127 | 'virtualenv-%s' % virtualenv_entry['version'] |
|
128 | 128 | ) |
|
129 | 129 | virtualenv_py = virtualenv_src_path / 'virtualenv.py' |
|
130 | 130 | |
|
131 | 131 | if not virtualenv_src_path.exists(): |
|
132 | 132 | extract_tar_to_directory(virtualenv_pkg, build_dir) |
|
133 | 133 | |
|
134 | 134 | py2exe_source_path = build_dir / ('py2exe-%s' % py2exe_entry['version']) |
|
135 | 135 | |
|
136 | 136 | if not py2exe_source_path.exists(): |
|
137 | 137 | extract_zip_to_directory(py2exe_pkg, build_dir) |
|
138 | 138 | |
|
139 | 139 | if not venv_path.exists(): |
|
140 | 140 | print('creating virtualenv with dependencies') |
|
141 | 141 | subprocess.run( |
|
142 | 142 | [str(python_exe), str(virtualenv_py), str(venv_path)], check=True |
|
143 | 143 | ) |
|
144 | 144 | |
|
145 | 145 | venv_python = venv_path / 'Scripts' / 'python.exe' |
|
146 | 146 | venv_pip = venv_path / 'Scripts' / 'pip.exe' |
|
147 | 147 | |
|
148 | 148 | subprocess.run( |
|
149 | 149 | [str(venv_pip), 'install', '-r', str(venv_requirements_txt)], check=True |
|
150 | 150 | ) |
|
151 | 151 | |
|
152 | 152 | # Force distutils to use VC++ settings from environment, which was |
|
153 | 153 | # validated above. |
|
154 | 154 | env = dict(os.environ) |
|
155 | 155 | env['DISTUTILS_USE_SDK'] = '1' |
|
156 | 156 | env['MSSdk'] = '1' |
|
157 | 157 | |
|
158 | 158 | if extra_packages_script: |
|
159 | 159 | more_packages = set( |
|
160 | 160 | subprocess.check_output(extra_packages_script, cwd=build_dir) |
|
161 | 161 | .split(b'\0')[-1] |
|
162 | 162 | .strip() |
|
163 | 163 | .decode('utf-8') |
|
164 | 164 | .splitlines() |
|
165 | 165 | ) |
|
166 | 166 | if more_packages: |
|
167 | 167 | if not extra_packages: |
|
168 | 168 | extra_packages = more_packages |
|
169 | 169 | else: |
|
170 | 170 | extra_packages |= more_packages |
|
171 | 171 | |
|
172 | 172 | if extra_packages: |
|
173 | 173 | env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages)) |
|
174 | 174 | hgext3rd_extras = sorted( |
|
175 | 175 | e for e in extra_packages if e.startswith('hgext3rd.') |
|
176 | 176 | ) |
|
177 | 177 | if hgext3rd_extras: |
|
178 | 178 | env['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'] = ' '.join(hgext3rd_extras) |
|
179 | 179 | if extra_excludes: |
|
180 | 180 | env['HG_PY2EXE_EXTRA_EXCLUDES'] = ' '.join(sorted(extra_excludes)) |
|
181 | 181 | if extra_dll_excludes: |
|
182 | 182 | env['HG_PY2EXE_EXTRA_DLL_EXCLUDES'] = ' '.join( |
|
183 | 183 | sorted(extra_dll_excludes) |
|
184 | 184 | ) |
|
185 | 185 | |
|
186 | 186 | py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe' |
|
187 | 187 | if not py2exe_py_path.exists(): |
|
188 | 188 | print('building py2exe') |
|
189 | 189 | subprocess.run( |
|
190 | 190 | [str(venv_python), 'setup.py', 'install'], |
|
191 | 191 | cwd=py2exe_source_path, |
|
192 | 192 | env=env, |
|
193 | 193 | check=True, |
|
194 | 194 | ) |
|
195 | 195 | |
|
196 | 196 | # Register location of msgfmt and other binaries. |
|
197 | 197 | env['PATH'] = '%s%s%s' % ( |
|
198 | 198 | env['PATH'], |
|
199 | 199 | os.pathsep, |
|
200 | 200 | str(gettext_root / 'bin'), |
|
201 | 201 | ) |
|
202 | 202 | |
|
203 | 203 | print('building Mercurial') |
|
204 | 204 | subprocess.run( |
|
205 | 205 | [str(venv_python), 'setup.py', 'py2exe', 'build_doc', '--html'], |
|
206 | 206 | cwd=str(source_dir), |
|
207 | 207 | env=env, |
|
208 | 208 | check=True, |
|
209 | 209 | ) |
|
210 | 210 | |
|
211 | 211 | |
|
212 | 212 | def stage_install( |
|
213 | 213 | source_dir: pathlib.Path, staging_dir: pathlib.Path, lower_case=False |
|
214 | 214 | ): |
|
215 | 215 | """Copy all files to be installed to a directory. |
|
216 | 216 | |
|
217 | 217 | This allows packaging to simply walk a directory tree to find source |
|
218 | 218 | files. |
|
219 | 219 | """ |
|
220 | 220 | if lower_case: |
|
221 | 221 | rules = [] |
|
222 | 222 | for source, dest in STAGING_RULES: |
|
223 | 223 | # Only lower directory names. |
|
224 | 224 | if '/' in dest: |
|
225 | 225 | parent, leaf = dest.rsplit('/', 1) |
|
226 | 226 | dest = '%s/%s' % (parent.lower(), leaf) |
|
227 | 227 | rules.append((source, dest)) |
|
228 | 228 | else: |
|
229 | 229 | rules = STAGING_RULES |
|
230 | 230 | |
|
231 | 231 | process_install_rules(rules, source_dir, staging_dir) |
|
232 | 232 | |
|
233 | 233 | # Write out a default editor.rc file to configure notepad as the |
|
234 | 234 | # default editor. |
|
235 | 235 | with (staging_dir / 'hgrc.d' / 'editor.rc').open( |
|
236 | 236 | 'w', encoding='utf-8' |
|
237 | 237 | ) as fh: |
|
238 | 238 | fh.write('[ui]\neditor = notepad\n') |
|
239 | 239 | |
|
240 | 240 | # Purge any files we don't want to be there. |
|
241 | 241 | for f in STAGING_EXCLUDES: |
|
242 | 242 | p = staging_dir / f |
|
243 | 243 | if p.exists(): |
|
244 | 244 | print('removing %s' % p) |
|
245 | 245 | p.unlink() |
@@ -1,143 +1,143 b'' | |||
|
1 | 1 | <?xml version='1.0' encoding='windows-1252'?> |
|
2 | 2 | <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'> |
|
3 | 3 | |
|
4 | 4 | <!-- Copyright 2010 Steve Borho <steve@borho.org> |
|
5 | 5 | |
|
6 | 6 | This software may be used and distributed according to the terms of the |
|
7 | 7 | GNU General Public License version 2 or any later version. --> |
|
8 | 8 | |
|
9 | 9 | <?include guids.wxi ?> |
|
10 | 10 | <?include defines.wxi ?> |
|
11 | 11 | |
|
12 | 12 | <?if $(var.Platform) = "x64" ?> |
|
13 | 13 | <?define PFolder = ProgramFiles64Folder ?> |
|
14 | 14 | <?else?> |
|
15 | 15 | <?define PFolder = ProgramFilesFolder ?> |
|
16 | 16 | <?endif?> |
|
17 | 17 | |
|
18 | 18 | <Product Id='*' |
|
19 | 19 | Name='Mercurial $(var.Version) ($(var.Platform))' |
|
20 | 20 | UpgradeCode='$(var.ProductUpgradeCode)' |
|
21 | 21 | Language='1033' Codepage='1252' Version='$(var.Version)' |
|
22 | 22 | Manufacturer='Matt Mackall and others'> |
|
23 | 23 | |
|
24 | 24 | <Package Id='*' |
|
25 | 25 | Keywords='Installer' |
|
26 | 26 | Description="Mercurial distributed SCM (version $(var.Version))" |
|
27 | 27 | Comments='$(var.Comments)' |
|
28 | 28 | Platform='$(var.Platform)' |
|
29 | 29 | Manufacturer='Matt Mackall and others' |
|
30 | 30 | InstallerVersion='300' Languages='1033' Compressed='yes' SummaryCodepage='1252' /> |
|
31 | 31 | |
|
32 | 32 | <Media Id='1' Cabinet='mercurial.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1' |
|
33 | 33 | CompressionLevel='high' /> |
|
34 | 34 | <Property Id='DiskPrompt' Value="Mercurial $(var.Version) Installation [1]" /> |
|
35 | 35 | |
|
36 | 36 | <Condition Message='Mercurial MSI installers require Windows XP or higher'> |
|
37 | 37 | VersionNT >= 501 |
|
38 | 38 | </Condition> |
|
39 | 39 | |
|
40 | 40 | <Property Id="INSTALLDIR"> |
|
41 | 41 | <ComponentSearch Id='SearchForMainExecutableComponent' |
|
42 | 42 | Guid='$(var.ComponentMainExecutableGUID)' /> |
|
43 | 43 | </Property> |
|
44 | 44 | |
|
45 | 45 | <!--Property Id='ARPCOMMENTS'>any comments</Property--> |
|
46 | 46 | <Property Id='ARPCONTACT'>mercurial@mercurial-scm.org</Property> |
|
47 | 47 | <Property Id='ARPHELPLINK'>https://mercurial-scm.org/wiki/</Property> |
|
48 | 48 | <Property Id='ARPURLINFOABOUT'>https://mercurial-scm.org/about/</Property> |
|
49 | 49 | <Property Id='ARPURLUPDATEINFO'>https://mercurial-scm.org/downloads/</Property> |
|
50 | 50 | <Property Id='ARPHELPTELEPHONE'>https://mercurial-scm.org/wiki/Support</Property> |
|
51 | 51 | <Property Id='ARPPRODUCTICON'>hgIcon.ico</Property> |
|
52 | 52 | |
|
53 | 53 | <Property Id='INSTALLEDMERCURIALPRODUCTS' Secure='yes'></Property> |
|
54 | 54 | <Property Id='REINSTALLMODE'>amus</Property> |
|
55 | 55 | |
|
56 | 56 | <!--Auto-accept the license page--> |
|
57 | 57 | <Property Id='LicenseAccepted'>1</Property> |
|
58 | 58 | |
|
59 | 59 | <Directory Id='TARGETDIR' Name='SourceDir'> |
|
60 | 60 | <Directory Id='$(var.PFolder)' Name='PFiles'> |
|
61 | 61 | <Directory Id='INSTALLDIR' Name='Mercurial'> |
|
62 | 62 | <Component Id='MainExecutable' Guid='$(var.ComponentMainExecutableGUID)' Win64='$(var.IsX64)'> |
|
63 | 63 | <CreateFolder /> |
|
64 | 64 | <Environment Id="Environment" Name="PATH" Part="last" System="yes" |
|
65 | 65 | Permanent="no" Value="[INSTALLDIR]" Action="set" /> |
|
66 | 66 | </Component> |
|
67 | 67 | </Directory> |
|
68 | 68 | </Directory> |
|
69 | 69 | |
|
70 | 70 | <Directory Id="ProgramMenuFolder" Name="Programs"> |
|
71 | 71 | <Directory Id="ProgramMenuDir" Name="Mercurial $(var.Version)"> |
|
72 | 72 | <Component Id="ProgramMenuDir" Guid="$(var.ProgramMenuDir.guid)" Win64='$(var.IsX64)'> |
|
73 | 73 | <RemoveFolder Id='ProgramMenuDir' On='uninstall' /> |
|
74 | 74 | <RegistryValue Root='HKCU' Key='Software\Mercurial\InstallDir' Type='string' |
|
75 | 75 | Value='[INSTALLDIR]' KeyPath='yes' /> |
|
76 | 76 | <Shortcut Id='UrlShortcut' Directory='ProgramMenuDir' Name='Mercurial Web Site' |
|
77 | 77 | Target='[ARPHELPLINK]' Icon="hgIcon.ico" IconIndex='0' /> |
|
78 | 78 | </Component> |
|
79 | 79 | </Directory> |
|
80 | 80 | </Directory> |
|
81 | 81 | |
|
82 | 82 | <?if $(var.Platform) = "x86" ?> |
|
83 | 83 | <Merge Id='VCRuntime' DiskId='1' Language='1033' |
|
84 | 84 | SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x86_msm.msm' /> |
|
85 | 85 | <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033' |
|
86 | 86 | SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x86_msm.msm' /> |
|
87 | 87 | <?else?> |
|
88 | 88 | <Merge Id='VCRuntime' DiskId='1' Language='1033' |
|
89 | 89 | SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x64_msm.msm' /> |
|
90 | 90 | <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033' |
|
91 | 91 | SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x64_msm.msm' /> |
|
92 | 92 | <?endif?> |
|
93 | 93 | </Directory> |
|
94 | 94 | |
|
95 | 95 | <Feature Id='Complete' Title='Mercurial' Description='The complete package' |
|
96 | 96 | Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR' > |
|
97 | 97 | <Feature Id='MainProgram' Title='Program' Description='Mercurial command line app' |
|
98 | 98 | Level='1' Absent='disallow' > |
|
99 | 99 | <ComponentRef Id='MainExecutable' /> |
|
100 | 100 | <ComponentRef Id='ProgramMenuDir' /> |
|
101 | 101 | <ComponentGroupRef Id="hg.group.ROOT" /> |
|
102 | 102 | <ComponentGroupRef Id="hg.group.hgrc.d" /> |
|
103 | <ComponentGroupRef Id="hg.group.help" /> | |
|
103 | <ComponentGroupRef Id="hg.group.helptext" /> | |
|
104 | 104 | <ComponentGroupRef Id="hg.group.lib" /> |
|
105 | 105 | <ComponentGroupRef Id="hg.group.templates" /> |
|
106 | 106 | <MergeRef Id='VCRuntime' /> |
|
107 | 107 | <MergeRef Id='VCRuntimePolicy' /> |
|
108 | 108 | </Feature> |
|
109 | 109 | <?ifdef MercurialExtraFeatures?> |
|
110 | 110 | <?foreach EXTRAFEAT in $(var.MercurialExtraFeatures)?> |
|
111 | 111 | <FeatureRef Id="$(var.EXTRAFEAT)" /> |
|
112 | 112 | <?endforeach?> |
|
113 | 113 | <?endif?> |
|
114 | 114 | <Feature Id='Locales' Title='Translations' Description='Translations' Level='1'> |
|
115 | 115 | <ComponentGroupRef Id="hg.group.locale" /> |
|
116 | 116 | </Feature> |
|
117 | 117 | <Feature Id='Documentation' Title='Documentation' Description='HTML man pages' Level='1'> |
|
118 | 118 | <ComponentGroupRef Id="hg.group.doc" /> |
|
119 | 119 | </Feature> |
|
120 | 120 | <Feature Id='Misc' Title='Miscellaneous' Description='Contributed scripts' Level='1'> |
|
121 | 121 | <ComponentGroupRef Id="hg.group.contrib" /> |
|
122 | 122 | </Feature> |
|
123 | 123 | </Feature> |
|
124 | 124 | |
|
125 | 125 | <UIRef Id="WixUI_FeatureTree" /> |
|
126 | 126 | <UIRef Id="WixUI_ErrorProgressText" /> |
|
127 | 127 | |
|
128 | 128 | <WixVariable Id="WixUILicenseRtf" Value="contrib\packaging\wix\COPYING.rtf" /> |
|
129 | 129 | |
|
130 | 130 | <Icon Id="hgIcon.ico" SourceFile="contrib/win32/mercurial.ico" /> |
|
131 | 131 | |
|
132 | 132 | <Upgrade Id='$(var.ProductUpgradeCode)'> |
|
133 | 133 | <UpgradeVersion |
|
134 | 134 | IncludeMinimum='yes' Minimum='0.0.0' IncludeMaximum='no' OnlyDetect='no' |
|
135 | 135 | Property='INSTALLEDMERCURIALPRODUCTS' /> |
|
136 | 136 | </Upgrade> |
|
137 | 137 | |
|
138 | 138 | <InstallExecuteSequence> |
|
139 | 139 | <RemoveExistingProducts After='InstallInitialize'/> |
|
140 | 140 | </InstallExecuteSequence> |
|
141 | 141 | |
|
142 | 142 | </Product> |
|
143 | 143 | </Wix> |
@@ -1,1722 +1,1722 b'' | |||
|
1 | 1 | # |
|
2 | 2 | # This is the mercurial setup script. |
|
3 | 3 | # |
|
4 | 4 | # 'python setup.py install', or |
|
5 | 5 | # 'python setup.py --help' for more options |
|
6 | 6 | |
|
7 | 7 | import os |
|
8 | 8 | |
|
9 | 9 | # Mercurial will never work on Python 3 before 3.5 due to a lack |
|
10 | 10 | # of % formatting on bytestrings, and can't work on 3.6.0 or 3.6.1 |
|
11 | 11 | # due to a bug in % formatting in bytestrings. |
|
12 | 12 | # We cannot support Python 3.5.0, 3.5.1, 3.5.2 because of bug in |
|
13 | 13 | # codecs.escape_encode() where it raises SystemError on empty bytestring |
|
14 | 14 | # bug link: https://bugs.python.org/issue25270 |
|
15 | 15 | supportedpy = ','.join( |
|
16 | 16 | [ |
|
17 | 17 | '>=2.7', |
|
18 | 18 | '!=3.0.*', |
|
19 | 19 | '!=3.1.*', |
|
20 | 20 | '!=3.2.*', |
|
21 | 21 | '!=3.3.*', |
|
22 | 22 | '!=3.4.*', |
|
23 | 23 | '!=3.5.0', |
|
24 | 24 | '!=3.5.1', |
|
25 | 25 | '!=3.5.2', |
|
26 | 26 | '!=3.6.0', |
|
27 | 27 | '!=3.6.1', |
|
28 | 28 | ] |
|
29 | 29 | ) |
|
30 | 30 | |
|
31 | 31 | import sys, platform |
|
32 | 32 | import sysconfig |
|
33 | 33 | |
|
34 | 34 | if sys.version_info[0] >= 3: |
|
35 | 35 | printf = eval('print') |
|
36 | 36 | libdir_escape = 'unicode_escape' |
|
37 | 37 | |
|
38 | 38 | def sysstr(s): |
|
39 | 39 | return s.decode('latin-1') |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | else: |
|
43 | 43 | libdir_escape = 'string_escape' |
|
44 | 44 | |
|
45 | 45 | def printf(*args, **kwargs): |
|
46 | 46 | f = kwargs.get('file', sys.stdout) |
|
47 | 47 | end = kwargs.get('end', '\n') |
|
48 | 48 | f.write(b' '.join(args) + end) |
|
49 | 49 | |
|
50 | 50 | def sysstr(s): |
|
51 | 51 | return s |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | # Attempt to guide users to a modern pip - this means that 2.6 users |
|
55 | 55 | # should have a chance of getting a 4.2 release, and when we ratchet |
|
56 | 56 | # the version requirement forward again hopefully everyone will get |
|
57 | 57 | # something that works for them. |
|
58 | 58 | if sys.version_info < (2, 7, 0, 'final'): |
|
59 | 59 | pip_message = ( |
|
60 | 60 | 'This may be due to an out of date pip. ' |
|
61 | 61 | 'Make sure you have pip >= 9.0.1.' |
|
62 | 62 | ) |
|
63 | 63 | try: |
|
64 | 64 | import pip |
|
65 | 65 | |
|
66 | 66 | pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]]) |
|
67 | 67 | if pip_version < (9, 0, 1): |
|
68 | 68 | pip_message = ( |
|
69 | 69 | 'Your pip version is out of date, please install ' |
|
70 | 70 | 'pip >= 9.0.1. pip {} detected.'.format(pip.__version__) |
|
71 | 71 | ) |
|
72 | 72 | else: |
|
73 | 73 | # pip is new enough - it must be something else |
|
74 | 74 | pip_message = '' |
|
75 | 75 | except Exception: |
|
76 | 76 | pass |
|
77 | 77 | error = """ |
|
78 | 78 | Mercurial does not support Python older than 2.7. |
|
79 | 79 | Python {py} detected. |
|
80 | 80 | {pip} |
|
81 | 81 | """.format( |
|
82 | 82 | py=sys.version_info, pip=pip_message |
|
83 | 83 | ) |
|
84 | 84 | printf(error, file=sys.stderr) |
|
85 | 85 | sys.exit(1) |
|
86 | 86 | |
|
87 | 87 | if sys.version_info[0] >= 3: |
|
88 | 88 | DYLIB_SUFFIX = sysconfig.get_config_vars()['EXT_SUFFIX'] |
|
89 | 89 | else: |
|
90 | 90 | # deprecated in Python 3 |
|
91 | 91 | DYLIB_SUFFIX = sysconfig.get_config_vars()['SO'] |
|
92 | 92 | |
|
93 | 93 | # Solaris Python packaging brain damage |
|
94 | 94 | try: |
|
95 | 95 | import hashlib |
|
96 | 96 | |
|
97 | 97 | sha = hashlib.sha1() |
|
98 | 98 | except ImportError: |
|
99 | 99 | try: |
|
100 | 100 | import sha |
|
101 | 101 | |
|
102 | 102 | sha.sha # silence unused import warning |
|
103 | 103 | except ImportError: |
|
104 | 104 | raise SystemExit( |
|
105 | 105 | "Couldn't import standard hashlib (incomplete Python install)." |
|
106 | 106 | ) |
|
107 | 107 | |
|
108 | 108 | try: |
|
109 | 109 | import zlib |
|
110 | 110 | |
|
111 | 111 | zlib.compressobj # silence unused import warning |
|
112 | 112 | except ImportError: |
|
113 | 113 | raise SystemExit( |
|
114 | 114 | "Couldn't import standard zlib (incomplete Python install)." |
|
115 | 115 | ) |
|
116 | 116 | |
|
117 | 117 | # The base IronPython distribution (as of 2.7.1) doesn't support bz2 |
|
118 | 118 | isironpython = False |
|
119 | 119 | try: |
|
120 | 120 | isironpython = ( |
|
121 | 121 | platform.python_implementation().lower().find("ironpython") != -1 |
|
122 | 122 | ) |
|
123 | 123 | except AttributeError: |
|
124 | 124 | pass |
|
125 | 125 | |
|
126 | 126 | if isironpython: |
|
127 | 127 | sys.stderr.write("warning: IronPython detected (no bz2 support)\n") |
|
128 | 128 | else: |
|
129 | 129 | try: |
|
130 | 130 | import bz2 |
|
131 | 131 | |
|
132 | 132 | bz2.BZ2Compressor # silence unused import warning |
|
133 | 133 | except ImportError: |
|
134 | 134 | raise SystemExit( |
|
135 | 135 | "Couldn't import standard bz2 (incomplete Python install)." |
|
136 | 136 | ) |
|
137 | 137 | |
|
138 | 138 | ispypy = "PyPy" in sys.version |
|
139 | 139 | |
|
140 | 140 | hgrustext = os.environ.get('HGWITHRUSTEXT') |
|
141 | 141 | # TODO record it for proper rebuild upon changes |
|
142 | 142 | # (see mercurial/__modulepolicy__.py) |
|
143 | 143 | if hgrustext != 'cpython' and hgrustext is not None: |
|
144 | 144 | hgrustext = 'direct-ffi' |
|
145 | 145 | |
|
146 | 146 | import ctypes |
|
147 | 147 | import errno |
|
148 | 148 | import stat, subprocess, time |
|
149 | 149 | import re |
|
150 | 150 | import shutil |
|
151 | 151 | import tempfile |
|
152 | 152 | from distutils import log |
|
153 | 153 | |
|
154 | 154 | # We have issues with setuptools on some platforms and builders. Until |
|
155 | 155 | # those are resolved, setuptools is opt-in except for platforms where |
|
156 | 156 | # we don't have issues. |
|
157 | 157 | issetuptools = os.name == 'nt' or 'FORCE_SETUPTOOLS' in os.environ |
|
158 | 158 | if issetuptools: |
|
159 | 159 | from setuptools import setup |
|
160 | 160 | else: |
|
161 | 161 | from distutils.core import setup |
|
162 | 162 | from distutils.ccompiler import new_compiler |
|
163 | 163 | from distutils.core import Command, Extension |
|
164 | 164 | from distutils.dist import Distribution |
|
165 | 165 | from distutils.command.build import build |
|
166 | 166 | from distutils.command.build_ext import build_ext |
|
167 | 167 | from distutils.command.build_py import build_py |
|
168 | 168 | from distutils.command.build_scripts import build_scripts |
|
169 | 169 | from distutils.command.install import install |
|
170 | 170 | from distutils.command.install_lib import install_lib |
|
171 | 171 | from distutils.command.install_scripts import install_scripts |
|
172 | 172 | from distutils.spawn import spawn, find_executable |
|
173 | 173 | from distutils import file_util |
|
174 | 174 | from distutils.errors import ( |
|
175 | 175 | CCompilerError, |
|
176 | 176 | DistutilsError, |
|
177 | 177 | DistutilsExecError, |
|
178 | 178 | ) |
|
179 | 179 | from distutils.sysconfig import get_python_inc, get_config_var |
|
180 | 180 | from distutils.version import StrictVersion |
|
181 | 181 | |
|
182 | 182 | # Explain to distutils.StrictVersion how our release candidates are versionned |
|
183 | 183 | StrictVersion.version_re = re.compile(r'^(\d+)\.(\d+)(\.(\d+))?-?(rc(\d+))?$') |
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | def write_if_changed(path, content): |
|
187 | 187 | """Write content to a file iff the content hasn't changed.""" |
|
188 | 188 | if os.path.exists(path): |
|
189 | 189 | with open(path, 'rb') as fh: |
|
190 | 190 | current = fh.read() |
|
191 | 191 | else: |
|
192 | 192 | current = b'' |
|
193 | 193 | |
|
194 | 194 | if current != content: |
|
195 | 195 | with open(path, 'wb') as fh: |
|
196 | 196 | fh.write(content) |
|
197 | 197 | |
|
198 | 198 | |
|
199 | 199 | scripts = ['hg'] |
|
200 | 200 | if os.name == 'nt': |
|
201 | 201 | # We remove hg.bat if we are able to build hg.exe. |
|
202 | 202 | scripts.append('contrib/win32/hg.bat') |
|
203 | 203 | |
|
204 | 204 | |
|
205 | 205 | def cancompile(cc, code): |
|
206 | 206 | tmpdir = tempfile.mkdtemp(prefix='hg-install-') |
|
207 | 207 | devnull = oldstderr = None |
|
208 | 208 | try: |
|
209 | 209 | fname = os.path.join(tmpdir, 'testcomp.c') |
|
210 | 210 | f = open(fname, 'w') |
|
211 | 211 | f.write(code) |
|
212 | 212 | f.close() |
|
213 | 213 | # Redirect stderr to /dev/null to hide any error messages |
|
214 | 214 | # from the compiler. |
|
215 | 215 | # This will have to be changed if we ever have to check |
|
216 | 216 | # for a function on Windows. |
|
217 | 217 | devnull = open('/dev/null', 'w') |
|
218 | 218 | oldstderr = os.dup(sys.stderr.fileno()) |
|
219 | 219 | os.dup2(devnull.fileno(), sys.stderr.fileno()) |
|
220 | 220 | objects = cc.compile([fname], output_dir=tmpdir) |
|
221 | 221 | cc.link_executable(objects, os.path.join(tmpdir, "a.out")) |
|
222 | 222 | return True |
|
223 | 223 | except Exception: |
|
224 | 224 | return False |
|
225 | 225 | finally: |
|
226 | 226 | if oldstderr is not None: |
|
227 | 227 | os.dup2(oldstderr, sys.stderr.fileno()) |
|
228 | 228 | if devnull is not None: |
|
229 | 229 | devnull.close() |
|
230 | 230 | shutil.rmtree(tmpdir) |
|
231 | 231 | |
|
232 | 232 | |
|
233 | 233 | # simplified version of distutils.ccompiler.CCompiler.has_function |
|
234 | 234 | # that actually removes its temporary files. |
|
235 | 235 | def hasfunction(cc, funcname): |
|
236 | 236 | code = 'int main(void) { %s(); }\n' % funcname |
|
237 | 237 | return cancompile(cc, code) |
|
238 | 238 | |
|
239 | 239 | |
|
240 | 240 | def hasheader(cc, headername): |
|
241 | 241 | code = '#include <%s>\nint main(void) { return 0; }\n' % headername |
|
242 | 242 | return cancompile(cc, code) |
|
243 | 243 | |
|
244 | 244 | |
|
245 | 245 | # py2exe needs to be installed to work |
|
246 | 246 | try: |
|
247 | 247 | import py2exe |
|
248 | 248 | |
|
249 | 249 | py2exe.Distribution # silence unused import warning |
|
250 | 250 | py2exeloaded = True |
|
251 | 251 | # import py2exe's patched Distribution class |
|
252 | 252 | from distutils.core import Distribution |
|
253 | 253 | except ImportError: |
|
254 | 254 | py2exeloaded = False |
|
255 | 255 | |
|
256 | 256 | |
|
257 | 257 | def runcmd(cmd, env, cwd=None): |
|
258 | 258 | p = subprocess.Popen( |
|
259 | 259 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd |
|
260 | 260 | ) |
|
261 | 261 | out, err = p.communicate() |
|
262 | 262 | return p.returncode, out, err |
|
263 | 263 | |
|
264 | 264 | |
|
265 | 265 | class hgcommand(object): |
|
266 | 266 | def __init__(self, cmd, env): |
|
267 | 267 | self.cmd = cmd |
|
268 | 268 | self.env = env |
|
269 | 269 | |
|
270 | 270 | def run(self, args): |
|
271 | 271 | cmd = self.cmd + args |
|
272 | 272 | returncode, out, err = runcmd(cmd, self.env) |
|
273 | 273 | err = filterhgerr(err) |
|
274 | 274 | if err or returncode != 0: |
|
275 | 275 | printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr) |
|
276 | 276 | printf(err, file=sys.stderr) |
|
277 | 277 | return '' |
|
278 | 278 | return out |
|
279 | 279 | |
|
280 | 280 | |
|
281 | 281 | def filterhgerr(err): |
|
282 | 282 | # If root is executing setup.py, but the repository is owned by |
|
283 | 283 | # another user (as in "sudo python setup.py install") we will get |
|
284 | 284 | # trust warnings since the .hg/hgrc file is untrusted. That is |
|
285 | 285 | # fine, we don't want to load it anyway. Python may warn about |
|
286 | 286 | # a missing __init__.py in mercurial/locale, we also ignore that. |
|
287 | 287 | err = [ |
|
288 | 288 | e |
|
289 | 289 | for e in err.splitlines() |
|
290 | 290 | if ( |
|
291 | 291 | not e.startswith(b'not trusting file') |
|
292 | 292 | and not e.startswith(b'warning: Not importing') |
|
293 | 293 | and not e.startswith(b'obsolete feature not enabled') |
|
294 | 294 | and not e.startswith(b'*** failed to import extension') |
|
295 | 295 | and not e.startswith(b'devel-warn:') |
|
296 | 296 | and not ( |
|
297 | 297 | e.startswith(b'(third party extension') |
|
298 | 298 | and e.endswith(b'or newer of Mercurial; disabling)') |
|
299 | 299 | ) |
|
300 | 300 | ) |
|
301 | 301 | ] |
|
302 | 302 | return b'\n'.join(b' ' + e for e in err) |
|
303 | 303 | |
|
304 | 304 | |
|
305 | 305 | def findhg(): |
|
306 | 306 | """Try to figure out how we should invoke hg for examining the local |
|
307 | 307 | repository contents. |
|
308 | 308 | |
|
309 | 309 | Returns an hgcommand object.""" |
|
310 | 310 | # By default, prefer the "hg" command in the user's path. This was |
|
311 | 311 | # presumably the hg command that the user used to create this repository. |
|
312 | 312 | # |
|
313 | 313 | # This repository may require extensions or other settings that would not |
|
314 | 314 | # be enabled by running the hg script directly from this local repository. |
|
315 | 315 | hgenv = os.environ.copy() |
|
316 | 316 | # Use HGPLAIN to disable hgrc settings that would change output formatting, |
|
317 | 317 | # and disable localization for the same reasons. |
|
318 | 318 | hgenv['HGPLAIN'] = '1' |
|
319 | 319 | hgenv['LANGUAGE'] = 'C' |
|
320 | 320 | hgcmd = ['hg'] |
|
321 | 321 | # Run a simple "hg log" command just to see if using hg from the user's |
|
322 | 322 | # path works and can successfully interact with this repository. Windows |
|
323 | 323 | # gives precedence to hg.exe in the current directory, so fall back to the |
|
324 | 324 | # python invocation of local hg, where pythonXY.dll can always be found. |
|
325 | 325 | check_cmd = ['log', '-r.', '-Ttest'] |
|
326 | 326 | if os.name != 'nt': |
|
327 | 327 | try: |
|
328 | 328 | retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) |
|
329 | 329 | except EnvironmentError: |
|
330 | 330 | retcode = -1 |
|
331 | 331 | if retcode == 0 and not filterhgerr(err): |
|
332 | 332 | return hgcommand(hgcmd, hgenv) |
|
333 | 333 | |
|
334 | 334 | # Fall back to trying the local hg installation. |
|
335 | 335 | hgenv = localhgenv() |
|
336 | 336 | hgcmd = [sys.executable, 'hg'] |
|
337 | 337 | try: |
|
338 | 338 | retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) |
|
339 | 339 | except EnvironmentError: |
|
340 | 340 | retcode = -1 |
|
341 | 341 | if retcode == 0 and not filterhgerr(err): |
|
342 | 342 | return hgcommand(hgcmd, hgenv) |
|
343 | 343 | |
|
344 | 344 | raise SystemExit( |
|
345 | 345 | 'Unable to find a working hg binary to extract the ' |
|
346 | 346 | 'version from the repository tags' |
|
347 | 347 | ) |
|
348 | 348 | |
|
349 | 349 | |
|
350 | 350 | def localhgenv(): |
|
351 | 351 | """Get an environment dictionary to use for invoking or importing |
|
352 | 352 | mercurial from the local repository.""" |
|
353 | 353 | # Execute hg out of this directory with a custom environment which takes |
|
354 | 354 | # care to not use any hgrc files and do no localization. |
|
355 | 355 | env = { |
|
356 | 356 | 'HGMODULEPOLICY': 'py', |
|
357 | 357 | 'HGRCPATH': '', |
|
358 | 358 | 'LANGUAGE': 'C', |
|
359 | 359 | 'PATH': '', |
|
360 | 360 | } # make pypi modules that use os.environ['PATH'] happy |
|
361 | 361 | if 'LD_LIBRARY_PATH' in os.environ: |
|
362 | 362 | env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] |
|
363 | 363 | if 'SystemRoot' in os.environ: |
|
364 | 364 | # SystemRoot is required by Windows to load various DLLs. See: |
|
365 | 365 | # https://bugs.python.org/issue13524#msg148850 |
|
366 | 366 | env['SystemRoot'] = os.environ['SystemRoot'] |
|
367 | 367 | return env |
|
368 | 368 | |
|
369 | 369 | |
|
370 | 370 | version = '' |
|
371 | 371 | |
|
372 | 372 | if os.path.isdir('.hg'): |
|
373 | 373 | hg = findhg() |
|
374 | 374 | cmd = ['log', '-r', '.', '--template', '{tags}\n'] |
|
375 | 375 | numerictags = [t for t in sysstr(hg.run(cmd)).split() if t[0:1].isdigit()] |
|
376 | 376 | hgid = sysstr(hg.run(['id', '-i'])).strip() |
|
377 | 377 | if not hgid: |
|
378 | 378 | # Bail out if hg is having problems interacting with this repository, |
|
379 | 379 | # rather than falling through and producing a bogus version number. |
|
380 | 380 | # Continuing with an invalid version number will break extensions |
|
381 | 381 | # that define minimumhgversion. |
|
382 | 382 | raise SystemExit('Unable to determine hg version from local repository') |
|
383 | 383 | if numerictags: # tag(s) found |
|
384 | 384 | version = numerictags[-1] |
|
385 | 385 | if hgid.endswith('+'): # propagate the dirty status to the tag |
|
386 | 386 | version += '+' |
|
387 | 387 | else: # no tag found |
|
388 | 388 | ltagcmd = ['parents', '--template', '{latesttag}'] |
|
389 | 389 | ltag = sysstr(hg.run(ltagcmd)) |
|
390 | 390 | changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag] |
|
391 | 391 | changessince = len(hg.run(changessincecmd).splitlines()) |
|
392 | 392 | version = '%s+%s-%s' % (ltag, changessince, hgid) |
|
393 | 393 | if version.endswith('+'): |
|
394 | 394 | version += time.strftime('%Y%m%d') |
|
395 | 395 | elif os.path.exists('.hg_archival.txt'): |
|
396 | 396 | kw = dict( |
|
397 | 397 | [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')] |
|
398 | 398 | ) |
|
399 | 399 | if 'tag' in kw: |
|
400 | 400 | version = kw['tag'] |
|
401 | 401 | elif 'latesttag' in kw: |
|
402 | 402 | if 'changessincelatesttag' in kw: |
|
403 | 403 | version = '%(latesttag)s+%(changessincelatesttag)s-%(node).12s' % kw |
|
404 | 404 | else: |
|
405 | 405 | version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw |
|
406 | 406 | else: |
|
407 | 407 | version = kw.get('node', '')[:12] |
|
408 | 408 | |
|
409 | 409 | if version: |
|
410 | 410 | versionb = version |
|
411 | 411 | if not isinstance(versionb, bytes): |
|
412 | 412 | versionb = versionb.encode('ascii') |
|
413 | 413 | |
|
414 | 414 | write_if_changed( |
|
415 | 415 | 'mercurial/__version__.py', |
|
416 | 416 | b''.join( |
|
417 | 417 | [ |
|
418 | 418 | b'# this file is autogenerated by setup.py\n' |
|
419 | 419 | b'version = b"%s"\n' % versionb, |
|
420 | 420 | ] |
|
421 | 421 | ), |
|
422 | 422 | ) |
|
423 | 423 | |
|
424 | 424 | try: |
|
425 | 425 | oldpolicy = os.environ.get('HGMODULEPOLICY', None) |
|
426 | 426 | os.environ['HGMODULEPOLICY'] = 'py' |
|
427 | 427 | from mercurial import __version__ |
|
428 | 428 | |
|
429 | 429 | version = __version__.version |
|
430 | 430 | except ImportError: |
|
431 | 431 | version = b'unknown' |
|
432 | 432 | finally: |
|
433 | 433 | if oldpolicy is None: |
|
434 | 434 | del os.environ['HGMODULEPOLICY'] |
|
435 | 435 | else: |
|
436 | 436 | os.environ['HGMODULEPOLICY'] = oldpolicy |
|
437 | 437 | |
|
438 | 438 | |
|
439 | 439 | class hgbuild(build): |
|
440 | 440 | # Insert hgbuildmo first so that files in mercurial/locale/ are found |
|
441 | 441 | # when build_py is run next. |
|
442 | 442 | sub_commands = [('build_mo', None)] + build.sub_commands |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | class hgbuildmo(build): |
|
446 | 446 | |
|
447 | 447 | description = "build translations (.mo files)" |
|
448 | 448 | |
|
449 | 449 | def run(self): |
|
450 | 450 | if not find_executable('msgfmt'): |
|
451 | 451 | self.warn( |
|
452 | 452 | "could not find msgfmt executable, no translations " |
|
453 | 453 | "will be built" |
|
454 | 454 | ) |
|
455 | 455 | return |
|
456 | 456 | |
|
457 | 457 | podir = 'i18n' |
|
458 | 458 | if not os.path.isdir(podir): |
|
459 | 459 | self.warn("could not find %s/ directory" % podir) |
|
460 | 460 | return |
|
461 | 461 | |
|
462 | 462 | join = os.path.join |
|
463 | 463 | for po in os.listdir(podir): |
|
464 | 464 | if not po.endswith('.po'): |
|
465 | 465 | continue |
|
466 | 466 | pofile = join(podir, po) |
|
467 | 467 | modir = join('locale', po[:-3], 'LC_MESSAGES') |
|
468 | 468 | mofile = join(modir, 'hg.mo') |
|
469 | 469 | mobuildfile = join('mercurial', mofile) |
|
470 | 470 | cmd = ['msgfmt', '-v', '-o', mobuildfile, pofile] |
|
471 | 471 | if sys.platform != 'sunos5': |
|
472 | 472 | # msgfmt on Solaris does not know about -c |
|
473 | 473 | cmd.append('-c') |
|
474 | 474 | self.mkpath(join('mercurial', modir)) |
|
475 | 475 | self.make_file([pofile], mobuildfile, spawn, (cmd,)) |
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | class hgdist(Distribution): |
|
479 | 479 | pure = False |
|
480 | 480 | rust = hgrustext is not None |
|
481 | 481 | cffi = ispypy |
|
482 | 482 | |
|
483 | 483 | global_options = Distribution.global_options + [ |
|
484 | 484 | ('pure', None, "use pure (slow) Python code instead of C extensions"), |
|
485 | 485 | ('rust', None, "use Rust extensions additionally to C extensions"), |
|
486 | 486 | ] |
|
487 | 487 | |
|
488 | 488 | def has_ext_modules(self): |
|
489 | 489 | # self.ext_modules is emptied in hgbuildpy.finalize_options which is |
|
490 | 490 | # too late for some cases |
|
491 | 491 | return not self.pure and Distribution.has_ext_modules(self) |
|
492 | 492 | |
|
493 | 493 | |
|
494 | 494 | # This is ugly as a one-liner. So use a variable. |
|
495 | 495 | buildextnegops = dict(getattr(build_ext, 'negative_options', {})) |
|
496 | 496 | buildextnegops['no-zstd'] = 'zstd' |
|
497 | 497 | buildextnegops['no-rust'] = 'rust' |
|
498 | 498 | |
|
499 | 499 | |
|
500 | 500 | class hgbuildext(build_ext): |
|
501 | 501 | user_options = build_ext.user_options + [ |
|
502 | 502 | ('zstd', None, 'compile zstd bindings [default]'), |
|
503 | 503 | ('no-zstd', None, 'do not compile zstd bindings'), |
|
504 | 504 | ( |
|
505 | 505 | 'rust', |
|
506 | 506 | None, |
|
507 | 507 | 'compile Rust extensions if they are in use ' |
|
508 | 508 | '(requires Cargo) [default]', |
|
509 | 509 | ), |
|
510 | 510 | ('no-rust', None, 'do not compile Rust extensions'), |
|
511 | 511 | ] |
|
512 | 512 | |
|
513 | 513 | boolean_options = build_ext.boolean_options + ['zstd', 'rust'] |
|
514 | 514 | negative_opt = buildextnegops |
|
515 | 515 | |
|
516 | 516 | def initialize_options(self): |
|
517 | 517 | self.zstd = True |
|
518 | 518 | self.rust = True |
|
519 | 519 | |
|
520 | 520 | return build_ext.initialize_options(self) |
|
521 | 521 | |
|
522 | 522 | def finalize_options(self): |
|
523 | 523 | # Unless overridden by the end user, build extensions in parallel. |
|
524 | 524 | # Only influences behavior on Python 3.5+. |
|
525 | 525 | if getattr(self, 'parallel', None) is None: |
|
526 | 526 | self.parallel = True |
|
527 | 527 | |
|
528 | 528 | return build_ext.finalize_options(self) |
|
529 | 529 | |
|
530 | 530 | def build_extensions(self): |
|
531 | 531 | ruststandalones = [ |
|
532 | 532 | e for e in self.extensions if isinstance(e, RustStandaloneExtension) |
|
533 | 533 | ] |
|
534 | 534 | self.extensions = [ |
|
535 | 535 | e for e in self.extensions if e not in ruststandalones |
|
536 | 536 | ] |
|
537 | 537 | # Filter out zstd if disabled via argument. |
|
538 | 538 | if not self.zstd: |
|
539 | 539 | self.extensions = [ |
|
540 | 540 | e for e in self.extensions if e.name != 'mercurial.zstd' |
|
541 | 541 | ] |
|
542 | 542 | |
|
543 | 543 | # Build Rust standalon extensions if it'll be used |
|
544 | 544 | # and its build is not explictely disabled (for external build |
|
545 | 545 | # as Linux distributions would do) |
|
546 | 546 | if self.distribution.rust and self.rust and hgrustext != 'direct-ffi': |
|
547 | 547 | for rustext in ruststandalones: |
|
548 | 548 | rustext.build('' if self.inplace else self.build_lib) |
|
549 | 549 | |
|
550 | 550 | return build_ext.build_extensions(self) |
|
551 | 551 | |
|
552 | 552 | def build_extension(self, ext): |
|
553 | 553 | if ( |
|
554 | 554 | self.distribution.rust |
|
555 | 555 | and self.rust |
|
556 | 556 | and isinstance(ext, RustExtension) |
|
557 | 557 | ): |
|
558 | 558 | ext.rustbuild() |
|
559 | 559 | try: |
|
560 | 560 | build_ext.build_extension(self, ext) |
|
561 | 561 | except CCompilerError: |
|
562 | 562 | if not getattr(ext, 'optional', False): |
|
563 | 563 | raise |
|
564 | 564 | log.warn( |
|
565 | 565 | "Failed to build optional extension '%s' (skipping)", ext.name |
|
566 | 566 | ) |
|
567 | 567 | |
|
568 | 568 | |
|
569 | 569 | class hgbuildscripts(build_scripts): |
|
570 | 570 | def run(self): |
|
571 | 571 | if os.name != 'nt' or self.distribution.pure: |
|
572 | 572 | return build_scripts.run(self) |
|
573 | 573 | |
|
574 | 574 | exebuilt = False |
|
575 | 575 | try: |
|
576 | 576 | self.run_command('build_hgexe') |
|
577 | 577 | exebuilt = True |
|
578 | 578 | except (DistutilsError, CCompilerError): |
|
579 | 579 | log.warn('failed to build optional hg.exe') |
|
580 | 580 | |
|
581 | 581 | if exebuilt: |
|
582 | 582 | # Copying hg.exe to the scripts build directory ensures it is |
|
583 | 583 | # installed by the install_scripts command. |
|
584 | 584 | hgexecommand = self.get_finalized_command('build_hgexe') |
|
585 | 585 | dest = os.path.join(self.build_dir, 'hg.exe') |
|
586 | 586 | self.mkpath(self.build_dir) |
|
587 | 587 | self.copy_file(hgexecommand.hgexepath, dest) |
|
588 | 588 | |
|
589 | 589 | # Remove hg.bat because it is redundant with hg.exe. |
|
590 | 590 | self.scripts.remove('contrib/win32/hg.bat') |
|
591 | 591 | |
|
592 | 592 | return build_scripts.run(self) |
|
593 | 593 | |
|
594 | 594 | |
|
595 | 595 | class hgbuildpy(build_py): |
|
596 | 596 | def finalize_options(self): |
|
597 | 597 | build_py.finalize_options(self) |
|
598 | 598 | |
|
599 | 599 | if self.distribution.pure: |
|
600 | 600 | self.distribution.ext_modules = [] |
|
601 | 601 | elif self.distribution.cffi: |
|
602 | 602 | from mercurial.cffi import ( |
|
603 | 603 | bdiffbuild, |
|
604 | 604 | mpatchbuild, |
|
605 | 605 | ) |
|
606 | 606 | |
|
607 | 607 | exts = [ |
|
608 | 608 | mpatchbuild.ffi.distutils_extension(), |
|
609 | 609 | bdiffbuild.ffi.distutils_extension(), |
|
610 | 610 | ] |
|
611 | 611 | # cffi modules go here |
|
612 | 612 | if sys.platform == 'darwin': |
|
613 | 613 | from mercurial.cffi import osutilbuild |
|
614 | 614 | |
|
615 | 615 | exts.append(osutilbuild.ffi.distutils_extension()) |
|
616 | 616 | self.distribution.ext_modules = exts |
|
617 | 617 | else: |
|
618 | 618 | h = os.path.join(get_python_inc(), 'Python.h') |
|
619 | 619 | if not os.path.exists(h): |
|
620 | 620 | raise SystemExit( |
|
621 | 621 | 'Python headers are required to build ' |
|
622 | 622 | 'Mercurial but weren\'t found in %s' % h |
|
623 | 623 | ) |
|
624 | 624 | |
|
625 | 625 | def run(self): |
|
626 | 626 | basepath = os.path.join(self.build_lib, 'mercurial') |
|
627 | 627 | self.mkpath(basepath) |
|
628 | 628 | |
|
629 | 629 | rust = self.distribution.rust |
|
630 | 630 | if self.distribution.pure: |
|
631 | 631 | modulepolicy = 'py' |
|
632 | 632 | elif self.build_lib == '.': |
|
633 | 633 | # in-place build should run without rebuilding and Rust extensions |
|
634 | 634 | modulepolicy = 'rust+c-allow' if rust else 'allow' |
|
635 | 635 | else: |
|
636 | 636 | modulepolicy = 'rust+c' if rust else 'c' |
|
637 | 637 | |
|
638 | 638 | content = b''.join( |
|
639 | 639 | [ |
|
640 | 640 | b'# this file is autogenerated by setup.py\n', |
|
641 | 641 | b'modulepolicy = b"%s"\n' % modulepolicy.encode('ascii'), |
|
642 | 642 | ] |
|
643 | 643 | ) |
|
644 | 644 | write_if_changed(os.path.join(basepath, '__modulepolicy__.py'), content) |
|
645 | 645 | |
|
646 | 646 | build_py.run(self) |
|
647 | 647 | |
|
648 | 648 | |
|
649 | 649 | class buildhgextindex(Command): |
|
650 | 650 | description = 'generate prebuilt index of hgext (for frozen package)' |
|
651 | 651 | user_options = [] |
|
652 | 652 | _indexfilename = 'hgext/__index__.py' |
|
653 | 653 | |
|
654 | 654 | def initialize_options(self): |
|
655 | 655 | pass |
|
656 | 656 | |
|
657 | 657 | def finalize_options(self): |
|
658 | 658 | pass |
|
659 | 659 | |
|
660 | 660 | def run(self): |
|
661 | 661 | if os.path.exists(self._indexfilename): |
|
662 | 662 | with open(self._indexfilename, 'w') as f: |
|
663 | 663 | f.write('# empty\n') |
|
664 | 664 | |
|
665 | 665 | # here no extension enabled, disabled() lists up everything |
|
666 | 666 | code = ( |
|
667 | 667 | 'import pprint; from mercurial import extensions; ' |
|
668 | 668 | 'pprint.pprint(extensions.disabled())' |
|
669 | 669 | ) |
|
670 | 670 | returncode, out, err = runcmd( |
|
671 | 671 | [sys.executable, '-c', code], localhgenv() |
|
672 | 672 | ) |
|
673 | 673 | if err or returncode != 0: |
|
674 | 674 | raise DistutilsExecError(err) |
|
675 | 675 | |
|
676 | 676 | with open(self._indexfilename, 'wb') as f: |
|
677 | 677 | f.write(b'# this file is autogenerated by setup.py\n') |
|
678 | 678 | f.write(b'docs = ') |
|
679 | 679 | f.write(out) |
|
680 | 680 | |
|
681 | 681 | |
|
682 | 682 | class buildhgexe(build_ext): |
|
683 | 683 | description = 'compile hg.exe from mercurial/exewrapper.c' |
|
684 | 684 | user_options = build_ext.user_options + [ |
|
685 | 685 | ( |
|
686 | 686 | 'long-paths-support', |
|
687 | 687 | None, |
|
688 | 688 | 'enable support for long paths on ' |
|
689 | 689 | 'Windows (off by default and ' |
|
690 | 690 | 'experimental)', |
|
691 | 691 | ), |
|
692 | 692 | ] |
|
693 | 693 | |
|
694 | 694 | LONG_PATHS_MANIFEST = """ |
|
695 | 695 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
|
696 | 696 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
|
697 | 697 | <application> |
|
698 | 698 | <windowsSettings |
|
699 | 699 | xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> |
|
700 | 700 | <ws2:longPathAware>true</ws2:longPathAware> |
|
701 | 701 | </windowsSettings> |
|
702 | 702 | </application> |
|
703 | 703 | </assembly>""" |
|
704 | 704 | |
|
705 | 705 | def initialize_options(self): |
|
706 | 706 | build_ext.initialize_options(self) |
|
707 | 707 | self.long_paths_support = False |
|
708 | 708 | |
|
709 | 709 | def build_extensions(self): |
|
710 | 710 | if os.name != 'nt': |
|
711 | 711 | return |
|
712 | 712 | if isinstance(self.compiler, HackedMingw32CCompiler): |
|
713 | 713 | self.compiler.compiler_so = self.compiler.compiler # no -mdll |
|
714 | 714 | self.compiler.dll_libraries = [] # no -lmsrvc90 |
|
715 | 715 | |
|
716 | 716 | pythonlib = None |
|
717 | 717 | |
|
718 | 718 | if getattr(sys, 'dllhandle', None): |
|
719 | 719 | # Different Python installs can have different Python library |
|
720 | 720 | # names. e.g. the official CPython distribution uses pythonXY.dll |
|
721 | 721 | # and MinGW uses libpythonX.Y.dll. |
|
722 | 722 | _kernel32 = ctypes.windll.kernel32 |
|
723 | 723 | _kernel32.GetModuleFileNameA.argtypes = [ |
|
724 | 724 | ctypes.c_void_p, |
|
725 | 725 | ctypes.c_void_p, |
|
726 | 726 | ctypes.c_ulong, |
|
727 | 727 | ] |
|
728 | 728 | _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong |
|
729 | 729 | size = 1000 |
|
730 | 730 | buf = ctypes.create_string_buffer(size + 1) |
|
731 | 731 | filelen = _kernel32.GetModuleFileNameA( |
|
732 | 732 | sys.dllhandle, ctypes.byref(buf), size |
|
733 | 733 | ) |
|
734 | 734 | |
|
735 | 735 | if filelen > 0 and filelen != size: |
|
736 | 736 | dllbasename = os.path.basename(buf.value) |
|
737 | 737 | if not dllbasename.lower().endswith(b'.dll'): |
|
738 | 738 | raise SystemExit( |
|
739 | 739 | 'Python DLL does not end with .dll: %s' % dllbasename |
|
740 | 740 | ) |
|
741 | 741 | pythonlib = dllbasename[:-4] |
|
742 | 742 | |
|
743 | 743 | if not pythonlib: |
|
744 | 744 | log.warn( |
|
745 | 745 | 'could not determine Python DLL filename; assuming pythonXY' |
|
746 | 746 | ) |
|
747 | 747 | |
|
748 | 748 | hv = sys.hexversion |
|
749 | 749 | pythonlib = b'python%d%d' % (hv >> 24, (hv >> 16) & 0xFF) |
|
750 | 750 | |
|
751 | 751 | log.info('using %s as Python library name' % pythonlib) |
|
752 | 752 | with open('mercurial/hgpythonlib.h', 'wb') as f: |
|
753 | 753 | f.write(b'/* this file is autogenerated by setup.py */\n') |
|
754 | 754 | f.write(b'#define HGPYTHONLIB "%s"\n' % pythonlib) |
|
755 | 755 | |
|
756 | 756 | macros = None |
|
757 | 757 | if sys.version_info[0] >= 3: |
|
758 | 758 | macros = [('_UNICODE', None), ('UNICODE', None)] |
|
759 | 759 | |
|
760 | 760 | objects = self.compiler.compile( |
|
761 | 761 | ['mercurial/exewrapper.c'], |
|
762 | 762 | output_dir=self.build_temp, |
|
763 | 763 | macros=macros, |
|
764 | 764 | ) |
|
765 | 765 | dir = os.path.dirname(self.get_ext_fullpath('dummy')) |
|
766 | 766 | self.hgtarget = os.path.join(dir, 'hg') |
|
767 | 767 | self.compiler.link_executable( |
|
768 | 768 | objects, self.hgtarget, libraries=[], output_dir=self.build_temp |
|
769 | 769 | ) |
|
770 | 770 | if self.long_paths_support: |
|
771 | 771 | self.addlongpathsmanifest() |
|
772 | 772 | |
|
773 | 773 | def addlongpathsmanifest(self): |
|
774 | 774 | r"""Add manifest pieces so that hg.exe understands long paths |
|
775 | 775 | |
|
776 | 776 | This is an EXPERIMENTAL feature, use with care. |
|
777 | 777 | To enable long paths support, one needs to do two things: |
|
778 | 778 | - build Mercurial with --long-paths-support option |
|
779 | 779 | - change HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\ |
|
780 | 780 | LongPathsEnabled to have value 1. |
|
781 | 781 | |
|
782 | 782 | Please ignore 'warning 81010002: Unrecognized Element "longPathAware"'; |
|
783 | 783 | it happens because Mercurial uses mt.exe circa 2008, which is not |
|
784 | 784 | yet aware of long paths support in the manifest (I think so at least). |
|
785 | 785 | This does not stop mt.exe from embedding/merging the XML properly. |
|
786 | 786 | |
|
787 | 787 | Why resource #1 should be used for .exe manifests? I don't know and |
|
788 | 788 | wasn't able to find an explanation for mortals. But it seems to work. |
|
789 | 789 | """ |
|
790 | 790 | exefname = self.compiler.executable_filename(self.hgtarget) |
|
791 | 791 | fdauto, manfname = tempfile.mkstemp(suffix='.hg.exe.manifest') |
|
792 | 792 | os.close(fdauto) |
|
793 | 793 | with open(manfname, 'w') as f: |
|
794 | 794 | f.write(self.LONG_PATHS_MANIFEST) |
|
795 | 795 | log.info("long paths manifest is written to '%s'" % manfname) |
|
796 | 796 | inputresource = '-inputresource:%s;#1' % exefname |
|
797 | 797 | outputresource = '-outputresource:%s;#1' % exefname |
|
798 | 798 | log.info("running mt.exe to update hg.exe's manifest in-place") |
|
799 | 799 | # supplying both -manifest and -inputresource to mt.exe makes |
|
800 | 800 | # it merge the embedded and supplied manifests in the -outputresource |
|
801 | 801 | self.spawn( |
|
802 | 802 | [ |
|
803 | 803 | 'mt.exe', |
|
804 | 804 | '-nologo', |
|
805 | 805 | '-manifest', |
|
806 | 806 | manfname, |
|
807 | 807 | inputresource, |
|
808 | 808 | outputresource, |
|
809 | 809 | ] |
|
810 | 810 | ) |
|
811 | 811 | log.info("done updating hg.exe's manifest") |
|
812 | 812 | os.remove(manfname) |
|
813 | 813 | |
|
814 | 814 | @property |
|
815 | 815 | def hgexepath(self): |
|
816 | 816 | dir = os.path.dirname(self.get_ext_fullpath('dummy')) |
|
817 | 817 | return os.path.join(self.build_temp, dir, 'hg.exe') |
|
818 | 818 | |
|
819 | 819 | |
|
820 | 820 | class hgbuilddoc(Command): |
|
821 | 821 | description = 'build documentation' |
|
822 | 822 | user_options = [ |
|
823 | 823 | ('man', None, 'generate man pages'), |
|
824 | 824 | ('html', None, 'generate html pages'), |
|
825 | 825 | ] |
|
826 | 826 | |
|
827 | 827 | def initialize_options(self): |
|
828 | 828 | self.man = None |
|
829 | 829 | self.html = None |
|
830 | 830 | |
|
831 | 831 | def finalize_options(self): |
|
832 | 832 | # If --man or --html are set, only generate what we're told to. |
|
833 | 833 | # Otherwise generate everything. |
|
834 | 834 | have_subset = self.man is not None or self.html is not None |
|
835 | 835 | |
|
836 | 836 | if have_subset: |
|
837 | 837 | self.man = True if self.man else False |
|
838 | 838 | self.html = True if self.html else False |
|
839 | 839 | else: |
|
840 | 840 | self.man = True |
|
841 | 841 | self.html = True |
|
842 | 842 | |
|
843 | 843 | def run(self): |
|
844 | 844 | def normalizecrlf(p): |
|
845 | 845 | with open(p, 'rb') as fh: |
|
846 | 846 | orig = fh.read() |
|
847 | 847 | |
|
848 | 848 | if b'\r\n' not in orig: |
|
849 | 849 | return |
|
850 | 850 | |
|
851 | 851 | log.info('normalizing %s to LF line endings' % p) |
|
852 | 852 | with open(p, 'wb') as fh: |
|
853 | 853 | fh.write(orig.replace(b'\r\n', b'\n')) |
|
854 | 854 | |
|
855 | 855 | def gentxt(root): |
|
856 | 856 | txt = 'doc/%s.txt' % root |
|
857 | 857 | log.info('generating %s' % txt) |
|
858 | 858 | res, out, err = runcmd( |
|
859 | 859 | [sys.executable, 'gendoc.py', root], os.environ, cwd='doc' |
|
860 | 860 | ) |
|
861 | 861 | if res: |
|
862 | 862 | raise SystemExit( |
|
863 | 863 | 'error running gendoc.py: %s' % '\n'.join([out, err]) |
|
864 | 864 | ) |
|
865 | 865 | |
|
866 | 866 | with open(txt, 'wb') as fh: |
|
867 | 867 | fh.write(out) |
|
868 | 868 | |
|
869 | 869 | def gengendoc(root): |
|
870 | 870 | gendoc = 'doc/%s.gendoc.txt' % root |
|
871 | 871 | |
|
872 | 872 | log.info('generating %s' % gendoc) |
|
873 | 873 | res, out, err = runcmd( |
|
874 | 874 | [sys.executable, 'gendoc.py', '%s.gendoc' % root], |
|
875 | 875 | os.environ, |
|
876 | 876 | cwd='doc', |
|
877 | 877 | ) |
|
878 | 878 | if res: |
|
879 | 879 | raise SystemExit( |
|
880 | 880 | 'error running gendoc: %s' % '\n'.join([out, err]) |
|
881 | 881 | ) |
|
882 | 882 | |
|
883 | 883 | with open(gendoc, 'wb') as fh: |
|
884 | 884 | fh.write(out) |
|
885 | 885 | |
|
886 | 886 | def genman(root): |
|
887 | 887 | log.info('generating doc/%s' % root) |
|
888 | 888 | res, out, err = runcmd( |
|
889 | 889 | [ |
|
890 | 890 | sys.executable, |
|
891 | 891 | 'runrst', |
|
892 | 892 | 'hgmanpage', |
|
893 | 893 | '--halt', |
|
894 | 894 | 'warning', |
|
895 | 895 | '--strip-elements-with-class', |
|
896 | 896 | 'htmlonly', |
|
897 | 897 | '%s.txt' % root, |
|
898 | 898 | root, |
|
899 | 899 | ], |
|
900 | 900 | os.environ, |
|
901 | 901 | cwd='doc', |
|
902 | 902 | ) |
|
903 | 903 | if res: |
|
904 | 904 | raise SystemExit( |
|
905 | 905 | 'error running runrst: %s' % '\n'.join([out, err]) |
|
906 | 906 | ) |
|
907 | 907 | |
|
908 | 908 | normalizecrlf('doc/%s' % root) |
|
909 | 909 | |
|
910 | 910 | def genhtml(root): |
|
911 | 911 | log.info('generating doc/%s.html' % root) |
|
912 | 912 | res, out, err = runcmd( |
|
913 | 913 | [ |
|
914 | 914 | sys.executable, |
|
915 | 915 | 'runrst', |
|
916 | 916 | 'html', |
|
917 | 917 | '--halt', |
|
918 | 918 | 'warning', |
|
919 | 919 | '--link-stylesheet', |
|
920 | 920 | '--stylesheet-path', |
|
921 | 921 | 'style.css', |
|
922 | 922 | '%s.txt' % root, |
|
923 | 923 | '%s.html' % root, |
|
924 | 924 | ], |
|
925 | 925 | os.environ, |
|
926 | 926 | cwd='doc', |
|
927 | 927 | ) |
|
928 | 928 | if res: |
|
929 | 929 | raise SystemExit( |
|
930 | 930 | 'error running runrst: %s' % '\n'.join([out, err]) |
|
931 | 931 | ) |
|
932 | 932 | |
|
933 | 933 | normalizecrlf('doc/%s.html' % root) |
|
934 | 934 | |
|
935 | 935 | # This logic is duplicated in doc/Makefile. |
|
936 | 936 | sources = set( |
|
937 | 937 | f |
|
938 | for f in os.listdir('mercurial/help') | |
|
938 | for f in os.listdir('mercurial/helptext') | |
|
939 | 939 | if re.search(r'[0-9]\.txt$', f) |
|
940 | 940 | ) |
|
941 | 941 | |
|
942 | 942 | # common.txt is a one-off. |
|
943 | 943 | gentxt('common') |
|
944 | 944 | |
|
945 | 945 | for source in sorted(sources): |
|
946 | 946 | assert source[-4:] == '.txt' |
|
947 | 947 | root = source[:-4] |
|
948 | 948 | |
|
949 | 949 | gentxt(root) |
|
950 | 950 | gengendoc(root) |
|
951 | 951 | |
|
952 | 952 | if self.man: |
|
953 | 953 | genman(root) |
|
954 | 954 | if self.html: |
|
955 | 955 | genhtml(root) |
|
956 | 956 | |
|
957 | 957 | |
|
958 | 958 | class hginstall(install): |
|
959 | 959 | |
|
960 | 960 | user_options = install.user_options + [ |
|
961 | 961 | ( |
|
962 | 962 | 'old-and-unmanageable', |
|
963 | 963 | None, |
|
964 | 964 | 'noop, present for eggless setuptools compat', |
|
965 | 965 | ), |
|
966 | 966 | ( |
|
967 | 967 | 'single-version-externally-managed', |
|
968 | 968 | None, |
|
969 | 969 | 'noop, present for eggless setuptools compat', |
|
970 | 970 | ), |
|
971 | 971 | ] |
|
972 | 972 | |
|
973 | 973 | # Also helps setuptools not be sad while we refuse to create eggs. |
|
974 | 974 | single_version_externally_managed = True |
|
975 | 975 | |
|
976 | 976 | def get_sub_commands(self): |
|
977 | 977 | # Screen out egg related commands to prevent egg generation. But allow |
|
978 | 978 | # mercurial.egg-info generation, since that is part of modern |
|
979 | 979 | # packaging. |
|
980 | 980 | excl = set(['bdist_egg']) |
|
981 | 981 | return filter(lambda x: x not in excl, install.get_sub_commands(self)) |
|
982 | 982 | |
|
983 | 983 | |
|
984 | 984 | class hginstalllib(install_lib): |
|
985 | 985 | ''' |
|
986 | 986 | This is a specialization of install_lib that replaces the copy_file used |
|
987 | 987 | there so that it supports setting the mode of files after copying them, |
|
988 | 988 | instead of just preserving the mode that the files originally had. If your |
|
989 | 989 | system has a umask of something like 027, preserving the permissions when |
|
990 | 990 | copying will lead to a broken install. |
|
991 | 991 | |
|
992 | 992 | Note that just passing keep_permissions=False to copy_file would be |
|
993 | 993 | insufficient, as it might still be applying a umask. |
|
994 | 994 | ''' |
|
995 | 995 | |
|
996 | 996 | def run(self): |
|
997 | 997 | realcopyfile = file_util.copy_file |
|
998 | 998 | |
|
999 | 999 | def copyfileandsetmode(*args, **kwargs): |
|
1000 | 1000 | src, dst = args[0], args[1] |
|
1001 | 1001 | dst, copied = realcopyfile(*args, **kwargs) |
|
1002 | 1002 | if copied: |
|
1003 | 1003 | st = os.stat(src) |
|
1004 | 1004 | # Persist executable bit (apply it to group and other if user |
|
1005 | 1005 | # has it) |
|
1006 | 1006 | if st[stat.ST_MODE] & stat.S_IXUSR: |
|
1007 | 1007 | setmode = int('0755', 8) |
|
1008 | 1008 | else: |
|
1009 | 1009 | setmode = int('0644', 8) |
|
1010 | 1010 | m = stat.S_IMODE(st[stat.ST_MODE]) |
|
1011 | 1011 | m = (m & ~int('0777', 8)) | setmode |
|
1012 | 1012 | os.chmod(dst, m) |
|
1013 | 1013 | |
|
1014 | 1014 | file_util.copy_file = copyfileandsetmode |
|
1015 | 1015 | try: |
|
1016 | 1016 | install_lib.run(self) |
|
1017 | 1017 | finally: |
|
1018 | 1018 | file_util.copy_file = realcopyfile |
|
1019 | 1019 | |
|
1020 | 1020 | |
|
1021 | 1021 | class hginstallscripts(install_scripts): |
|
1022 | 1022 | ''' |
|
1023 | 1023 | This is a specialization of install_scripts that replaces the @LIBDIR@ with |
|
1024 | 1024 | the configured directory for modules. If possible, the path is made relative |
|
1025 | 1025 | to the directory for scripts. |
|
1026 | 1026 | ''' |
|
1027 | 1027 | |
|
1028 | 1028 | def initialize_options(self): |
|
1029 | 1029 | install_scripts.initialize_options(self) |
|
1030 | 1030 | |
|
1031 | 1031 | self.install_lib = None |
|
1032 | 1032 | |
|
1033 | 1033 | def finalize_options(self): |
|
1034 | 1034 | install_scripts.finalize_options(self) |
|
1035 | 1035 | self.set_undefined_options('install', ('install_lib', 'install_lib')) |
|
1036 | 1036 | |
|
1037 | 1037 | def run(self): |
|
1038 | 1038 | install_scripts.run(self) |
|
1039 | 1039 | |
|
1040 | 1040 | # It only makes sense to replace @LIBDIR@ with the install path if |
|
1041 | 1041 | # the install path is known. For wheels, the logic below calculates |
|
1042 | 1042 | # the libdir to be "../..". This is because the internal layout of a |
|
1043 | 1043 | # wheel archive looks like: |
|
1044 | 1044 | # |
|
1045 | 1045 | # mercurial-3.6.1.data/scripts/hg |
|
1046 | 1046 | # mercurial/__init__.py |
|
1047 | 1047 | # |
|
1048 | 1048 | # When installing wheels, the subdirectories of the "<pkg>.data" |
|
1049 | 1049 | # directory are translated to system local paths and files therein |
|
1050 | 1050 | # are copied in place. The mercurial/* files are installed into the |
|
1051 | 1051 | # site-packages directory. However, the site-packages directory |
|
1052 | 1052 | # isn't known until wheel install time. This means we have no clue |
|
1053 | 1053 | # at wheel generation time what the installed site-packages directory |
|
1054 | 1054 | # will be. And, wheels don't appear to provide the ability to register |
|
1055 | 1055 | # custom code to run during wheel installation. This all means that |
|
1056 | 1056 | # we can't reliably set the libdir in wheels: the default behavior |
|
1057 | 1057 | # of looking in sys.path must do. |
|
1058 | 1058 | |
|
1059 | 1059 | if ( |
|
1060 | 1060 | os.path.splitdrive(self.install_dir)[0] |
|
1061 | 1061 | != os.path.splitdrive(self.install_lib)[0] |
|
1062 | 1062 | ): |
|
1063 | 1063 | # can't make relative paths from one drive to another, so use an |
|
1064 | 1064 | # absolute path instead |
|
1065 | 1065 | libdir = self.install_lib |
|
1066 | 1066 | else: |
|
1067 | 1067 | common = os.path.commonprefix((self.install_dir, self.install_lib)) |
|
1068 | 1068 | rest = self.install_dir[len(common) :] |
|
1069 | 1069 | uplevel = len([n for n in os.path.split(rest) if n]) |
|
1070 | 1070 | |
|
1071 | 1071 | libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common) :] |
|
1072 | 1072 | |
|
1073 | 1073 | for outfile in self.outfiles: |
|
1074 | 1074 | with open(outfile, 'rb') as fp: |
|
1075 | 1075 | data = fp.read() |
|
1076 | 1076 | |
|
1077 | 1077 | # skip binary files |
|
1078 | 1078 | if b'\0' in data: |
|
1079 | 1079 | continue |
|
1080 | 1080 | |
|
1081 | 1081 | # During local installs, the shebang will be rewritten to the final |
|
1082 | 1082 | # install path. During wheel packaging, the shebang has a special |
|
1083 | 1083 | # value. |
|
1084 | 1084 | if data.startswith(b'#!python'): |
|
1085 | 1085 | log.info( |
|
1086 | 1086 | 'not rewriting @LIBDIR@ in %s because install path ' |
|
1087 | 1087 | 'not known' % outfile |
|
1088 | 1088 | ) |
|
1089 | 1089 | continue |
|
1090 | 1090 | |
|
1091 | 1091 | data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape)) |
|
1092 | 1092 | with open(outfile, 'wb') as fp: |
|
1093 | 1093 | fp.write(data) |
|
1094 | 1094 | |
|
1095 | 1095 | |
|
1096 | 1096 | # virtualenv installs custom distutils/__init__.py and |
|
1097 | 1097 | # distutils/distutils.cfg files which essentially proxy back to the |
|
1098 | 1098 | # "real" distutils in the main Python install. The presence of this |
|
1099 | 1099 | # directory causes py2exe to pick up the "hacked" distutils package |
|
1100 | 1100 | # from the virtualenv and "import distutils" will fail from the py2exe |
|
1101 | 1101 | # build because the "real" distutils files can't be located. |
|
1102 | 1102 | # |
|
1103 | 1103 | # We work around this by monkeypatching the py2exe code finding Python |
|
1104 | 1104 | # modules to replace the found virtualenv distutils modules with the |
|
1105 | 1105 | # original versions via filesystem scanning. This is a bit hacky. But |
|
1106 | 1106 | # it allows us to use virtualenvs for py2exe packaging, which is more |
|
1107 | 1107 | # deterministic and reproducible. |
|
1108 | 1108 | # |
|
1109 | 1109 | # It's worth noting that the common StackOverflow suggestions for this |
|
1110 | 1110 | # problem involve copying the original distutils files into the |
|
1111 | 1111 | # virtualenv or into the staging directory after setup() is invoked. |
|
1112 | 1112 | # The former is very brittle and can easily break setup(). Our hacking |
|
1113 | 1113 | # of the found modules routine has a similar result as copying the files |
|
1114 | 1114 | # manually. But it makes fewer assumptions about how py2exe works and |
|
1115 | 1115 | # is less brittle. |
|
1116 | 1116 | |
|
1117 | 1117 | # This only catches virtualenvs made with virtualenv (as opposed to |
|
1118 | 1118 | # venv, which is likely what Python 3 uses). |
|
1119 | 1119 | py2exehacked = py2exeloaded and getattr(sys, 'real_prefix', None) is not None |
|
1120 | 1120 | |
|
1121 | 1121 | if py2exehacked: |
|
1122 | 1122 | from distutils.command.py2exe import py2exe as buildpy2exe |
|
1123 | 1123 | from py2exe.mf import Module as py2exemodule |
|
1124 | 1124 | |
|
1125 | 1125 | class hgbuildpy2exe(buildpy2exe): |
|
1126 | 1126 | def find_needed_modules(self, mf, files, modules): |
|
1127 | 1127 | res = buildpy2exe.find_needed_modules(self, mf, files, modules) |
|
1128 | 1128 | |
|
1129 | 1129 | # Replace virtualenv's distutils modules with the real ones. |
|
1130 | 1130 | modules = {} |
|
1131 | 1131 | for k, v in res.modules.items(): |
|
1132 | 1132 | if k != 'distutils' and not k.startswith('distutils.'): |
|
1133 | 1133 | modules[k] = v |
|
1134 | 1134 | |
|
1135 | 1135 | res.modules = modules |
|
1136 | 1136 | |
|
1137 | 1137 | import opcode |
|
1138 | 1138 | |
|
1139 | 1139 | distutilsreal = os.path.join( |
|
1140 | 1140 | os.path.dirname(opcode.__file__), 'distutils' |
|
1141 | 1141 | ) |
|
1142 | 1142 | |
|
1143 | 1143 | for root, dirs, files in os.walk(distutilsreal): |
|
1144 | 1144 | for f in sorted(files): |
|
1145 | 1145 | if not f.endswith('.py'): |
|
1146 | 1146 | continue |
|
1147 | 1147 | |
|
1148 | 1148 | full = os.path.join(root, f) |
|
1149 | 1149 | |
|
1150 | 1150 | parents = ['distutils'] |
|
1151 | 1151 | |
|
1152 | 1152 | if root != distutilsreal: |
|
1153 | 1153 | rel = os.path.relpath(root, distutilsreal) |
|
1154 | 1154 | parents.extend(p for p in rel.split(os.sep)) |
|
1155 | 1155 | |
|
1156 | 1156 | modname = '%s.%s' % ('.'.join(parents), f[:-3]) |
|
1157 | 1157 | |
|
1158 | 1158 | if modname.startswith('distutils.tests.'): |
|
1159 | 1159 | continue |
|
1160 | 1160 | |
|
1161 | 1161 | if modname.endswith('.__init__'): |
|
1162 | 1162 | modname = modname[: -len('.__init__')] |
|
1163 | 1163 | path = os.path.dirname(full) |
|
1164 | 1164 | else: |
|
1165 | 1165 | path = None |
|
1166 | 1166 | |
|
1167 | 1167 | res.modules[modname] = py2exemodule( |
|
1168 | 1168 | modname, full, path=path |
|
1169 | 1169 | ) |
|
1170 | 1170 | |
|
1171 | 1171 | if 'distutils' not in res.modules: |
|
1172 | 1172 | raise SystemExit('could not find distutils modules') |
|
1173 | 1173 | |
|
1174 | 1174 | return res |
|
1175 | 1175 | |
|
1176 | 1176 | |
|
1177 | 1177 | cmdclass = { |
|
1178 | 1178 | 'build': hgbuild, |
|
1179 | 1179 | 'build_doc': hgbuilddoc, |
|
1180 | 1180 | 'build_mo': hgbuildmo, |
|
1181 | 1181 | 'build_ext': hgbuildext, |
|
1182 | 1182 | 'build_py': hgbuildpy, |
|
1183 | 1183 | 'build_scripts': hgbuildscripts, |
|
1184 | 1184 | 'build_hgextindex': buildhgextindex, |
|
1185 | 1185 | 'install': hginstall, |
|
1186 | 1186 | 'install_lib': hginstalllib, |
|
1187 | 1187 | 'install_scripts': hginstallscripts, |
|
1188 | 1188 | 'build_hgexe': buildhgexe, |
|
1189 | 1189 | } |
|
1190 | 1190 | |
|
1191 | 1191 | if py2exehacked: |
|
1192 | 1192 | cmdclass['py2exe'] = hgbuildpy2exe |
|
1193 | 1193 | |
|
1194 | 1194 | packages = [ |
|
1195 | 1195 | 'mercurial', |
|
1196 | 1196 | 'mercurial.cext', |
|
1197 | 1197 | 'mercurial.cffi', |
|
1198 | 1198 | 'mercurial.helptext', |
|
1199 | 1199 | 'mercurial.helptext.internals', |
|
1200 | 1200 | 'mercurial.hgweb', |
|
1201 | 1201 | 'mercurial.interfaces', |
|
1202 | 1202 | 'mercurial.pure', |
|
1203 | 1203 | 'mercurial.thirdparty', |
|
1204 | 1204 | 'mercurial.thirdparty.attr', |
|
1205 | 1205 | 'mercurial.thirdparty.zope', |
|
1206 | 1206 | 'mercurial.thirdparty.zope.interface', |
|
1207 | 1207 | 'mercurial.utils', |
|
1208 | 1208 | 'mercurial.revlogutils', |
|
1209 | 1209 | 'mercurial.testing', |
|
1210 | 1210 | 'hgext', |
|
1211 | 1211 | 'hgext.convert', |
|
1212 | 1212 | 'hgext.fsmonitor', |
|
1213 | 1213 | 'hgext.fastannotate', |
|
1214 | 1214 | 'hgext.fsmonitor.pywatchman', |
|
1215 | 1215 | 'hgext.highlight', |
|
1216 | 1216 | 'hgext.infinitepush', |
|
1217 | 1217 | 'hgext.largefiles', |
|
1218 | 1218 | 'hgext.lfs', |
|
1219 | 1219 | 'hgext.narrow', |
|
1220 | 1220 | 'hgext.remotefilelog', |
|
1221 | 1221 | 'hgext.zeroconf', |
|
1222 | 1222 | 'hgext3rd', |
|
1223 | 1223 | 'hgdemandimport', |
|
1224 | 1224 | ] |
|
1225 | 1225 | if sys.version_info[0] == 2: |
|
1226 | 1226 | packages.extend( |
|
1227 | 1227 | [ |
|
1228 | 1228 | 'mercurial.thirdparty.concurrent', |
|
1229 | 1229 | 'mercurial.thirdparty.concurrent.futures', |
|
1230 | 1230 | ] |
|
1231 | 1231 | ) |
|
1232 | 1232 | |
|
1233 | 1233 | if 'HG_PY2EXE_EXTRA_INSTALL_PACKAGES' in os.environ: |
|
1234 | 1234 | # py2exe can't cope with namespace packages very well, so we have to |
|
1235 | 1235 | # install any hgext3rd.* extensions that we want in the final py2exe |
|
1236 | 1236 | # image here. This is gross, but you gotta do what you gotta do. |
|
1237 | 1237 | packages.extend(os.environ['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'].split(' ')) |
|
1238 | 1238 | |
|
1239 | 1239 | common_depends = [ |
|
1240 | 1240 | 'mercurial/bitmanipulation.h', |
|
1241 | 1241 | 'mercurial/compat.h', |
|
1242 | 1242 | 'mercurial/cext/util.h', |
|
1243 | 1243 | ] |
|
1244 | 1244 | common_include_dirs = ['mercurial'] |
|
1245 | 1245 | |
|
1246 | 1246 | osutil_cflags = [] |
|
1247 | 1247 | osutil_ldflags = [] |
|
1248 | 1248 | |
|
1249 | 1249 | # platform specific macros |
|
1250 | 1250 | for plat, func in [('bsd', 'setproctitle')]: |
|
1251 | 1251 | if re.search(plat, sys.platform) and hasfunction(new_compiler(), func): |
|
1252 | 1252 | osutil_cflags.append('-DHAVE_%s' % func.upper()) |
|
1253 | 1253 | |
|
1254 | 1254 | for plat, macro, code in [ |
|
1255 | 1255 | ( |
|
1256 | 1256 | 'bsd|darwin', |
|
1257 | 1257 | 'BSD_STATFS', |
|
1258 | 1258 | ''' |
|
1259 | 1259 | #include <sys/param.h> |
|
1260 | 1260 | #include <sys/mount.h> |
|
1261 | 1261 | int main() { struct statfs s; return sizeof(s.f_fstypename); } |
|
1262 | 1262 | ''', |
|
1263 | 1263 | ), |
|
1264 | 1264 | ( |
|
1265 | 1265 | 'linux', |
|
1266 | 1266 | 'LINUX_STATFS', |
|
1267 | 1267 | ''' |
|
1268 | 1268 | #include <linux/magic.h> |
|
1269 | 1269 | #include <sys/vfs.h> |
|
1270 | 1270 | int main() { struct statfs s; return sizeof(s.f_type); } |
|
1271 | 1271 | ''', |
|
1272 | 1272 | ), |
|
1273 | 1273 | ]: |
|
1274 | 1274 | if re.search(plat, sys.platform) and cancompile(new_compiler(), code): |
|
1275 | 1275 | osutil_cflags.append('-DHAVE_%s' % macro) |
|
1276 | 1276 | |
|
1277 | 1277 | if sys.platform == 'darwin': |
|
1278 | 1278 | osutil_ldflags += ['-framework', 'ApplicationServices'] |
|
1279 | 1279 | |
|
1280 | 1280 | xdiff_srcs = [ |
|
1281 | 1281 | 'mercurial/thirdparty/xdiff/xdiffi.c', |
|
1282 | 1282 | 'mercurial/thirdparty/xdiff/xprepare.c', |
|
1283 | 1283 | 'mercurial/thirdparty/xdiff/xutils.c', |
|
1284 | 1284 | ] |
|
1285 | 1285 | |
|
1286 | 1286 | xdiff_headers = [ |
|
1287 | 1287 | 'mercurial/thirdparty/xdiff/xdiff.h', |
|
1288 | 1288 | 'mercurial/thirdparty/xdiff/xdiffi.h', |
|
1289 | 1289 | 'mercurial/thirdparty/xdiff/xinclude.h', |
|
1290 | 1290 | 'mercurial/thirdparty/xdiff/xmacros.h', |
|
1291 | 1291 | 'mercurial/thirdparty/xdiff/xprepare.h', |
|
1292 | 1292 | 'mercurial/thirdparty/xdiff/xtypes.h', |
|
1293 | 1293 | 'mercurial/thirdparty/xdiff/xutils.h', |
|
1294 | 1294 | ] |
|
1295 | 1295 | |
|
1296 | 1296 | |
|
1297 | 1297 | class RustCompilationError(CCompilerError): |
|
1298 | 1298 | """Exception class for Rust compilation errors.""" |
|
1299 | 1299 | |
|
1300 | 1300 | |
|
1301 | 1301 | class RustExtension(Extension): |
|
1302 | 1302 | """Base classes for concrete Rust Extension classes. |
|
1303 | 1303 | """ |
|
1304 | 1304 | |
|
1305 | 1305 | rusttargetdir = os.path.join('rust', 'target', 'release') |
|
1306 | 1306 | |
|
1307 | 1307 | def __init__( |
|
1308 | 1308 | self, mpath, sources, rustlibname, subcrate, py3_features=None, **kw |
|
1309 | 1309 | ): |
|
1310 | 1310 | Extension.__init__(self, mpath, sources, **kw) |
|
1311 | 1311 | srcdir = self.rustsrcdir = os.path.join('rust', subcrate) |
|
1312 | 1312 | self.py3_features = py3_features |
|
1313 | 1313 | |
|
1314 | 1314 | # adding Rust source and control files to depends so that the extension |
|
1315 | 1315 | # gets rebuilt if they've changed |
|
1316 | 1316 | self.depends.append(os.path.join(srcdir, 'Cargo.toml')) |
|
1317 | 1317 | cargo_lock = os.path.join(srcdir, 'Cargo.lock') |
|
1318 | 1318 | if os.path.exists(cargo_lock): |
|
1319 | 1319 | self.depends.append(cargo_lock) |
|
1320 | 1320 | for dirpath, subdir, fnames in os.walk(os.path.join(srcdir, 'src')): |
|
1321 | 1321 | self.depends.extend( |
|
1322 | 1322 | os.path.join(dirpath, fname) |
|
1323 | 1323 | for fname in fnames |
|
1324 | 1324 | if os.path.splitext(fname)[1] == '.rs' |
|
1325 | 1325 | ) |
|
1326 | 1326 | |
|
1327 | 1327 | @staticmethod |
|
1328 | 1328 | def rustdylibsuffix(): |
|
1329 | 1329 | """Return the suffix for shared libraries produced by rustc. |
|
1330 | 1330 | |
|
1331 | 1331 | See also: https://doc.rust-lang.org/reference/linkage.html |
|
1332 | 1332 | """ |
|
1333 | 1333 | if sys.platform == 'darwin': |
|
1334 | 1334 | return '.dylib' |
|
1335 | 1335 | elif os.name == 'nt': |
|
1336 | 1336 | return '.dll' |
|
1337 | 1337 | else: |
|
1338 | 1338 | return '.so' |
|
1339 | 1339 | |
|
1340 | 1340 | def rustbuild(self): |
|
1341 | 1341 | env = os.environ.copy() |
|
1342 | 1342 | if 'HGTEST_RESTOREENV' in env: |
|
1343 | 1343 | # Mercurial tests change HOME to a temporary directory, |
|
1344 | 1344 | # but, if installed with rustup, the Rust toolchain needs |
|
1345 | 1345 | # HOME to be correct (otherwise the 'no default toolchain' |
|
1346 | 1346 | # error message is issued and the build fails). |
|
1347 | 1347 | # This happens currently with test-hghave.t, which does |
|
1348 | 1348 | # invoke this build. |
|
1349 | 1349 | |
|
1350 | 1350 | # Unix only fix (os.path.expanduser not really reliable if |
|
1351 | 1351 | # HOME is shadowed like this) |
|
1352 | 1352 | import pwd |
|
1353 | 1353 | |
|
1354 | 1354 | env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir |
|
1355 | 1355 | |
|
1356 | 1356 | cargocmd = ['cargo', 'rustc', '-vv', '--release'] |
|
1357 | 1357 | if sys.version_info[0] == 3 and self.py3_features is not None: |
|
1358 | 1358 | cargocmd.extend( |
|
1359 | 1359 | ('--features', self.py3_features, '--no-default-features') |
|
1360 | 1360 | ) |
|
1361 | 1361 | cargocmd.append('--') |
|
1362 | 1362 | if sys.platform == 'darwin': |
|
1363 | 1363 | cargocmd.extend( |
|
1364 | 1364 | ("-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup") |
|
1365 | 1365 | ) |
|
1366 | 1366 | try: |
|
1367 | 1367 | subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir) |
|
1368 | 1368 | except OSError as exc: |
|
1369 | 1369 | if exc.errno == errno.ENOENT: |
|
1370 | 1370 | raise RustCompilationError("Cargo not found") |
|
1371 | 1371 | elif exc.errno == errno.EACCES: |
|
1372 | 1372 | raise RustCompilationError( |
|
1373 | 1373 | "Cargo found, but permisssion to execute it is denied" |
|
1374 | 1374 | ) |
|
1375 | 1375 | else: |
|
1376 | 1376 | raise |
|
1377 | 1377 | except subprocess.CalledProcessError: |
|
1378 | 1378 | raise RustCompilationError( |
|
1379 | 1379 | "Cargo failed. Working directory: %r, " |
|
1380 | 1380 | "command: %r, environment: %r" |
|
1381 | 1381 | % (self.rustsrcdir, cargocmd, env) |
|
1382 | 1382 | ) |
|
1383 | 1383 | |
|
1384 | 1384 | |
|
1385 | 1385 | class RustEnhancedExtension(RustExtension): |
|
1386 | 1386 | """A C Extension, conditionally enhanced with Rust code. |
|
1387 | 1387 | |
|
1388 | 1388 | If the HGRUSTEXT environment variable is set to something else |
|
1389 | 1389 | than 'cpython', the Rust sources get compiled and linked within the |
|
1390 | 1390 | C target shared library object. |
|
1391 | 1391 | """ |
|
1392 | 1392 | |
|
1393 | 1393 | def __init__(self, mpath, sources, rustlibname, subcrate, **kw): |
|
1394 | 1394 | RustExtension.__init__( |
|
1395 | 1395 | self, mpath, sources, rustlibname, subcrate, **kw |
|
1396 | 1396 | ) |
|
1397 | 1397 | if hgrustext != 'direct-ffi': |
|
1398 | 1398 | return |
|
1399 | 1399 | self.extra_compile_args.append('-DWITH_RUST') |
|
1400 | 1400 | self.libraries.append(rustlibname) |
|
1401 | 1401 | self.library_dirs.append(self.rusttargetdir) |
|
1402 | 1402 | |
|
1403 | 1403 | def rustbuild(self): |
|
1404 | 1404 | if hgrustext == 'direct-ffi': |
|
1405 | 1405 | RustExtension.rustbuild(self) |
|
1406 | 1406 | |
|
1407 | 1407 | |
|
1408 | 1408 | class RustStandaloneExtension(RustExtension): |
|
1409 | 1409 | def __init__(self, pydottedname, rustcrate, dylibname, **kw): |
|
1410 | 1410 | RustExtension.__init__( |
|
1411 | 1411 | self, pydottedname, [], dylibname, rustcrate, **kw |
|
1412 | 1412 | ) |
|
1413 | 1413 | self.dylibname = dylibname |
|
1414 | 1414 | |
|
1415 | 1415 | def build(self, target_dir): |
|
1416 | 1416 | self.rustbuild() |
|
1417 | 1417 | target = [target_dir] |
|
1418 | 1418 | target.extend(self.name.split('.')) |
|
1419 | 1419 | target[-1] += DYLIB_SUFFIX |
|
1420 | 1420 | shutil.copy2( |
|
1421 | 1421 | os.path.join( |
|
1422 | 1422 | self.rusttargetdir, self.dylibname + self.rustdylibsuffix() |
|
1423 | 1423 | ), |
|
1424 | 1424 | os.path.join(*target), |
|
1425 | 1425 | ) |
|
1426 | 1426 | |
|
1427 | 1427 | |
|
1428 | 1428 | extmodules = [ |
|
1429 | 1429 | Extension( |
|
1430 | 1430 | 'mercurial.cext.base85', |
|
1431 | 1431 | ['mercurial/cext/base85.c'], |
|
1432 | 1432 | include_dirs=common_include_dirs, |
|
1433 | 1433 | depends=common_depends, |
|
1434 | 1434 | ), |
|
1435 | 1435 | Extension( |
|
1436 | 1436 | 'mercurial.cext.bdiff', |
|
1437 | 1437 | ['mercurial/bdiff.c', 'mercurial/cext/bdiff.c'] + xdiff_srcs, |
|
1438 | 1438 | include_dirs=common_include_dirs, |
|
1439 | 1439 | depends=common_depends + ['mercurial/bdiff.h'] + xdiff_headers, |
|
1440 | 1440 | ), |
|
1441 | 1441 | Extension( |
|
1442 | 1442 | 'mercurial.cext.mpatch', |
|
1443 | 1443 | ['mercurial/mpatch.c', 'mercurial/cext/mpatch.c'], |
|
1444 | 1444 | include_dirs=common_include_dirs, |
|
1445 | 1445 | depends=common_depends, |
|
1446 | 1446 | ), |
|
1447 | 1447 | RustEnhancedExtension( |
|
1448 | 1448 | 'mercurial.cext.parsers', |
|
1449 | 1449 | [ |
|
1450 | 1450 | 'mercurial/cext/charencode.c', |
|
1451 | 1451 | 'mercurial/cext/dirs.c', |
|
1452 | 1452 | 'mercurial/cext/manifest.c', |
|
1453 | 1453 | 'mercurial/cext/parsers.c', |
|
1454 | 1454 | 'mercurial/cext/pathencode.c', |
|
1455 | 1455 | 'mercurial/cext/revlog.c', |
|
1456 | 1456 | ], |
|
1457 | 1457 | 'hgdirectffi', |
|
1458 | 1458 | 'hg-direct-ffi', |
|
1459 | 1459 | include_dirs=common_include_dirs, |
|
1460 | 1460 | depends=common_depends |
|
1461 | 1461 | + [ |
|
1462 | 1462 | 'mercurial/cext/charencode.h', |
|
1463 | 1463 | 'mercurial/cext/revlog.h', |
|
1464 | 1464 | 'rust/hg-core/src/ancestors.rs', |
|
1465 | 1465 | 'rust/hg-core/src/lib.rs', |
|
1466 | 1466 | ], |
|
1467 | 1467 | ), |
|
1468 | 1468 | Extension( |
|
1469 | 1469 | 'mercurial.cext.osutil', |
|
1470 | 1470 | ['mercurial/cext/osutil.c'], |
|
1471 | 1471 | include_dirs=common_include_dirs, |
|
1472 | 1472 | extra_compile_args=osutil_cflags, |
|
1473 | 1473 | extra_link_args=osutil_ldflags, |
|
1474 | 1474 | depends=common_depends, |
|
1475 | 1475 | ), |
|
1476 | 1476 | Extension( |
|
1477 | 1477 | 'mercurial.thirdparty.zope.interface._zope_interface_coptimizations', |
|
1478 | 1478 | [ |
|
1479 | 1479 | 'mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c', |
|
1480 | 1480 | ], |
|
1481 | 1481 | ), |
|
1482 | 1482 | Extension( |
|
1483 | 1483 | 'hgext.fsmonitor.pywatchman.bser', ['hgext/fsmonitor/pywatchman/bser.c'] |
|
1484 | 1484 | ), |
|
1485 | 1485 | RustStandaloneExtension( |
|
1486 | 1486 | 'mercurial.rustext', 'hg-cpython', 'librusthg', py3_features='python3' |
|
1487 | 1487 | ), |
|
1488 | 1488 | ] |
|
1489 | 1489 | |
|
1490 | 1490 | |
|
1491 | 1491 | sys.path.insert(0, 'contrib/python-zstandard') |
|
1492 | 1492 | import setup_zstd |
|
1493 | 1493 | |
|
1494 | 1494 | extmodules.append( |
|
1495 | 1495 | setup_zstd.get_c_extension( |
|
1496 | 1496 | name='mercurial.zstd', root=os.path.abspath(os.path.dirname(__file__)) |
|
1497 | 1497 | ) |
|
1498 | 1498 | ) |
|
1499 | 1499 | |
|
1500 | 1500 | try: |
|
1501 | 1501 | from distutils import cygwinccompiler |
|
1502 | 1502 | |
|
1503 | 1503 | # the -mno-cygwin option has been deprecated for years |
|
1504 | 1504 | mingw32compilerclass = cygwinccompiler.Mingw32CCompiler |
|
1505 | 1505 | |
|
1506 | 1506 | class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler): |
|
1507 | 1507 | def __init__(self, *args, **kwargs): |
|
1508 | 1508 | mingw32compilerclass.__init__(self, *args, **kwargs) |
|
1509 | 1509 | for i in 'compiler compiler_so linker_exe linker_so'.split(): |
|
1510 | 1510 | try: |
|
1511 | 1511 | getattr(self, i).remove('-mno-cygwin') |
|
1512 | 1512 | except ValueError: |
|
1513 | 1513 | pass |
|
1514 | 1514 | |
|
1515 | 1515 | cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler |
|
1516 | 1516 | except ImportError: |
|
1517 | 1517 | # the cygwinccompiler package is not available on some Python |
|
1518 | 1518 | # distributions like the ones from the optware project for Synology |
|
1519 | 1519 | # DiskStation boxes |
|
1520 | 1520 | class HackedMingw32CCompiler(object): |
|
1521 | 1521 | pass |
|
1522 | 1522 | |
|
1523 | 1523 | |
|
1524 | 1524 | if os.name == 'nt': |
|
1525 | 1525 | # Allow compiler/linker flags to be added to Visual Studio builds. Passing |
|
1526 | 1526 | # extra_link_args to distutils.extensions.Extension() doesn't have any |
|
1527 | 1527 | # effect. |
|
1528 | 1528 | from distutils import msvccompiler |
|
1529 | 1529 | |
|
1530 | 1530 | msvccompilerclass = msvccompiler.MSVCCompiler |
|
1531 | 1531 | |
|
1532 | 1532 | class HackedMSVCCompiler(msvccompiler.MSVCCompiler): |
|
1533 | 1533 | def initialize(self): |
|
1534 | 1534 | msvccompilerclass.initialize(self) |
|
1535 | 1535 | # "warning LNK4197: export 'func' specified multiple times" |
|
1536 | 1536 | self.ldflags_shared.append('/ignore:4197') |
|
1537 | 1537 | self.ldflags_shared_debug.append('/ignore:4197') |
|
1538 | 1538 | |
|
1539 | 1539 | msvccompiler.MSVCCompiler = HackedMSVCCompiler |
|
1540 | 1540 | |
|
1541 | 1541 | packagedata = { |
|
1542 | 1542 | 'mercurial': [ |
|
1543 | 1543 | 'locale/*/LC_MESSAGES/hg.mo', |
|
1544 | 1544 | 'default.d/*.rc', |
|
1545 | 1545 | 'dummycert.pem', |
|
1546 | 1546 | ], |
|
1547 | 1547 | 'mercurial.helptext': ['*.txt',], |
|
1548 | 1548 | 'mercurial.helptext.internals': ['*.txt',], |
|
1549 | 1549 | } |
|
1550 | 1550 | |
|
1551 | 1551 | |
|
1552 | 1552 | def ordinarypath(p): |
|
1553 | 1553 | return p and p[0] != '.' and p[-1] != '~' |
|
1554 | 1554 | |
|
1555 | 1555 | |
|
1556 | 1556 | for root in ('templates',): |
|
1557 | 1557 | for curdir, dirs, files in os.walk(os.path.join('mercurial', root)): |
|
1558 | 1558 | curdir = curdir.split(os.sep, 1)[1] |
|
1559 | 1559 | dirs[:] = filter(ordinarypath, dirs) |
|
1560 | 1560 | for f in filter(ordinarypath, files): |
|
1561 | 1561 | f = os.path.join(curdir, f) |
|
1562 | 1562 | packagedata['mercurial'].append(f) |
|
1563 | 1563 | |
|
1564 | 1564 | datafiles = [] |
|
1565 | 1565 | |
|
1566 | 1566 | # distutils expects version to be str/unicode. Converting it to |
|
1567 | 1567 | # unicode on Python 2 still works because it won't contain any |
|
1568 | 1568 | # non-ascii bytes and will be implicitly converted back to bytes |
|
1569 | 1569 | # when operated on. |
|
1570 | 1570 | assert isinstance(version, bytes) |
|
1571 | 1571 | setupversion = version.decode('ascii') |
|
1572 | 1572 | |
|
1573 | 1573 | extra = {} |
|
1574 | 1574 | |
|
1575 | 1575 | py2exepackages = [ |
|
1576 | 1576 | 'hgdemandimport', |
|
1577 | 1577 | 'hgext3rd', |
|
1578 | 1578 | 'hgext', |
|
1579 | 1579 | 'email', |
|
1580 | 1580 | # implicitly imported per module policy |
|
1581 | 1581 | # (cffi wouldn't be used as a frozen exe) |
|
1582 | 1582 | 'mercurial.cext', |
|
1583 | 1583 | #'mercurial.cffi', |
|
1584 | 1584 | 'mercurial.pure', |
|
1585 | 1585 | ] |
|
1586 | 1586 | |
|
1587 | 1587 | py2exeexcludes = [] |
|
1588 | 1588 | py2exedllexcludes = ['crypt32.dll'] |
|
1589 | 1589 | |
|
1590 | 1590 | if issetuptools: |
|
1591 | 1591 | extra['python_requires'] = supportedpy |
|
1592 | 1592 | |
|
1593 | 1593 | if py2exeloaded: |
|
1594 | 1594 | extra['console'] = [ |
|
1595 | 1595 | { |
|
1596 | 1596 | 'script': 'hg', |
|
1597 | 1597 | 'copyright': 'Copyright (C) 2005-2019 Matt Mackall and others', |
|
1598 | 1598 | 'product_version': version, |
|
1599 | 1599 | } |
|
1600 | 1600 | ] |
|
1601 | 1601 | # Sub command of 'build' because 'py2exe' does not handle sub_commands. |
|
1602 | 1602 | # Need to override hgbuild because it has a private copy of |
|
1603 | 1603 | # build.sub_commands. |
|
1604 | 1604 | hgbuild.sub_commands.insert(0, ('build_hgextindex', None)) |
|
1605 | 1605 | # put dlls in sub directory so that they won't pollute PATH |
|
1606 | 1606 | extra['zipfile'] = 'lib/library.zip' |
|
1607 | 1607 | |
|
1608 | 1608 | # We allow some configuration to be supplemented via environment |
|
1609 | 1609 | # variables. This is better than setup.cfg files because it allows |
|
1610 | 1610 | # supplementing configs instead of replacing them. |
|
1611 | 1611 | extrapackages = os.environ.get('HG_PY2EXE_EXTRA_PACKAGES') |
|
1612 | 1612 | if extrapackages: |
|
1613 | 1613 | py2exepackages.extend(extrapackages.split(' ')) |
|
1614 | 1614 | |
|
1615 | 1615 | excludes = os.environ.get('HG_PY2EXE_EXTRA_EXCLUDES') |
|
1616 | 1616 | if excludes: |
|
1617 | 1617 | py2exeexcludes.extend(excludes.split(' ')) |
|
1618 | 1618 | |
|
1619 | 1619 | dllexcludes = os.environ.get('HG_PY2EXE_EXTRA_DLL_EXCLUDES') |
|
1620 | 1620 | if dllexcludes: |
|
1621 | 1621 | py2exedllexcludes.extend(dllexcludes.split(' ')) |
|
1622 | 1622 | |
|
1623 | 1623 | if os.name == 'nt': |
|
1624 | 1624 | # Windows binary file versions for exe/dll files must have the |
|
1625 | 1625 | # form W.X.Y.Z, where W,X,Y,Z are numbers in the range 0..65535 |
|
1626 | 1626 | setupversion = setupversion.split(r'+', 1)[0] |
|
1627 | 1627 | |
|
1628 | 1628 | if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'): |
|
1629 | 1629 | version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[1].splitlines() |
|
1630 | 1630 | if version: |
|
1631 | 1631 | version = version[0] |
|
1632 | 1632 | if sys.version_info[0] == 3: |
|
1633 | 1633 | version = version.decode('utf-8') |
|
1634 | 1634 | xcode4 = version.startswith('Xcode') and StrictVersion( |
|
1635 | 1635 | version.split()[1] |
|
1636 | 1636 | ) >= StrictVersion('4.0') |
|
1637 | 1637 | xcode51 = re.match(r'^Xcode\s+5\.1', version) is not None |
|
1638 | 1638 | else: |
|
1639 | 1639 | # xcodebuild returns empty on OS X Lion with XCode 4.3 not |
|
1640 | 1640 | # installed, but instead with only command-line tools. Assume |
|
1641 | 1641 | # that only happens on >= Lion, thus no PPC support. |
|
1642 | 1642 | xcode4 = True |
|
1643 | 1643 | xcode51 = False |
|
1644 | 1644 | |
|
1645 | 1645 | # XCode 4.0 dropped support for ppc architecture, which is hardcoded in |
|
1646 | 1646 | # distutils.sysconfig |
|
1647 | 1647 | if xcode4: |
|
1648 | 1648 | os.environ['ARCHFLAGS'] = '' |
|
1649 | 1649 | |
|
1650 | 1650 | # XCode 5.1 changes clang such that it now fails to compile if the |
|
1651 | 1651 | # -mno-fused-madd flag is passed, but the version of Python shipped with |
|
1652 | 1652 | # OS X 10.9 Mavericks includes this flag. This causes problems in all |
|
1653 | 1653 | # C extension modules, and a bug has been filed upstream at |
|
1654 | 1654 | # http://bugs.python.org/issue21244. We also need to patch this here |
|
1655 | 1655 | # so Mercurial can continue to compile in the meantime. |
|
1656 | 1656 | if xcode51: |
|
1657 | 1657 | cflags = get_config_var('CFLAGS') |
|
1658 | 1658 | if cflags and re.search(r'-mno-fused-madd\b', cflags) is not None: |
|
1659 | 1659 | os.environ['CFLAGS'] = ( |
|
1660 | 1660 | os.environ.get('CFLAGS', '') + ' -Qunused-arguments' |
|
1661 | 1661 | ) |
|
1662 | 1662 | |
|
1663 | 1663 | setup( |
|
1664 | 1664 | name='mercurial', |
|
1665 | 1665 | version=setupversion, |
|
1666 | 1666 | author='Matt Mackall and many others', |
|
1667 | 1667 | author_email='mercurial@mercurial-scm.org', |
|
1668 | 1668 | url='https://mercurial-scm.org/', |
|
1669 | 1669 | download_url='https://mercurial-scm.org/release/', |
|
1670 | 1670 | description=( |
|
1671 | 1671 | 'Fast scalable distributed SCM (revision control, version ' |
|
1672 | 1672 | 'control) system' |
|
1673 | 1673 | ), |
|
1674 | 1674 | long_description=( |
|
1675 | 1675 | 'Mercurial is a distributed SCM tool written in Python.' |
|
1676 | 1676 | ' It is used by a number of large projects that require' |
|
1677 | 1677 | ' fast, reliable distributed revision control, such as ' |
|
1678 | 1678 | 'Mozilla.' |
|
1679 | 1679 | ), |
|
1680 | 1680 | license='GNU GPLv2 or any later version', |
|
1681 | 1681 | classifiers=[ |
|
1682 | 1682 | 'Development Status :: 6 - Mature', |
|
1683 | 1683 | 'Environment :: Console', |
|
1684 | 1684 | 'Intended Audience :: Developers', |
|
1685 | 1685 | 'Intended Audience :: System Administrators', |
|
1686 | 1686 | 'License :: OSI Approved :: GNU General Public License (GPL)', |
|
1687 | 1687 | 'Natural Language :: Danish', |
|
1688 | 1688 | 'Natural Language :: English', |
|
1689 | 1689 | 'Natural Language :: German', |
|
1690 | 1690 | 'Natural Language :: Italian', |
|
1691 | 1691 | 'Natural Language :: Japanese', |
|
1692 | 1692 | 'Natural Language :: Portuguese (Brazilian)', |
|
1693 | 1693 | 'Operating System :: Microsoft :: Windows', |
|
1694 | 1694 | 'Operating System :: OS Independent', |
|
1695 | 1695 | 'Operating System :: POSIX', |
|
1696 | 1696 | 'Programming Language :: C', |
|
1697 | 1697 | 'Programming Language :: Python', |
|
1698 | 1698 | 'Topic :: Software Development :: Version Control', |
|
1699 | 1699 | ], |
|
1700 | 1700 | scripts=scripts, |
|
1701 | 1701 | packages=packages, |
|
1702 | 1702 | ext_modules=extmodules, |
|
1703 | 1703 | data_files=datafiles, |
|
1704 | 1704 | package_data=packagedata, |
|
1705 | 1705 | cmdclass=cmdclass, |
|
1706 | 1706 | distclass=hgdist, |
|
1707 | 1707 | options={ |
|
1708 | 1708 | 'py2exe': { |
|
1709 | 1709 | 'bundle_files': 3, |
|
1710 | 1710 | 'dll_excludes': py2exedllexcludes, |
|
1711 | 1711 | 'excludes': py2exeexcludes, |
|
1712 | 1712 | 'packages': py2exepackages, |
|
1713 | 1713 | }, |
|
1714 | 1714 | 'bdist_mpkg': { |
|
1715 | 1715 | 'zipdist': False, |
|
1716 | 1716 | 'license': 'COPYING', |
|
1717 | 1717 | 'readme': 'contrib/packaging/macosx/Readme.html', |
|
1718 | 1718 | 'welcome': 'contrib/packaging/macosx/Welcome.html', |
|
1719 | 1719 | }, |
|
1720 | 1720 | }, |
|
1721 | 1721 | **extra |
|
1722 | 1722 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now