Skip to content

Commit 51565f9

Browse files
cjhopmanfacebook-github-bot
authored andcommitted
un-nest more code
Summary: Just pulling out a bunch of code from within a match case. Reviewed By: JakobDegen Differential Revision: D64281584 fbshipit-source-id: 96de9f79ee9e34f0733b49e196af7b5da2050c8e
1 parent 5d5f75a commit 51565f9

File tree

1 file changed

+56
-71
lines changed

1 file changed

+56
-71
lines changed

app/buck2_bxl/src/profile_command.rs

+56-71
Original file line numberDiff line numberDiff line change
@@ -85,79 +85,64 @@ impl ServerCommandTemplate for BxlProfileServerCommand {
8585
let profile_mode =
8686
starlark_profiler_configuration_from_request(&self.req, server_ctx.project_root())?;
8787

88-
let profile_data = match profile_mode {
89-
StarlarkProfilerConfiguration::ProfileBxl(profile_mode) => {
90-
let cwd = server_ctx.working_dir();
91-
92-
let cell_resolver = ctx.get_cell_resolver().await?;
93-
let cell_alias_resolver = ctx.get_cell_alias_resolver_for_dir(cwd).await?;
94-
let bxl_label = parse_bxl_label_from_cli(
95-
cwd,
96-
&opts.bxl_label,
97-
&cell_resolver,
98-
&cell_alias_resolver,
99-
)?;
100-
101-
let bxl_args = match get_bxl_cli_args(
102-
cwd,
103-
&mut ctx,
104-
&bxl_label,
105-
&opts.bxl_args,
106-
&cell_resolver,
107-
)
108-
.await?
109-
{
110-
BxlResolvedCliArgs::Resolved(bxl_args) => Arc::new(bxl_args),
111-
_ => {
112-
return Err(buck2_error!(
113-
buck2_error::ErrorTag::Input,
114-
"Help docs were displayed. No profiler data available"
115-
));
116-
}
117-
};
118-
119-
let global_cfg_options = global_cfg_options_from_client_context(
120-
opts.target_cfg
121-
.as_ref()
122-
.internal_error("target_cfg must be set")?,
123-
server_ctx,
124-
&mut ctx,
125-
)
126-
.await?;
127-
128-
let bxl_key = BxlKey::new(
129-
bxl_label.clone(),
130-
bxl_args,
131-
/* force print stacktrace */ false,
132-
global_cfg_options,
133-
);
134-
135-
server_ctx
136-
.cancellation_context()
137-
.with_structured_cancellation(|observer| {
138-
async move {
139-
buck2_error::Ok(
140-
eval(
141-
&mut ctx,
142-
bxl_key,
143-
StarlarkProfileMode::Profile(profile_mode),
144-
observer,
145-
)
146-
.await?
147-
.1
148-
.map(Arc::new)
149-
.expect("No bxl profile data found"),
150-
)
151-
}
152-
.boxed()
153-
})
154-
.await?
155-
}
156-
_ => {
157-
return Err(internal_error!("Incorrect profile mode"));
158-
}
88+
let StarlarkProfilerConfiguration::ProfileBxl(profile_mode) = profile_mode else {
89+
return Err(internal_error!("Incorrect profile mode"));
15990
};
16091

92+
let cwd = server_ctx.working_dir();
93+
94+
let cell_resolver = ctx.get_cell_resolver().await?;
95+
let cell_alias_resolver = ctx.get_cell_alias_resolver_for_dir(cwd).await?;
96+
let bxl_label =
97+
parse_bxl_label_from_cli(cwd, &opts.bxl_label, &cell_resolver, &cell_alias_resolver)?;
98+
99+
let BxlResolvedCliArgs::Resolved(bxl_args) =
100+
get_bxl_cli_args(cwd, &mut ctx, &bxl_label, &opts.bxl_args, &cell_resolver).await?
101+
else {
102+
return Err(buck2_error!(
103+
buck2_error::ErrorTag::Input,
104+
"Help docs were displayed. No profiler data available"
105+
));
106+
};
107+
let bxl_args = Arc::new(bxl_args);
108+
109+
let global_cfg_options = global_cfg_options_from_client_context(
110+
opts.target_cfg
111+
.as_ref()
112+
.internal_error("target_cfg must be set")?,
113+
server_ctx,
114+
&mut ctx,
115+
)
116+
.await?;
117+
118+
let bxl_key = BxlKey::new(
119+
bxl_label.clone(),
120+
bxl_args,
121+
/* force print stacktrace */ false,
122+
global_cfg_options,
123+
);
124+
125+
let profile_data = server_ctx
126+
.cancellation_context()
127+
.with_structured_cancellation(|observer| {
128+
async move {
129+
buck2_error::Ok(
130+
eval(
131+
&mut ctx,
132+
bxl_key,
133+
StarlarkProfileMode::Profile(profile_mode),
134+
observer,
135+
)
136+
.await?
137+
.1
138+
.map(Arc::new)
139+
.expect("No bxl profile data found"),
140+
)
141+
}
142+
.boxed()
143+
})
144+
.await?;
145+
161146
Ok(get_profile_response(profile_data, output)?)
162147
}
163148

0 commit comments

Comments
 (0)