Skip to content
Closed
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
673 changes: 298 additions & 375 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions bazel-bep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ license = "MIT"
repository = "https://github.com/ChristianBelloni/bazel-bep"

[dependencies]
prost = "0.12.6"
prost-types = "0.12.6"
pbjson = "0.6"
pbjson-types = "0.6"
prost = "0.14"
prost-types = "0.14"
pbjson = "0.9"
pbjson-types = "0.9"
serde = { version = "1.0.215", default-features = false, features = ["derive"] }
serde_json = "1.0.133"
tonic = { version = "0.11", optional = true }

[build-dependencies]
tonic-build = "0.11.0"
prost-build = "0.12.6"
pbjson-build = "0.6.2"
protox = "0.6.1"

[features]
default = []
client = ["tonic/transport"]
server = []
prost-build = "0.14"
pbjson-build = "0.9"
protox = "0.9"
2 changes: 2 additions & 0 deletions bazel-bep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Original protos found [here](https://github.com/bazelbuild/bazel/blob/master/src

The protos in `proto/` are from **Bazel 9.0.1**.

The JSON parser skips fields and enum values these protos don't have (`ignore_unknown_fields`, `ignore_unknown_enum_variants` in `build.rs`), so a newer Bazel's JSON still parses; an unknown enum value reads as the enum's default. Update the protos when we need what a new Bazel adds.

## Updating Protos for New Bazel Versions

### Current Situation
Expand Down
13 changes: 4 additions & 9 deletions bazel-bep/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,23 @@ fn main() -> io::Result<()> {

let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");

let compiler = tonic_build::configure();
#[cfg(not(feature = "client"))]
let compiler = compiler.build_client(false);
#[cfg(not(feature = "server"))]
let compiler = compiler.build_server(false);

let file_descriptors = protox::compile(&protos, ["proto/"]).unwrap();
let file_descriptors_bytes = file_descriptors.encode_to_vec();

fs::write(&descriptor_path, &file_descriptors_bytes).unwrap();

compiler
prost_build::Config::new()
.file_descriptor_set_path(&descriptor_path)
.skip_protoc_run()
.compile_well_known_types(true)
.compile_well_known_types()
// Override prost-types with pbjson-types
.extern_path(".google.protobuf", "::pbjson_types")
.compile(&protos, &["proto/"])?;
.compile_protos(&protos, &["proto/"])?;

pbjson_build::Builder::new()
.register_descriptors(&file_descriptors_bytes)?
.ignore_unknown_fields()
.ignore_unknown_enum_variants()
.build(&["."])?;

Ok(())
Expand Down
13 changes: 1 addition & 12 deletions bazel-bep/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@
//!
//! To learn what does what check out [bazel's docs](https://bazel.build/remote/bep)

pub use prost;
pub use prost_types;

#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub mod client {
pub use super::google::devtools::build::v1::publish_build_event_client::*;
}

#[cfg(feature = "server")]
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
pub mod server {
pub use super::google::devtools::build::v1::publish_build_event_server::*;
}

pub mod types {
pub mod build_event_stream {
pub use crate::build_event_stream::*;
Expand Down
4 changes: 2 additions & 2 deletions context/src/bazel_bep/binary_parser.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::io::Read;
use std::path::PathBuf;

use bazel_bep::prost::Message;
use bazel_bep::prost::bytes::Buf;
use bazel_bep::types::build_event_stream::BuildEvent;
use prost::Message;
use prost::bytes::Buf;

use crate::bazel_bep::common::BepParseResult;

Expand Down
17 changes: 17 additions & 0 deletions context/src/bazel_bep/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mod tests {
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";
const UNKNOWN_ENUM_VALUES_EXAMPLE: &str = "test_fixtures/bep_unknown_enum_values.json";

#[test]
fn test_parse_bep_with_unknown_fields() {
Expand Down Expand Up @@ -85,6 +86,22 @@ mod tests {
assert!(parse_result.errors.is_empty(), "{:?}", parse_result.errors);
}

#[test]
fn test_parse_json_bep_with_unknown_enum_values() {
let input_file = get_test_file_path(UNKNOWN_ENUM_VALUES_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);
Expand Down
3 changes: 3 additions & 0 deletions context/test_fixtures/bep_unknown_enum_values.json
Original file line number Diff line number Diff line change
@@ -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": ["AN_EFFECT_FROM_A_LATER_BAZEL"], "metadataTags": ["A_TAG_FROM_A_LATER_BAZEL"]}]}}]}}
{"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"}}
Loading