[acceptance-tests] Add code from xamarin/mono extensions branch
authorZoltan Varga <vargaz@gmail.com>
Wed, 7 Oct 2015 14:32:13 +0000 (16:32 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 19 Oct 2015 14:37:17 +0000 (16:37 +0200)
This provides a "git submodule"-like tool which can be used to
checkout optional repositories.

acceptance-tests/Makefile [new file with mode: 0644]
acceptance-tests/README.md [new file with mode: 0644]
acceptance-tests/SUBMODULES.json [new file with mode: 0644]
acceptance-tests/versions.mk [new file with mode: 0644]
acceptance-tests/versions.rb [new file with mode: 0755]

diff --git a/acceptance-tests/Makefile b/acceptance-tests/Makefile
new file mode 100644 (file)
index 0000000..43a1e59
--- /dev/null
@@ -0,0 +1,6 @@
+TOP=..
+MONO_EXTENSIONS_PATH=$(TOP)/../mono-extensions
+LLVM_PATH=$(TOP)/../llvm
+
+CHECK_VERSIONS=all
+include versions.mk
diff --git a/acceptance-tests/README.md b/acceptance-tests/README.md
new file mode 100644 (file)
index 0000000..d1322fc
--- /dev/null
@@ -0,0 +1,14 @@
+This directory contains functionality for handling optional non git submodule based submodules.
+
+The SUBMODULES.json file stores information about the submodules, and make targets are used to check out submodules, check their versions, and update the submodule information.
+
+By convention, submodules repositories are at the same level as the mono repository.
+
+Make targets available:
+
+make check-<module> - Checks whenever <module> is checked out and matches the version in the info file.
+make reset-<module> - Clones <module>if neccesary and checks out the revision specified in the info file.
+make bump-<module> - Updates the revision stored in the info file for <module>.
+make bump-current-<module> - Updates the revision stored in the info file for <module> to the current revision.
+make commit-bump-<module> - Same as make bump-<module>, but commits the change.
+make commit-bump-current-<module> - Same as make bump-current-<module>, but commits the change.
diff --git a/acceptance-tests/SUBMODULES.json b/acceptance-tests/SUBMODULES.json
new file mode 100644 (file)
index 0000000..d3065ee
--- /dev/null
@@ -0,0 +1,18 @@
+[
+  {
+    "name": "mono-extensions",
+    "directory": "mono-extensions",
+    "url": "git@github.com:xamarin/mono-extensions.git",
+    "branch": "master",
+    "remote-branch": "origin/master",
+    "rev": "45d7121a6d2e717c85522bf8c4cff16bdc9debda"
+  },
+  {
+    "name": "llvm",
+    "directory": "llvm",
+    "url": "git@github.com:mono/llvm.git",
+    "branch": "master",
+    "remote-branch": "origin/master",
+    "rev": "e1b4ee2f4e2ae2b9ebc402255972cec110878011"
+  }
+]
diff --git a/acceptance-tests/versions.mk b/acceptance-tests/versions.mk
new file mode 100644 (file)
index 0000000..5890dbe
--- /dev/null
@@ -0,0 +1,162 @@
+.PHONY: check-versions reset-versions check-mono
+
+README=SUBMODULES.json
+
+# usage $(call CheckVersionTemplate (name,MAKEFILE VAR,repo name))
+# usage $(call CheckVersionTemplate (mono,MONO,mono))
+
+define CheckVersionTemplate
+#$(eval REPOSITORY_$(2):=$(shell test -z $(3) && echo $(1) || echo "$(3)"))
+#$(eval DIRECTORY_$(2):=$(shell ruby versions.rb get-dir $(1)))
+#$(eval DIRECTORY_$(2):=$(shell test -z $(DIRECTORY_$(2)) && echo $(1) || echo $(DIRECTORY_$(2))))
+#$(eval MODULE_$(2):=$(shell ruby versions.rb get-url $(1)))
+#$(eval NEEDED_$(2)_VERSION:=$(shell ruby versions.rb get-rev $(1)))
+#$(eval $(2)_BRANCH_AND_REMOTE:=$(shell ruby versions.rb get-remote-branch $(1)))
+
+#$(eval $(2)_VERSION:=$$$$(shell cd $($(2)_PATH) 2>/dev/null && git rev-parse HEAD ))
+
+#$(eval NEEDED_$(2)_BRANCH:=$(word 2, $(subst /, ,$($(2)_BRANCH_AND_REMOTE))))
+#$(eval NEEDED_$(2)_REMOTE:=$(word 1, $(subst /, ,$($(2)_BRANCH_AND_REMOTE))))
+#$(eval $(2)_BRANCH:=$$$$(shell cd $($(2)_PATH) 2>/dev/null && git symbolic-ref --short HEAD 2>/dev/null))
+
+check-$(1)::
+       @if test x$$(IGNORE_$(2)_VERSION) = "x"; then \
+           if test ! -d $($(2)_PATH); then \
+                       if test x$$(RESET_VERSIONS) != "x"; then \
+                               make reset-$(1) || exit 1; \
+                       else \
+                               echo "Your $(1) checkout is missing, please run 'make reset-$(1)'"; \
+                               touch .check-versions-failure; \
+                       fi; \
+           else \
+                       if test "x$($(2)_VERSION)" != "x$(NEEDED_$(2)_VERSION)" ; then \
+                               if test x$$(RESET_VERSIONS) != "x"; then \
+                                       make reset-$(1) || exit 1; \
+                               else \
+                                   echo "Your $(1) version is out of date, please run 'make reset-$(1)' (found $($(2)_VERSION), expected $(NEEDED_$(2)_VERSION))"; \
+                                   test -z "$(BUILD_REVISION)" || $(MAKE) test-$(1); \
+                               touch .check-versions-failure; \
+                               fi; \
+               elif test "x$($(2)_BRANCH)" != "x$(NEEDED_$(2)_BRANCH)" ; then \
+                               if test x$$(RESET_VERSIONS) != "x"; then \
+                                       test -z "$(BUILD_REVISION)" || $(MAKE) test-$(1); \
+                                       make reset-$(1) || exit 1; \
+                               else \
+                                   echo "Your $(1) branch is out of date, please run 'make reset-$(1)' (found $($(2)_BRANCH), expected $(NEEDED_$(2)_BRANCH))"; \
+                               touch .check-versions-failure; \
+                               fi; \
+              fi; \
+           fi; \
+       fi
+
+test-$(1)::
+       @echo $(1)
+       @echo "   REPOSITORY_$(2)=$(REPOSITORY_$(2))"
+       @echo "   DIRECTORY_$(2)=$(DIRECTORY_$(2))"
+       @echo "   MODULE_$(2)=$(MODULE_$(2))"
+       @echo "   NEEDED_$(2)_VERSION=$(NEEDED_$(2)_VERSION)"
+       @echo "   $(2)_VERSION=$($(2)_VERSION)"
+       @echo "   $(2)_BRANCH_AND_REMOTE=$($(2)_BRANCH_AND_REMOTE)"
+       @echo "   NEEDED_$(2)_BRANCH=$(NEEDED_$(2)_BRANCH)"
+       @echo "   NEEDED_$(2)_REMOTE=$(NEEDED_$(2)_REMOTE)"
+       @echo "   $(2)_BRANCH=$($(2)_BRANCH)"
+       @echo "   $(2)_PATH=$($(2)_PATH) => $(abspath $($(2)_PATH))"
+
+reset-$(1)::
+       @if test -d $($(2)_PATH); then \
+               if ! (cd $($(2)_PATH) && git show $(NEEDED_$(2)_VERSION) >/dev/null 2>&1 && git log -1 $(NEEDED_$(2)_REMOTE) >/dev/null 2>&1) ; then \
+                       echo "*** git fetch `basename $$($(2)_PATH)`" && (cd $($(2)_PATH) && git fetch); \
+               fi;  \
+       else \
+               echo "*** git clone $(MODULE_$(2)) --recursive $(DIRECTORY_$(2))" && (cd `dirname $($(2)_PATH)` && git clone $(MODULE_$(2)) --recursive $(DIRECTORY_$(2))); \
+       fi
+       @if test x$$(IGNORE_$(2)_VERSION) = "x"; then \
+               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)); \
+               echo "*** [$(1)] git reset --hard $(NEEDED_$(2)_VERSION)" && (cd $($(2)_PATH) && git reset --hard $(NEEDED_$(2)_VERSION)); \
+       fi
+       @echo "*** [$(1)] git submodule update --init --recursive" && (cd $($(2)_PATH) && git submodule update --init --recursive)
+
+print-$(1)::
+       @printf "*** %-16s %-45s %s (%s)\n" "$(DIRECTORY_$(2))" "$(MODULE_$(2))" "$(NEEDED_$(2)_VERSION)" "$(NEEDED_$(2)_BRANCH)"
+
+.PHONY: check-$(1) reset-$(1) print-$(1)
+
+reset-versions:: reset-$(1)
+check-versions:: check-$(1)
+print-versions:: print-$(1)
+
+endef
+
+ifneq ($(findstring mono-extensions, $(CHECK_VERSIONS)),)
+    $(eval $(call CheckVersionTemplate,mono-extensions,MONO_EXTENSIONS))
+endif
+
+reset-versions::
+
+check-versions::
+       @if test -e .check-versions-failure; then  \
+               rm .check-versions-failure; \
+               echo One or more modules needs update;  \
+               exit 1; \
+       else \
+               echo All dependent modules up to date;  \
+       fi
+
+reset:
+       @make check-versions RESET_VERSIONS=1
+
+XAMARIN_SUBMODULES=mono-extensions
+
+check-versions-xamarin:
+       $(MAKE) check-versions CHECK_VERSIONS=$(XAMARIN_SUBMODULES)
+
+reset-versions-xamarin:
+       $(MAKE) reset-versions CHECK_VERSIONS=$(XAMARIN_SUBMODULES)
+
+reset-xamarin:
+       $(MAKE) check-versions CHECK_VERSIONS=$(XAMARIN_SUBMODULES) RESET_VERSIONS=1
+
+__bump-version-%:
+       @if [ "$(REV)" == "" ]; then echo "Usage: make bump-version-$* REV=<ref>"; exit 1; fi
+       @if [ "$(COMMIT)" == "1" ]; then git pull; fi
+       ruby versions.rb set-rev $* $(REV)
+       @if [ "$(COMMIT)" == "1" ]; then echo "Bump $* to pick up $(REV)." > msg; echo >> msg; cat msg | git commit -F - $(README); rm -f msg; fi
+
+__bump-branch-%:
+       @if [ "$(BRANCH)" == "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
+       @if [ "$(REMOTE_BRANCH)" == "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
+       @if [ "$(COMMIT)" == "1" ]; then git pull; fi
+       ruby versions.rb set-branch $* $(BRANCH)
+       ruby versions.rb set-remote-branch $* $(REMOTE_BRANCH)
+       @if [ "$(COMMIT)" == "1" ]; then echo "Bump $* to switch to $(BRANCH) $(REMOTE BRANCH)." > msg; echo >> msg; cat msg | git commit -F - $(README); rm -f msg; fi
+
+__bump-current-version-%:
+       @if [ "$(COMMIT)" == "1" ]; then git pull; fi
+       REV=$(shell cd $(TOP)/../$* && git log -1 --pretty=format:%H); \
+       ruby versions.rb set-rev $* $$REV
+       if [ "$(COMMIT)" == "1" ]; then echo "Bump $* to pick up $$REV:" > msg; echo >> msg; cat msg | git commit -F - $(README); rm -f msg; fi
+
+# Bump the given submodule to the revision given by the REV make variable
+# If COMMIT is 1, commit the change
+bump-mono-extensions: __bump-version-mono-extensions
+bump-llvm: __bump-version-llvm
+
+# Bump the given submodule to the branch given by the BRANCH/REMOTE_BRANCH make variables
+# If COMMIT is 1, commit the change
+bump-branch-mono-extensions: __bump-branch-mono-extensions
+bump-branch-llvm: __bump-branch-llvm
+
+# Bump the given submodule to its current GIT version
+# If COMMIT is 1, commit the change
+bump-current-mono-extensions: __bump-current-version-mono-extensions
+bump-current-llvm: __bump-current-version-llvm
+
+commit-bump-mono-extensions:
+       $(MAKE) bump-mono-extensions COMMIT=1
+commit-bump-llvm:
+       $(MAKE) bump-llvm COMMIT=1
+
+commit-bump-current-mono-extensions:
+       $(MAKE) bump-current-mono-extensions COMMIT=1
+commit-bump-current-llvm:
+       $(MAKE) bump-current-llvm COMMIT=1
diff --git a/acceptance-tests/versions.rb b/acceptance-tests/versions.rb
new file mode 100755 (executable)
index 0000000..ff43d73
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+require 'json'
+
+def find_module(submodules, name)
+  mod = submodules.find { |m| m['name'] == name }
+  if mod == nil
+    # FIXME:
+    puts "Not found"
+    exit 1
+  end
+  return mod
+end
+  
+if ARGV.length < 1 then
+  puts "Usage: versions.rb <command>"
+  exit(1)
+end
+
+command = ARGV[0]
+
+submodules = JSON.parse(File.read("SUBMODULES.json"))
+
+case command
+when "get-rev"
+  mod = find_module(submodules, ARGV[1])
+  puts mod['rev']
+when "get-url"
+  mod = find_module(submodules, ARGV[1])
+  puts mod['url']
+when "get-dir"
+  mod = find_module(submodules, ARGV[1])
+  puts mod['directory']
+when "get-remote-branch"
+  mod = find_module(submodules, ARGV[1])
+  puts mod['remote-branch']
+when "set-rev"
+  mod = find_module(submodules, ARGV[1])
+  mod['rev'] = ARGV[2]
+  f = File.new("SUBMODULES.json", "w")
+  f.write(JSON.pretty_generate(submodules))
+  f.close()
+when "set-branch"
+  mod = find_module(submodules, ARGV[1])
+  mod['branch'] = ARGV[2]
+  f = File.new("SUBMODULES.json", "w")
+  f.write(JSON.pretty_generate(submodules))
+  f.close()
+when "set-remote-branch"
+  mod = find_module(submodules, ARGV[1])
+  mod['remote-branch'] = ARGV[2]
+  f = File.new("SUBMODULES.json", "w")
+  f.write(JSON.pretty_generate(submodules))
+  f.close()
+when "cat"
+  puts JSON.pretty_generate(submodules)
+else
+  puts "Unknown command '#{command}'."
+  exit 1
+end