diff --git a/.travis.yml b/.travis.yml index 25a62a5bf..70000ca32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,12 +26,13 @@ install: - cd $SNAP_SOURCE # change dir into source - make script: -- make check 2>&1 # Run test suite +- make test 2>&1 # Run test suite notifications: email: false slack: secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= before_deploy: +- make all - "./scripts/pre_deploy.sh" deploy: provider: s3 diff --git a/Makefile b/Makefile index 97b9e27c1..4fd9adee0 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,8 @@ ARCH = $(shell uname -m) default: $(MAKE) deps - $(MAKE) all + $(MAKE) snap + $(MAKE) plugins deps: bash -c "./scripts/deps.sh" test: @@ -33,10 +34,19 @@ test-medium: bash -c "./scripts/test.sh medium" test-large: bash -c "./scripts/test.sh large" -check: - $(MAKE) test -all: +# NOTE: +# By default compiles will use all cpu cores, use BUILD_JOBS to control number +# of parallel builds: `BUILD_JOBS=2 make plugins` +# +# Build only snapd/snapctl +snap: bash -c "./scripts/build_snap.sh" +# Build only plugins +plugins: + bash -c "./scripts/build_plugins.sh" +# Build snap and plugins for all platforms +all: + bash -c "./scripts/build_all.sh" install: cp build/$(OS)/$(ARCH)/snapd /usr/local/bin/ cp build/$(OS)/$(ARCH)/snapctl /usr/local/bin/ diff --git a/plugin/helper/helper.go b/plugin/helper/helper.go index d73a1d2c9..30fd563aa 100644 --- a/plugin/helper/helper.go +++ b/plugin/helper/helper.go @@ -51,7 +51,7 @@ func PluginPath() string { arch = runtime.GOARCH } - fpath := path.Join(BuildPath, runtime.GOOS, arch) + fpath := path.Join(BuildPath, runtime.GOOS, arch, "plugins") return fpath } diff --git a/scripts/build_all.sh b/scripts/build_all.sh new file mode 100755 index 000000000..c82567f80 --- /dev/null +++ b/scripts/build_all.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +export GOOS=linux +export GOARCH=amd64 +"${__dir}/build_snap.sh" & +"${__dir}/build_plugins.sh" & + +export GOOS=darwin +export GOARCH=amd64 +"${__dir}/build_snap.sh" & +"${__dir}/build_plugins.sh" & + +wait diff --git a/scripts/build_plugin.sh b/scripts/build_plugin.sh index 3195f6611..8ba0228ba 100755 --- a/scripts/build_plugin.sh +++ b/scripts/build_plugin.sh @@ -27,14 +27,17 @@ __proj_dir="$(dirname "$__dir")" # shellcheck source=scripts/common.sh . "${__dir}/common.sh" -build_dir="${__proj_dir}/build" -plugin_dir="${build_dir}/${GOOS}/x86_64" +if [[ "${GOARCH}" == "amd64" ]]; then + build_dir="${__proj_dir}/build/${GOOS}/x86_64/plugins" +else + build_dir="${__proj_dir}/build/${GOOS}/${GOARCH}/plugins" +fi plugin_src_path=$1 plugin_name=$(basename "${plugin_src_path}") go_build=(go build -a -ldflags "-w") _debug "plugin source: ${plugin_src_path}" -_info "building ${plugin_name}" +_info "building ${plugin_name} for ${GOOS}/${GOARCH}" -(cd "${plugin_src_path}" && "${go_build[@]}" -o "${plugin_dir}/${plugin_name}" . || exit 1) +(cd "${plugin_src_path}" && "${go_build[@]}" -o "${build_dir}/${plugin_name}" . || exit 1) diff --git a/scripts/build_plugins.sh b/scripts/build_plugins.sh new file mode 100755 index 000000000..fed44c801 --- /dev/null +++ b/scripts/build_plugins.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +#http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +#Copyright 2015 Intel Corporation +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +_info "project path: ${__proj_dir}" + +git_version=$(_git_version) +go_build=(go build -ldflags "-w -X main.gitversion=${git_version}") + +_info "git commit: $(git log --pretty=format:"%H" -1)" + +# Disable CGO for builds. +export CGO_ENABLED=0 + +# rebuild binaries: +export GOOS=${GOOS:-$(uname -s | tr '[:upper:]' '[:lower:]')} +export GOARCH=${GOARCH:-"amd64"} + +OS=$(uname -s) +if [[ "${OS}" == "Darwin" ]]; then + p=$(type -p sysctl > /dev/null && sysctl -n hw.ncpu || echo "1") +elif [[ "${OS}" == "Linux" ]]; then + p=$(type -p nproc > /dev/null && nproc || echo "1") +else + p="1" +fi +p=${BUILD_JOBS:-"${p}"} + +if [[ "${GOARCH}" == "amd64" ]]; then + build_path="${__proj_dir}/build/${GOOS}/x86_64" +else + build_path="${__proj_dir}/build/${GOOS}/${GOARCH}" +fi + +mkdir -p "${build_path}/plugins" +_info "building plugins for ${GOOS}/${GOARCH} in ${p} parallels" +find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -P $p -I{} "${__dir}/build_plugin.sh" {} diff --git a/scripts/build_snap.sh b/scripts/build_snap.sh index 2bbcc9f32..c93f6abf9 100755 --- a/scripts/build_snap.sh +++ b/scripts/build_snap.sh @@ -17,11 +17,6 @@ #See the License for the specific language governing permissions and #limitations under the License. -git_branch=$(git symbolic-ref HEAD 2> /dev/null | cut -b 12-) -git_branch="${git_branch:-test}" -git_sha=$(git log --pretty=format:"%h" -1) -git_version=$(git describe --always --exact-match 2> /dev/null || echo "${git_branch}-${git_sha}") - set -e set -u set -o pipefail @@ -34,7 +29,7 @@ __proj_dir="$(dirname "$__dir")" _info "project path: ${__proj_dir}" -build_path="${__proj_dir}/build" +git_version=$(_git_version) go_build=(go build -ldflags "-w -X main.gitversion=${git_version}") _info "snap build version: ${git_version}" @@ -44,24 +39,16 @@ _info "git commit: $(git log --pretty=format:"%H" -1)" export CGO_ENABLED=0 # rebuild binaries: -export GOOS=linux -export GOARCH=amd64 -bin_path="${build_path}/${GOOS}/x86_64" -mkdir -p "${bin_path}" -_info "building snapd/snapctl for ${GOOS}/${GOARCH}" -"${go_build[@]}" -o "${bin_path}/snapd" . || exit 1 -(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${bin_path}/snapctl" . || exit 1) +export GOOS=${GOOS:-$(uname -s | tr '[:upper:]' '[:lower:]')} +export GOARCH=${GOARCH:-"amd64"} -_info "building plugins for ${GOOS}/${GOARCH}" -find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -I{} "${__dir}/build_plugin.sh" {} +if [[ "${GOARCH}" == "amd64" ]]; then + build_path="${__proj_dir}/build/${GOOS}/x86_64" +else + build_path="${__proj_dir}/build/${GOOS}/${GOARCH}" +fi -export GOOS=darwin -export GOARCH=amd64 -bin_path="${build_path}/${GOOS}/x86_64" -mkdir -p "${bin_path}" +mkdir -p "${build_path}" _info "building snapd/snapctl for ${GOOS}/${GOARCH}" -"${go_build[@]}" -o "${bin_path}/snapd" . || exit 1 -(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${bin_path}/snapctl" . || exit 1) - -_info "building plugins for ${GOOS}/${GOARCH}" -find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -I{} "${__dir}/build_plugin.sh" {} +"${go_build[@]}" -o "${build_path}/snapd" . || exit 1 +(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${build_path}/snapctl" . || exit 1) diff --git a/scripts/common.sh b/scripts/common.sh index 75c0c9248..d989a1be1 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -122,3 +122,11 @@ _go_test() { _go_cover() { go tool cover -func "profile-${TEST_TYPE}.cov" } + +_git_version() { + git_branch=$(git symbolic-ref HEAD 2> /dev/null | cut -b 12-) + git_branch="${git_branch:-test}" + git_sha=$(git log --pretty=format:"%h" -1) + git_version=$(git describe --always --exact-match 2> /dev/null || echo "${git_branch}-${git_sha}") + echo "${git_version}" +}