Skip to content

Commit

Permalink
Update build.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Elzner <[email protected]>
  • Loading branch information
enteraga6 authored Oct 23, 2023
1 parent 1d08a79 commit 614163e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/builders/bazel/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ binaries_dir="bazel_builder_binaries_to_upload_to_gh_7bc972367cb286b7f36ab4457f0
mkdir ${binaries_dir}

# Transfer flags and targets to their respective arrays
IFS=' ' read -r -a build_flags <<< "${FLAGS}"
IFS=' ' read -r -a build_targets <<< "${TARGETS}"
IFS=' ' read -r -a build_flags <<< "${UNTRUSTED_FLAGS}"
IFS=' ' read -r -a build_targets <<< "${UNTRUSTED_TARGETS}"

# If the targets includes Java targets, include Java build flag
# and add Github Runner Java rule to WORKSPACE
if [[ "${INCLUDES_JAVA}" == "true" ]]
if [[ "${UNTRUSTED_INCLUDES_JAVA}" == "true" ]]
then
build_flags+=("--java_runtime_version=myjdk")

Expand All @@ -52,20 +52,20 @@ declare -A targets_set
################################################

for input in "${build_targets[@]}"; do

# Using bazel query extracts all targets from a glob pattern.
# Thus we can change Java targets to their _deploy.jar target.
for target in $(bazel query "$input"); do

# Check to see if the target is a Java target. If it is the output is a Java target.
# Note: targets that already have the _deploy.jar suffix will have no output from the query
output=$(bazel query "kind(java_binary, $target)" 2>/dev/null)

# If there is a Java target without _deploy.jar suffix, add suffix, build and add to target set.
if [[ -n "$output" ]]
then
bazel build "${build_flags[@]}" "${target}_deploy.jar"
targets_set["${target}_deploy.jar"]="1"
targets_set["${target}_deploy.jar"]="1"
else
# Build target regularly.
bazel build "${build_flags[@]}" "$target"
Expand All @@ -81,7 +81,7 @@ done
################################################

for curr_target in "${!targets_set[@]}"; do

# Removes everything up to and including the first colon
# "//src/internal:fib" --> "fib"
binary_name=${curr_target#*:}
Expand All @@ -107,7 +107,7 @@ for curr_target in "${!targets_set[@]}"; do
# Copy JAR to artifact-specific dir in ./${binaries_dir} and remove symbolic links.
file="$bazel_generated"
cp -Lr "$file" "./${binaries_dir}/$run_script_name"

# Get the path the to run-script associated with the {$curr_target}_deploy.jar
# If the user inputted the path to their local JAVABIN insert that into the run-script to define it.
# Inputting a local path to JAVABIN is needed or else run-script will not work as it points to Github Runner JAVABIN
Expand All @@ -118,19 +118,19 @@ for curr_target in "${!targets_set[@]}"; do
# to run the run-script themselves, which would not be possible as it is either set to the Github Runner VM Java bin path
# if no flag to USER_LOCAL_JAVABIN is passed in their workflow or to the path passed in their flag.
awk -v n=66 -v s=' --local_javabin=*) USER_JAVA_BIN=( "${1#--local_javabin=}" ) ;;' 'NR == n {print s} {print}' "$run_script_path" > temp_file && mv -f temp_file "$run_script_path"

# Updates Java Bin in run-script after the flags get proccessed
awk -v n=127 -v s='' 'NR == n {print s} {print}' "$run_script_path" > temp_file && mv -f temp_file "$run_script_path"
awk -v n=128 -v s='if [[ -n $USER_JAVA_BIN ]]; then JAVABIN=$USER_JAVA_BIN; fi' 'NR == n {print s} {print}' "$run_script_path" > temp_file && mv -f temp_file "$run_script_path"

cp -L "$run_script_path" "./${binaries_dir}/$run_script_name"

################################################
# #
# Logic for Non-Java Targets #
# #
################################################

else

################################################
Expand All @@ -139,7 +139,7 @@ for curr_target in "${!targets_set[@]}"; do
# #
################################################

if [[ "${NEEDS_RUNFILES}" == "true" ]]
if [[ "${UNTRUSTED_NEEDS_RUNFILES}" == "true" ]]
then
# Get file(s) generated from build with respect to the target
bazel_generated=$(bazel cquery --output=starlark --starlark:expr="'\n'.join([f.path for f in target.files.to_list()])" "$curr_target" 2>/dev/null)
Expand Down Expand Up @@ -178,7 +178,7 @@ for curr_target in "${!targets_set[@]}"; do
else
# Get file(s) generated from build with respect to the target
bazel_generated=$(bazel cquery --output=starlark --starlark:expr="'\n'.join([f.path for f in target.files.to_list()])" "$curr_target" 2>/dev/null)

# Uses a Starlark expression to pass new line seperated list of file(s) into the set of files
while read -r file; do
cp -L "$file" ./${binaries_dir}
Expand Down

0 comments on commit 614163e

Please sign in to comment.