aboutsummaryrefslogtreecommitdiffstats
path: root/build/f_repos/Makefile
diff options
context:
space:
mode:
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>2016-09-24 17:27:16 +0200
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>2016-10-05 21:44:58 +0200
commit6de5bac371844b70b96b9bd75b62b8d06e5f51fc (patch)
tree7105db6f62d236c91130d47283842aa4a6f16156 /build/f_repos/Makefile
parent49f066e78e52fde9ce0d467a838211270f518591 (diff)
build: Use git submodules for Fuel git repos
This change reworks support for cloning (fetching) and patching all Fuel components (fuel-library ... fuel-ui, see [1] for full list), both outside the ISO build process (for development purposes, like testing OPNFV patches apply cleanly to each component), and during the ISO build. The implementation relies heavily on git submodules and patches, so backporting pending upstream gerrit changes, as well as adding new out-of-upstream-tree patches, should be trivial. Also, since without tracking remotes the repos rarely change, leverage the in-place OPNFV build caching mechanism to drastically reduce the number of git clones during each build. The mechanism is detailed more in-depth in the JIRA ticket [3], and it's merely a rehash of the submodule handling in Armband, implemented initially by Stanislaw Kardach <stanislaw.kardach@cavium.com>. Pros (+ new features): - OPNFV patches for Fuel components can be applied (imported) or developed (exported) outside of the ISO build process; - git repo caching reduces the number of external pulls; - reuse the same fuel-* componets in ALL targets e.g. fuel-mirror used to employ 2 slightly different git trees; - one step closer to Fuel/Armband merge (lots of steps left though); Cons: - adds a lot complexity to solve a non-problem (handling the repos is fine in the current form, for the current goals); However, patching <fuel-astute> or <fuel-agent> seems to be quite complicated with the current mechanism, as env vars override our locally patched repos for these components). The proposed change should eliminate this issue completely. CHANGE: Aligned divergent fuel-mirror in ISO vs local repo build by applying the 302 redirect fix ("Fixed handling http redirects") [2] on top of 9.0.1 tag in fuel-mirror repo, and using that for both. This obsoleted the followking mk file: - build/f_isoroot/f_repobuild/config.mk CHANGE: Removed unused make target `get-fuel-repo` from build/config.mk. FIXME: Remote tracking is currently deactivated for all branches. Change this when remote HEAD should be tracked instead, e.g. during Newton rebase. [1] https://github.com/openstack/fuel-main/blob/stable/mitaka/repos.mk#L32 [2] https://review.openstack.org/#/c/334882/ [3] https://jira.opnfv.org/browse/FUEL-200 TODO: Extend build/f_repos/README.md with info about: - branch changes; - tag bumps; - patching now supports subdirs; v5 -> v6: * Added support for nesting patches in subdirs, to be used for feature groups and related changes across submodules. E.g. Upcoming multiarch EFI support could go in: - .../f_repos/patch/fuel-agent/multiarch-efi/...; - .../f_repos/patch/fuel-astute/multiarch-efi/...; While Armband patches could go in: - .../f_repos/patch/fuel-agent/armband/...; - .../f_repos/patch/fuel-astute/armband/...; etc. v6 -> v13: * fix wrong tag used for VERSION dump; * fix wrong tag used for patches-export; * move OPNFV_TAG to main config.mk and use it in FUEL_*_COMMIT; * only run `patches-import` when patches changed / not yet applied; * only run `clean` for stale `.cacheid` (avoid re-applying patches); * allow git submodule path/name to be different (FIXED); * put-cache should only run when artifact is not already cached; * `git am`: use 3-way merge so already applied patches are gently skipped (useful for upstreaming patches from Armband); * Properly support nested patch dirs; * Colorize the output a little; JIRA: FUEL-200 Change-Id: I9dbdd9b3022896d4497d21be8dacc859730db489 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Diffstat (limited to 'build/f_repos/Makefile')
-rw-r--r--build/f_repos/Makefile165
1 files changed, 165 insertions, 0 deletions
diff --git a/build/f_repos/Makefile b/build/f_repos/Makefile
new file mode 100644
index 000000000..66abf2d71
--- /dev/null
+++ b/build/f_repos/Makefile
@@ -0,0 +1,165 @@
+##############################################################################
+# Copyright (c) 2015,2016 Ericsson AB, Enea AB and others.
+# stefan.k.berg@ericsson.com
+# jonas.bjurel@ericsson.com
+# Alexandru.Avadanii@enea.com
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+SHELL = /bin/bash
+REPOINFO = $(shell readlink -e ../repo_info.sh)
+FREPODIR = $(shell pwd)
+FPATCHES = $(shell find ${F_PATCH_DIR} -name '*.patch')
+
+include ../config.mk
+
+# NOTE: Mechanism overview is presented in ./README.md.
+
+# Submodule consistent states:
+# - NOT initialized (submodule trees are not populated at all);
+# - initialized, bound to saved commits;
+# - initialized, tracking remote origin (only for FUEL_TRACK_REMOTES);
+# - patched (local patches are applied);
+
+# In order to keep things sort of separate, we should only pass up (to main
+# Makefile) the fully-pactched repos, and gather any fingerprinting info here.
+
+# Fuel@OPNFV relies on upstream git repos (one per component) in 1 of 2 ways:
+# - pinned down to tag objects (e.g. "9.0.1")
+# - tracking upstream remote HEAD on a stable or master branch
+# FIXME(alav): Should we support mixed cases? (e.g. pin down only fuel-main)
+
+# To enable remote tracking, set the following var to any non-empty string.
+# Leaving this var empty will bind each git submodule to its saved commit.
+# NOTE: For non-stable branches, unless overriden, always track remotes
+FUEL_TRACK_REMOTES ?= $(shell git symbolic-ref --short HEAD | grep -v stable)
+
+.PHONY: all
+all: release
+
+##############################################################################
+# git submodule operations - to be used stand-alone or from parent Makefile
+##############################################################################
+
+# Fetch & update git submodules, checkout remote HEAD or saved commit
+# Also gather fingerprints for parent gitinfo_fuel.txt.
+.PHONY: sub
+sub: .cachefuelinfo
+
+.cachefuelinfo:
+ @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
+ git submodule update --init --remote; \
+ else \
+ git submodule update --init; \
+ fi
+ @rm -f $@
+ @git submodule -q foreach '${REPOINFO} . >> ${FREPODIR}/$@'
+
+# Generate patches from submodules
+.PHONY: patches-export
+patches-export: sub
+ @git submodule -q foreach ' \
+ SUB_DIR=${F_PATCH_DIR}/$$name; \
+ git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
+ SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
+ echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
+ mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
+ git format-patch --no-signature --ignore-space-at-eol \
+ -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
+ done'
+ @sed -i -e '1d' -e 's/[[:space:]]*$$//' ${FPATCHES}
+
+# Apply patches from patch/* to respective submodules
+# We rely on `make sub` and/or `make clean` to checkout correct base
+.PHONY: patches-import
+patches-import: sub .cachepatched
+
+.cachepatched: ${FPATCHES}
+ @$(MAKE) clean
+ @git submodule -q foreach ' \
+ SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
+ git tag ${F_OPNFV_TAG}-root && \
+ git checkout -q -b opnfv-fuel && \
+ find $$SUB_DIR -type d | sort | while read p_dir; do \
+ SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
+ if [ -n "$$SUB_PATCHES" ]; then \
+ SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
+ SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
+ echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
+ git tag $$SUB_TAG-root && git am -3 --whitespace=nowarn \
+ --committer-date-is-author-date $$SUB_PATCHES && \
+ git tag $$SUB_TAG || exit 1; \
+ fi \
+ done && \
+ git tag ${F_OPNFV_TAG}'
+ @touch $@
+
+# Clean any changes made to submodules, checkout upstream Fuel root commit
+.PHONY: clean
+clean:
+ @git submodule -q foreach ' \
+ git am -q --abort > /dev/null 2>&1; \
+ git checkout -q ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
+ git branch -q -D opnfv-fuel > /dev/null 2>&1; \
+ git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
+ git reset -q --hard HEAD; \
+ git clean -xdff'
+ @rm -f .cachepatched
+
+.PHONY: deepclean
+deepclean: clean clean-cache
+ @git submodule deinit -f .
+ @rm -f .cache*
+
+.PHONY: release
+release: sub
+ # Store artifact in cache straight away if caching is enabled
+ # (no .cacheid will be present unless this is a cached build)
+ test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
+ # NOTE: Patches are not included in cache
+ $(MAKE) -f Makefile patches-import
+
+##############################################################################
+# Cache operations - only used when building through ci/build.sh
+##############################################################################
+
+# NOTE: Current method of collecting submodule refs requires submodules to be
+# NOT initialized <OR> NO patches applied.
+# NOTE: Querying `git submodule status` from parent will show the patched tree.
+# Create a unique hash to be used for getting and putting cache, based on:
+# - git submodule SHAs, collected with `git submodule status`
+# - The contents of this Makefile
+.cacheid:
+ @$(MAKE) clean
+ sha1sum Makefile > .cachedata
+ git submodule status | cut -c2-41 >> .cachedata
+ cat .cachedata | $(CACHETOOL) getid > .cacheid
+
+# Clean local data related to caching - called prior to ordinary build
+.PHONY: clean-cache
+clean-cache: clean
+ rm -f .cachedata .cacheid
+
+# Try to download cache - called prior to ordinary build
+.PHONY: get-cache
+get-cache: .cacheid
+ @if $(CACHETOOL) check $(shell cat .cacheid); then \
+ $(MAKE) clean && \
+ $(CACHETOOL) get $(shell cat .cacheid) | \
+ tar xf - -C ${F_GIT_ROOT}/.git; \
+ else \
+ echo "No cache item found for $(shell cat .cacheid)" ;\
+ exit 0;\
+ fi
+
+# Store cache if not already stored - called after ordinary build
+.PHONY: put-cache
+put-cache: .cacheid
+ @if ! $(CACHETOOL) check $(shell cat .cacheid); then \
+ $(MAKE) clean && \
+ tar cf - -C ${F_GIT_ROOT}/.git modules | \
+ $(CACHETOOL) put $(shell cat .cacheid); \
+ fi