summaryrefslogtreecommitdiffstats
path: root/build/f_repos/Makefile
blob: 2d2d0bf40fb7afdf8244945ccf585a7a3b90188c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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_DIR}; \
	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_DIR} modules | \
			$(CACHETOOL) put $(shell cat .cacheid); \
	fi
> # If true, links to the reST sources are added to the pages. # html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. # html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. # html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a <link> tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. # html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). # html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' # html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # 'ja' uses this config value. # 'zh' user can custom change `jieba` dictionary path. # html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. # html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. htmlhelp_basename = 'OPNFV' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', # Latex figure (float) alignment #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'OPNFV.tex', 'OPNFV Documentation', 'OPNFV Project', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. # latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. # latex_use_parts = False # If true, show page references after internal links. # latex_show_pagerefs = False # If true, show URL addresses after external links. # latex_show_urls = False # Documents to append as an appendix to all manuals. # latex_appendices = [] # If false, no module index is generated. # latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'OPNFVDocs', 'OPNFV Documentation', [author], 1) ] # If true, show URL addresses after external links. # man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'OPNFVDocs', 'OPNFV Documentation', author, 'OPNFV', 'One line description of project.', 'Miscellaneous'), ] html_sidebars = {'**': ['my_custom_sidebar.html']} # Documents to append as an appendix to all manuals. # texinfo_appendices = [] # If false, no module index is generated. # texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. # texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. # texinfo_no_detailmenu = False # intersphinx_mapping = # {'RTD':('http://opnfvdocsdemo.readthedocs.io/projects/', None)}