From 41beaf8f9f8112bf283b4096e1e818fec1b14d7d Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 22 Sep 2016 00:18:12 -0700 Subject: [PATCH] Add windows as a supported cross-compile platform. Add cross-compiling for supported platforms to our CircleCI builders. Signed-off-by: Ying Li --- Makefile | 2 +- buildscripts/circle_parallelism.sh | 1 + buildscripts/cross.sh | 20 +++++++++------- buildscripts/testclient.py | 38 ++++++++++++++++++++++-------- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 2c2ee16ea2..d31b1fe670 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif CTIMEVAR=-X $(NOTARY_PKG)/version.GitCommit=$(GITCOMMIT) -X $(NOTARY_PKG)/version.NotaryVersion=$(NOTARY_VERSION) GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)" GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static" -GOOSES = darwin linux +GOOSES = darwin linux windows NOTARY_BUILDTAGS ?= pkcs11 NOTARYDIR := /go/src/github.com/docker/notary diff --git a/buildscripts/circle_parallelism.sh b/buildscripts/circle_parallelism.sh index cc07fdc2d0..961d90a6ad 100755 --- a/buildscripts/circle_parallelism.sh +++ b/buildscripts/circle_parallelism.sh @@ -8,6 +8,7 @@ case $CIRCLE_NODE_INDEX in ;; 2) SKIPENVCHECK=1 make TESTDB=mysql testdb SKIPENVCHECK=1 make TESTDB=mysql integration + SKIPENVCHECK=1 make cross # just trying not to exceed 5 builders ;; 3) SKIPENVCHECK=1 make TESTDB=rethink testdb SKIPENVCHECK=1 make TESTDB=rethink integration diff --git a/buildscripts/cross.sh b/buildscripts/cross.sh index 840a751aa6..324f50081f 100755 --- a/buildscripts/cross.sh +++ b/buildscripts/cross.sh @@ -7,15 +7,9 @@ GOARCH="amd64" -if [[ "${NOTARY_BUILDTAGS}" == *pkcs11* ]]; then - export CGO_ENABLED=1 -else - export CGO_ENABLED=0 -fi - - for os in "$@"; do export GOOS="${os}" + BUILDTAGS="${NOTARY_BUILDTAGS}" if [[ "${GOOS}" == "darwin" ]]; then export CC="o64-clang" @@ -24,18 +18,28 @@ for os in "$@"; do # darwin binaries can't be compiled to be completely static with the -static flag LDFLAGS="-s" else + # no building with Cgo. Also no building with pkcs11 + if [[ "${GOOS}" == "windows" ]]; then + BUILDTAGS="" + fi unset CC unset CXX LDFLAGS="-extldflags -static" fi + if [[ "${BUILDTAGS}" == *pkcs11* ]]; then + export CGO_ENABLED=1 + else + export CGO_ENABLED=0 + fi + mkdir -p "${NOTARYDIR}/cross/${GOOS}/${GOARCH}"; set -x; go build \ -o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/notary" \ -a \ - -tags "${NOTARY_BUILDTAGS}" \ + -tags "${BUILDTAGS}" \ -ldflags "-w ${CTIMEVAR} ${LDFLAGS}" \ ./cmd/notary; set +x; diff --git a/buildscripts/testclient.py b/buildscripts/testclient.py index e92598aef0..9a18098473 100755 --- a/buildscripts/testclient.py +++ b/buildscripts/testclient.py @@ -13,11 +13,13 @@ import os from shutil import rmtree from subprocess import CalledProcessError, PIPE, Popen, call +import sys from tempfile import mkdtemp, mkstemp from textwrap import dedent from time import sleep, time from uuid import uuid4 + def reporoot(): """ Get the root of the git repo @@ -25,6 +27,10 @@ def reporoot(): return os.path.dirname( os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) + +DEFAULT_BINARY = os.path.join(reporoot(), "bin", "notary") + + # Returns the reponame and server name def parse_args(args=None): """ @@ -58,9 +64,13 @@ def parse_args(args=None): parser.add_argument( '-u', '--username', dest="username", type=str, help="Username to use to log into the Notary Server (you will be asked for the password") + parser.add_argument( + '-b', '--binary', dest="binary", type=str, default=DEFAULT_BINARY, + help="Absolute path to the notary binary to use") parsed = parser.parse_args(args) - return parsed.reponame, parsed.server, parsed.username + return parsed.reponame, parsed.server, parsed.username, parsed.binary + def cleanup(*paths): """ @@ -79,15 +89,15 @@ def cleanup(*paths): except OSError: pass + class Client(object): """ Object that will run the notary client with the proper command lines """ - def __init__(self, notary_server, username_passwd=()): + def __init__(self, notary_binary, notary_server, username_passwd=()): self.notary_server = notary_server self.username_passwd = username_passwd - binary = os.path.join(reporoot(), "bin", "notary") self.env = os.environ.copy() self.env.update({ "NOTARY_ROOT_PASSPHRASE": "root_ponies", @@ -97,9 +107,9 @@ def __init__(self, notary_server, username_passwd=()): }) if notary_server is None: - self.client = [binary, "-c", "cmd/notary/config.json"] + self.client = [notary_binary, "-c", "cmd/notary/config.json"] else: - self.client = [binary, "-s", notary_server] + self.client = [notary_binary, "-s", notary_server] def run(self, args, trust_dir, stdinput=None, username_passwd=None): """ @@ -140,6 +150,7 @@ def run(self, args, trust_dir, stdinput=None, username_passwd=None): raise CalledProcessError(retcode, command, output=output) return output + class Tester(object): """ Thing that runs the test @@ -307,6 +318,7 @@ def run(self): cleanup(self.dir) + def wait_for_server(server, timeout_in_seconds): """ Attempts to contact the server until it is up @@ -334,11 +346,12 @@ def wait_for_server(server, timeout_in_seconds): raise Exception( "Could not connect to {0} after {1} seconds.".format(server, timeout_in_seconds)) + def run(): """ Run the client tests """ - repo_name, server, username = parse_args() + repo_name, server, username, notary_binary = parse_args() if not repo_name: repo_name = uuid4().hex if server is not None: @@ -347,9 +360,14 @@ def run(): if server in ("https://notary-server:4443", "https://notaryserver:4443", ""): server = None - print("building a new client binary") - call(['make', '-C', reporoot(), 'client']) - print('---') + if not os.path.isfile(notary_binary): + if notary_binary == DEFAULT_BINARY: + print("building a new client binary") + call(['make', '-C', reporoot(), 'client']) + print('---') + else: + print("no such notary client file: {}".format(notary_binary)) + sys.exit(1) username_passwd = () if username is not None and username.strip(): @@ -359,7 +377,7 @@ def run(): wait_for_server(server, 120) - Tester(repo_name, Client(server, username_passwd)).run() + Tester(repo_name, Client(notary_binary, server, username_passwd)).run() try: with open("/test_output/SUCCESS", 'wb') as successFile: