Merge 'remotes/trunk'
[0ad.git] / build / jenkins / build-patch.sh
blob8fe4e4293936aa76afdddfb4e82e77f62a0cc7d1
1 #!/bin/sh
3 set -e
5 # This script allows Jenkins to build and test a patch inside the phabricator
6 # workspace.
8 # The important thing is determining how much cleanup is needed. For instance,
9 # if a patch adds a source file, it is necessary to delete it afterwards and
10 # remove all related build artifacts. It will also be necessary to rebuild the game
11 # for testing the next patch, even if that new patch doesn't change the code.
13 # However, rebuilding everything each time is expensive and prevents us from
14 # handling a decent input of patches on Phabricator.
16 # This script does its best to determine a somewhat minimal necessary amount of
17 # cleanup, and resorts to a clean checkout in case of failure.
19 if [ -z "$DIFF_ID" ]; then
20 echo 'No patch ID provided, aborting'
21 exit 1
24 # Build environment
25 JOBS=${JOBS:="-j2"}
27 # Move to the root of the repository (this script is in build/jenkins/)
28 cd "$(dirname $0)"/../../
30 # Utility functions
32 fully_cleaned=false
34 patch()
36 # Revert previously applied changes or deleted files (see full_cleanup).
37 svn revert -R .
39 # Removing non-ignored files from binaries/data/ might be necessary and
40 # doesn't impact the build, so do it each time.
41 svn status binaries/data/ | cut -c 9- | xargs rm -rf
43 # If we have non-ignored files under source/, we must delete them and
44 # clean the workspaces.
45 if [ "$(svn status source/)" ]; then
46 svn status source/ | cut -c 9- | xargs rm -rf
47 build/workspaces/clean-workspaces.sh --preserve-libs
50 # Apply the patch
51 # Patch errors (including successful hunks) are written to the Phab comment.
52 # If patching is successful, this will be overwritten in the build() step.
53 # If patching fails, the comment will be explicit about it.
54 arc patch --diff "$DIFF_ID" --force 2> .phabricator-comment
57 full_cleanup()
59 fully_cleaned=true
60 svn st --no-ignore | cut -c 9- | xargs rm -rf
61 patch # patch will revert everything, so don't worry about deleted files
64 build()
67 echo 'Updating workspaces...'
68 build/workspaces/update-workspaces.sh "${JOBS}" --with-system-nvtt --without-miniupnpc >/dev/null || echo 'Updating workspaces failed!'
69 cd build/workspaces/gcc
70 echo 'Build (release)...'
71 make "${JOBS}" config=release 2>&1 1>/dev/null
72 echo 'Build (debug)...'
73 make "${JOBS}" config=debug 2>&1 1>/dev/null
74 cd ../../../binaries/system
75 echo 'Running release tests...'
76 ./test 2>&1
77 echo 'Running debug tests...'
78 ./test_dbg 2>&1
79 cd ../../source/tools/xmlvalidator
80 echo 'Checking XML files...'
81 perl validate.pl 2>&1 1>/dev/null
82 } > .phabricator-comment
86 # Try to patch, if that manages to fail, clean up everything.
87 # If it patches, make sure the libraries are not touched.
88 if ! patch; then
89 full_cleanup
90 elif svn status libraries/source/ | grep -v '^?' >/dev/null 2>&1; then
91 full_cleanup
94 # Try to build, if that fails, clean up everything.
95 if ! build && [ "$fully_cleaned" != true ]; then
96 full_cleanup
97 build