Skip to content

fix: handle Bazel load statements in extension-check - #7083

Open
immanuwell wants to merge 1 commit into
istio:masterfrom
immanuwell:fix/extension-check-load-statements
Open

fix: handle Bazel load statements in extension-check#7083
immanuwell wants to merge 1 commit into
istio:masterfrom
immanuwell:fix/extension-check-load-statements

Conversation

@immanuwell

Copy link
Copy Markdown
Member

What this PR does / why we need it:
tools/extension-check blows up on normal Bazel config files because the embedded Starlark runner does not handle load(...).

This strips top level load(...) statements before evaluation, returns regular errors instead of panics, and removes the README workaround. Pretty small fix, but it makes the tool usable out of the box.

Which issue this PR fixes:
N/A, this repo has issues disabled.

Special notes for your reviewer:
Repro before this patch:
go run ./tools/extension-check --envoy-extensions-build-config ./bazel/extension_config/extensions_build_config.bzl --proxy-extensions-build-config ./bazel/extension_config/extensions_build_config.bzl --ignore-extensions ./tools/extension-check/wellknown-extensions

Before:
panic: load not implemented by this application

After:
it loads the checked-in file and reaches the normal missing-extension output. so yeah, this is a real bug on a real file, not some weird edge case.

Checks:
go test ./tools/extension-check
go test ./... -run '^$'

@immanuwell
immanuwell requested a review from a team as a code owner June 7, 2026 11:32
@istio-policy-bot

Copy link
Copy Markdown

😊 Welcome @immanuwell! This is either your first contribution to the Istio proxy repo, or it's been
a while since you've been here.

You can learn more about the Istio working groups, Code of Conduct, and contribution guidelines
by referring to Contributing to Istio.

Thanks for contributing!

Courtesy of your friendly welcome wagon.

@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 7, 2026
@istio-testing

Copy link
Copy Markdown
Collaborator

Hi @immanuwell. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Aug 6, 2026
@istio-testing

Copy link
Copy Markdown
Collaborator

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@jwendell jwendell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this PR was raised we removed the load() from our .bzl file. If you still want to pursue this, here are some review.

}
globals, err := starlark.ExecFile(thread, filename, nil, nil)
globals, err := starlark.ExecFile(thread, filename, stripLoadStatements(string(src)), nil)
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Merge conflict / API regression

This PR uses starlark.ExecFile but master already migrated to starlark.ExecFileOptions in commit 1c3f7912. The PR is in a CONFLICTING state and needs a rebase.

The correct resolution should use the new API:

globals, err := starlark.ExecFileOptions(syntax.LegacyFileOptions(), thread, filename, stripLoadStatements(string(src)), nil)

@@ -0,0 +1,41 @@
package main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Missing copyright banner

This file is missing the required Apache 2.0 copyright header. make lint (lint-copyright-banner) will fail — it scans all *.go files for Apache License, Version 2 and Copyright. See main.go for the standard 13-line header.

skippingLoad = false
parenDepth = 0
}
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💡 Line-number shift in error messages

stripLoadStatements removes load-statement lines entirely, which shifts starlark error positions by the number of stripped lines. For example, a 4-line load block followed by an error on line 10 would be reported at line 6.

Consider replacing removed lines with empty strings instead of skipping them:

// Instead of: continue
filtered = append(filtered, "")

func stripLoadStatements(src string) string {
lines := strings.Split(src, "\n")
filtered := make([]string, 0, len(lines))
skippingLoad := false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💡 Redundant state variable

skippingLoad is always equivalent to parenDepth > 0 at iteration boundaries. You could collapse both into just parenDepth, simplifying the logic and avoiding potential desync:

if parenDepth == 0 && strings.HasPrefix(trimmed, "load(") {
    // enter skipping mode via parenDepth alone
}


// stripLoadStatements removes Bazel load() statements so build config files can
// be evaluated without resolving external repositories.
func stripLoadStatements(src string) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💭 Consider AST-level filtering

Text-level line removal is fragile against edge cases (parentheses in string literals, load()-like text in triple-quoted strings). The starlark library provides syntax.FileOptions.Parse() and syntax.LoadStmt — you could parse the file, filter out LoadStmt nodes from File.Stmts, and compile with starlark.FileProgram. This would handle all formatting edge cases correctly by construction and avoid the line-number shift issue above.

Not a blocker since the current approach works for the known .bzl files, but worth considering for robustness.

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

Labels

needs-ok-to-test needs-rebase Indicates a PR needs to be rebased before being merged size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants