Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / scripts / submodules / versions.mk
1 #
2 # This is a python script and a set of make targets to implement support for conditional submodules
3 # Set the SUBMODULES_CONFIG_FILE make variable to the srcdir path of a SUBMODULES.json file which contains information about the submodules.
4 #
5
6 SCRIPT=$(top_srcdir)/scripts/submodules/versions.py
7
8 # usage $(call ValidateVersionTemplate (name,MAKEFILE VAR,repo name))
9 # usage $(call ValidateVersionTemplate (mono,MONO,mono))
10
11 define ValidateVersionTemplate
12 #$(eval REPOSITORY_$(2):=$(shell test -z $(3) && echo $(1) || echo "$(3)"))
13 #$(eval DIRECTORY_$(2):=$(shell python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) get-dir $(1)))
14 #$(eval DIRECTORY_$(2):=$(shell test -z $(DIRECTORY_$(2)) && echo $(1) || echo $(DIRECTORY_$(2))))
15 #$(eval MODULE_$(2):=$(shell python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) get-url $(1)))
16 #$(eval NEEDED_$(2)_VERSION:=$(shell python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) get-rev $(1)))
17 #$(eval $(2)_BRANCH_AND_REMOTE:=$(shell python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) get-remote-branch $(1)))
18
19 #$(eval $(2)_VERSION:=$$$$(shell cd $($(2)_PATH) 2>/dev/null && git rev-parse HEAD ))
20
21 #$(eval NEEDED_$(2)_BRANCH:=$(word 2, $(subst /, ,$($(2)_BRANCH_AND_REMOTE))))
22 #$(eval NEEDED_$(2)_REMOTE:=$(word 1, $(subst /, ,$($(2)_BRANCH_AND_REMOTE))))
23 #$(eval $(2)_BRANCH:=$$$$(shell cd $($(2)_PATH) 2>/dev/null && git symbolic-ref --short HEAD 2>/dev/null))
24
25 validate-$(1)::
26         @if test x$$(IGNORE_$(2)_VERSION) = "x"; then \
27             if test ! -d $($(2)_PATH); then \
28                         if test x$$(RESET_VERSIONS) != "x"; then \
29                                 $(MAKE) reset-$(1) || exit 1; \
30                         else \
31                                 echo "Your $(1) checkout is missing, please run 'make reset-$(1)'"; \
32                                 touch .validate-versions-failure; \
33                         fi; \
34             else \
35                         if test "x$($(2)_VERSION)" != "x$(NEEDED_$(2)_VERSION)" ; then \
36                                 if test x$$(RESET_VERSIONS) != "x"; then \
37                                         $(MAKE) reset-$(1) || exit 1; \
38                                 else \
39                                     echo "Your $(1) version is out of date, please run 'make reset-$(1)' (found $($(2)_VERSION), expected $(NEEDED_$(2)_VERSION))"; \
40                                     test -z "$(BUILD_REVISION)" || $(MAKE) test-$(1); \
41                                 touch .validate-versions-failure; \
42                                 fi; \
43                 elif test "x$($(2)_BRANCH)" != "x$(NEEDED_$(2)_BRANCH)" ; then \
44                                 if test x$$(RESET_VERSIONS) != "x"; then \
45                                         test -z "$(BUILD_REVISION)" || $(MAKE) test-$(1); \
46                                         $(MAKE) reset-$(1) || exit 1; \
47                                 else \
48                                     echo "Your $(1) branch is out of date, please run 'make reset-$(1)' (found $($(2)_BRANCH), expected $(NEEDED_$(2)_BRANCH))"; \
49                                 touch .validate-versions-failure; \
50                                 fi; \
51                fi; \
52             fi; \
53         fi
54
55 test-$(1)::
56         @echo $(1)
57         @echo "   REPOSITORY_$(2)=$(REPOSITORY_$(2))"
58         @echo "   DIRECTORY_$(2)=$(DIRECTORY_$(2))"
59         @echo "   MODULE_$(2)=$(MODULE_$(2))"
60         @echo "   NEEDED_$(2)_VERSION=$(NEEDED_$(2)_VERSION)"
61         @echo "   $(2)_VERSION=$($(2)_VERSION)"
62         @echo "   $(2)_BRANCH_AND_REMOTE=$($(2)_BRANCH_AND_REMOTE)"
63         @echo "   NEEDED_$(2)_BRANCH=$(NEEDED_$(2)_BRANCH)"
64         @echo "   NEEDED_$(2)_REMOTE=$(NEEDED_$(2)_REMOTE)"
65         @echo "   $(2)_BRANCH=$($(2)_BRANCH)"
66         @echo "   $(2)_PATH=$($(2)_PATH) => $(abspath $($(2)_PATH))"
67
68 reset-$(1)::
69         @if test -d $($(2)_PATH); then \
70                 if ! (cd $($(2)_PATH) && git show $(NEEDED_$(2)_VERSION) >/dev/null 2>&1 && git log -1 $(NEEDED_$(2)_REMOTE/NEEDED_$(2)_BRANCH) >/dev/null 2>&1) ; then \
71                         echo "*** git fetch `basename $$($(2)_PATH)`" && (cd $($(2)_PATH) && git fetch); \
72                 fi;  \
73         else \
74                 echo "*** git clone $(MODULE_$(2)) --recursive $(DIRECTORY_$(2))" && (cd `dirname $($(2)_PATH)` && git clone $(MODULE_$(2)) --recursive $(DIRECTORY_$(2)) || exit 1 ); \
75         fi
76         @if test x$$(IGNORE_$(2)_VERSION) = "x"; then \
77                 echo "*** [$(1)] git checkout -f" $(NEEDED_$(2)_BRANCH) && (cd $($(2)_PATH) ; git checkout -f $(NEEDED_$(2)_BRANCH) || git checkout -f -b $($(2)_BRANCH_AND_REMOTE)); \
78                 echo "*** [$(1)] git reset --hard $(NEEDED_$(2)_VERSION)" && (cd $($(2)_PATH) && git reset --hard $(NEEDED_$(2)_VERSION)); \
79         fi
80         @echo "*** [$(1)] git submodule update --init --recursive" && (cd $($(2)_PATH) && git submodule update --init --recursive)
81
82 print-$(1)::
83         @printf "*** %-16s %-45s %s (%s)\n" "$(DIRECTORY_$(2))" "$(MODULE_$(2))" "$(NEEDED_$(2)_VERSION)" "$(NEEDED_$(2)_BRANCH)"
84
85 .PHONY: validate-$(1) reset-$(1) print-$(1)
86
87 reset-versions:: reset-$(1)
88 validate-versions:: validate-$(1)
89 print-versions:: print-$(1)
90
91 endef
92
93 reset-versions::
94
95 validate-versions::
96         @if test -e .validate-versions-failure; then  \
97                 rm .validate-versions-failure; \
98                 echo One or more modules needs update;  \
99                 exit 1; \
100         else \
101                 echo All dependent modules up to date;  \
102         fi
103
104 reset:
105         @$(MAKE) validate-versions RESET_VERSIONS=1
106
107 __bump-version-%:
108         @if [ "$(REV)" = "" ]; then echo "Usage: make bump-version-$* REV=<ref>"; exit 1; fi
109         python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) set-rev $* $(REV)
110         @if [ "$(COMMIT)" = "1" ]; then echo "[submodules] Bump $* to pick up $(REV)." | git commit -F - $(SUBMODULES_CONFIG_FILE); fi
111
112 __bump-branch-%:
113         @if [ "$(BRANCH)" = "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
114         @if [ "$(REMOTE_BRANCH)" == "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
115         python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) set-branch $* $(BRANCH)
116         python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) set-remote-branch $* $(REMOTE_BRANCH)
117         @if [ "$(COMMIT)" = "1" ]; then echo "[submodules] Bump $* to switch to $(BRANCH) $(REMOTE BRANCH)." | git commit -F - $(SUBMODULES_CONFIG_FILE); fi
118
119 __bump-current-version-%:
120         REV=$(shell cd $(ACCEPTANCE_TESTS_PATH)/$* && git log -1 --pretty=format:%H); \
121         python $(SCRIPT) $(SUBMODULES_CONFIG_FILE) set-rev $* $$REV; \
122         if [ "$(COMMIT)" = "1" ]; then echo "[submodules] Bump $* to pick up $$REV:" | git commit -F - $(SUBMODULES_CONFIG_FILE); fi