Skip to content

Add per-target bazel run arg/env delegation for itest_* targets - #84

Open
darkrift wants to merge 1 commit into
hermeticbuild:masterfrom
darkrift:command_line_flags
Open

Add per-target bazel run arg/env delegation for itest_* targets#84
darkrift wants to merge 1 commit into
hermeticbuild:masterfrom
darkrift:command_line_flags

Conversation

@darkrift

@darkrift darkrift commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

This is useful when using bazel run to locally launch stacks that require custom/personalized arguments and env vars.

Summary

  • add delegated per-target runtime args for executable itest_* targets via --target_arg
  • add delegated per-target runtime env injection via --target_env
  • support Bazel aliases when resolving delegated target labels in the itest dependency graph
  • make svc startup and command healthcheck logs quote arguments to avoid ambiguity
  • add tests, docs, and an example covering the new behavior

Details

  • extend svcinit to parse bazel run CLI sections and append delegated args to the matching target’s configured args
  • inject delegated KEY=VALUE env vars into the matching executable target before launch
  • preserve alias labels from the macro layer into the generated service graph so runtime resolution can accept aliases
  • reject non-executable group targets when used with delegated arg/env flags
  • update the example to demonstrate:
    • one --target_arg carrying multiple arguments for a target
    • --target_env for per-target env injection
    • filtered TARGET_ARGS_ env output for readability

Testing

  • bazel test //cmd/svcinit:svcinit_test //cmd/svcinit/target_args:target_args_test
  • cd examples && bazel build //target_args:workflow

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2574af7cd0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread itest.bzl
Comment on lines +47 to +49
return [
str(native.package_relative_label(label))
for label in labels

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve configurable service labels

When deps or services is supplied as a configurable select(...), this new helper tries to iterate that selector during macro expansion before forwarding it to the underlying attr.label_list. Those attrs were previously passed through unchanged, so existing users with platform/config-specific service graphs now fail to load even if they are not using target-argument delegation. Consider preserving select values or making the new internal metadata configurable as well.

Useful? React with 👍 / 👎.

Comment thread docs/itest.md
bazel run //path/to:target -- \
--target_env //path/to:some_task EXTRA_ENV=value \
--target_arg //path/to:some_task --flag value --other-flag "two words" \
--target_env //path/to:service_alias EXTRA_ENV=value "OTHER_ENV=value with space" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't document unsupported multi-env syntax

The documented command shows two KEY=VALUE entries after one --target_env, but the parser only consumes the single token at i+2; the second assignment is then treated as a positional argument for the previous --target_arg section. Users following this example will silently pass OTHER_ENV=... as an arg instead of setting it on service_alias, so split the example into separate --target_env invocations or update the parser to consume multiple assignments.

Useful? React with 👍 / 👎.

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.

1 participant