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 # Need to disable this logic temporarily as Newton doesn't seem to have stable
39 # branches in all repos. /Stefan
40 # FUEL_TRACK_REMOTES ?= $(shell git symbolic-ref --short HEAD | grep -v stable)
45 ##############################################################################
46 # git submodule operations - to be used stand-alone or from parent Makefile
47 ##############################################################################
49 # Fetch & update git submodules, checkout remote HEAD or saved commit
50 # Also gather fingerprints for parent gitinfo_fuel.txt.
55 @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
56 git submodule update --init --remote 2>/dev/null; \
58 git submodule update --init 2>/dev/null; \
61 @git submodule -q foreach '${REPOINFO} . >> ${FREPODIR}/$@'
63 # Generate patches from submodules
64 .PHONY: patches-export
66 @git submodule -q foreach ' \
67 SUB_DIR=${F_PATCH_DIR}/$$name; \
68 git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
69 SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
70 echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
71 mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
72 git format-patch --no-signature --ignore-space-at-eol \
73 -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
74 sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
75 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
78 # Apply patches from patch/* to respective submodules
79 # We rely on `make sub` and/or `make clean` to checkout correct base
80 .PHONY: patches-import
81 patches-import: sub .cachepatched
83 .cachepatched: ${FPATCHES}
85 @git submodule -q foreach ' \
86 SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
87 git tag ${F_OPNFV_TAG}-root && \
88 git checkout -q -b opnfv-fuel && \
89 find $$SUB_DIR -type d | sort | while read p_dir; do \
90 SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
91 if [ -n "$$SUB_PATCHES" ]; then \
92 SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
93 SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
94 echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
95 git tag $$SUB_TAG-root && git am -3 --whitespace=nowarn \
96 --committer-date-is-author-date $$SUB_PATCHES && \
97 git tag $$SUB_TAG || exit 1; \
100 git tag ${F_OPNFV_TAG}'
103 # Clean any changes made to submodules, checkout upstream Fuel root commit
106 @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
107 git am -q --abort > /dev/null 2>&1; \
108 git checkout -q -f ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
109 git branch -q -D opnfv-fuel > /dev/null 2>&1; \
110 git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
111 git reset -q --hard HEAD; \
116 deepclean: clean clean-cache
117 @git submodule deinit -f .
122 # Store artifact in cache straight away if caching is enabled
123 # (no .cacheid will be present unless this is a cached build)
124 test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
125 # NOTE: Patches are not included in cache
126 $(MAKE) -f Makefile patches-import
128 ##############################################################################
129 # Cache operations - only used when building through ci/build.sh
130 ##############################################################################
132 # NOTE: Current method of collecting submodule refs requires submodules to be
133 # NOT initialized <OR> NO patches applied.
134 # NOTE: Querying `git submodule status` from parent will show the patched tree.
135 # Create a unique hash to be used for getting and putting cache, based on:
136 # - git submodule SHAs, collected with `git submodule status`
137 # - The contents of this Makefile
140 sha1sum Makefile > .cachedata
141 git submodule status | cut -c2-41 >> .cachedata
142 cat .cachedata | $(CACHETOOL) getid > .cacheid
144 # Clean local data related to caching - called prior to ordinary build
147 rm -f .cachedata .cacheid
149 # Try to download cache - called prior to ordinary build
152 @if $(CACHETOOL) check $(shell cat .cacheid); then \
154 $(CACHETOOL) get $(shell cat .cacheid) | \
155 tar xf - -C ${F_GIT_DIR}; \
157 echo "No cache item found for $(shell cat .cacheid)" ;\
161 # Store cache if not already stored - called after ordinary build
164 @if ! $(CACHETOOL) check $(shell cat .cacheid); then \
166 tar cf - -C ${F_GIT_DIR} modules | \
167 $(CACHETOOL) put $(shell cat .cacheid); \