Skip to content

Commit baee919

Browse files
Use path APIs instead of MAIN_SEPARATOR splitting in app/build.rs (#14563)
## Description `get_build_profile_name()` in `app/build.rs` derived the Cargo profile name by reading `OUT_DIR` as a plain string and splitting it on `std::path::MAIN_SEPARATOR`. Choosing the separator by hand is brittle, so this replaces the string split with real path handling: `OUT_DIR` becomes a `PathBuf` and the profile directory is resolved with `ancestors().nth(3)` + `Path::file_name()`. Behavior is unchanged for the standard `OUT_DIR` layout (`.../<profile>/build/<crate>-<hash>/out` -> `<profile>`), and the path-based version additionally tolerates a trailing separator, which the old split did not. Per the requester, no comments and no tests were added, and the change is limited to that one function. ## Linked Issue [APP-5072](https://linear.app/warpdotdev/issue/APP-5072/use-path-apis-instead-of-main-separator-string-splitting-in-appbuildrs) ## Testing Testing-exempt: the requester explicitly asked for no new tests, and this is a behavior-preserving refactor of a build-script helper. Verification performed instead: - Equivalence check: compiled and ran a standalone harness with the old and new implementations side by side over representative `OUT_DIR` values (`/code/core/target/cli/build/my-build-info-9f91ba6f99d7a061/out`, `.../debug/build/warp-abc123/out`, `.../release-lto/build/warp-1/out`) — both return the same profile name (`cli`, `debug`, `release-lto`). With a trailing separator the old split returns `build` while the new path-based version still returns `cli`. - `cargo fmt -p warp -- --check` passes. - `cargo check -p warp` passes — the build script compiles and runs (`target/debug/build/warp-*/output` produced). - `cargo clippy -p warp --all-targets --tests -- -D warnings` passes. - No UI surface (build script only), so no computer-use verification applies. - [ ] I have manually tested my changes locally with `./script/run` ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode Originating thread: https://warpdev.slack.com/archives/C0BDQDW8V5E/p1785445025743429 CHANGELOG-NONE <!-- factory-agent: {"source":"factory-agent","task_id":"APP-5072","task_source":"linear","task_url":"https://linear.app/warpdotdev/issue/APP-5072/use-path-apis-instead-of-main-separator-string-splitting-in-appbuildrs","oz_run_id":"019fb544-9a9c-7b19-bf65-bee1c2de61bc","repo":"warpdotdev/warp"} --> Co-authored-by: Andy <andy@warp.dev>
1 parent 2c86dce commit baee919

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

app/build.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ fn generate_channel_config_if_needed(target_family: &str, target_os: &str) {
218218
fn get_build_profile_name() -> String {
219219
// The profile name is always the 3rd last part of the path (with 1 based indexing).
220220
// e.g. /code/core/target/cli/build/my-build-info-9f91ba6f99d7a061/out
221-
env::var("OUT_DIR")
222-
.expect("OUT_DIR must be set")
223-
.split(std::path::MAIN_SEPARATOR)
224-
.nth_back(3)
221+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set"));
222+
out_dir
223+
.ancestors()
224+
.nth(3)
225+
.and_then(Path::file_name)
225226
.expect("could not get profile name")
226-
.to_string()
227+
.to_string_lossy()
228+
.into_owned()
227229
}
228230

229231
fn add_features(target_family: &str, target_os: &str) {

0 commit comments

Comments
 (0)