Skip to content

Commit 6679044

Browse files
committed
bxl: get output artifacts for an Action
- Rename action to bxl.Action so it is findable in docs (I don't know if that was what was preventing docs generation, but it's worth a try!) - Add a method to get the output artifacts for an action in bxl. This allows selectively rebuilding the action by ensuring those outputs. I added a test, but I have no way to run those besides www.metacareers.com: #1027 This is part of making action graph debugging slightly easier, which I want to prototype by writing some rather nasty BXLs: #1217 Unfortunately I *think* there's no way to get the dependencies after the fact, since I *just* have a RegisteredAction. I believe that I can probably do something very bad with owner() then rerunning the analysis to get deps though.
1 parent a72a88b commit 6679044

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

app/buck2_bxl/src/bxl/starlark_defs/nodes/action.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use std::convert::Infallible;
1212
use std::sync::Arc;
1313

1414
use allocative::Allocative;
15+
use buck2_artifact::artifact::artifact_type::Artifact;
1516
use buck2_build_api::actions::RegisteredAction;
1617
use buck2_build_api::actions::query::ActionQueryNode;
1718
use buck2_build_api::actions::query::OwnedActionAttr;
19+
use buck2_build_api::interpreter::rule_defs::artifact::starlark_artifact::StarlarkArtifact;
1820
use buck2_core::deferred::base_deferred_key::BaseDeferredKey;
1921
use buck2_error::buck2_error;
2022
use buck2_interpreter::types::target_label::StarlarkConfiguredTargetLabel;
@@ -49,7 +51,7 @@ pub(crate) struct StarlarkAction(pub(crate) Arc<RegisteredAction>);
4951

5052
starlark_simple_value!(StarlarkAction);
5153

52-
#[starlark_value(type = "action")]
54+
#[starlark_value(type = "bxl.Action")]
5355
impl<'v> StarlarkValue<'v> for StarlarkAction {
5456
fn get_methods() -> Option<&'static Methods> {
5557
static RES: MethodsStatic = MethodsStatic::new();
@@ -67,7 +69,7 @@ impl<'a> UnpackValue<'a> for StarlarkAction {
6769
}
6870
}
6971

70-
/// Methods for an action.
72+
/// Methods for an action obtained from [`bxl.AuditContext.output()`](../AuditContext#output).
7173
#[starlark_module]
7274
fn action_methods(builder: &mut MethodsBuilder) {
7375
/// Gets the owning configured target label for an action.
@@ -90,6 +92,17 @@ fn action_methods(builder: &mut MethodsBuilder) {
9092
.into()),
9193
}
9294
}
95+
96+
/// Gets the artifacts built by this action.
97+
fn outputs<'v>(this: StarlarkAction) -> starlark::Result<Vec<StarlarkArtifact>> {
98+
Ok(this
99+
.0
100+
.action()
101+
.outputs()
102+
.iter()
103+
.map(|a| StarlarkArtifact::new(Artifact::from(a.clone())))
104+
.collect())
105+
}
93106
}
94107

95108
#[derive(Debug, Display, ProvidesStaticType, Allocative)]

tests/core/bxl/test_audit_data/audit.bxl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def _audit_output_action_exists_impl(ctx):
1515
action = ctx.audit().output(buck_out)
1616

1717
asserts.equals(action.owner(), target.label)
18+
asserts.equals(actions.outputs()[0].basename, "with_output.txt")
1819

1920
audit_output_action_exists = bxl_main(
2021
impl = _audit_output_action_exists_impl,

tests/core/query/aquery/test_aquery_data/aquery.bxl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _impl_action_query_node(ctx):
130130
action = result[0]
131131
analysis = result[1]
132132

133-
_assert_eq(type(action.action()), "action")
133+
_assert_eq(type(action.action()), "bxl.Action")
134134
_assert_eq(action.rule_type, "copy")
135135
_assert_eq(str(action.action().owner().raw_target()), "root//:test")
136136

0 commit comments

Comments
 (0)