1 ##############################################################################
2 # Copyright (c) 2015,2016 Ericsson AB, Enea AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # Alexandru.Avadanii@enea.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
13 REPOINFO = $(shell readlink -e ../repo_info.sh)
14 FREPODIR = $(shell pwd)
15 FPATCHES = $(shell find ${F_PATCH_DIR} -name '*.patch')
19 # NOTE: Mechanism overview is presented in ./README.md.
21 # Submodule consistent states:
22 # - NOT initialized (submodule trees are not populated at all);
23 # - initialized, bound to saved commits;
24 # - initialized, tracking remote origin (only for FUEL_TRACK_REMOTES);
25 # - patched (local patches are applied);
27 # In order to keep things sort of separate, we should only pass up (to main
28 # Makefile) the fully-pactched repos, and gather any fingerprinting info here.
30 # Fuel@OPNFV relies on upstream git repos (one per component) in 1 of 2 ways:
31 # - pinned down to tag objects (e.g. "9.0.1")
32 # - tracking upstream remote HEAD on a stable or master branch
33 # FIXME(alav): Should we support mixed cases? (e.g. pin down only fuel-main)
35 # To enable remote tracking, set the following var to any non-empty string.
36 # Leaving this var empty will bind each git submodule to its saved commit.
37 # NOTE: For non-stable branches, unless overriden, always track remotes
38 FUEL_TRACK_REMOTES ?= $(shell git symbolic-ref --short HEAD | grep -v stable)
43 ##############################################################################
44 # git submodule operations - to be used stand-alone or from parent Makefile
45 ##############################################################################
47 # Fetch & update git submodules, checkout remote HEAD or saved commit
48 # Also gather fingerprints for parent gitinfo_fuel.txt.
53 @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
54 git submodule update --init --remote; \
56 git submodule update --init; \
59 @git submodule -q foreach '${REPOINFO} . >> ${FREPODIR}/$@'
61 # Generate patches from submodules
62 .PHONY: patches-export
64 @git submodule -q foreach ' \
65 SUB_DIR=${F_PATCH_DIR}/$$name; \
66 git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
67 SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
68 echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
69 mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
70 git format-patch --no-signature --ignore-space-at-eol \
71 -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
73 @sed -i -e '1d' -e 's/[[:space:]]*$$//' ${FPATCHES}
75 # Apply patches from patch/* to respective submodules
76 # We rely on `make sub` and/or `make clean` to checkout correct base
77 .PHONY: patches-import
78 patches-import: sub .cachepatched
80 .cachepatched: ${FPATCHES}
82 @git submodule -q foreach ' \
83 SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
84 git tag ${F_OPNFV_TAG}-root && \
85 git checkout -q -b opnfv-fuel && \
86 find $$SUB_DIR -type d | sort | while read p_dir; do \
87 SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
88 if [ -n "$$SUB_PATCHES" ]; then \
89 SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
90 SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
91 echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
92 git tag $$SUB_TAG-root && git am -3 --whitespace=nowarn \
93 --committer-date-is-author-date $$SUB_PATCHES && \
94 git tag $$SUB_TAG || exit 1; \
97 git tag ${F_OPNFV_TAG}'
100 # Clean any changes made to submodules, checkout upstream Fuel root commit
103 @git submodule -q foreach ' \
104 git am -q --abort > /dev/null 2>&1; \
105 git checkout -q ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
106 git branch -q -D opnfv-fuel > /dev/null 2>&1; \
107 git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
108 git reset -q --hard HEAD; \
113 deepclean: clean clean-cache
114 @git submodule deinit -f .
119 # Store artifact in cache straight away if caching is enabled
120 # (no .cacheid will be present unless this is a cached build)
121 test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
122 # NOTE: Patches are not included in cache
123 $(MAKE) -f Makefile patches-import
125 ##############################################################################
126 # Cache operations - only used when building through ci/build.sh
127 ##############################################################################
129 # NOTE: Current method of collecting submodule refs requires submodules to be
130 # NOT initialized <OR> NO patches applied.
131 # NOTE: Querying `git submodule status` from parent will show the patched tree.
132 # Create a unique hash to be used for getting and putting cache, based on:
133 # - git submodule SHAs, collected with `git submodule status`
134 # - The contents of this Makefile
137 sha1sum Makefile > .cachedata
138 git submodule status | cut -c2-41 >> .cachedata
139 cat .cachedata | $(CACHETOOL) getid > .cacheid
141 # Clean local data related to caching - called prior to ordinary build
144 rm -f .cachedata .cacheid
146 # Try to download cache - called prior to ordinary build
149 @if $(CACHETOOL) check $(shell cat .cacheid); then \
151 $(CACHETOOL) get $(shell cat .cacheid) | \
152 tar xf - -C ${F_GIT_ROOT}/.git; \
154 echo "No cache item found for $(shell cat .cacheid)" ;\
158 # Store cache if not already stored - called after ordinary build
161 @if ! $(CACHETOOL) check $(shell cat .cacheid); then \
163 tar cf - -C ${F_GIT_ROOT}/.git modules | \
164 $(CACHETOOL) put $(shell cat .cacheid); \