versions.mk 5.4 KB

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