mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
Separate test-only Rust sources from Bazel library and binary inputs (#57741)
## What changed Add `unit_test_srcs` to `codex_rust_crate` to exclude test-only modules from library and binary sources while making them available to unit tests through `compile_data`. Configure `codex-core` and `codex-tui` to use this option for their test modules and support files. GitOrigin-RevId: 437b5ddb75e66a96f3c5cb9b309cb0e2608ba169
This commit is contained in:
@@ -41,5 +41,17 @@ codex_rust_crate(
|
||||
"@platforms//os:macos": 1,
|
||||
"//conditions:default": 0,
|
||||
}),
|
||||
unit_test_srcs = glob([
|
||||
"src/**/*_test.rs",
|
||||
"src/**/*_tests.rs",
|
||||
"src/**/tests.rs",
|
||||
"src/**/tests/**/*.rs",
|
||||
]) + [
|
||||
"src/apps/render.rs",
|
||||
"src/config/schema.rs",
|
||||
"src/context/world_state/test_support.rs",
|
||||
"src/guardian/test_host.rs",
|
||||
"src/plugins/test_support.rs",
|
||||
],
|
||||
unit_test_timeout = "long",
|
||||
)
|
||||
|
||||
@@ -22,4 +22,13 @@ codex_rust_crate(
|
||||
},
|
||||
# The startup symlink test applies its own Seatbelt policy, which cannot be nested.
|
||||
test_tags = ["no-sandbox"],
|
||||
unit_test_srcs = glob([
|
||||
"src/**/*_test_support.rs",
|
||||
"src/**/*_tests.rs",
|
||||
"src/**/*_tests/**/*.rs",
|
||||
"src/**/test_fixtures.rs",
|
||||
"src/**/test_support.rs",
|
||||
"src/**/tests.rs",
|
||||
"src/**/tests/**/*.rs",
|
||||
]) + ["src/test_backend.rs"],
|
||||
)
|
||||
|
||||
@@ -187,6 +187,7 @@ def codex_rust_crate(
|
||||
crate_name,
|
||||
crate_features = [],
|
||||
crate_srcs = None,
|
||||
unit_test_srcs = [],
|
||||
crate_edition = None,
|
||||
proc_macro = False,
|
||||
build_script_enabled = True,
|
||||
@@ -232,6 +233,8 @@ def codex_rust_crate(
|
||||
optional functionality to a separate crate.
|
||||
crate_srcs: Optional explicit library srcs; [] disables the library target.
|
||||
Defaults to `src/**/*.rs` excluding binary entrypoints.
|
||||
unit_test_srcs: Rust modules loaded only under cfg(test). Excluded from
|
||||
library and binary sources, but available when compiling unit tests.
|
||||
crate_edition: Rust edition override, if not default.
|
||||
You probably don't want this, it's only here for a single caller.
|
||||
proc_macro: Whether this crate builds a proc-macro library.
|
||||
@@ -315,6 +318,7 @@ def codex_rust_crate(
|
||||
binaries = package_data["binaries"]
|
||||
|
||||
lib_srcs = crate_srcs if crate_srcs != None else native.glob(["src/**/*.rs"], exclude = binaries.values(), allow_empty = True)
|
||||
lib_srcs = [src for src in lib_srcs if src not in unit_test_srcs]
|
||||
|
||||
maybe_deps = []
|
||||
|
||||
@@ -359,6 +363,7 @@ def codex_rust_crate(
|
||||
name = unit_test_binary,
|
||||
crate = name,
|
||||
crate_features = crate_features,
|
||||
compile_data = unit_test_srcs,
|
||||
deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra,
|
||||
# Unit tests also compile to standalone Windows executables, so
|
||||
# keep their stack reserve aligned with binaries and integration
|
||||
@@ -434,7 +439,7 @@ def codex_rust_crate(
|
||||
# Isolate status inputs in build-commit-env's cheap action so its
|
||||
# output, and hence this compiler input, changes only with the commit.
|
||||
rustc_env_files = ["//bazel/build-info:build-commit-env"] if binary in binaries_with_build_commit else [],
|
||||
srcs = native.glob(["src/**/*.rs"], exclude = [main], allow_empty = True) + [main],
|
||||
srcs = native.glob(["src/**/*.rs"], exclude = [main] + unit_test_srcs, allow_empty = True) + [main],
|
||||
testonly = binary in test_only_binaries,
|
||||
stamp = 0,
|
||||
version = crate_version,
|
||||
@@ -451,6 +456,7 @@ def codex_rust_crate(
|
||||
name = binary_unit_test_binary,
|
||||
crate = ":" + binary,
|
||||
crate_features = crate_features,
|
||||
compile_data = unit_test_srcs,
|
||||
deps = all_crate_deps(normal_dev = True),
|
||||
rustc_flags = rustc_flags_extra + WINDOWS_RUSTC_LINK_FLAGS + [
|
||||
"--remap-path-prefix=../codex-rs=",
|
||||
|
||||
Reference in New Issue
Block a user