Debian Codegraph @

Makefile

raw
1 # If you want to change PREFIX, do not just edit it below. The changed
2 # value wont get passed on to recursive make calls. You should instead
3 # override the variable on the command like:
4 #
5 # % make PREFIX=/opt/ install
6
7 export PREFIX=/usr/local
8
9 # Default to Python 3.
10 #
11 # Windows ships Python 3 as `python.exe`, which may not be on PATH. py.exe is.
12 ifeq ($(OS),Windows_NT)
13 PYTHON?=py -3
14 EXE:=.exe
15 else
16 PYTHON?=python3
17 EXE:=
18 endif
19
20 # to support PYTHON equal to "py -3", "py.exe -3", "3.13" and other strings
21 ifneq (,$(findstring py ,$(PYTHON)))
22 PYTHON_FOR_UV=$(shell $(PYTHON) -c "import sys; print(sys.executable)")
23 else
24 PYTHON_FOR_UV=$(PYTHON)
25 endif
26 ifneq (,$(findstring py.exe ,$(PYTHON)))
27 PYTHON_FOR_UV=$(shell $(PYTHON) -c "import sys; print(sys.executable)")
28 endif
29
30 PYOXIDIZER?=pyoxidizer
31
32 $(eval HGROOT := $(shell pwd))
33 HGPYTHONS ?= $(HGROOT)/build/pythons
34 PURE=
35 OFFLINE=
36
37 ifeq ($(OFFLINE),1)
38 OFFLINE_UV_OPTION=--offline
39 CARGO_NET_OFFLINE?=true
40 else
41 OFFLINE_UV_OPTION=
42 CARGO_NET_OFFLINE?=false
43 endif
44
45 PIP_OPTIONS_PURE=--config-settings --global-option="$(PURE)"
46 PIP_OPTIONS_INSTALL=--no-deps --ignore-installed --no-build-isolation
47 PIP_PREFIX=$(PREFIX)
48 PYFILESCMD=find mercurial hgext doc -name '*.py'
49 PYFILES:=$(shell $(PYFILESCMD))
50 DOCFILES=mercurial/helptext/*.txt
51 export LANGUAGE=C
52 export LC_ALL=C
53 TESTFLAGS ?= $(shell echo $$HGTESTFLAGS)
54 CARGO = cargo
55
56 PYBINDIRNAME=$(shell $(PYTHON) -c "import os; print('Scripts' if os.name == 'nt' else 'bin')")
57
58 .PHONY: help
59 help:
60 @echo 'Commonly used make targets:'
61 @echo ' install - install program and man pages to $$PREFIX ($(PREFIX))'
62 @echo ' install-home - install with pip install --user'
63 @echo ' local - build for inplace usage'
64 @echo ' tests - run all tests in the automatic test suite'
65 @echo ' test-foo - run only specified tests (e.g. test-merge1.t)'
66 @echo ' dist - run all tests and create a source tarball in dist/'
67 @echo ' clean - remove files created by other targets'
68 @echo ' (except installed files or dist source tarball)'
69 @echo ' update-pot - update i18n/hg.pot'
70 @echo
71 @echo 'See CONTRIBUTING.md for the build and development dependencies.'
72 @echo
73 @echo 'Example for a system-wide installation under /usr/local for'
74 @echo 'downstream packaging (build and runtime deps have to be installed by hand)'
75 @echo ' su -c "make install" && hg version'
76 @echo
77 @echo 'Example for a system-wide installation under /usr/local:'
78 @echo ' make doc'
79 @echo ' su -c "make install PIP_OPTIONS_INSTALL=" && hg version'
80 @echo
81 @echo 'On some Linux distributions, you might need to specify both'
82 @echo 'PREFIX and PIP_PREFIX (here to install everything in /data/local)'
83 @echo ' make install PREFIX=/data/local PIP_PREFIX=/data PIP_OPTIONS_INSTALL='
84 @echo
85 @echo 'Example for a local installation (usable in this directory):'
86 @echo ' make local && ./hg-local version'
87 @echo
88 @echo 'Example for a local installation in offline mode:'
89 @echo ' make local OFFLINE=1'
90
91 .PHONY: local
92 local:
93 uv venv -p $(PYTHON_FOR_UV) .local-venv --clear --system-site-packages
94 env CARGO_NET_OFFLINE=$(CARGO_NET_OFFLINE) uv pip install -e . $(OFFLINE_UV_OPTION) \
95 -p .local-venv/$(PYBINDIRNAME)/python$(EXE) \
96 -C=--global-option="$(PURE)"
97 env HGRCPATH= .local-venv/$(PYBINDIRNAME)/hg$(EXE) version
98 test -e .local-venv/$(PYBINDIRNAME)/hg$(EXE) && ln -s -f .local-venv/$(PYBINDIRNAME)/hg$(EXE) hg-local$(EXE)
99
100 .PHONY: build-chg
101 build-chg:
102 make -C contrib/chg
103
104 .PHONY: build-rhg
105 build-rhg:
106 (cd rust/rhg; cargo build --release --features "$(HG_RUST_FEATURES)")
107
108 .PHONY: wheel
109 wheel:
110 $(PYTHON) -m build --config-setting=--global-option="$(PURE)"
111 .PHONY: doc
112 doc:
113 $(MAKE) -C doc
114
115 .PHONY: cleanbutpackages
116 cleanbutpackages:
117 rm -f hg.exe
118 rm -rf mercurial.egg-info
119 find contrib doc hgext hgext3rd i18n mercurial tests hgdemandimport \
120 \( -name '*.py[cdo]' -o -name '*.so' \) -exec rm -f '{}' ';'
121 rm -rf .local-venv
122 rm -f hg-local$(EXE)
123 rm -f hgext/__index__.py tests/*.err
124 rm -f mercurial/__modulepolicy__.py
125 if test -d .hg; then rm -f mercurial/__version__.py; fi
126 rm -rf build mercurial/locale
127 $(MAKE) -C doc clean
128 $(MAKE) -C contrib/chg distclean
129 rm -rf rust/target
130
131 .PHONY: clean
132 clean: cleanbutpackages
133 rm -rf packages
134
135 .PHONY: install
136 install: install-bin install-doc
137
138 .PHONY: install-bin
139 install-bin:
140 $(PYTHON) -m pip install . --prefix="$(PIP_PREFIX)" --force -v $(PIP_OPTIONS_PURE) $(PIP_OPTIONS_INSTALL)
141
142 .PHONY: install-chg
143 install-chg: build-chg
144 make -C contrib/chg install PREFIX="$(PREFIX)"
145
146 .PHONY: install-doc
147 install-doc:
148 $(MAKE) -C doc $(MFLAGS) PREFIX="$(PREFIX)" install
149
150 .PHONY: install-home
151 install-home: install-home-bin install-home-doc
152
153 .PHONY: install-home-bin
154 install-home-bin:
155 $(PYTHON) -m pip install . --user --force -v $(PIP_OPTIONS_PURE) $(PIP_OPTIONS_INSTALL)
156
157 .PHONY: install-home-doc
158 install-home-doc:
159 $(MAKE) -C doc $(MFLAGS) PREFIX="$(HOME)" install
160
161 .PHONY: install-rhg
162 install-rhg: build-rhg
163 install -m 755 rust/target/release/rhg "$(PREFIX)"/bin/
164
165 .PHONY: dist
166 dist: tests dist-notests
167
168 .PHONY: dist-notests
169 dist-notests: doc
170 TAR_OPTIONS="--owner=root --group=root --mode=u+w,go-w,a+rX-s" $(PYTHON) -m build --sdist
171
172 .PHONY: check
173 check: tests
174
175 .PHONY: tests
176 tests:
177 # Run Rust tests if cargo is installed
178 if command -v $(CARGO) >/dev/null 2>&1; then \
179 $(MAKE) rust-tests; \
180 $(MAKE) cargo-clippy; \
181 fi
182 cd tests && $(PYTHON) run-tests.py $(TESTFLAGS)
183
184 .PHONY: test-%
185 test-%:
186 cd tests && $(PYTHON) run-tests.py $(TESTFLAGS) $@
187
188 .PHONY: testpy-%
189 testpy-%:
190 @echo Looking for Python $* in $(HGPYTHONS)
191 [ -e $(HGPYTHONS)/$*/bin/python ] || ( \
192 cd $$(mktemp --directory --tmpdir) && \
193 $(MAKE) -f $(HGROOT)/contrib/Makefile.python PYTHONVER=$* PREFIX=$(HGPYTHONS)/$* python )
194 cd tests && $(HGPYTHONS)/$*/bin/python run-tests.py $(TESTFLAGS)
195
196 .PHONY: rust-tests
197 rust-tests:
198 cd $(HGROOT)/rust \
199 && $(CARGO) test --quiet --all \
200 --features "full-tracing" --no-default-features \
201 && $(CARGO) test --quiet --all --no-default-features
202
203 .PHONY: cargo-clippy
204 cargo-clippy:
205 cd $(HGROOT)/rust \
206 && $(CARGO) clippy --all -- -D warnings \
207 && $(CARGO) clippy --all --features "full-tracing" -- -D warnings
208
209 .PHONY: check-code
210 check-code:
211 hg manifest | xargs python contrib/check-code.py
212
213 .PHONY: setup-format
214 setup-format: .hg/dev-tools/fix-conf.rc
215
216 # the format target exist as an entry point for new devs, but it is expected
217 # that they run `hg fix` directly.
218 .PHONY: format-wdir
219 format-wdir: .hg/dev-tools/fix-conf.rc
220 hg --config extensions.fix= fix --working-dir
221
222 # requires topic to have a stack in the first place.
223 .PHONY: format-stack
224 format-stack: .hg/dev-tools/fix-conf.rc
225 hg --config extensions.fix= fix --rev ".#stack" --rev "wdir()"
226
227 .hg/dev-tools/fix-conf.rc: contrib/fix-conf.rc contrib/setup-dev-tool.sh
228 ./contrib/setup-dev-tool.sh
229
230 .PHONY: format-c
231 format-c:
232 clang-format --style file -i \
233 `hg files 'set:(**.c or **.cc or **.h) and not "listfile:contrib/clang-format-ignorelist"'`
234
235 .PHONY: update-pot
236 update-pot: i18n/hg.pot
237
238 i18n/hg.pot: $(PYFILES) $(DOCFILES) i18n/posplit i18n/hggettext
239 $(PYTHON) i18n/hggettext mercurial/commands.py \
240 hgext/*.py hgext/*/__init__.py \
241 mercurial/fileset.py mercurial/revset.py \
242 mercurial/templatefilters.py \
243 mercurial/templatefuncs.py \
244 mercurial/templatekw.py \
245 mercurial/filemerge.py \
246 mercurial/hgweb/webcommands.py \
247 mercurial/util.py \
248 $(DOCFILES) > i18n/hg.pot.tmp
249 # All strings marked for translation in Mercurial contain
250 # ASCII characters only. But some files contain string
251 # literals like this '\037\213'. xgettext thinks it has to
252 # parse them even though they are not marked for translation.
253 # Extracting with an explicit encoding of ISO-8859-1 will make
254 # xgettext "parse" and ignore them.
255 $(PYFILESCMD) | xargs \
256 xgettext --package-name "Mercurial" \
257 --msgid-bugs-address "<[email protected]>" \
258 --copyright-holder "Olivia Mackall <[email protected]> and others" \
259 --from-code ISO-8859-1 --join --sort-by-file --add-comments=i18n: \
260 -d hg -p i18n -o hg.pot.tmp
261 $(PYTHON) i18n/posplit i18n/hg.pot.tmp
262 # The target file is not created before the last step. So it never is in
263 # an intermediate state.
264 mv -f i18n/hg.pot.tmp i18n/hg.pot
265
266 %.po: i18n/hg.pot
267 # work on a temporary copy for never having a half completed target
268 cp $@ [email protected]
269 msgmerge --no-location --update [email protected] $^
270 mv -f [email protected] $@
271
272 # Packaging targets
273
274 packaging_targets := \
275 rhel7 \
276 rhel8 \
277 rhel9 \
278 rhel10 \
279 deb \
280 docker-rhel7 \
281 docker-rhel8 \
282 docker-rhel9 \
283 docker-rhel10 \
284 docker-debian-bullseye \
285 docker-debian-buster \
286 docker-debian-stretch \
287 docker-fedora \
288 docker-ubuntu-xenial \
289 docker-ubuntu-xenial-ppa \
290 docker-ubuntu-bionic \
291 docker-ubuntu-bionic-ppa \
292 docker-ubuntu-focal \
293 docker-ubuntu-focal-ppa \
294 fedora \
295 linux-wheels \
296 linux-wheels-x86_64 \
297 linux-wheels-x86_64-musl \
298 linux-wheels-i686 \
299 linux-wheels-i686-musl \
300 ppa
301
302 # Forward packaging targets for convenience.
303 .PHONY: $(packaging_targets)
304 $(packaging_targets):
305 $(MAKE) -C contrib/packaging $(MAKEFLAGS) $@
306
307
308 .PHONY: pyoxidizer
309 pyoxidizer:
310 $(PYOXIDIZER) build --path ./rust/hgcli --release
311
312
313 # a temporary target to setup all we need for run-tests.py --pyoxidizer
314 # (should go away as the run-tests implementation improves
315 .PHONY: pyoxidizer-windows-tests
316 pyoxidizer-windows-tests: PYOX_DIR=build/pyoxidizer/x86_64-pc-windows-msvc/release/app
317 pyoxidizer-windows-tests: pyoxidizer
318 rm -rf $(PYOX_DIR)/templates
319 cp -ar $(PYOX_DIR)/lib/mercurial/templates $(PYOX_DIR)/templates
320 rm -rf $(PYOX_DIR)/helptext
321 cp -ar $(PYOX_DIR)/lib/mercurial/helptext $(PYOX_DIR)/helptext
322 rm -rf $(PYOX_DIR)/defaultrc
323 cp -ar $(PYOX_DIR)/lib/mercurial/defaultrc $(PYOX_DIR)/defaultrc
324 rm -rf $(PYOX_DIR)/contrib
325 cp -ar contrib $(PYOX_DIR)/contrib
326 rm -rf $(PYOX_DIR)/doc
327 cp -ar doc $(PYOX_DIR)/doc
328
329
330 # a temporary target to setup all we need for run-tests.py --pyoxidizer
331 # (should go away as the run-tests implementation improves
332 .PHONY: pyoxidizer-macos-tests
333 pyoxidizer-macos-tests: PYOX_DIR=build/pyoxidizer/x86_64-apple-darwin/release/app
334 pyoxidizer-macos-tests: pyoxidizer
335 rm -rf $(PYOX_DIR)/templates
336 cp -a mercurial/templates $(PYOX_DIR)/templates
337 rm -rf $(PYOX_DIR)/helptext
338 cp -a mercurial/helptext $(PYOX_DIR)/helptext
339 rm -rf $(PYOX_DIR)/defaultrc
340 cp -a mercurial/defaultrc $(PYOX_DIR)/defaultrc
341 rm -rf $(PYOX_DIR)/contrib
342 cp -a contrib $(PYOX_DIR)/contrib
343 rm -rf $(PYOX_DIR)/doc
344 cp -a doc $(PYOX_DIR)/doc
345
346 .PHONY: pytype-docker
347 pytype-docker:
348 contrib/docker/pytype/recipe.sh
349
350 .PHONY: pytype-graph-docker
351 pytype-graph-docker:
352 contrib/docker/pytype/recipe.sh --import-graph