Turn ovs-plugin on
[fuel.git] / build / f_repos / Makefile
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 ##############################################################################
11
12 SHELL = /bin/sh
13 REPOINFO = $(shell readlink -e ../repo_info.sh)
14 FREPODIR = $(shell pwd)
15 FPATCHES = $(shell find ${F_PATCH_DIR} -name '*.patch')
16
17 include ../config.mk
18
19 # NOTE: Mechanism overview is presented in ./README.md.
20
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);
26
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.
29
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)
34
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)
41
42 .PHONY: all
43 all: release
44
45 ##############################################################################
46 # git submodule operations - to be used stand-alone or from parent Makefile
47 ##############################################################################
48
49 # Fetch & update git submodules, checkout remote HEAD or saved commit
50 # Also gather fingerprints for parent gitinfo_fuel.txt.
51 .PHONY: sub
52 sub: .cachefuelinfo
53
54 .cachefuelinfo:
55         @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
56                 git submodule update --init --remote 2>/dev/null; \
57         else \
58                 git submodule update --init 2>/dev/null; \
59         fi
60         @rm -f $@
61         @git submodule -q foreach '${REPOINFO} . >> ${FREPODIR}/$@'
62
63 # Generate patches from submodules
64 .PHONY: patches-export
65 patches-export: sub
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; \
76                 done'
77
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
82
83 .cachepatched: ${FPATCHES}
84         @$(MAKE) clean
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; \
98                         fi \
99                 done && \
100                 git tag ${F_OPNFV_TAG}'
101         @touch $@
102
103 # Clean any changes made to submodules, checkout upstream Fuel root commit
104 .PHONY: clean
105 clean:
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; \
112                 git clean -xdff'
113         @rm -f .cachepatched
114
115 .PHONY: deepclean
116 deepclean: clean clean-cache
117         @git submodule deinit -f .
118         @rm -f .cache*
119
120 .PHONY: release
121 release: sub
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
127
128 ##############################################################################
129 # Cache operations - only used when building through ci/build.sh
130 ##############################################################################
131
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
138 .cacheid:
139         @$(MAKE) clean
140         sha1sum Makefile > .cachedata
141         git submodule status | cut -c2-41 >> .cachedata
142         cat .cachedata | $(CACHETOOL) getid > .cacheid
143
144 # Clean local data related to caching - called prior to ordinary build
145 .PHONY: clean-cache
146 clean-cache: clean
147         rm -f .cachedata .cacheid
148
149 # Try to download cache - called prior to ordinary build
150 .PHONY: get-cache
151 get-cache: .cacheid
152         @if $(CACHETOOL) check $(shell cat .cacheid); then \
153                 $(MAKE) clean && \
154                 $(CACHETOOL) get $(shell cat .cacheid) | \
155                         tar xf - -C ${F_GIT_DIR}; \
156         else \
157                 echo "No cache item found for $(shell cat .cacheid)" ;\
158                 exit 0;\
159         fi
160
161 # Store cache if not already stored - called after ordinary build
162 .PHONY: put-cache
163 put-cache: .cacheid
164         @if ! $(CACHETOOL) check $(shell cat .cacheid); then \
165                 $(MAKE) clean && \
166                 tar cf - -C ${F_GIT_DIR} modules | \
167                         $(CACHETOOL) put $(shell cat .cacheid); \
168         fi