From 15d47b01ea8997a24f4c534fba69b2f49624c829 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Mon, 30 Oct 2017 12:10:36 +0000 Subject: [PATCH] Activate macos build in CircleCI (#241) * Activate macos build in CircleCI --- .circleci/config.yml | 31 ++++++++++++++++++++++++++++- install.sh | 4 ++-- src/parse/cffi/cffi_compiler.py | 5 +---- src/parse/rules/go_rules.build_defs | 4 +++- tools/cache/cluster/cluster_test.go | 27 +++++++++++++++++-------- tools/sandbox/main.c | 2 +- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3de1b72db9..41e66f6c41 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2 jobs: - build: + build-linux: working_directory: ~/please docker: - image: thoughtmachine/please_ubuntu:latest @@ -22,3 +22,32 @@ jobs: mv plz-out/gen/package/*.deb plz-out/gen/package/*.tar.gz /tmp/artifacts - store_artifacts: path: /tmp/artifacts + + build-darwin: + macos: + xcode: "9.0" + steps: + - checkout + - run: + name: Install deps + command: brew install go python3 pypy unittest-cpp nasm pkg-config + - run: + name: Bootstrap & Build + command: ./bootstrap.sh -p --exclude no_circleci --test_results_file plz-out/results/test_results.xml + - store_test_results: + path: plz-out/results/test_results.xml + - run: + name: Package + command: | + ./plz-out/bin/src/please build -p //package:all --exclude asc --exclude deb && + mkdir /tmp/artifacts && + mv plz-out/gen/package/*.tar.gz /tmp/artifacts + - store_artifacts: + path: /tmp/artifacts + +workflows: + version: 2 + build-all: + jobs: + - build-linux + - build-darwin diff --git a/install.sh b/install.sh index c847090dd2..c01dcefc6e 100755 --- a/install.sh +++ b/install.sh @@ -17,8 +17,8 @@ rm -f ${DEST}/please ${DEST}/please_pex ${DEST}/junit_runner.jar ${DEST}/jarcat cp -f plz-out/bin/src/please ${DEST}/please chmod 0775 ${DEST}/please ln -sf ${DEST}/please ${DEST}/plz -cp -f plz-out/bin/src/libplease_parser_*.so ${DEST} -chmod 0664 ${DEST}/libplease_parser_*.so +cp -f plz-out/bin/src/libplease_parser_* ${DEST} +chmod 0664 ${DEST}/libplease_parser_* cp -f plz-out/bin/tools/please_pex/please_pex ${DEST}/please_pex chmod 0775 ${DEST}/please_pex cp -f plz-out/bin/tools/junit_runner/junit_runner.jar ${DEST}/junit_runner.jar diff --git a/src/parse/cffi/cffi_compiler.py b/src/parse/cffi/cffi_compiler.py index 332980fe18..8681ffbfa6 100644 --- a/src/parse/cffi/cffi_compiler.py +++ b/src/parse/cffi/cffi_compiler.py @@ -15,10 +15,7 @@ def main(defs_file, parser_file, verbose): ldflags = ['-Wl,-rpath=./plz-out/gen/_remote/_pypy/bin'] if platform.python_implementation() == 'CPython' and platform.system() == 'Darwin': version = platform.python_version_tuple() - ldflags = [ - '-L/usr/local/Cellar/python3/{}/Frameworks/Python.framework/Versions/{}/lib' - .format('{}.{}.{}'.format(*version), '{}.{}'.format(*version)) - ] + ldflags = ['-L' + os.path.join(sys.prefix, 'lib')] ffi.set_source('parser_interface', '#include "%s"' % defs_file, extra_link_args=ldflags) with open(parser_file) as f: diff --git a/src/parse/rules/go_rules.build_defs b/src/parse/rules/go_rules.build_defs index ef2a9fb274..ff2861037c 100644 --- a/src/parse/rules/go_rules.build_defs +++ b/src/parse/rules/go_rules.build_defs @@ -101,7 +101,7 @@ def go_generate(name, srcs, tools, deps=None, visibility=None, test_only=False): # It's also essential that the compiled .a files are under this prefix, otherwise gcimporter won't find them. 'mkdir pkg', 'ln -s $TMP_DIR pkg/%s_%s' % (CONFIG.OS, CONFIG.ARCH), - 'export PATH="$(echo "$TOOLS_GEN " | sed -re \'s|/[^/]+[ ]|:|g\')$PATH"', + 'export PATH="$(echo "$TOOLS_GEN " | sed -E -e \'s|/[^/]+[ ]|:|g\')$PATH"', 'GOPATH="$TMP_DIR$(echo ":$(%s)" | sed "s/:$//g")" $TOOLS_GO generate $SRCS' % gopath, 'mv $PKG_DIR/*.go .', 'ls *.go' @@ -171,6 +171,8 @@ def cgo_library(name, srcs, go_srcs=None, c_srcs=None, hdrs=None, out=None, comp cmd = ' && '.join([ 'cd $PKG_DIR', '$TOOL tool cgo -objdir $TMP_DIR -importpath ${PKG#*src/} *.go', + # Remote the .o file which BSD sed gets upset about in the next command + 'rm -f $TMP_DIR/_cgo_.o', # cgo leaves absolute paths in these files which we must get rid of :( 'find $TMP_DIR -type f -maxdepth 1 | xargs sed -i -e "s|$TMP_DIR/||g"', 'cd $TMP_DIR', diff --git a/tools/cache/cluster/cluster_test.go b/tools/cache/cluster/cluster_test.go index c15ebfd07d..983e1cfec6 100644 --- a/tools/cache/cluster/cluster_test.go +++ b/tools/cache/cluster/cluster_test.go @@ -14,13 +14,15 @@ import ( ) func TestBringUpCluster(t *testing.T) { + lis := openRPCPort(6995) c1 := NewCluster(5995, 6995, "c1") - m1 := newRPCServer(c1, 6995) + m1 := newRPCServer(c1, lis) c1.Init(3) log.Notice("Cluster seeded") + lis = openRPCPort(6996) c2 := NewCluster(5996, 6996, "c2") - m2 := newRPCServer(c2, 6996) + m2 := newRPCServer(c2, lis) c2.Join([]string{"127.0.0.1:5995"}) log.Notice("c2 joined cluster") @@ -42,8 +44,9 @@ func TestBringUpCluster(t *testing.T) { assert.Equal(t, expected, c1.GetMembers()) assert.Equal(t, expected, c2.GetMembers()) + lis = openRPCPort(6997) c3 := NewCluster(5997, 6997, "c3") - m3 := newRPCServer(c2, 6997) + m3 := newRPCServer(c2, lis) c3.Join([]string{"127.0.0.1:5995", "127.0.0.1:5996"}) expected = []*pb.Node{ @@ -124,16 +127,24 @@ func (r *mockRPCServer) Replicate(ctx context.Context, req *pb.ReplicateRequest) return &pb.ReplicateResponse{Success: true}, nil } +// openRPCPort opens a port for the gRPC server. +// This is rather awkwardly split up from below to try to avoid races around the port opening. +// There's something of a circular dependency between starting the gossip service (which triggers +// RPC calls) and starting the gRPC server (which refers to said gossip service). +func openRPCPort(port int) net.Listener { + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) + if err != nil { + log.Fatalf("Failed to listen on port %d: %v", port, err) + } + return lis +} + // newRPCServer creates a new mockRPCServer, starts a gRPC server running it, and returns it. // It's not possible to stop it again... -func newRPCServer(cluster *Cluster, port int) *mockRPCServer { +func newRPCServer(cluster *Cluster, lis net.Listener) *mockRPCServer { m := &mockRPCServer{cluster: cluster} s := grpc.NewServer() pb.RegisterRpcServerServer(s, m) - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) - if err != nil { - log.Fatalf("Failed to listen on port %d: %v", port, err) - } go s.Serve(lis) return m } diff --git a/tools/sandbox/main.c b/tools/sandbox/main.c index 17402da5ad..54c70500d8 100644 --- a/tools/sandbox/main.c +++ b/tools/sandbox/main.c @@ -9,10 +9,10 @@ #define _GNU_SOURCE #include +#include #include #ifdef __linux__ -#include #include #include #include