1 ##############################################################################
2 # Copyright (c) 2015,2016,2017 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 ##############################################################################
15 FPATCHES = $(shell find ${F_PATCH_DIR} -name '*.patch')
17 # NOTE: Mechanism overview is presented in ./README.md.
19 # Submodule consistent states:
20 # - NOT initialized (submodule trees are not populated at all);
21 # - initialized, bound to saved commits;
22 # - initialized, tracking remote origin (only for FUEL_TRACK_REMOTES);
23 # - patched (local patches are applied);
25 # In order to keep things sort of separate, we should only pass up (to main
26 # Makefile) the fully-patched repos, and gather any fingerprinting info here.
28 # Fuel@OPNFV relies on upstream git repos (one per component) in 1 of 2 ways:
29 # - pinned down to tag objects (e.g. "9.0.1")
30 # - tracking upstream remote HEAD on a stable or master branch
31 # FIXME(alav): Should we support mixed cases? (e.g. pin down only fuel-main)
33 # To enable remote tracking, set the following var to any non-empty string.
34 # Leaving this var empty will bind each git submodule to its saved commit.
40 ##############################################################################
41 # git submodule operations - to be used stand-alone or from parent Makefile
42 ##############################################################################
44 # Fetch & update git submodules, checkout remote HEAD or saved commit
45 # Also gather fingerprints for parent gitinfo_fuel.txt.
50 @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
51 cd ${F_GIT_ROOT} && git submodule update --init --remote 2>/dev/null; \
53 cd ${F_GIT_ROOT} && git submodule update --init 2>/dev/null; \
57 # Generate patches from submodules
58 .PHONY: patches-export
60 @git submodule -q foreach ' \
61 SUB_DIR=${F_PATCH_DIR}/$$name; \
63 git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
64 SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
65 echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
66 mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
67 git format-patch --no-signature --ignore-space-at-eol \
68 -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
69 sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
70 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
73 # Apply patches from patch/* to respective submodules
74 # We rely on `make sub` and/or `make clean` to checkout correct base
75 .PHONY: patches-import
76 patches-import: sub .cachepatched
78 .cachepatched: ${FPATCHES}
80 @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
81 SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
82 git tag ${F_OPNFV_TAG}-root && \
83 git checkout -q -b opnfv-fuel && \
84 find $$SUB_DIR -type d | sort | while read p_dir; do \
85 SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
86 if [ -n "$$SUB_PATCHES" ]; then \
87 SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
88 SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
89 echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
90 git tag $$SUB_TAG-root && \
91 git am -3 --ignore-whitespace --patch-format=mbox \
92 --committer-date-is-author-date $$SUB_PATCHES && \
93 git tag $$SUB_TAG || exit 1; \
96 git tag ${F_OPNFV_TAG}'
99 # Add copyright header to patch files if not already present
100 .PHONY: patches-copyright
102 @grep -e "Copyright (c)" -L ${FPATCHES} | while read p_file; do \
104 cat fuel-patch-copyright.template $$p_file > $$ptmp && \
105 mv $$ptmp $$p_file; \
108 # Clean any changes made to submodules, checkout upstream Fuel root commit
111 @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
112 git am -q --abort > /dev/null 2>&1; \
113 git checkout -q -f ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
114 git branch -q -D opnfv-fuel > /dev/null 2>&1; \
115 git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
116 git reset -q --hard HEAD; \
122 @cd ${F_GIT_ROOT} && git submodule deinit -f ${F_GIT_ROOT}
127 $(MAKE) -f Makefile patches-import