Skip to content

test: Migrate test_semanticdb.sh to Bazel-native sh_test targets - #1949

Open
bor-p-s wants to merge 4 commits into
masterfrom
bor-p-s/migrate-test-semanticdb
Open

test: Migrate test_semanticdb.sh to Bazel-native sh_test targets#1949
bor-p-s wants to merge 4 commits into
masterfrom
bor-p-s/migrate-test-semanticdb

Conversation

@bor-p-s

@bor-p-s bor-p-s commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Description

The other 4 functions check post-build state: provider values read from a generated script, whether .semanticdb output was produced, and whether a source glob picks up an added/removed file. That's outside what expect_build_failure.bzl's macros model (a build/test pass/fail outcome), so these are hand-written sh_test scripts on nested_bazel.sh, the same pattern as expect_no_ijar.sh.

nested_bazel.sh gets two small fixes for the new bazel query call it needs: it now skips --symlink_prefix for query specifically, since that's the one subcommand that rejects the flag, and its Windows arg-conversion list now covers labels( too, the same label-mangling guard it already has for --extra_toolchains=. This second fix is reasoned from the existing guard, not verified on a real Windows run.

scala/BUILD and scala/private/BUILD each gain one exports_files entry (semanticdb_provider.bzl, phases/phase_semanticdb.bzl), so the Scala 2 produces_semanticdb_test variants can list them as data. Their fixture's only own action is a template expansion, which the fingerprint mechanism reads by mnemonic only, so a bug in the provider's fields wouldn't otherwise bust the test's cache.

Motivation

Continues the move off the old shell-test runner (test_rules_scala.sh) toward native bazel test //....

Release impact: tests only.

@bor-p-s
bor-p-s requested a review from PawelLipski August 27, 2026 13:50
@bor-p-s
bor-p-s marked this pull request as ready for review August 27, 2026 13:50
@bor-p-s

bor-p-s commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

@PawelLipski

# Keep the nested build's convenience symlinks out of the workspace so they do
# not clobber the parent invocation's `bazel-bin` etc.
_nested_bazel_common_opts+=("--symlink_prefix=${_nested_bazel_output_base}/convenience_symlinks/")
# not clobber the parent invocation's `bazel-bin` etc. Kept separate from

@PawelLipski PawelLipski Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so up to now there was no bazel query run via nested bazel?

I remember you've used cquery instead of query (probably for this reason) somewhere recently right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, switched to cquery — it already accepts --symlink_prefix and supports labels(srcs, ...). Reverted the query-specific branching in nested_bazel_run, so this file's diff is now just the labels( addition to MSYS2_ARG_CONV_EXCL (still needed since the label sits mid-string here too).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you - query + fix to nested_bazel.sh can also stay here and in other places (cquery can arguably be confusing as we don't care about configured graph here)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point on cquery being confusing here — switched back to query + the --symlink_prefix skip, since we really just need srcs membership, not the configured graph.

Comment thread test/semanticdb/BUILD
Comment thread test/semanticdb/BUILD Outdated
[
sh_test(
name = "produces_semanticdb_test_scala%d_%s" % (
scala_majver,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IIRC the scheme calls these segments EPOCH.MAJOR.MINOR, pls verify & if so consider changing to scala_epoch (unless this repo uses major for that already)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — extract_major_version already returns "2.13"/"3.3" here, so scala_majver collided with that. Renamed to scala_epoch.

Comment thread test/semanticdb/produces_semanticdb_test.sh Outdated
Comment thread test/semanticdb/no_semanticdb_test.sh Outdated
fi

if [[ "$(find "${target_out}" -type f -name '*.semanticdb' | wc -l)" -gt 0 ]]; then
echo "Error: Semanticdb files erroneously found in target output" >&2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so it shouldn't be a loose file but inside a jar instead? if so, pls clarify the error message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's loose files, the jar check is separate below. Reworded both messages to say which and name the file.

source "${bazel_bin}/test/semanticdb/semantic_provider_vars_all.sh"

if [[ "${semanticdb_enabled}" -ne 1 ]]; then
echo "Error: SemanticdbInfo.semanticdb_enabled not equal to true" >&2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear from error message what kind of config (?) key it is and where it's read from

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same for the ones below)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded to show actual vs expected, plus one comment noting these are SemanticdbInfo fields from scala/semanticdb_provider.bzl.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix applied to all four checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants