diff options
| author | zhangjie <iamkadisi@163.com> | 2020-02-04 15:50:23 +0800 |
|---|---|---|
| committer | zhangjie <iamkadisi@163.com> | 2020-02-18 16:11:47 +0800 |
| commit | 0e4424217c83f6d01296604e4414a0ee607149be (patch) | |
| tree | 641f943eeb7940cc2567267e7fb76fb909191c95 /hack | |
| parent | Merge pull request #1473 from chendave/fix_ci (diff) | |
| download | kubeedge-0e4424217c83f6d01296604e4414a0ee607149be.tar.gz | |
use bash to build kubeedge components, and use WHAT param
Signed-off-by: zhangjie <iamkadisi@163.com>
Diffstat (limited to 'hack')
| -rw-r--r--[-rwxr-xr-x] | hack/lib/golang.sh (renamed from hack/lib/version.sh) | 127 | ||||
| -rw-r--r-- | hack/lib/init.sh | 30 | ||||
| -rwxr-xr-x | hack/make-rules/build.sh | 27 |
3 files changed, 178 insertions, 6 deletions
diff --git a/hack/lib/version.sh b/hack/lib/golang.sh index a2e3718e5..4786e71bf 100755..100644 --- a/hack/lib/version.sh +++ b/hack/lib/golang.sh @@ -19,14 +19,13 @@ # KubeEdge Authors: # To Get Detail Version Info for KubeEdge Project - set -o errexit set -o nounset set -o pipefail -KUBEEDGE_GO_PACKAGE="github.com/kubeedge/kubeedge" +readonly KUBEEDGE_GO_PACKAGE="github.com/kubeedge/kubeedge" -edge::version::get_version_info() { +kubeedge::version::get_version_info() { GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null) @@ -87,8 +86,8 @@ edge::version::get_version_info() { } # Get the value that needs to be passed to the -ldflags parameter of go build -edge::version::ldflags() { - edge::version::get_version_info +kubeedge::version::ldflags() { + kubeedge::version::get_version_info local -a ldflags function add_ldflag() { @@ -119,5 +118,121 @@ edge::version::ldflags() { echo "${ldflags[*]-}" } -edge::version::ldflags +# kubeedge::binaries_from_targets take a list of build targets and return the +# full go package to be built +kubeedge::golang::binaries_from_targets() { + local target + for target in "$@"; do + echo "${KUBEEDGE_GO_PACKAGE}/${target}" + done +} + +kubeedge::check::env() { + local -a errors + + if [ -z $GOPATH ]; then + errors+="GOPATH environment value not set" + fi + + # check other env + + # check lenth of errors + if [[ ${#errors[@]} -ne 0 ]] ; then + local error + for error in ${errors[@]}; do + echo "Error: "$error + done + exit 1 + fi +} + + +ALL_BINARIES_AND_TARGETS=( + cloudcore:cloud/cmd/cloudcore + admission:cloud/cmd/admission + keadm:keadm/cmd/keadm + edgecore:edge/cmd/edgecore + edgesite:edgesite/cmd/edgesite +) + +kubeedge::golang::get_target_by_binary() { + local key=$1 + for bt in "${ALL_BINARIES_AND_TARGETS[@]}" ; do + local binary="${bt%%:*}" + if [ "${binary}" == "${key}" ]; then + local target="${bt##*:}" + echo "$target" + return + fi + done + echo "can not find binary: $key" + exit 1 +} + +kubeedge::golang::get_all_targets() { + local -a targets + for bt in "${ALL_BINARIES_AND_TARGETS[@]}" ; do + targets+=("${bt##*:}") + done + echo ${targets[@]} +} + +kubeedge::golang::get_all_binares() { + local -a binares + for bt in "${ALL_BINARIES_AND_TARGETS[@]}" ; do + binares+=("${bt%%:*}") + done + echo ${binares[@]} +} + + +IFS=" " read -ra KUBEEDGE_ALL_TARGETS <<< "$(kubeedge::golang::get_all_targets)" +IFS=" " read -ra KUBEEDGE_ALL_BINARIES<<< "$(kubeedge::golang::get_all_binares)" + +kubeedge::golang::build_binaries() { + echo "building binares $@" + kubeedge::check::env + + local -a targets=() + local binArg + for binArg in "$@"; do + targets+=("$(kubeedge::golang::get_target_by_binary $binArg)") + done + + if [[ ${#targets[@]} -eq 0 ]]; then + targets=("${KUBEEDGE_ALL_TARGETS[@]}") + fi + + local -a binaries + while IFS="" read -r binary; do binaries+=("$binary"); done < <(kubeedge::golang::binaries_from_targets "${targets[@]}") + + local ldflags + read -r ldflags <<< "$(kubeedge::version::ldflags)" + + for bin in ${binaries[@]}; do + go install -ldflags "$ldflags" $bin + done + +} + +kubeedge::golang::place_bins() { + echo "Placing binaries $@" + + local -a binaries=() + local binArg + for binArg in "$@"; do + binaries+=("${binArg}") + done + + if [[ ${#binaries[@]} -eq 0 ]]; then + binaries=("${KUBEEDGE_ALL_BINARIES[@]}") + fi + + mkdir -p ${KUBEEDGE_OUTPUT_BINPATH} + + local name + for name in ${binaries[@]}; do + mv -f "${GOPATH}/bin/${name}" ${KUBEEDGE_OUTPUT_BINPATH} + done +} diff --git a/hack/lib/init.sh b/hack/lib/init.sh new file mode 100644 index 000000000..776cf4384 --- /dev/null +++ b/hack/lib/init.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +### +#Copyright 2020 The KubeEdge Authors. +# +#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 -o errexit +set -o nounset +set -o pipefail + +# The root of the build/dist directory +KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" + +KUBEEDGE_OUTPUT_SUBPATH="${KUBEEDGE_OUTPUT_SUBPATH:-_output/local}" +KUBEEDGE_OUTPUT="${KUBEEDGE_ROOT}/${KUBEEDGE_OUTPUT_SUBPATH}" +KUBEEDGE_OUTPUT_BINPATH="${KUBEEDGE_OUTPUT}/bin" + +source "${KUBEEDGE_ROOT}/hack/lib/golang.sh" diff --git a/hack/make-rules/build.sh b/hack/make-rules/build.sh new file mode 100755 index 000000000..63e31e9be --- /dev/null +++ b/hack/make-rules/build.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +### +#Copyright 2020 The KubeEdge Authors. +# +#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 -o errexit +set -o nounset +set -o pipefail + +KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" +source "${KUBEEDGE_ROOT}/hack/lib/init.sh" + +kubeedge::golang::build_binaries "$@" +kubeedge::golang::place_bins "$@" |
