Rakefiles: automagically checkout revisions for given branch
To simplify creation and management development branches, the
`checkout` and `update` tasks selects the revision to checkout
as follows: given a package, it (in that order):
* if rbspec-file specifies `:revision`, then checkout or update
to that one, else
* if there's a bookmark with the same name as rakefile's
active bookmark or branch, If so, checkout or update to
that one, else
* if there are multiple heads then, then check out bookmark
`master`, else
* if there's only one head checkout that head.
This allows one to create a development branch just by branching
rakefiles and then using bookmarks whenever one needs to use specific
branch of a package.
Note, that previously it was necessary not only to bookmark the package
but also update rbspec-file. So updating rbspec-file is no longer
necessary.
--- a/rakelib/scm.rb Wed Jun 27 21:21:19 2018 +0100
+++ b/rakelib/scm.rb Fri Jul 06 16:35:55 2018 +0100
@@ -164,7 +164,9 @@
revision = hg.bookmark
unless revision
bookmarks = hg.bookmarks(branch)
- if bookmarks.has_key? 'master'
+ if bookmarks.has_key? BUILD_BRANCH
+ revision = BUILD_BRANCH
+ elsif bookmarks.has_key? 'master'
revision = 'master'
else
if hg.heads(branch, include_secret: false).size > 1
@@ -290,7 +292,9 @@
# head rev to use.
unless revision
bookmarks = hg.bookmarks(branch)
- if bookmarks.has_key? 'master'
+ if bookmarks.has_key? BUILD_BRANCH
+ revision = BUILD_BRANCH
+ elsif bookmarks.has_key? 'master'
revision = 'master'
else
if hg.heads(branch).size > 1
--- a/rakelib/setup.rake Wed Jun 27 21:21:19 2018 +0100
+++ b/rakelib/setup.rake Fri Jul 06 16:35:55 2018 +0100
@@ -20,6 +20,14 @@
unless defined? BUILD_TARGET; BUILD_TARGET = ENV['BUILD_TARGET'] || build_target_guess(); end
+# "Guess" the current "branch".
+def build_branch_guess()
+ repo = HG::Repository.new('.')
+ return repo.bookmark() || repo.branch()
+end
+
+BUILD_BRANCH = build_branch_guess()
+
unless defined? TOOLCHAIN
if ENV.has_key? 'TOOLCHAIN'
TOOLCHAIN = ENV['TOOLCHAIN']