Skip to contentSkip to conversation

scripts: introduce a script for build test

PATCH Superseded Wei Liu 4 participants 14 messages Oct 23, 2017 – Oct 25, 2017

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v2 1/1 scripts: introduce a script for build test

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Anthony PERARD <[email protected]>

---
 scripts/build-test.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100755 scripts/build-test.sh
scripts/build-test.sh new file +53 -0
new file mode 100755
index 0000000000..316419d6b7
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# Run command on every commit within the range specified. If no command is
+# provided, use the default one to clean and build the whole tree.
+#
+# Cross-build is not yet supported.
+
+set -e
+
+if ! test -f xen/common/kernel.c; then
+    echo "Please run this script from top-level directory"
+    exit 1
+fi
+
+if test $# -lt 2 ; then
+    echo "Usage: $0 <BASE> <TIP> [CMD]"
+    exit 1
+fi
+
+status=`git status -s`
+if test -n "$status"; then
+    echo "Tree is dirty, aborted"
+    exit 1
+fi
+
+if git branch | grep -q '^\*.\+detached at'; then
+    echo "Detached HEAD, aborted"
+    exit 1
+fi
+
+BASE=$1; shift
+TIP=$1; shift
+ORIG_BRANCH=`git rev-parse --abbrev-ref HEAD`
+
+if ! git merge-base --is-ancestor $BASE $TIP; then
+    echo "$BASE is not an ancestor of $TIP, aborted"
+    exit 1
+fi
+
+git rev-list $BASE..$TIP | nl -ba | tac | \
+while read num rev; do
+    echo "Testing $num $rev"
+    git checkout $rev
+    if test $# -eq 0 ; then
+        make -j4 distclean && ./configure && make -j4
+    else
+        "$@"
+    fi
+    echo
+done
+
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Wei Liu writes ("[PATCH v2] scripts: introduce a script for build test"):
...

Quoted 1 line

+if git branch | grep -q '^\*.\+detached at'; then

You mean some rune involving git-symbolic-ref.

git-symbolic-ref -q HEAD exits with status 1 if HEAD is detached, 0 if HEAD is a branch, or some other status in case of trouble.

But you could combine this test with your ORIG_BRANCH thing, and just say
git-symbolic-ref HEAD
which exits 128 if HEAD is detached.

scripts/build-test.sh line 38

Quoted 4 lines
scripts/build-test.sh new file +4 -0
+if ! git merge-base --is-ancestor $BASE $TIP; then
+    echo "$BASE is not an ancestor of $TIP, aborted"
+    exit 1
+fi

I would remove this check. There is nothing wrong with asking "does this branch build everywhere" even if it hasn't rebased yet.

The rest LGTM.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
In reply to Wei Liu
Quoted 5 lines · Wei Liu
scripts/build-test.sh new file +5 -0
+
+if test $# -lt 2 ; then
+    echo "Usage: $0 <BASE> <TIP> [CMD]"
+    exit 1
+fi

[...]

scripts/build-test.sh line 47

Quoted 8 lines
scripts/build-test.sh new file +8 -0
+git rev-list $BASE..$TIP | nl -ba | tac | \
+while read num rev; do
+    echo "Testing $num $rev"
+    git checkout $rev
+    if test $# -eq 0 ; then
+        make -j4 distclean && ./configure && make -j4
+    else
+        "$@"

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

I can see only two options, but I'm not sure if it is what you had in mind:
- Option #1: a script

$ echo 'make -j8 distclean && ./configure && make -j8' > tmp-script.sh
$ ./script/build-test.sh master my-feature bash tmp-script.sh

- Option #2: with eval!

$ ./script/build-test.sh master my-feature eval make -j8 distclean '&&' ./configure '&&' make -j8
# notice the eval ................... here ^^^^ :-)

scripts/build-test.sh line 53

Quoted 6 lines
scripts/build-test.sh new file +6 -0
+    fi
+    echo
+done
+
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

Another thing that can be done is do the build test in a temporary checkout, but I'm not sure if it is a good idea.

(I'm still trying to find out how a script can do a better job than a plain git rebase --interactive --exec 'blah', it is maybe just because I know what to do if there is an issue.)

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

Quoted 7 lines

scripts/build-test.sh line 53

Quoted 2 lines
scripts/build-test.sh new file +2 -0
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#4 lore raw
Quoted 9 lines · Ian Jackson

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

I don't think we should call git-clean unconditionally -- imagine someone knew for sure they only needed to build part of the tools or the hypervisor.

Quoted 10 lines
Quoted 7 lines

scripts/build-test.sh line 53

Quoted 2 lines
scripts/build-test.sh new file +2 -0
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Not sure I follow. Do you want the script to trap SIGCHLD, test the return value and act accordingly?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 11 lines · Wei Liu
Quoted 7 lines · Ian Jackson
Quoted 4 lines

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Not sure I follow. Do you want the script to trap SIGCHLD, test the return value and act accordingly?

In scripts with set -e, trap 'echo something failed' EXIT is enough. But that is probably not necessary here, you could just check the return value of the build command, then start printing imformation about what/where it went wrong, and how to go back.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#6 lore raw
Quoted 10 lines · Anthony PERARD
Quoted 9 lines · Wei Liu
Quoted 7 lines · Ian Jackson
Quoted 4 lines

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Quoted 7 lines
Quoted 2 lines

Not sure I follow. Do you want the script to trap SIGCHLD, test the return value and act accordingly?

In scripts with set -e, trap 'echo something failed' EXIT is enough. But that is probably not necessary here, you could just check the return value of the build command, then start printing imformation about what/where it went wrong, and how to go back.

Either is fine. Thanks for the suggestion.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
In reply to Wei Liu

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 5 lines · Ian Jackson
Quoted 4 lines

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

Quoted 8 lines
Quoted 4 lines

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

I don't think we should call git-clean unconditionally -- imagine someone knew for sure they only needed to build part of the tools or the hypervisor.

If you are worried about this you should check that there are no uncommitted files before starting.

I have a visceral loathing of clean targets. They are often flaky, and ours are no exception.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

scripts/build-test.sh line 53

Quoted 2 lines
scripts/build-test.sh new file +2 -0
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

Quoted 5 lines
Quoted 2 lines

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Not sure I follow. Do you want the script to trap SIGCHLD, test the return value and act accordingly?

I don't mean you should trap SIGCHLD.

But you should probably trap '' and use it to print a helpful message containing ORIG_BRANCH. On success you would disable the trap before exiting.

Alternatively you could defuse `set -e' around the invocation of the build command, and handle $? explicitly.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#8 lore raw
Quoted 11 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 10 lines · Ian Jackson
Quoted 8 lines

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

Quoted 6 lines
Quoted 3 lines

I don't think we should call git-clean unconditionally -- imagine someone knew for sure they only needed to build part of the tools or the hypervisor.

If you are worried about this you should check that there are no uncommitted files before starting.

This is already done in this version.

I don't worry if there is uncommitted file, I just don't want to stop developers from being smarter than the script when they know git-clean is not necessary.

Quoted 18 lines

I have a visceral loathing of clean targets. They are often flaky, and ours are no exception.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

scripts/build-test.sh line 53

Quoted 2 lines
scripts/build-test.sh new file +2 -0
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

Quoted 5 lines
Quoted 2 lines

IWBNI it would at least print the branch to checkout. Tools like "git bisect" record the information in .git and allow "git bisect reset".

Not sure I follow. Do you want the script to trap SIGCHLD, test the return value and act accordingly?

Quoted 9 lines

I don't mean you should trap SIGCHLD.

But you should probably trap '' and use it to print a helpful message containing ORIG_BRANCH. On success you would disable the trap before exiting.

Alternatively you could defuse `set -e' around the invocation of the build command, and handle $? explicitly.

OK, that sounds easy enough.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 9 lines · Ian Jackson
Quoted 2 lines

If you are worried about this you should check that there are no uncommitted files before starting.

This is already done in this version.

I don't worry if there is uncommitted file, I just don't want to stop developers from being smarter than the script when they know git-clean is not necessary.

I don't understand your point. If there are no uncommitted files at the start of the run, then git clean is certainly safe later, since everything that will be deleted was made by `make'. Therefore doing it unconditionally is fine.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#10 lore raw
Quoted 7 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 6 lines · Ian Jackson
Quoted 2 lines

If you are worried about this you should check that there are no uncommitted files before starting.

This is already done in this version.

Quoted 8 lines
Quoted 3 lines

I don't worry if there is uncommitted file, I just don't want to stop developers from being smarter than the script when they know git-clean is not necessary.

I don't understand your point. If there are no uncommitted files at the start of the run, then git clean is certainly safe later, since everything that will be deleted was made by `make'. Therefore doing it unconditionally is fine.

I mean I don't want git-clean to delete all the object files so that they don't need to be rebuilt.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw
In reply to Wei Liu
Quoted 16 lines · Wei Liu
Quoted 15 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 13 lines · Ian Jackson
Quoted 8 lines

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

I don't think we should call git-clean unconditionally -- imagine someone knew for sure they only needed to build part of the tools or the hypervisor.

Quoted 8 lines
Quoted 2 lines

If you are worried about this you should check that there are no uncommitted files before starting.

This is already done in this version.

I don't worry if there is uncommitted file, I just don't want to stop developers from being smarter than the script when they know git-clean is not necessary.

What kind of "smarter" did you have in mind?

This script sounds like an aid to developers who don't have the motivation / experience / whatever to write their own script (or do something fancier, like git rebase --exec). If people want to be smarter they can write their own script, using this as a starting point.

FWIW in xsatool I use 'git clean' extensively.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#12 lore raw
Quoted 27 lines · George Dunlap
Quoted 16 lines · Wei Liu
Quoted 15 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 13 lines · Ian Jackson
Quoted 8 lines

Anthony PERARD writes ("Re: [PATCH v2] scripts: introduce a script for build test"):

Quoted 2 lines

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

.../build-test sh -ec make -j4 distclean && ./configure && make -j4

But I think Anthony has a point. The clean should 1. be git-clean, not make distclean 2. be run anyway.

I don't think we should call git-clean unconditionally -- imagine someone knew for sure they only needed to build part of the tools or the hypervisor.

Quoted 8 lines
Quoted 2 lines

If you are worried about this you should check that there are no uncommitted files before starting.

This is already done in this version.

I don't worry if there is uncommitted file, I just don't want to stop developers from being smarter than the script when they know git-clean is not necessary.

Quoted 6 lines

What kind of "smarter" did you have in mind?

This script sounds like an aid to developers who don't have the motivation / experience / whatever to write their own script (or do something fancier, like git rebase --exec). If people want to be smarter they can write their own script, using this as a starting point.

Exactly. If they want to supply their script, then fine. We shouldn't do a git-clean for them.

I'm fine with using 'git clean' in the default rune but I don't want to use it unconditionally.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#13 lore raw
In reply to Anthony PERARD
Quoted 19 lines · Anthony PERARD
Quoted 5 lines · Wei Liu
scripts/build-test.sh new file +5 -0
+
+if test $# -lt 2 ; then
+    echo "Usage: $0 <BASE> <TIP> [CMD]"
+    exit 1
+fi

[...]

scripts/build-test.sh line 47

Quoted 8 lines
scripts/build-test.sh new file +8 -0
+git rev-list $BASE..$TIP | nl -ba | tac | \
+while read num rev; do
+    echo "Testing $num $rev"
+    git checkout $rev
+    if test $# -eq 0 ; then
+        make -j4 distclean && ./configure && make -j4
+    else
+        "$@"

That feels wrong. How do I run the same exact command at the default one, but with -j8 instead of -j4?

Quoted 5 lines

I can see only two options, but I'm not sure if it is what you had in mind:
- Option #1: a script

$ echo 'make -j8 distclean && ./configure && make -j8' > tmp-script.sh
$ ./script/build-test.sh master my-feature bash tmp-script.sh

This is what I had in mind.

Quoted 19 lines

- Option #2: with eval!

$ ./script/build-test.sh master my-feature eval make -j8 distclean '&&' ./configure '&&' make -j8
# notice the eval ................... here ^^^^ :-)

scripts/build-test.sh line 53

Quoted 6 lines
scripts/build-test.sh new file +6 -0
+    fi
+    echo
+done
+
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH

Also, what a developper should do when the build fail? She can't modify the current code, because changes are going to be losts. Maybe we could trap failures, restore original HEAD and point out which commit fails to build.

Quoted 7 lines

Another thing that can be done is do the build test in a temporary checkout, but I'm not sure if it is a good idea.

(I'm still trying to find out how a script can do a better job than a plain git rebase --interactive --exec 'blah', it is maybe just because I know what to do if there is an issue.)

Frankly I myself would probably use git-rebase so that I can fix things on the fly, but I want to point contributors to something safer. And I'm tired of typing the same "ICYMI git-rebase can do this this this to build test your branch".

Quoted 2 lines
Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel