Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: facebook/buck2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9a92e6bd7f0b4de4b7d7f49cc6220eea6648cb8b
Choose a base ref
..
head repository: facebook/buck2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 76f13b52316cbb211c24e1446fddcc62922dc8d7
Choose a head ref
Showing with 111 additions and 59 deletions.
  1. +3 −0 app/buck2_data/error.proto
  2. +1 −0 app/buck2_error/src/classify.rs
  3. +51 −3 app/buck2_test/src/command.rs
  4. +4 −0 app/buck2_util/src/os/macos/host_cpu_load_info.rs
  5. +52 −56 prelude/rust/tools/rustc_action.py
3 changes: 3 additions & 0 deletions app/buck2_data/error.proto
Original file line number Diff line number Diff line change
@@ -226,6 +226,9 @@ enum ErrorTag {
// Tests
TEST_DEADLINE_EXPIRED = 5001;

// Error from TPX binary
TPX = 5500;

// None turned into an error. This carries no useful information whatsoever.
UNEXPECTED_NONE = 6001;
}
1 change: 1 addition & 0 deletions app/buck2_error/src/classify.rs
Original file line number Diff line number Diff line change
@@ -173,6 +173,7 @@ pub(crate) fn category_and_rank(tag: ErrorTag) -> (Option<Tier>, u32) {
ErrorTag::IoEdenUnknownField => rank!(unspecified),
ErrorTag::MaterializationError => rank!(unspecified),
ErrorTag::CleanInterrupt => rank!(unspecified),
ErrorTag::Tpx => rank!(unspecified),
ErrorTag::Http => rank!(unspecified),
ErrorTag::DownloadFileHeadRequest => rank!(unspecified),
ErrorTag::Install => rank!(unspecified),
54 changes: 51 additions & 3 deletions app/buck2_test/src/command.rs
Original file line number Diff line number Diff line change
@@ -104,6 +104,17 @@ use crate::session::TestSession;
use crate::session::TestSessionOptions;
use crate::translations::build_configured_target_handle;

#[derive(Debug, buck2_error::Error)]
#[buck2(tag = Input)]
enum TestError {
#[error("Test execution completed but the tests failed")]
TestFailed,
#[error("Test listing failed")]
ListingFailed,
#[error("Fatal error encountered during test execution")]
Fatal,
}

struct TestOutcome {
errors: Vec<buck2_data::ErrorReport>,
executor_report: ExecutorReport,
@@ -252,9 +263,16 @@ impl ServerCommandTemplate for TestServerCommand {
&self,
response: &Self::Response,
) -> Vec<buck2_data::ErrorReport> {
response.errors.clone()
if let Some(test_status) = &response.test_statuses {
[
response.errors.clone(),
error_report_for_test_errors(test_status),
]
.concat()
} else {
response.errors.clone()
}
}

async fn command(
&self,
server_ctx: &dyn ServerCommandContextTrait,
@@ -470,6 +488,36 @@ async fn test(
})
}

fn error_report_for_test_errors(
status: &buck2_cli_proto::test_response::TestStatuses,
) -> Vec<buck2_data::ErrorReport> {
let mut errors = vec![];

if let Some(failed) = &status.failed {
if failed.count > 0 {
errors.push(create_error_report(&buck2_error::Error::from(
TestError::TestFailed,
)));
}
}
if let Some(fatal) = &status.fatals {
if fatal.count > 0 {
errors.push(create_error_report(&buck2_error::Error::from(
TestError::Fatal,
)));
}
}
if let Some(listing_failed) = &status.listing_failed {
if listing_failed.count > 0 {
errors.push(create_error_report(&buck2_error::Error::from(
TestError::ListingFailed,
)));
}
}

errors
}

async fn test_targets(
ctx: DiceTransaction,
pattern: ResolvedPattern<ConfiguredProvidersPatternExtra>,
@@ -513,7 +561,7 @@ async fn test_targets(

let res = tag_result!(
"executor_launch_failed",
res.map_err(|e| from_any_with_tag(e, buck2_error::ErrorTag::Tier0)),
res.map_err(|e| from_any_with_tag(e, buck2_error::ErrorTag::Tpx)),
quiet: true,
daemon_in_memory_state_is_corrupted: true,
task: false
4 changes: 4 additions & 0 deletions app/buck2_util/src/os/macos/host_cpu_load_info.rs
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ pub fn host_cpu_load_info() -> buck2_error::Result<HostCpuLoadInfo> {
};

let res = libc::host_statistics64(
// TODO libc::mach_host_self is deprecated and is not yet part of the
// suggested `mach2` crate (https://github.com/JohnTitor/mach2/issues/34)
// Someone needs to add it upstream or implement a different route!
#[allow(deprecated)]
libc::mach_host_self(),
libc::HOST_CPU_LOAD_INFO,
&mut host_info as *mut _ as *mut libc::integer_t,
108 changes: 52 additions & 56 deletions prelude/rust/tools/rustc_action.py
Original file line number Diff line number Diff line change
@@ -30,11 +30,49 @@

DEBUG = False

NIX_ENV_VARS = [
INHERITED_ENV = [
"RUSTC_LOG",
"RUST_BACKTRACE",
"PATH",
"PWD",
"HOME",
"RUSTUP_HOME",
"TMPDIR",
# Required on Windows
"LOCALAPPDATA",
"PROGRAMDATA",
"TEMP",
"TMP",
# TODO(andirauter): Required by RE. Remove them when no longer required T119466023
"EXECUTION_ID",
"SESSION_ID",
"ACTION_DIGEST",
"RE_PLATFORM",
"CAS_DAEMON_PORT",
"CAS_DAEMON_ADDR",
# Required by Dotslash, which is how the Rust toolchain is shipped on Mac.
"USER",
"DOTSLASH_CACHE",
# Required to run Python on Windows (for linker wrapper).
"SYSTEMROOT",
# Our rustc wrapper. https://fburl.com/code/qcos5aho
"SYSROOT_MULTIPLEXER_DEBUG",
# Required on Windows for getpass.getuser() to work.
"USERNAME",
# Option to disable hg pre-fork client.
# We might pass it to avoid long-running process created inside a per-action cgroup.
# Such long-running process make it impossible to clean up systemd slices.
# Context https://fb.workplace.com/groups/mercurialusers/permalink/2901424916673036/
"CHGDISABLE",
# Nix
"NIX_BINTOOLS",
"NIX_BINTOOLS_FOR_TARGET",
"NIX_BINTOOLS_WRAPPER_TARGET_HOST_*",
"NIX_BINTOOLS_WRAPPER_TARGET_TARGET_*",
"NIX_CC",
"NIX_CC_FOR_TARGET",
"NIX_CC_WRAPPER_TARGET_HOST_*",
"NIX_CC_WRAPPER_TARGET_TARGET_*",
"NIX_CFLAGS_COMPILE",
"NIX_CFLAGS_COMPILE_FOR_TARGET",
"NIX_COREFOUNDATION_RPATH",
@@ -47,21 +85,6 @@
"NIX_LDFLAGS_FOR_TARGET",
"NIX_NO_SELF_RPATH",
]
NIX_ENV_VAR_PREFIXES = [
"NIX_BINTOOLS_WRAPPER_TARGET_HOST_",
"NIX_BINTOOLS_WRAPPER_TARGET_TARGET_",
"NIX_CC_WRAPPER_TARGET_HOST_",
"NIX_CC_WRAPPER_TARGET_TARGET_",
]


def nix_env(env: Dict[str, str]):
env.update({k: os.environ[k] for k in NIX_ENV_VARS if k in os.environ})
for prefix in NIX_ENV_VAR_PREFIXES:
vars_starting_with = dict(
filter(lambda pair: pair[0].startswith(prefix), os.environ.items())
)
env.update(vars_starting_with.items())


def eprint(*args: Any, **kwargs: Any) -> None:
@@ -186,6 +209,18 @@ def arg_eval(arg: str) -> str:
arg = rest


def inherited_env() -> Dict[str, str]:
env = {}
for pattern in INHERITED_ENV:
if pattern.endswith("*"):
for k in os.environ:
if k.startswith(pattern[:-1]):
env[k] = os.environ[k]
elif pattern in os.environ:
env[pattern] = os.environ[pattern]
return env


async def handle_output( # noqa: C901
proc: asyncio.subprocess.Process,
args: Args,
@@ -275,46 +310,7 @@ async def main() -> int: # noqa: C901
return 0

# Inherit a very limited initial environment, then add the new things
env = {
k: os.environ[k]
for k in [
"RUSTC_LOG",
"RUST_BACKTRACE",
"PATH",
"PWD",
"HOME",
"TMPDIR",
# Required on Windows
"LOCALAPPDATA",
"PROGRAMDATA",
"TEMP",
"TMP",
# TODO(andirauter): Required by RE. Remove them when no longer required T119466023
"EXECUTION_ID",
"SESSION_ID",
"ACTION_DIGEST",
"RE_PLATFORM",
"CAS_DAEMON_PORT",
"CAS_DAEMON_ADDR",
# Required by Dotslash, which is how the Rust toolchain is shipped
# on Mac.
"USER",
"DOTSLASH_CACHE",
# Required to run Python on Windows (for linker wrapper).
"SYSTEMROOT",
# Our rustc wrapper. https://fburl.com/code/qcos5aho
"SYSROOT_MULTIPLEXER_DEBUG",
# Required on Windows for getpass.getuser() to work.
"USERNAME",
# Option to disable hg pre-fork client.
# We might pass it to avoid long-running process created inside a per-action cgroup.
# Such long-running process make it impossible to clean up systemd slices.
# Context https://fb.workplace.com/groups/mercurialusers/permalink/2901424916673036/
"CHGDISABLE",
]
if k in os.environ
}
nix_env(env)
env = inherited_env()
if args.env:
# Unescape previously escaped newlines.
# Example: \\\\n\\n -> \\\n\n -> \\n\n