diff --git a/.build/README.md b/.build/README.md index c62424d89411..6c3c4922111e 100644 --- a/.build/README.md +++ b/.build/README.md @@ -4,6 +4,29 @@ Building and Testing with the helper sripts Information on building and testing beyond the use of ant. All scripts also print help if the first argument is `-h`. +`build-jars.sh`, `check-code.sh` and `run-tests.sh` accept `-s` (`--summary`). +That prints a summary of the failures in place of the full ant output, and keeps +the full output in a log file under the build directory. The scripts name that +file when a run fails. + +Building JARs +------------- + +Build in docker: + + .build/docker/build-jars.sh + + +Build without docker: + + .build/build-jars.sh + + +Remove the artifacts of a previous build first: + + .build/build-jars.sh --clean + + Code Checks and Lints --------------------- @@ -150,6 +173,19 @@ Debugging test scripts: DEBUG=true .build/docker/run-tests.sh -a test +Testing the helper scripts +-------------------------- + +The tests of the helper scripts need no JDK build. A stub `ant` and a stub `docker` +replay canned output, so each suite runs in seconds. + +Run them: + + python3 -m unittest discover -s .build/sh/test # the log summarizers + .build/sh/test/stub-ant-cases.sh # .build/*.sh + .build/sh/test/stub-docker-cases.sh # .build/docker/*.sh + + Running Sonar analysis (experimental) ------------------------------------- diff --git a/.build/build-jars.sh b/.build/build-jars.sh index cf2b91b08201..e61fb617b2f2 100755 --- a/.build/build-jars.sh +++ b/.build/build-jars.sh @@ -17,6 +17,25 @@ # temporary between CASSANDRA-18133 and CASSANDRA-18594 +print_help() { + echo "Usage: $0 [-c|--clean] [-s|--summary] [-h|--help]" + echo " -c, --clean Remove locally created artifacts (ant clean) before building" + echo " -s, --summary Print a summary of failures instead of the full ant output" + echo " -h, --help Print help" +} + +# arguments, with defaults +clean=false +summary=false +while [ "$#" -gt 0 ]; do + case "$1" in + -c|--clean) clean=true; shift ;; + -s|--summary) summary=true; shift ;; + -h|--help) print_help; exit 0 ;; + *) echo >&2 "Unknown argument $1"; print_help >&2; exit 1 ;; + esac +done + # variables, with defaults [ "x${CASSANDRA_DIR}" != "x" ] || CASSANDRA_DIR="$(readlink -f $(dirname -- "$0")/..)" @@ -24,7 +43,15 @@ command -v ant >/dev/null 2>&1 || { echo >&2 "ant needs to be installed"; exit 1; } [ -d "${CASSANDRA_DIR}" ] || { echo >&2 "Directory ${CASSANDRA_DIR} must exist"; exit 1; } [ -f "${CASSANDRA_DIR}/build.xml" ] || { echo >&2 "${CASSANDRA_DIR}/build.xml must exist"; exit 1; } +[ -f "${CASSANDRA_DIR}/.build/sh/_run-ant.sh" ] || { echo >&2 "${CASSANDRA_DIR}/.build/sh/_run-ant.sh must exist"; exit 1; } + +# defines run_ant(), which reads ${CASSANDRA_DIR} and ${summary} +# shellcheck source=.build/sh/_run-ant.sh +. "${CASSANDRA_DIR}/.build/sh/_run-ant.sh" # execute -ant -f "${CASSANDRA_DIR}/build.xml" jar +if ${clean}; then + run_ant clean +fi +run_ant jar exit $? diff --git a/.build/check-code.sh b/.build/check-code.sh index 4a540a653d4d..f79c6df81b2b 100755 --- a/.build/check-code.sh +++ b/.build/check-code.sh @@ -15,6 +15,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +print_help() { + echo "Usage: $0 [-s|--summary] [-h|--help]" + echo " -s, --summary Print a summary of failures instead of the full ant output" + echo " -h, --help Print help" +} + +# arguments, with defaults +summary=false +while [ "$#" -gt 0 ]; do + case "$1" in + -s|--summary) summary=true; shift ;; + -h|--help) print_help; exit 0 ;; + *) echo >&2 "Unknown argument $1"; print_help >&2; exit 1 ;; + esac +done + # variables, with defaults [ "x${CASSANDRA_DIR}" != "x" ] || { CASSANDRA_DIR="$(dirname -- "$0")/.."; } @@ -22,7 +38,17 @@ command -v ant >/dev/null 2>&1 || { echo >&2 "ant needs to be installed"; exit 1; } [ -d "${CASSANDRA_DIR}" ] || { echo >&2 "Directory ${CASSANDRA_DIR} must exist"; exit 1; } [ -f "${CASSANDRA_DIR}/build.xml" ] || { echo >&2 "${CASSANDRA_DIR}/build.xml must exist"; exit 1; } +[ -f "${CASSANDRA_DIR}/.build/sh/_run-ant.sh" ] || { echo >&2 "${CASSANDRA_DIR}/.build/sh/_run-ant.sh must exist"; exit 1; } + +# defines run_ant(), which reads ${CASSANDRA_DIR} and ${summary} +# shellcheck source=.build/sh/_run-ant.sh +. "${CASSANDRA_DIR}/.build/sh/_run-ant.sh" -# execute. memory needs to fit within the specified container size, see .jenkins/Jenkinsfile -ANT_OPTS="-Xmx2g -XX:+PrintClassHistogram -XX:OnOutOfMemoryError='kill -QUIT %p'" ant -f "${CASSANDRA_DIR}/build.xml" check # dependency-check # FIXME dependency-check now requires NVD key downloaded first +# execute. the check target runs rat-check, checkstyle and checkstyle-test, +# and depends on _main-jar, build-test and gen-asciidoc. see build.xml +# memory needs to fit within the specified container size, see .jenkins/Jenkinsfile +# dependency-check # FIXME dependency-check now requires NVD key downloaded first +# append, as .build/docker/_docker_run.sh puts -Dbuild.dir=${DIST_DIR} in ANT_OPTS +export ANT_OPTS="${ANT_OPTS:-} -Xmx2g -XX:+PrintClassHistogram -XX:OnOutOfMemoryError='kill -QUIT %p'" +run_ant check exit $? diff --git a/.build/docker/_docker_run.sh b/.build/docker/_docker_run.sh index 41cdae12074f..ee3784c76e45 100755 --- a/.build/docker/_docker_run.sh +++ b/.build/docker/_docker_run.sh @@ -18,7 +18,7 @@ # # Creates the artifacts, performing additional QA checks # -# Usage: _docker_run.sh +# Usage: _docker_run.sh [] [