Skip to content

Commit ca123a0

Browse files
prilrazheregelya
authored andcommitted
Add sync-sources target to the Makefile to deploy repo files to system leapp paths
1 parent e7ffe6e commit ca123a0

1 file changed

Lines changed: 63 additions & 1 deletion

File tree

Makefile

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ _COPR_REPO=$${COPR_REPO:-leapp}
4747
_COPR_REPO_TMP=$${COPR_REPO_TMP:-leapp-tmp}
4848
_COPR_CONFIG=$${COPR_CONFIG:-~/.config/copr_rh_oamg.conf}
4949

50+
# Paths used by `make sync-sources` to deploy the in-repo sources
51+
# to the system locations, matching the %install section of packaging/leapp-repository.spec.
52+
# Override on the command line if needed.
53+
SYNC_LEAPP_DATADIR ?= /usr/share/leapp-repository
54+
SYNC_REPOSITORYDIR ?= $(SYNC_LEAPP_DATADIR)/repositories
55+
SYNC_CUSTOM_REPOSITORYDIR ?= $(SYNC_LEAPP_DATADIR)/custom-repositories
56+
SYNC_LEAPP_SYSCONFDIR ?= /etc/leapp
57+
# rhel7 keeps el7toel8 (and uses python2); rhel8+ keeps el8toel9 (python3).
58+
SYNC_RHEL_MAJOR ?= $(shell rpm -E %{rhel} 2>/dev/null)
59+
SYNC_PYTHON_BIN ?= $(shell if [ "$(SYNC_RHEL_MAJOR)" = "7" ]; then echo /usr/bin/python2; else echo /usr/bin/python3; fi)
60+
# Resolve the system sitelib, bypassing any active virtualenv (make is often
61+
# invoked from an activated `tut/` venv in this repo, which would otherwise
62+
# point SYNC_PYTHON_SITELIB at the venv instead of the system location).
63+
SYNC_PYTHON_SITELIB ?= $(shell env -u VIRTUAL_ENV -u PYTHONPATH -u PYTHONHOME $(SYNC_PYTHON_BIN) -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])' 2>/dev/null)
64+
SYNC_LEAPP_CLI_DIR ?= $(SYNC_PYTHON_SITELIB)/leapp/cli/commands
65+
5066
# tool used to run containers for testing and building packages
5167
_CONTAINER_TOOL=$${CONTAINER_TOOL:-podman}
5268

@@ -105,6 +121,10 @@ help:
105121
@echo " help show this text"
106122
@echo " clean clean the mess"
107123
@echo " prepare clean the mess and prepare dirs"
124+
@echo " sync-sources deploy repo sources into system paths"
125+
@echo " (mirrors the spec %install section,"
126+
@echo " no rpmbuild). Requires the leapp"
127+
@echo " package to be installed."
108128
@echo " print_release print release how it should look like with"
109129
@echo " with the given parameters"
110130
@echo " source create the source tarball suitable for"
@@ -183,6 +203,48 @@ prepare: clean
183203
@echo "--- Prepare build directories ---"
184204
@mkdir -p packaging/{sources,SRPMS,BUILD,BUILDROOT,RPMS}/
185205
206+
# Deploy the in-repo sources to the system paths where the installed
207+
# leapp-upgrade-* rpm places them. Lets a developer iterate on actors
208+
# without rebuilding/reinstalling the package.
209+
# Mirrors packaging/leapp-repository.spec %install; does not strip tests or
210+
# Makefiles (harmless at runtime, useful for development).
211+
sync-sources:
212+
@echo "--- Syncing leapp-repository sources to system paths ---"
213+
@if [[ -z "$(SYNC_PYTHON_SITELIB)" ]] || [[ ! -d "$(SYNC_PYTHON_SITELIB)/leapp" ]]; then \
214+
echo "ERROR: leapp python sitelib not found (looked at '$(SYNC_PYTHON_SITELIB)')."; \
215+
echo "Install the leapp package (e.g. leapp-upgrade-el8toel9) on this host first."; \
216+
exit 1; \
217+
fi
218+
@install -m 0755 -d $(SYNC_REPOSITORYDIR) $(SYNC_CUSTOM_REPOSITORYDIR)
219+
@install -m 0755 -d $(SYNC_LEAPP_SYSCONFDIR)/repos.d \
220+
$(SYNC_LEAPP_SYSCONFDIR)/transaction \
221+
$(SYNC_LEAPP_SYSCONFDIR)/files
222+
@echo "--- repos/* -> $(SYNC_REPOSITORYDIR)/ ---"
223+
@cp -rf repos/common $(SYNC_REPOSITORYDIR)/
224+
@cp -rf repos/system_upgrade $(SYNC_REPOSITORYDIR)/
225+
@if [[ "$(SYNC_RHEL_MAJOR)" == "7" ]]; then \
226+
rm -rf $(SYNC_REPOSITORYDIR)/system_upgrade/el8toel9; \
227+
else \
228+
rm -rf $(SYNC_REPOSITORYDIR)/system_upgrade/el7toel8; \
229+
fi
230+
@echo "--- etc/leapp/transaction/* -> $(SYNC_LEAPP_SYSCONFDIR)/transaction/ ---"
231+
@install -m 0644 etc/leapp/transaction/* $(SYNC_LEAPP_SYSCONFDIR)/transaction/
232+
@echo "--- commands/* -> $(SYNC_LEAPP_CLI_DIR)/ ---"
233+
@install -m 0755 -d $(SYNC_LEAPP_CLI_DIR)
234+
@cp -rf commands/. $(SYNC_LEAPP_CLI_DIR)/
235+
@rm -rf $(SYNC_LEAPP_CLI_DIR)/tests
236+
@echo "--- Refresh /etc/leapp/repos.d symlinks ---"
237+
@for d in $$(find $(SYNC_REPOSITORYDIR)/ -mindepth 1 -maxdepth 1 -type d); do \
238+
name=$$(basename $$d); \
239+
ln -sfn $$d $(SYNC_LEAPP_SYSCONFDIR)/repos.d/$$name; \
240+
done
241+
@echo "--- Purge stale .pyc cache under synced paths ---"
242+
@find $(SYNC_REPOSITORYDIR) $(SYNC_LEAPP_CLI_DIR) \
243+
-name '__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true
244+
@find $(SYNC_REPOSITORYDIR) $(SYNC_LEAPP_CLI_DIR) \
245+
-name '*.pyc' -delete 2>/dev/null || true
246+
@echo "--- sync-sources done ---"
247+
186248
source: prepare
187249
@echo "--- Create source tarball ---"
188250
@echo git archive --prefix "$(PKGNAME)-$(VERSION)/" -o "packaging/sources/$(PKGNAME)-$(VERSION).tar.gz" HEAD
@@ -519,5 +581,5 @@ dashboard_data:
519581
$(_PYTHON_VENV) ../../../utils/dashboard-json-dump.py > ../../../discover.json; \
520582
popd
521583
522-
.PHONY: help build clean prepare source srpm copr_build _build_local build_container print_release register install-deps install-deps-fedora lint test_no_lint test dashboard_data fast_lint
584+
.PHONY: help build clean prepare sync-sources source srpm copr_build _build_local build_container print_release register install-deps install-deps-fedora lint test_no_lint test dashboard_data fast_lint
523585
.PHONY: test_container test_container_no_lint test_container_all test_container_all_no_lint clean_containers _build_container_image _test_container_ipu dev_test_no_lint

0 commit comments

Comments
 (0)