Skip to content

Commit

Permalink
Generate directories for build-report, if missing
Browse files Browse the repository at this point in the history
Summary:
This diff generates the directories for the build report, if necessary.  It's needed to reproduce CI failures locally, where this directory doesn't exist.  For examples, see this post:
* https://fb.workplace.com/groups/askbuck/permalink/27772005049088080/

```
Error writing build report

Caused by:
    0: create_file(/data/sandcastle/boxes/fbsource/fbcode/buck2/buck-out/v2/translator-build/build-report.json)
    1: No such file or directory (os error 2)
```

More context:

RL uses a translator subdirectory in buck for the build report output.  This was added in D39889050 and discussed in this post: * https://fb.workplace.com/groups/buck2eng/permalink/2998592690438211/

Reviewed By: IanChilds

Differential Revision: D68751966

fbshipit-source-id: 263b373f24748b70131e764574259914bc34de47
  • Loading branch information
dmetamayor authored and facebook-github-bot committed Jan 28, 2025
1 parent 31c3332 commit e111249
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
16 changes: 9 additions & 7 deletions app/buck2_build_api/src/build/build_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,15 @@ pub fn generate_build_report(
let mut serialized_build_report = None;

if !opts.unstable_build_report_filename.is_empty() {
let file = fs_util::create_file(
project_root
.resolve(cwd)
.as_abs_path()
.join(opts.unstable_build_report_filename),
)
.buck_error_context("Error writing build report")?;
let path = project_root
.resolve(cwd)
.as_abs_path()
.join(opts.unstable_build_report_filename);
if let Some(parent) = path.parent() {
fs_util::create_dir_all(parent)?;
}
let file =
fs_util::create_file(path.clone()).buck_error_context("Error writing build report")?;
let mut file = BufWriter::new(file);
serde_json::to_writer_pretty(&mut file, &build_report)?
} else {
Expand Down
19 changes: 9 additions & 10 deletions tests/core/build/test_build_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

import json

import pytest

from buck2.tests.e2e_util.api.buck import Buck
from buck2.tests.e2e_util.api.buck_result import BuckException
from buck2.tests.e2e_util.buck_workspace import buck_test
from buck2.tests.e2e_util.helper.utils import replace_hashes

Expand Down Expand Up @@ -138,10 +135,12 @@ async def test_build_report_package_project_relative_path(buck: Buck) -> None:
async def test_build_report_non_existent_directory(buck: Buck) -> None:
build_report = "non_existent_dir/report"

# FIXME(diegomontemayor): This should not fail
with pytest.raises(BuckException):
await buck.build(
"//:rule1",
"--build-report",
build_report,
)
await buck.build(
"//:rule1",
"--build-report",
build_report,
)

with open(buck.cwd / build_report) as file:
report = json.load(file)
assert report["success"]

0 comments on commit e111249

Please sign in to comment.