Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ tasks:
- echo "build --tool_java_language_version=21" >> .bazelrc
- echo "build --tool_java_runtime_version=21" >> .bazelrc
- "./test_rules_scala.sh"
dt_patches_linux:
name: "dt_patches/dt_patch_test"
platform: ubuntu2004
shell_commands:
- "dt_patches/dt_patch_test.sh"
dependency_versions_linux:
name: "./test_dependency_versions"
platform: ubuntu2004
Expand Down
236 changes: 115 additions & 121 deletions dt_patches/dt_patch_test.sh
Original file line number Diff line number Diff line change
@@ -1,160 +1,154 @@
#!/usr/bin/env bash

set -euo pipefail

dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'

run_test_local() {
# runs the tests locally
set +e
SECONDS=0
TEST_ARG=$@
echo "running test $TEST_ARG"
RES=$($TEST_ARG 2>&1)
RESPONSE_CODE=$?
DURATION=$SECONDS
if [ $RESPONSE_CODE -eq 0 ]; then
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
else
echo $RES
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
return $RESPONSE_CODE
fi
}
# shellcheck source=./test_runner.sh
. "${dir}"/../test/shell/test_runner.sh
. "${dir}"/../test/shell/test_helper.sh
runner="$(get_test_runner "${1:-local}")"

run_in_test_repo() {
local test_command=$1
local test_repo=$2
local test_repo="$1"
local test_command=("${@:2}")
local response_code=0

cd "${dir}/${test_repo}" || exit 1
${test_command}
RESPONSE_CODE=$?
cd "${dir}/${test_repo}" || return 1
"${test_command[@]}" || response_code=$?

bazel shutdown

cd ../..

return $RESPONSE_CODE
return $response_code
}

test_compiler_patch() {
local SCALA_VERSION="$1"

run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..." "test_dt_patches"
run_in_test_repo \
test_dt_patches \
bazel build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //...
}

test_compiler_srcjar() {
set -o pipefail
local SCALA_VERSION="$1"

run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..." "test_dt_patches_user_srcjar" 2>&1 | (! grep "canonical reproducible")
run_in_test_repo \
test_dt_patches_user_srcjar \
bazel build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //... 2>&1 |
(! grep "canonical reproducible")
}

test_compiler_srcjar_nonhermetic() {
set -o pipefail
local SCALA_VERSION="$1"

run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..." "test_dt_patches_user_srcjar" 2>&1 | grep "canonical reproducible"
run_in_test_repo \
test_dt_patches_user_srcjar \
bazel build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //... 2>&1 |
grep 'canonical reproducible'
}

test_compiler_srcjar_error() {
local SCALA_VERSION="$1"
local EXPECTED_ERROR="scala_compiler_srcjar invalid"

run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..." "test_dt_patches_user_srcjar" 2>&1 | grep "$EXPECTED_ERROR"
run_in_test_repo \
test_dt_patches_user_srcjar \
action_should_fail_with_message \
'scala_compiler_srcjar invalid' \
build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //...
}

#run_test_local test_compiler_patch 2.11.0
#run_test_local test_compiler_patch 2.11.1
#run_test_local test_compiler_patch 2.11.2
#run_test_local test_compiler_patch 2.11.3
#run_test_local test_compiler_patch 2.11.4
#run_test_local test_compiler_patch 2.11.5
#run_test_local test_compiler_patch 2.11.6
#run_test_local test_compiler_patch 2.11.7
#run_test_local test_compiler_patch 2.11.8
#run_test_local test_compiler_patch 2.11.9
#run_test_local test_compiler_patch 2.11.10
#run_test_local test_compiler_patch 2.11.11
run_test_local test_compiler_patch 2.11.12

#run_test_local test_compiler_patch 2.12.0
run_test_local test_compiler_patch 2.12.1
run_test_local test_compiler_patch 2.12.2
run_test_local test_compiler_patch 2.12.3
run_test_local test_compiler_patch 2.12.4
run_test_local test_compiler_patch 2.12.5
run_test_local test_compiler_patch 2.12.6
run_test_local test_compiler_patch 2.12.7
run_test_local test_compiler_patch 2.12.8
run_test_local test_compiler_patch 2.12.9
run_test_local test_compiler_patch 2.12.10
run_test_local test_compiler_patch 2.12.11
run_test_local test_compiler_patch 2.12.12
run_test_local test_compiler_patch 2.12.13
run_test_local test_compiler_patch 2.12.14
run_test_local test_compiler_patch 2.12.15
run_test_local test_compiler_patch 2.12.16
run_test_local test_compiler_patch 2.12.17
run_test_local test_compiler_patch 2.12.18
run_test_local test_compiler_patch 2.12.19
run_test_local test_compiler_patch 2.12.20

run_test_local test_compiler_patch 2.13.0
run_test_local test_compiler_patch 2.13.1
run_test_local test_compiler_patch 2.13.2
run_test_local test_compiler_patch 2.13.3
run_test_local test_compiler_patch 2.13.4
run_test_local test_compiler_patch 2.13.5
run_test_local test_compiler_patch 2.13.6
run_test_local test_compiler_patch 2.13.7
run_test_local test_compiler_patch 2.13.8
run_test_local test_compiler_patch 2.13.10
run_test_local test_compiler_patch 2.13.11
run_test_local test_compiler_patch 2.13.12
run_test_local test_compiler_patch 2.13.14
run_test_local test_compiler_patch 2.13.15
run_test_local test_compiler_patch 2.13.16

run_test_local test_compiler_patch 3.1.0 # Minimal supported version
run_test_local test_compiler_patch 3.1.3
run_test_local test_compiler_patch 3.2.2
run_test_local test_compiler_patch 3.3.6
run_test_local test_compiler_patch 3.4.3
run_test_local test_compiler_patch 3.5.2
run_test_local test_compiler_patch 3.6.4
run_test_local test_compiler_patch 3.7.0

run_test_local test_compiler_srcjar_error 2.12.11
run_test_local test_compiler_srcjar_error 2.12.12
run_test_local test_compiler_srcjar_error 2.12.13
#$runner test_compiler_patch 2.11.0
#$runner test_compiler_patch 2.11.1
#$runner test_compiler_patch 2.11.2
#$runner test_compiler_patch 2.11.3
#$runner test_compiler_patch 2.11.4
#$runner test_compiler_patch 2.11.5
#$runner test_compiler_patch 2.11.6
#$runner test_compiler_patch 2.11.7
#$runner test_compiler_patch 2.11.8
#$runner test_compiler_patch 2.11.9
#$runner test_compiler_patch 2.11.10
#$runner test_compiler_patch 2.11.11
$runner test_compiler_patch 2.11.12

#$runner test_compiler_patch 2.12.0
$runner test_compiler_patch 2.12.1
$runner test_compiler_patch 2.12.2
$runner test_compiler_patch 2.12.3
$runner test_compiler_patch 2.12.4
$runner test_compiler_patch 2.12.5
$runner test_compiler_patch 2.12.6
$runner test_compiler_patch 2.12.7
$runner test_compiler_patch 2.12.8
$runner test_compiler_patch 2.12.9
$runner test_compiler_patch 2.12.10
$runner test_compiler_patch 2.12.11
$runner test_compiler_patch 2.12.12
$runner test_compiler_patch 2.12.13
$runner test_compiler_patch 2.12.14
$runner test_compiler_patch 2.12.15
$runner test_compiler_patch 2.12.16
$runner test_compiler_patch 2.12.17
$runner test_compiler_patch 2.12.18
$runner test_compiler_patch 2.12.19
$runner test_compiler_patch 2.12.20

$runner test_compiler_patch 2.13.0
$runner test_compiler_patch 2.13.1
$runner test_compiler_patch 2.13.2
$runner test_compiler_patch 2.13.3
$runner test_compiler_patch 2.13.4
$runner test_compiler_patch 2.13.5
$runner test_compiler_patch 2.13.6
$runner test_compiler_patch 2.13.7
$runner test_compiler_patch 2.13.8
$runner test_compiler_patch 2.13.10
$runner test_compiler_patch 2.13.11
$runner test_compiler_patch 2.13.12
$runner test_compiler_patch 2.13.14
$runner test_compiler_patch 2.13.15
$runner test_compiler_patch 2.13.16

$runner test_compiler_patch 3.1.0 # Minimal supported version
$runner test_compiler_patch 3.1.3
$runner test_compiler_patch 3.2.2
$runner test_compiler_patch 3.3.6
$runner test_compiler_patch 3.4.3
$runner test_compiler_patch 3.5.2
$runner test_compiler_patch 3.6.4
$runner test_compiler_patch 3.7.0

$runner test_compiler_srcjar_error 2.12.11
$runner test_compiler_srcjar_error 2.12.12
$runner test_compiler_srcjar_error 2.12.13

# These tests are semi-stateful, if two tests are run sequentially with the
# same Scala version, the DEBUG message about a canonical reproducible form
# that we grep for will only be outputted the first time (on Bazel >= 6).
# So we clean the repo first to ensure consistency.

run_in_test_repo "bazel clean --expunge" "test_dt_patches_user_srcjar"

run_test_local test_compiler_srcjar 2.12.14
run_test_local test_compiler_srcjar 2.12.15
run_test_local test_compiler_srcjar 2.12.16
run_test_local test_compiler_srcjar_nonhermetic 2.12.17
run_test_local test_compiler_srcjar_nonhermetic 2.12.18
run_test_local test_compiler_srcjar_nonhermetic 2.12.19
run_test_local test_compiler_srcjar_nonhermetic 2.12.20

run_test_local test_compiler_srcjar_nonhermetic 2.13.11
run_test_local test_compiler_srcjar_nonhermetic 2.13.12
run_test_local test_compiler_srcjar_nonhermetic 2.13.14
run_test_local test_compiler_srcjar_nonhermetic 2.13.15
run_test_local test_compiler_srcjar_nonhermetic 2.13.16

run_test_local test_compiler_srcjar 3.1.3
run_test_local test_compiler_srcjar 3.2.2
run_test_local test_compiler_srcjar_nonhermetic 3.3.6
run_test_local test_compiler_srcjar 3.4.3
run_test_local test_compiler_srcjar_nonhermetic 3.5.2
run_test_local test_compiler_srcjar_nonhermetic 3.6.4
run_test_local test_compiler_srcjar_nonhermetic 3.7.0
run_in_test_repo 'test_dt_patches_user_srcjar' bazel clean --expunge

$runner test_compiler_srcjar 2.12.14
$runner test_compiler_srcjar 2.12.15
$runner test_compiler_srcjar 2.12.16
$runner test_compiler_srcjar_nonhermetic 2.12.17
$runner test_compiler_srcjar_nonhermetic 2.12.18
$runner test_compiler_srcjar_nonhermetic 2.12.19
$runner test_compiler_srcjar_nonhermetic 2.12.20

$runner test_compiler_srcjar_nonhermetic 2.13.11
$runner test_compiler_srcjar_nonhermetic 2.13.12
$runner test_compiler_srcjar_nonhermetic 2.13.14
$runner test_compiler_srcjar_nonhermetic 2.13.15
$runner test_compiler_srcjar_nonhermetic 2.13.16

$runner test_compiler_srcjar 3.1.3
$runner test_compiler_srcjar 3.2.2
$runner test_compiler_srcjar_nonhermetic 3.3.6
$runner test_compiler_srcjar 3.4.3
$runner test_compiler_srcjar_nonhermetic 3.5.2
$runner test_compiler_srcjar_nonhermetic 3.6.4
$runner test_compiler_srcjar_nonhermetic 3.7.0
1 change: 0 additions & 1 deletion dt_patches/test_dt_patches/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ scala_config = use_extension(
scala_config.settings(
enable_compiler_dependency_tracking = True,
)
use_repo(scala_config, "rules_scala_config")

bazel_dep(name = "compiler_sources")
local_path_override(
Expand Down
1 change: 0 additions & 1 deletion dt_patches/test_dt_patches_user_srcjar/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ scala_config = use_extension(
scala_config.settings(
enable_compiler_dependency_tracking = True,
)
use_repo(scala_config, "rules_scala_config")

bazel_dep(name = "compiler_sources")
local_path_override(
Expand Down
6 changes: 6 additions & 0 deletions scala/private/extensions/dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def dev_deps_repositories(

repositories(
fetch_sources = fetch_sources,
fetch_sources_by_id = {
# Required by test/shell/test_scala_import_source_jar.sh. Without
# this, the first test will always fail, and the
# `BAZEL_JVM_FETCH_SOURCES` environment variable has no effect.
"com_google_guava_guava_21_0": True,
},
for_artifact_ids = [
# test adding a scala jar:
"com_twitter__scalding_date",
Expand Down
6 changes: 4 additions & 2 deletions scala/private/macros/setup_scala_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def setup_scala_toolchain(
toolchain = ":%s_impl" % name,
toolchain_type = Label("//scala:toolchain_type"),
target_settings = [
"@rules_scala_config//:scala_version" +
version_suffix(scala_version),
Label(
"@rules_scala_config//:scala_version" +
version_suffix(scala_version),
),
],
visibility = visibility,
)
Expand Down
4 changes: 3 additions & 1 deletion scala/scala_cross_version_select.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def select_for_scala_version(default = [], **kwargs):
"""

return select({
"@rules_scala_config//:scala_version" + version_suffix(scala_version): _matches_for_version(scala_version, kwargs, default)
Label(
"@rules_scala_config//:scala_version" + version_suffix(scala_version),
): _matches_for_version(scala_version, kwargs, default)
for scala_version in SCALA_VERSIONS
})

Expand Down
21 changes: 12 additions & 9 deletions test/shell/test_build_event_protocol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
runner=$(get_test_runner "${1:-local}")

scala_binary_common_jar_is_exposed_in_build_event_protocol() {
local target=$1
local target_suffix=${2:-""}
local target="$1"
local target_suffix="${2:-}"
local bes_file="${target}_bes.txt"
local jar_file="test/${target}${target_suffix}.jar"
set +e
bazel build test:$target --build_event_text_file=$target_bes.txt
cat $target_bes.txt | grep "test/$target$target_suffix.jar"
if [ $? -ne 0 ]; then
echo "test/$target$target_suffix.jar was not found in build event protocol:"
cat $target_bes.txt
rm $target_bes.txt

bazel build "test:${target}" "--build_event_text_file=${bes_file}"
cat "${bes_file}" | grep "${jar_file}"
if [[ $? -ne 0 ]]; then
echo "${jar_file} was not found in build event protocol:"
cat "${bes_file}"
rm "${bes_file}"
exit 1
fi

rm $target_bes.txt
rm "${bes_file}"
set -e
}

Expand Down
Loading