github.phpd.cn/thought-machine/please@v12.2.0+incompatible/bootstrap.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 function notice { 6 >&2 echo -e "\033[32m$1\033[0m" 7 } 8 function noticen { 9 >&2 echo -n -e "\033[32m$1\033[0m" 10 } 11 function go_get { 12 go get $1 13 noticen "." 14 } 15 function warn { 16 >&2 echo -e "\033[33m$1\033[0m" 17 } 18 19 # PLZ_ARGS can be set to pass arguments to all plz invocations in this script. 20 PLZ_ARGS="${PLZ_ARGS:-}" 21 22 # Fetch the Go dependencies manually 23 noticen "Installing Go dependencies..." 24 mkdir -p "${PWD}/.bootstrap" 25 export GOPATH="${PWD}/.bootstrap:${PWD}" 26 go_get golang.org/x/crypto/ssh/terminal 27 go_get golang.org/x/sync/errgroup 28 go_get golang.org/x/tools/cover 29 go_get gopkg.in/op/go-logging.v1 30 go_get gopkg.in/gcfg.v1 31 go_get github.com/kevinburke/go-bindata/... 32 go_get github.com/jessevdk/go-flags 33 go_get github.com/dustin/go-humanize 34 go_get github.com/texttheater/golang-levenshtein/levenshtein 35 go_get github.com/Workiva/go-datastructures/queue 36 go_get github.com/coreos/go-semver/semver 37 go_get github.com/djherbis/atime 38 go_get github.com/karrick/godirwalk 39 go_get github.com/hashicorp/go-multierror 40 go_get github.com/google/shlex 41 notice "" 42 43 # Detect javac presence and swap to compiling locally if we find it. 44 if hash javac 2>/dev/null ; then 45 PLZ_ARGS="$PLZ_ARGS -o buildconfig.build_java:true" 46 else 47 warn "javac not found, using prebuilt Java plugins" 48 fi 49 50 # Clean out old artifacts. 51 rm -rf plz-out src/parse/rules/builtin_rules.bindata.go src/parse/rules/builtin_data.bindata.go 52 # Compile the builtin rules 53 notice "Compiling built-in rules..." 54 go run src/parse/asp/main/compiler.go -o plz-out/tmp/src/parse/rules src/parse/rules/*.build_defs 55 # Embed them into Go 56 .bootstrap/bin/go-bindata -o src/parse/rules/builtin_data.bindata.go -pkg rules -prefix plz-out/tmp/src/parse/rules plz-out/tmp/src/parse/rules 57 58 # Now invoke Go to run Please to build itself. 59 notice "Building Please..." 60 go run -tags bootstrap src/please.go $PLZ_ARGS build //src:please --log_file plz-out/log/bootstrap_build.log 61 # Use it to build the rest of the tools that come with it. 62 notice "Building the tools..." 63 plz-out/bin/src/please $PLZ_ARGS build //package:installed_files --log_file plz-out/log/tools_build.log 64 65 if [ $# -gt 0 ] && [ "$1" == "--skip_tests" ]; then 66 exit 0 67 fi 68 69 # Run the tests to make sure they still work 70 notice "Running tests..." 71 72 # Run the set of tests that will work on this machine. 73 # We assume the user has Java installed or the build will have already failed, 74 # but some other parts are optional until one actually tries to use the rule. 75 EXCLUDES="" 76 77 HAVE_UNITTEST=false 78 for path in `echo -e | cpp -xc++ -Wp,-v 2>&1 | grep "^ "`; do 79 if [ -f "${path}/UnitTest++/UnitTest++.h" ]; then 80 HAVE_UNITTEST=true 81 fi 82 done 83 if ! $HAVE_UNITTEST ; then 84 warn "UnitTest++.h not found, excluding C++ tests" 85 EXCLUDES="${EXCLUDES} --exclude=cc" 86 else 87 if [ "`uname`" = "Darwin" ]; then 88 if ! hash nasm 2>/dev/null ; then 89 # OSX comes with an ancient version of nasm that can't target 90 # 64-bit Mach-O binaries (?!!). Ensure we've got the Brew one. 91 if [ -n "`nasm -v | grep 'version 2'`" ]; then 92 warn "nasm 2.x not found, excluding C++ tests" 93 EXCLUDES="${EXCLUDES} --exclude=cc" 94 fi 95 fi 96 fi 97 fi 98 if ! hash docker 2>/dev/null ; then 99 warn "Docker not found, excluding containerised tests" 100 EXCLUDES="${EXCLUDES} --exclude=container" 101 fi 102 if ! hash python2 2>/dev/null ; then 103 warn "python2 not found, excluding python2 tests" 104 EXCLUDES="${EXCLUDES} --exclude=py2" 105 fi 106 if ! hash python3 2>/dev/null ; then 107 warn "python3 not found, excluding python3 tests" 108 EXCLUDES="${EXCLUDES} --exclude=py3 --exclude python3" 109 fi 110 if ! hash clang++ 2>/dev/null ; then 111 warn "Clang not found, excluding Clang tests" 112 EXCLUDES="${EXCLUDES} --exclude=clang" 113 fi 114 if ! hash gold 2>/dev/null ; then 115 warn "Gold not found, excluding Gold tests" 116 EXCLUDES="${EXCLUDES} --exclude=gold" 117 fi 118 if ! hash java 2>/dev/null ; then 119 warn "Java not found, excluding Java tests" 120 EXCLUDES="${EXCLUDES} --exclude=java" 121 fi 122 # If the proto files are installed in a different location, their tests won't work. 123 if [ ! -d "/usr/include/google/protobuf" ]; then 124 warn "google/protobuf not found, excluding relevant tests" 125 EXCLUDES="${EXCLUDES} --exclude=proto" 126 fi 127 GCCVER="`gcc -dumpversion`" 128 if [ ! -d "/usr/lib/gcc/x86_64-linux-gnu/${GCCVER%.*.*}/32" ]; then 129 warn "32-bit gcc libraries not found, excluding cross-compile tests" 130 EXCLUDES="${EXCLUDES} --exclude=x86" 131 fi 132 133 plz-out/bin/src/please $PLZ_ARGS ${PLZ_COVER:-test} $EXCLUDES --log_file plz-out/log/test_build.log --log_file_level 4 $@ 134 135 # Lint needs python3. 136 if hash python3 2>/dev/null ; then 137 # Don't run this in CI or any unusual workflows. 138 if [ $# -eq 0 ] ; then 139 tools/misc/ci_lint.py 140 fi 141 fi