Skip to content

Commit

Permalink
refactored binary build subshell use
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Apr 15, 2016
1 parent e40110d commit 8407af7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hack/build-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ fi

# Build the primary client/server for all platforms
OS_BUILD_PLATFORMS=("${platforms[@]}")
os::build::build_binaries "${OS_CROSS_COMPILE_TARGETS[@]}"
# Create a sub-shell so that we don't pollute the outer environment
( os::build::build_binaries "${OS_CROSS_COMPILE_TARGETS[@]}" )

# Build image binaries for a subset of platforms. Image binaries are currently
# linux-only, and are compiled with flags to make them static for use in Docker
Expand Down
3 changes: 2 additions & 1 deletion hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ if [[ -z "$@" ]]; then
fi
fi

os::build::build_binaries "$@"
# Create a sub-shell so that we don't pollute the outer environment
( os::build::build_binaries "$@" )
os::build::place_bins "$@"
os::build::make_openshift_binary_symlinks

Expand Down
6 changes: 2 additions & 4 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ EOF
# OS_BUILD_PLATFORMS - Incoming variable of targets to build for. If unset
# then just the host architecture is built.
os::build::build_static_binaries() {
CGO_ENABLED=0 os::build::build_binaries -a -installsuffix=cgo $@
# Create a sub-shell so that we don't pollute the outer environment
( CGO_ENABLED=0 os::build::build_binaries -a -installsuffix=cgo $@ )
}

# Build binaries targets specified
Expand All @@ -251,8 +252,6 @@ os::build::build_static_binaries() {
# OS_BUILD_PLATFORMS - Incoming variable of targets to build for. If unset
# then just the host architecture is built.
os::build::build_binaries() {
# Create a sub-shell so that we don't pollute the outer environment
(
# Check for `go` binary and set ${GOPATH}.
os::build::setup_env

Expand Down Expand Up @@ -319,7 +318,6 @@ os::build::build_binaries() {
"$(dirname ${test})"
done
done
)
}

# Generates the set of target packages, binaries, and platforms to build for.
Expand Down
7 changes: 4 additions & 3 deletions hack/lib/log/stacktrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ function os::log::stacktrace::print() {
local stack_index=1
local i
for (( i = stack_begin_index; i < ${#BASH_SOURCE[@]}; i++ )); do
local bash_source="$( os::util::repository_relative_path "${BASH_SOURCE[$i]}" )"
if [[ -z "${preamble_finished-}" ]]; then
preamble_finished=true
os::log::error "${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}: \`${last_command}\` exited with status ${return_code}." >&2
os::log::error "${bash_source}:${BASH_LINENO[$i-1]}: \`${last_command}\` exited with status ${return_code}." >&2
os::log::info $'\t\t'"Stack Trace: " >&2
os::log::info $'\t\t'" ${stack_index}: ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}: \`${last_command}\`" >&2
os::log::info $'\t\t'" ${stack_index}: ${bash_source}:${BASH_LINENO[$i-1]}: \`${last_command}\`" >&2
else
os::log::info $'\t\t'" ${stack_index}: ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}: ${FUNCNAME[$i-1]}" >&2
os::log::info $'\t\t'" ${stack_index}: ${bash_source}:${BASH_LINENO[$i-1]}: ${FUNCNAME[$i-1]}" >&2
fi
stack_index=$(( stack_index + 1 ))
done
Expand Down
22 changes: 22 additions & 0 deletions hack/lib/util/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,25 @@ function os::util::describe_return_code() {
function os::util::install_describe_return_code() {
export OS_DESCRIBE_RETURN_CODE="true"
}

# os::util::repository_relative_path returns the relative path from the $OS_ROOT directory to the
# given file, if the file is inside of the $OS_ROOT directory. If the file is outside of $OS_ROOT,
# this function will return the absolute path to the file
#
# Globals:
# - OS_ROOT
# Arguments:
# - 1: the path to relativize
# Returns:
# None
function os::util::repository_relative_path() {
local filename=$1

if which realpath >&/dev/null; then
local trim_path="$( realpath "${OS_ROOT}" )/"
filename="$( realpath "${filename}" )"
filename="${filename##*${trim_path}}"
fi

echo "${filename}"
}

0 comments on commit 8407af7

Please sign in to comment.