From e6549818c3dc8e71c788e7917f3b7ea6c1f14796 Mon Sep 17 00:00:00 2001 From: Tyler Beebe Date: Tue, 17 Nov 2026 22:12:37 +0000 Subject: [PATCH] fix(bazel): parse Bazel 9 JSON build events Bazel 9 tags options NON_CONFIGURABLE, a value our Bazel 8-era option_filters.proto lacks. The pbjson JSON parser rejects an unknown enum name, so --bazel-bep-path with Bazel 9 JSON found no tests at all. The binary parser was unaffected, since prost keeps unknown enum numbers. Update the vendored protos to Bazel 9.0.1, adding strategy_policy.proto, which invocation_policy.proto now imports. Co-Authored-By: Claude Opus 5.5 --- bazel-bep/README.md | 15 +- bazel-bep/proto/action_cache.proto | 28 ++- bazel-bep/proto/build_event_stream.proto | 259 ++++----------------- bazel-bep/proto/failure_details.proto | 29 ++- bazel-bep/proto/invocation_policy.proto | 14 +- bazel-bep/proto/option_filters.proto | 6 +- bazel-bep/proto/package_load_metrics.proto | 7 + bazel-bep/proto/strategy_policy.proto | 69 ++++++ bazel-bep/src/lib.rs | 4 + context/src/bazel_bep/parser.rs | 17 ++ context/test_fixtures/bep_bazel_9.json | 3 + 11 files changed, 207 insertions(+), 244 deletions(-) create mode 100644 bazel-bep/proto/strategy_policy.proto create mode 100644 context/test_fixtures/bep_bazel_9.json diff --git a/bazel-bep/README.md b/bazel-bep/README.md index f6bf9a59..f3fbe4d7 100644 --- a/bazel-bep/README.md +++ b/bazel-bep/README.md @@ -4,6 +4,8 @@ Based on [crate](https://crates.io/crates/bazel-bep), [repo](https://github.com/ Original protos found [here](https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto) +The protos in `proto/` are from **Bazel 9.0.1**. + ## Updating Protos for New Bazel Versions ### Current Situation @@ -27,14 +29,11 @@ When a new Bazel version is released, follow these steps to update the proto def - Check the [Bazel releases page](https://github.com/bazelbuild/bazel/releases) for the latest version - The proto files are located in the Bazel repository at: - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/action_cache.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/command_line.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/failure_details.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/package_load_metrics.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/publish_build_event.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_events.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/option_filters.proto` - - `src/main/java/com/google/devtools/build/lib/buildeventstream/proto/invocation_policy.proto` + - `src/main/java/com/google/devtools/build/lib/packages/metrics/package_load_metrics.proto` + - `src/main/protobuf/`: `action_cache.proto`, `command_line.proto`, `failure_details.proto`, `invocation_policy.proto`, `option_filters.proto` and `strategy_policy.proto` + - `third_party/googleapis/google/devtools/build/v1/`: `build_events.proto` and `publish_build_event.proto` + - Every file sits directly in `bazel-bep/proto/`, so rewrite each `import "src/main/…/.proto"` to `import ".proto"`. + - A new proto package needs a module in `src/lib.rs`, as `blaze.strategy_policy` has. 2. **Download the updated proto files** diff --git a/bazel-bep/proto/action_cache.proto b/bazel-bep/proto/action_cache.proto index 47d75ca7..4760d86d 100644 --- a/bazel-bep/proto/action_cache.proto +++ b/bazel-bep/proto/action_cache.proto @@ -16,6 +16,9 @@ syntax = "proto3"; package blaze; +option java_package = "com.google.devtools.build.lib.actions.cache"; +option java_outer_classname = "Protos"; + // Information about the action cache behavior during a single build. message ActionCacheStatistics { // Size of the action cache in bytes. @@ -30,13 +33,24 @@ message ActionCacheStatistics { // Reasons for not finding an action in the cache. enum MissReason { - DIFFERENT_ACTION_KEY = 0; - DIFFERENT_DEPS = 1; - DIFFERENT_ENVIRONMENT = 2; - DIFFERENT_FILES = 3; + DIFFERENT_ACTION_KEY = 0; // currently not used + DIFFERENT_DEPS = 1; // currently not used + DIFFERENT_ENVIRONMENT = 2; // currently not used + DIFFERENT_FILES = 3; // currently not used + + // A cache entry was found, but it was corrupted and we ignored it. CORRUPTED_CACHE_ENTRY = 4; + + // No cache entry was found. NOT_CACHED = 5; + + // Unconditional execution was requested. UNCONDITIONAL_EXECUTION = 6; + + // A cache entry was found, but it contained a different digest. + // This could be due to a change in the command line, input or output file + // paths or contents, environment variables, or certain build flags. + DIGEST_MISMATCH = 7; } // Detailed information for a particular miss reason. @@ -56,5 +70,9 @@ message ActionCacheStatistics { // action cache has not been loaded in this invocation. uint64 load_time_in_ms = 6; - // NEXT TAG: 7 + // Time spent waiting for the cache hit semaphore. Reported as 0 if the + // semaphore was not used. + uint64 cache_check_semaphore_wait_time_in_ms = 7; + + // NEXT TAG: 8 } diff --git a/bazel-bep/proto/build_event_stream.proto b/bazel-bep/proto/build_event_stream.proto index da424bb6..cb684015 100644 --- a/bazel-bep/proto/build_event_stream.proto +++ b/bazel-bep/proto/build_event_stream.proto @@ -256,44 +256,10 @@ message BuildEventId { // Identifier of an event providing convenience symlinks information. message ConvenienceSymlinksIdentifiedId {} - // Identifier of an event signalling that the coverage actions are finished. - message CoverageActionsFinishedId {} - // Identifier of an event providing the ExecRequest of a run command. message ExecRequestId {} - // BUILDBUDDY-SPECIFIC EVENTS BELOW - - // Identifier of an event providing a list of bazel commands that are - // run as part of a BuildBuddy workflow. - message WorkflowConfiguredId {} - - // Identifier of an event providing the status of a completed invocation - // within a BuildBuddy workflow. - // - // A workflow action can specify multiple bazel commands, creating a - // "sub-invocation" for each one. There will be one of these events generated - // for each of those Bazel commands, where the invocation ID here refers to - // the invocation ID of the Bazel command that was completed. - message WorkflowCommandCompletedId { - // Invocation ID of the command that was completed. - string invocation_id = 1; - } - - // Identifier of an event providing a list of commands that are - // run as children of this invocation. - message ChildInvocationsConfiguredId {} - - // Identifier of an event providing the status of a completed child - // invocation. - message ChildInvocationCompletedId { - // Invocation ID of the command that was completed. - string invocation_id = 1; - } - - // Identifier of an event providing metadata on a runnable target such as - // default arguments and runtime files. - message RunTargetAnalyzedId {} + reserved 27; oneof id { UnknownBuildEventId unknown = 1; @@ -323,17 +289,7 @@ message BuildEventId { WorkspaceConfigId workspace = 23; BuildMetadataId build_metadata = 24; ConvenienceSymlinksIdentifiedId convenience_symlinks_identified = 25; - CoverageActionsFinishedId coverage_actions_finished = 27; ExecRequestId exec_request = 28; - // BUILDBUDDY EVENTS BELOW - // Starting at field #1000 to avoid conflicting with potential future - // additions to Bazel's build event protocol. - - WorkflowConfiguredId workflow_configured = 1000; - WorkflowCommandCompletedId workflow_command_completed = 1001; - ChildInvocationsConfiguredId child_invocations_configured = 1002; - ChildInvocationCompletedId child_invocation_completed = 1003; - RunTargetAnalyzedId run_target_analyzed = 1004; } } @@ -440,6 +396,12 @@ message BuildStarted { // The process ID of the Bazel server. int64 server_pid = 8; + + // The short hostname of the machine where the build is running. + string host = 10; + + // The username of the user who started the build. + string user = 11; } // Configuration related to the blaze workspace and output tree. @@ -585,13 +547,6 @@ message File { int64 length = 6; } -message Tree { - // Where the tree is to be planted. - string name = 1; - // Bytestream URI for the tree digest. - string uri = 2; -} - // Payload of a message to describe a set of files, usually build artifacts, to // be referred to later by their name. In this way, files that occur identically // as outputs of several targets have to be named only once. @@ -608,6 +563,8 @@ message NamedSetOfFiles { // failing; however, consumers of the build-event protocol must not assume // that only failed actions are posted. message ActionExecuted { + reserved 10; + bool success = 1; // The mnemonic of the action that was executed @@ -636,10 +593,6 @@ message ActionExecuted { // The command-line of the action, if the action is a command. repeated string command_line = 9; - // List of paths to log files - repeated File action_metadata_logs = 10; - - // Only populated if success = false, and sometimes not even then. failure_details.FailureDetail failure_detail = 11; @@ -904,7 +857,15 @@ message TargetSummary { // Conjunction of TargetComplete events for this target, including aspects. bool overall_build_success = 1; - // Repeats TestSummary's overall_status if available. + // For non-test targets, set to NO_STATUS. For test targets, identical to + // TestSummary.overall_status. + // + // There are some cases where the `build` command on a test target succeeds, + // but the `test` command on the same target results in FAILED_TO_BUILD. In + // such cases, TargetComplete.overall_build_success is true, but this field is + // FAILED_TO_BUILD, and TestSummary may be missing. + // TODO - b/186996003: TestSummary is a child of TargetComplete and should be + // posted. TestStatus overall_test_status = 2; } @@ -1107,6 +1068,9 @@ message BuildMetrics { // The elapsed wall time in milliseconds until the first action execution // started (excluding workspace status actions). int64 actions_execution_start_in_ms = 5; + + // The elapsed wall time in milliseconds that the critical path took. + google.protobuf.Duration critical_path_time = 6; } TimingMetrics timing_metrics = 5; @@ -1403,6 +1367,25 @@ message BuildMetrics { } DynamicExecutionMetrics dynamic_execution_metrics = 12; + + // Statistics about remote analysis caching + message RemoteAnalysisCacheStatistics { + int64 cache_hits = 1; + int64 cache_misses = 2; + int64 value_store_value_bytes_received = 3; + int64 value_store_value_bytes_sent = 4; + int64 value_store_key_bytes_sent = 5; + int64 value_store_write_ops = 6; + int64 value_store_read_ops_successful = 7; + int64 value_store_read_ops_not_found = 8; + int64 value_store_read_batches = 10; + int64 value_store_write_batches = 11; + int64 analysis_cache_bytes_received = 12; + int64 analysis_cache_key_bytes_sent = 13; + int64 analysis_cache_ops = 14; + int64 analysis_cache_batches = 15; + } + RemoteAnalysisCacheStatistics remote_analysis_cache_statistics = 13; } // Event providing additional statistics/logs after completion of the build. @@ -1466,158 +1449,6 @@ message EnvironmentVariable { bytes value = 2; } -// BUILDBUDDY-SPECIFIC EVENTS BELOW - -// Event describing a workflow invocation as well as the bazel commands to be -// run by the workflow. -message WorkflowConfigured { - // ID of the BuildBuddy workflow. - // Example: "WF1234" - string workflow_id = 1; - - // Action name as defined in `buildbuddy.yaml`. - // Example: "Test all targets" - string action_name = 2; - - reserved 3; - - // Webhook event name that triggered the action. Can be one of "push" or - // "pull_request". - string action_trigger_event = 4; - - // Metadata for a Bazel invocation created by this workflow action. Each - // workflow action creates one invocation for the top-level workflow, and - // multiple "sub-invocations," one for each Bazel command in the workflow. - // Each of these represents one of the sub-invocations. - message InvocationMetadata { - // Bazel invocation ID (UUIDV4) for a sub-invocation created by a workflow - // action. Should not be set for bazel commands that do not create - // invocations, such as `bazel version`. - // Example: "86083af6-4699-4957-a0a3-d6a806104bb3" - string invocation_id = 1; - - // Bazel command as specified in `buildbuddy.yaml`. - // Example: "test //..." - string bazel_command = 2; - } - - // Bazel commands invoked by the workflow action. - repeated InvocationMetadata invocation = 5; - - // The repo that was pushed in order to trigger the worflow. - // Ex: "https://github.com/some-user/acme" - string pushed_repo_url = 6; - - // The branch that was pushed in order to trigger the workflow. - // Ex: "feature" - string pushed_branch = 7; - - // The commit SHA of the pushed branch. - // Ex: "a051dad04f8b07fb3514585bdb66a8f15a37328e" - string commit_sha = 8; - - // The repo into which the pushed branch is being merged (for PRs), - // or the pushed_repo_url (for push events). - // Ex: "https://github.com/acme-inc/acme" - string target_repo_url = 9; - - // The branch into which the pushed branch is being merged (for PRs), - // or the pushed_branch (for push events). - string target_branch = 10; - - // The OS on which the workflow is running. - // Adheres to the same naming convention as GOOS in golang. - string os = 11; - - // The CPU architecture on which the workflow is running. - // Adheres to the same naming convention as GOARCH in golang. - string arch = 12; - - // This formerly held the workflow's configured container image. It was - // dropped from protocol so that the event could be published earlier. - reserved 13; -} - -// Event describing a workflow command that completed. -// Note: the event ID holds the invocation ID that identifies the command. -// Next Tag: 6 -message WorkflowCommandCompleted { - // The overall status of the command. A command was successful if and only if - // this value is equal to 0. - int32 exit_code = 1; - - // Start time of the workflow command, in milliseconds since epoch. - // - // Deprecated. Use start_time instead. - int64 start_time_millis = 2 [deprecated = true]; - - // Start time of the workflow command - google.protobuf.Timestamp start_time = 4; - - // How long it took for the workflow to complete, in milliseconds. - // - // Deprecated. Use duration instead. - int64 duration_millis = 3 [deprecated = true]; - - // How long it took for the workflow to complete. - google.protobuf.Duration duration = 5; -} - -message ChildInvocationsConfigured { - // Metadata for a child Bazel invocation spawned from the current invocation. - message InvocationMetadata { - // Bazel invocation ID (UUIDV4) for a sub-invocation. - // Should not be set for bazel commands that do not create invocations, such - // as `bazel version`. Example: "86083af6-4699-4957-a0a3-d6a806104bb3" - string invocation_id = 1; - - // Bazel command. - // Example: "test //..." - string bazel_command = 2; - } - - // Child Bazel invocations. - repeated InvocationMetadata invocation = 1; -} - -// Event describing completion of a child invocation. -// Note: the event ID holds the invocation ID that identifies the command. -// Next Tag: 6 -message ChildInvocationCompleted { - // The overall status of the command. A command was successful if and only if - // this value is equal to 0. - int32 exit_code = 1; - - // Start time of the invocation, in milliseconds since epoch. - // - // Deprecated. Use start_time instead. - int64 start_time_millis = 2 [deprecated = true]; - - // Start time of the invocation - google.protobuf.Timestamp start_time = 4; - - // How long it took for the invocation to complete, in milliseconds. - // - // Deprecated. Use duration instead. - int64 duration_millis = 3; - - // How long it took for the invocation to complete. - google.protobuf.Duration duration = 5; -} - -// Event describing the runtime properties of a runnable target. -message RunTargetAnalyzed { - // Default arguments configured for the target, typically in the BUILD file. - // e.g. [--monitoring_port=8888, --max_shutdown_duration=30s] - repeated string arguments = 1; - // Path to the root of the runfiles directory. - string runfiles_root = 2; - // Any runtime file dependencies for the runnable target. - repeated File runfiles = 3; - // Any runtime directory dependencies for the runnable target. - repeated Tree runfileDirectories = 4; -} - // Message describing a build event. Events will have an identifier that // is unique within a given build invocation; they also announce follow-up // events as children. More details, which are specific to the kind of event @@ -1654,15 +1485,5 @@ message BuildEvent { BuildMetadata build_metadata = 26; ConvenienceSymlinksIdentified convenience_symlinks_identified = 27; ExecRequestConstructed exec_request = 29; - - // BUILDBUDDY-SPECIFIC EVENTS BELOW. - // Starting at field #1000 to avoid conflicting with potential future - // additions to Bazel's build event protocol. - - WorkflowConfigured workflow_configured = 1000; - WorkflowCommandCompleted workflow_command_completed = 1001; - ChildInvocationsConfigured child_invocations_configured = 1002; - ChildInvocationCompleted child_invocation_completed = 1003; - RunTargetAnalyzed run_target_analyzed = 1004; } } diff --git a/bazel-bep/proto/failure_details.proto b/bazel-bep/proto/failure_details.proto index 6652a6e7..6f508ca4 100644 --- a/bazel-bep/proto/failure_details.proto +++ b/bazel-bep/proto/failure_details.proto @@ -259,6 +259,9 @@ message ExternalRepository { BAD_DOWNLOADER_CONFIG = 2 [(metadata) = { exit_code: 2 }]; REPOSITORY_MAPPING_RESOLUTION_FAILED = 3 [(metadata) = { exit_code: 37 }]; CREDENTIALS_INIT_FAILURE = 4 [(metadata) = { exit_code: 2 }]; + BAD_REPO_CONTENTS_CACHE = 5 [(metadata) = { exit_code: 2 }]; + UNKNOWN_REGISTRY = 6 [(metadata) = { exit_code: 2 }]; + SYMLINKING_FAILED = 7 [(metadata) = { exit_code: 2 }]; } Code code = 1; // Additional data could include external repository names. @@ -332,11 +335,6 @@ message Crash { // to the outermost exception and at most 4 nested causes (so, max size of 5). repeated Throwable causes = 2; - // True when the root cause of the crash was not an OutOfMemoryError, but - // CRASH_OOM was chosen because an OutOfMemoryError was detected prior to the - // crash. - bool oom_detector_override = 3; - enum OomCauseCategory { // This was not an OOM. NONE = 0; @@ -347,8 +345,6 @@ message Crash { // Originally a crash, but changed to an OOM because Blaze's native code was // told by the JVM there was an OOM, and then Blaze's app-land code assumed // the crash was a symptom of that OOM. - // - // Conveys the same thing that the field oom_detector_override does. OOM_DETECTOR_OVERRIDE = 2; // Blaze gave up and pretended it OOM'd because its post-full-GC heap size @@ -356,10 +352,18 @@ message Crash { // // See --gc_thrashing_threshold and --gc_thrashing_limits. GC_THRASHING = 3; + + // Blaze gave up and pretended it OOM'd because it has spent too much of the + // invocation wall time doing full GCs. + // + // See --gc_churning_threshold. + GC_CHURNING = 4; } // If Blaze OOM'd (code = CRASH_OOM), the category of cause of that OOM. OomCauseCategory oom_cause_category = 4; + + reserved 3; } message Throwable { @@ -403,9 +407,9 @@ message Skyfocus { // The defined working set cannot be used for the focused targets. For // example, this happens when the intersection of the working set and the // transitive closure of the focused target is empty. - INVALID_WORKING_SET = 0 [(metadata) = { exit_code: 2 }]; + INVALID_ACTIVE_DIRECTORIES = 0 [(metadata) = { exit_code: 2 }]; // The user needs to augment their working set to include the new file(s). - NON_WORKING_SET_CHANGE = 1 [(metadata) = { exit_code: 2 }]; + NON_ACTIVE_DIRECTORIES_CHANGE = 1 [(metadata) = { exit_code: 2 }]; CONFIGURATION_CHANGE = 2 [(metadata) = { exit_code: 2 }]; DISALLOWED_OPERATION_ON_FOCUSED_GRAPH = 3 [(metadata) = { exit_code: 2 }]; } @@ -419,6 +423,9 @@ message RemoteAnalysisCaching { REMOTE_ANALYSIS_CACHING_UNKNOWN = 0 [(metadata) = { exit_code: 1 }]; SERIALIZED_FRONTIER_PROFILE_FAILED = 1 [(metadata) = { exit_code: 1 }]; PROJECT_FILE_NOT_FOUND = 2 [(metadata) = { exit_code: 2 }]; + INCOMPATIBLE_OPTIONS = 3 [(metadata) = { exit_code: 2 }]; + INVALID_SERVER_ADDRESS = 4 [(metadata) = { exit_code: 2 }]; + CANNOT_OPEN_LOG_FILE = 5 [(metadata) = { exit_code: 36 }]; } Code code = 1; @@ -567,6 +574,7 @@ message Filesystem { [(metadata) = { exit_code: 2 }]; FILESYSTEM_JNI_NOT_AVAILABLE = 8 [(metadata) = { exit_code: 36 }]; FAILED_TO_LOCK_INSTALL_BASE = 12 [(metadata) = { exit_code: 36 }]; + REMOTE_FILE_EVICTED = 13 [(metadata) = { exit_code: 39 }]; reserved 7, 9, 10; // For internal use } @@ -777,6 +785,7 @@ message LocalExecution { LOCAL_EXECUTION_UNKNOWN = 0 [(metadata) = { exit_code: 37 }]; LOCKFREE_OUTPUT_PREREQ_UNMET = 1 [(metadata) = { exit_code: 2 }]; UNTRACKED_RESOURCE = 2 [(metadata) = { exit_code: 1 }]; + NOT_ENOUGH_LOCAL_RESOURCE = 3 [(metadata) = { exit_code: 1 }]; } Code code = 1; @@ -1133,6 +1142,7 @@ message CppCompile { D_FILE_PARSE_FAILURE = 9 [(metadata) = { exit_code: 1 }]; COVERAGE_NOTES_CREATION_FAILURE = 10 [(metadata) = { exit_code: 1 }]; MODULE_EXPANSION_MISSING_DATA = 11 [(metadata) = { exit_code: 1 }]; + MODMAP_INPUT_FILE_READ_FAILURE = 12 [(metadata) = { exit_code: 36 }]; } Code code = 1; @@ -1379,6 +1389,7 @@ message ExternalDeps { ERROR_ACCESSING_REGISTRY = 5 [(metadata) = { exit_code: 32 }]; INVALID_EXTENSION_IMPORT = 6 [(metadata) = { exit_code: 48 }]; BAD_LOCKFILE = 7 [(metadata) = { exit_code: 48 }]; + EXTENSION_EVAL_ERROR = 8 [(metadata) = { exit_code: 48 }]; } Code code = 1; diff --git a/bazel-bep/proto/invocation_policy.proto b/bazel-bep/proto/invocation_policy.proto index 31d4837e..daecff2d 100644 --- a/bazel-bep/proto/invocation_policy.proto +++ b/bazel-bep/proto/invocation_policy.proto @@ -13,9 +13,11 @@ // limitations under the License. syntax = "proto2"; + package blaze.invocation_policy; -option go_package = "invocation_policy"; +import "strategy_policy.proto"; + // option java_api_version = 2; option java_package = "com.google.devtools.build.lib.runtime.proto"; @@ -27,6 +29,8 @@ message InvocationPolicy { // requirements, only the final policy on a specific flag will be enforced // onto the user's command line. repeated FlagPolicy flag_policies = 1; + + optional blaze.strategy_policy.StrategyPolicy strategy_policy = 2; } // A policy for controlling the value of a flag. @@ -58,6 +62,8 @@ message FlagPolicy { DisallowValues disallow_values = 5; AllowValues allow_values = 6; } + + optional string custom_error_message = 7; } message SetValue { @@ -115,9 +121,13 @@ message SetValue { // Matching old flag values: append = true, overridable = false. APPEND = 2; // Set a final value of the flag. Any overrides provided by the user for - // this flag will be ignored. + // this flag will be silently ignored. // Matching old flag values: append = false, overridable = false. FINAL_VALUE_IGNORE_OVERRIDES = 3; + // Set a final value of the flag and throw an error if the user provides + // an override. + // Matching old flag values: append = false, overridable = false. + FINAL_VALUE_THROW_ON_OVERRIDE = 4; } // Defines how invocation policy should interact with user settings for the diff --git a/bazel-bep/proto/option_filters.proto b/bazel-bep/proto/option_filters.proto index 7412570c..bfbe840b 100644 --- a/bazel-bep/proto/option_filters.proto +++ b/bazel-bep/proto/option_filters.proto @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. syntax = "proto3"; + package options; -option go_package = "option_filters"; // option java_api_version = 2; option java_package = "com.google.devtools.common.options.proto"; @@ -55,5 +55,9 @@ enum OptionMetadataTag { INTERNAL = 4; reserved "TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES"; reserved 5; + reserved "EXPLICIT_IN_OUTPUT_PATH"; reserved 6; + reserved "IMMUTABLE"; + reserved 7; + NON_CONFIGURABLE = 8; } diff --git a/bazel-bep/proto/package_load_metrics.proto b/bazel-bep/proto/package_load_metrics.proto index e27eccea..270c8f8d 100644 --- a/bazel-bep/proto/package_load_metrics.proto +++ b/bazel-bep/proto/package_load_metrics.proto @@ -41,4 +41,11 @@ message PackageLoadMetrics { // with a loaded package. Values are an approximate but reasonable proxy for // the real storage costs of a package. optional uint64 package_overhead = 6; + + // "Cost" of the filesystem operations performed across all `glob` calls while + // loading the package. + // + // `stat` operations cost 1 and `readdir` operations cost 1 + D, where D is + // the number of dirents. + optional uint64 glob_filesystem_operation_cost = 7; } diff --git a/bazel-bep/proto/strategy_policy.proto b/bazel-bep/proto/strategy_policy.proto new file mode 100644 index 00000000..50c382e3 --- /dev/null +++ b/bazel-bep/proto/strategy_policy.proto @@ -0,0 +1,69 @@ +// Copyright 2022 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto2"; + +package blaze.strategy_policy; + +option java_multiple_files = true; +// option java_api_version = 2; +option java_package = "com.google.devtools.build.lib.runtime.proto"; + +// Provides control over what strategies (local, remote, etc) may be used. +// +// An empty policies (e.g. unset) implies no enforcement, anything is allowed. +// +// Policies are enforced against both user-provided values (flags) and +// application-internal defaults. The latter is useful for guarding against +// unexpectedly hard-coded defaults. +// +// Sample usage to allow everything to execute remotely, while only allowing +// genrules to execute both remotely and locally: +// +// strategy_policy { +// mnemonic_policy { +// default_allowlist: ["remote"] +// strategy_allowlist: [ +// { mnemonic: "Genrule" strategy: ["remote", "local"] } +// ] +// } +// } +message StrategyPolicy { + // Controls per-mnemonic policies for regular spawn/action execution. Relevant + // command-line flags this controls include --spawn_strategy, --strategy and + // --genrule_strategy. + optional MnemonicPolicy mnemonic_policy = 1; + + // Controls per-mnemonic policies for the remote execution leg of dynamic + // execution. Relevant flag is --dynamic_remote_strategy. + optional MnemonicPolicy dynamic_remote_policy = 2; + + // Controls per-mnemonic policies for the local execution leg of dynamic + // execution. Relevant flag is --dynamic_local_strategy. + optional MnemonicPolicy dynamic_local_policy = 3; +} + +message MnemonicPolicy { + // Default allowed strategies for mnemonics not present in `strategy` list. + repeated string default_allowlist = 1; + + // Later entries overwrite previous ones for the same mnemonic. + repeated StrategiesForMnemonic strategy_allowlist = 2; +} + +// Per-mnemonic allowlist settings. +message StrategiesForMnemonic { + optional string mnemonic = 1; + repeated string strategy = 2; +} diff --git a/bazel-bep/src/lib.rs b/bazel-bep/src/lib.rs index 903ddcd8..bff7083d 100644 --- a/bazel-bep/src/lib.rs +++ b/bazel-bep/src/lib.rs @@ -63,6 +63,10 @@ pub(crate) mod blaze { "/blaze.invocation_policy.serde.rs" )); } + pub mod strategy_policy { + include!(concat!(env!("OUT_DIR"), "/blaze.strategy_policy.rs")); + include!(concat!(env!("OUT_DIR"), "/blaze.strategy_policy.serde.rs")); + } } pub(crate) mod command_line { diff --git a/context/src/bazel_bep/parser.rs b/context/src/bazel_bep/parser.rs index 641f4ba4..3221ab02 100644 --- a/context/src/bazel_bep/parser.rs +++ b/context/src/bazel_bep/parser.rs @@ -50,6 +50,7 @@ mod tests { const FLAKY_SUMMARY_EXAMPLE: &str = "test_fixtures/bep_flaky_summary"; const RETRIES_EXAMPLE: &str = "test_fixtures/bep_retries"; const UNKNOWN_FIELDS_EXAMPLE: &str = "test_fixtures/bep_unknown_fields.json"; + const BAZEL_9_EXAMPLE: &str = "test_fixtures/bep_bazel_9.json"; #[test] fn test_parse_bep_with_unknown_fields() { @@ -68,6 +69,22 @@ mod tests { assert!(parse_result.errors.is_empty()); } + #[test] + fn test_parse_bazel_9_json_bep() { + let input_file = get_test_file_path(BAZEL_9_EXAMPLE); + let mut parser = BazelBepParser::new(input_file); + let parse_result = parser.parse().unwrap(); + + assert_eq!( + parse_result.uncached_xml_files(), + vec![JunitReportFileWithTestRunnerReport { + junit_path: "/tmp/hello_test/test.xml".to_string(), + test_runner_report: None + }] + ); + assert!(parse_result.errors.is_empty(), "{:?}", parse_result.errors); + } + #[test] fn test_parse_simple_bep() { let input_file = get_test_file_path(SIMPLE_EXAMPLE); diff --git a/context/test_fixtures/bep_bazel_9.json b/context/test_fixtures/bep_bazel_9.json new file mode 100644 index 00000000..9a987758 --- /dev/null +++ b/context/test_fixtures/bep_bazel_9.json @@ -0,0 +1,3 @@ +{"id": {"started": {}}, "children": [{"structuredCommandLine": {"commandLineLabel": "canonical"}}, {"buildFinished": {}}], "started": {"uuid": "test-uuid", "startTimeMillis": "1763416777000", "buildToolVersion": "9.0.1", "command": "test", "workingDirectory": "/repos/trunk", "workspaceDirectory": "/repos/trunk", "serverPid": "4030542"}} +{"id": {"structuredCommandLine": {"commandLineLabel": "canonical"}}, "structuredCommandLine": {"commandLineLabel": "canonical", "sections": [{"sectionLabel": "command options", "optionList": {"option": [{"combinedForm": "--enable_bzlmod", "optionName": "enable_bzlmod", "optionValue": "1", "effectTags": ["LOADING_AND_ANALYSIS"], "metadataTags": ["NON_CONFIGURABLE"]}]}}]}} +{"id": {"testResult": {"label": "//trunk/hello_world/cc:hello_test", "run": 1, "shard": 1, "attempt": 1, "configuration": {"id": "abc123"}}}, "testResult": {"testActionOutput": [{"name": "test.log", "uri": "file:///tmp/hello_test/test.log"}, {"name": "test.xml", "uri": "file:///tmp/hello_test/test.xml"}], "testAttemptDurationMillis": "153", "status": "PASSED"}}