Skip to content

Commit f85baf6

Browse files
miguelfrdeCQ Bot
authored andcommitted
[iquery] Remove ":expose:" in accessor arguments
Fixed: 381127117 Change-Id: Idf9f6c6d4f74962e2bc4d2f49d3c77364c0a089f Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1164092 Reviewed-by: Clayton McCray <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Fuchsia-Auto-Submit: Miguel Flores <[email protected]>
1 parent a4ade7d commit f85baf6

File tree

18 files changed

+125
-312
lines changed

18 files changed

+125
-312
lines changed

src/developer/ffx/plugins/inspect/src/accessor_provider.rs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use anyhow::anyhow;
66
use diagnostics_data::Data;
77
use fidl_fuchsia_developer_remotecontrol::RemoteControlProxy;
88
use fidl_fuchsia_diagnostics::ClientSelectorConfiguration::{SelectAll, Selectors};
9-
use fidl_fuchsia_diagnostics::{
10-
Format, Selector, SelectorArgument, StreamParameters, StringSelector, TreeSelector,
11-
};
9+
use fidl_fuchsia_diagnostics::{Format, Selector, SelectorArgument, StreamParameters};
1210
use fidl_fuchsia_diagnostics_host::{ArchiveAccessorMarker, ArchiveAccessorProxy};
1311
use fidl_fuchsia_io::OpenFlags;
1412
use fidl_fuchsia_sys2 as fsys2;
@@ -35,43 +33,18 @@ fn add_host_before_last_dot(input: &str) -> Result<String, Error> {
3533
Ok(format!("{}.host.{}", rest, last))
3634
}
3735

38-
struct MonikerAndProtocol {
39-
protocol: String,
40-
moniker: String,
36+
struct MonikerAndProtocol<'a> {
37+
protocol: &'a str,
38+
moniker: &'a str,
4139
}
4240

43-
impl TryFrom<Selector> for MonikerAndProtocol {
41+
impl<'a> TryFrom<&'a str> for MonikerAndProtocol<'a> {
4442
type Error = Error;
4543

46-
fn try_from(selector: Selector) -> Result<Self, Self::Error> {
47-
Ok(MonikerAndProtocol {
48-
moniker: selector
49-
.component_selector
50-
.map(|selector| selector.moniker_segments)
51-
.flatten()
52-
.into_iter()
53-
.flatten()
54-
.map(|value| match value {
55-
StringSelector::ExactMatch(value) => Ok(value),
56-
_ => Err(Error::MustBeExactMoniker),
57-
})
58-
.collect::<Result<Vec<_>, Error>>()?
59-
.join("/"),
60-
protocol: selector
61-
.tree_selector
62-
.map(|value| match value {
63-
TreeSelector::PropertySelector(value) => Ok(value.target_properties),
64-
_ => Err(Error::MustUsePropertySelector),
65-
})
66-
.into_iter()
67-
.flatten()
68-
.map(|value| match value {
69-
StringSelector::ExactMatch(value) => Ok(value),
70-
_ => Err(Error::MustBeExactProtocol),
71-
})
72-
.next()
73-
.ok_or(Error::MustBeExactProtocol)??,
74-
})
44+
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
45+
s.rsplit_once(":")
46+
.map(|(moniker, protocol)| MonikerAndProtocol { moniker, protocol })
47+
.ok_or_else(|| Error::invalid_accessor(s))
7548
}
7649
}
7750

@@ -82,7 +55,7 @@ impl HostArchiveReader {
8255

8356
pub async fn snapshot_diagnostics_data<D>(
8457
&self,
85-
accessor: &Option<String>,
58+
accessor: Option<&str>,
8659
selectors: impl IntoIterator<Item = Selector>,
8760
) -> Result<Vec<Data<D>>, Error>
8861
where
@@ -95,18 +68,14 @@ impl HostArchiveReader {
9568
Selectors(selectors.map(|s| SelectorArgument::StructuredSelector(s)).collect())
9669
};
9770

98-
let accessor = match accessor {
99-
Some(ref s) => {
71+
let accessor = match accessor.as_deref() {
72+
Some(s) => {
10073
let s = add_host_before_last_dot(s)?;
101-
let selector = selectors::parse_verbose(&s).map_err(|e| {
102-
Error::ParseSelector("unable to parse selector".to_owned(), anyhow!("{:?}", e))
103-
})?;
104-
let moniker_and_protocol = MonikerAndProtocol::try_from(selector)?;
105-
74+
let moniker_and_protocol = MonikerAndProtocol::try_from(s.as_str())?;
10675
let (client, server) = fidl::endpoints::create_endpoints::<ArchiveAccessorMarker>();
10776
self.rcs_proxy
10877
.deprecated_open_capability(
109-
&format!("/{}", moniker_and_protocol.moniker),
78+
&format!("{}", moniker_and_protocol.moniker),
11079
fsys2::OpenDirType::ExposedDir,
11180
&moniker_and_protocol.protocol,
11281
server.into_channel(),
@@ -156,7 +125,7 @@ impl HostArchiveReader {
156125
impl DiagnosticsProvider for HostArchiveReader {
157126
async fn snapshot<D>(
158127
&self,
159-
accessor_path: &Option<String>,
128+
accessor_path: Option<&str>,
160129
selectors: impl IntoIterator<Item = Selector>,
161130
) -> Result<Vec<Data<D>>, Error>
162131
where

src/developer/ffx/plugins/inspect/src/apply_selectors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub async fn execute(
4242
.context(format!("Unable to deserialize {}.", snapshot_file.display()))?
4343
} else {
4444
let provider = HostArchiveReader::new(diagnostics_proxy, rcs_proxy);
45-
provider.snapshot::<Inspect>(&cmd.accessor_path, std::iter::empty()).await?
45+
provider.snapshot::<Inspect>(cmd.accessor_path.as_deref(), std::iter::empty()).await?
4646
};
4747
let moniker = match cmd.moniker {
4848
Some(m) => Some(ExtendedMoniker::parse_str(&m)?),

src/developer/ffx/plugins/inspect/src/tests/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ async fn test_list_with_data_with_manifest_and_archive() {
137137
let cmd = ListCommand {
138138
manifest: Some(String::from("moniker1")),
139139
with_url: true,
140-
accessor: Some("./test/component:expose:fuchsia.diagnostics.ArchiveAccessor".to_owned()),
140+
accessor: Some("test/component:fuchsia.diagnostics.ArchiveAccessor".to_owned()),
141141
};
142142
let (accessor, _task) = setup_fake_rcs_with_embedded_archive_accessor(
143143
setup_fake_archive_accessor(vec![FakeAccessorData::new(
144144
params.clone(),
145145
expected_responses.clone(),
146146
)]),
147-
"/test/component".into(),
147+
"test/component".into(),
148148
"fuchsia.diagnostics.host.ArchiveAccessor".into(),
149149
);
150150
run_command(

src/developer/ffx/plugins/inspect/src/tests/list_accessors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ async fn test_list_accessors() {
2222
.unwrap();
2323

2424
let expected = serde_json::to_string(&vec![
25-
String::from("example/component:expose:fuchsia.diagnostics.ArchiveAccessor"),
26-
String::from("foo/bar/thing\\:instance:expose:fuchsia.diagnostics.FeedbackArchiveAccessor"),
27-
String::from("foo/component:expose:fuchsia.diagnostics.FeedbackArchiveAccessor"),
25+
String::from("example/component:fuchsia.diagnostics.ArchiveAccessor"),
26+
String::from("foo/bar/thing\\:instance:fuchsia.diagnostics.FeedbackArchiveAccessor"),
27+
String::from("foo/component:fuchsia.diagnostics.FeedbackArchiveAccessor"),
2828
])
2929
.unwrap();
3030
let output = test_buffers.into_stdout_str();

src/developer/ffx/tests/cli-goldens/goldens/ffx/inspect/list.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"optionality": "optional",
4141
"long": "--accessor",
4242
"short": null,
43-
"description": "A selector specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. The selector will be in the form of: <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName Typically this is the output of `iquery list-accessors`. For example: `bootstrap/archivist:expose:fuchsia.diagnostics.FeedbackArchiveAccessor` means that the command will connect to the `FeedbackArchiveAccecssor` exposed by `bootstrap/archivist`.",
43+
"description": "A selector specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. The selector will be in the form of: <moniker>:fuchsia.diagnostics.ArchiveAccessorName Typically this is the output of `iquery list-accessors`. For example: `bootstrap/archivist:fuchsia.diagnostics.FeedbackArchiveAccessor` means that the command will connect to the `FeedbackArchiveAccecssor` exposed by `bootstrap/archivist`.",
4444
"hidden": false
4545
}
4646
],

src/developer/ffx/tests/cli-goldens/goldens/ffx/inspect/selectors.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"optionality": "optional",
4545
"long": "--accessor",
4646
"short": null,
47-
"description": "A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. This can be copied from the output of `ffx inspect list-accessors`. The selector will be in the form of: <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName",
47+
"description": "A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. This can be copied from the output of `ffx inspect list-accessors`. The selector will be in the form of: <moniker>:fuchsia.diagnostics.ArchiveAccessorName",
4848
"hidden": false
4949
}
5050
],

src/developer/ffx/tests/cli-goldens/goldens/ffx/inspect/show.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"optionality": "optional",
4545
"long": "--accessor",
4646
"short": null,
47-
"description": "A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. This can be copied from the output of `ffx inspect list-accessors`. The selector will be in the form of: <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName",
47+
"description": "A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to. This can be copied from the output of `ffx inspect list-accessors`. The selector will be in the form of: <moniker>:fuchsia.diagnostics.ArchiveAccessorName",
4848
"hidden": false
4949
},
5050
{

src/diagnostics/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ group("tests") {
3838
"tests",
3939
"triage:tests",
4040
"validator:tests",
41+
"//src/developer/ffx/plugins/inspect:tests($host_toolchain)",
42+
"//src/developer/ffx/plugins/log:tests($host_toolchain)",
43+
"//src/developer/ffx/tools/triage:tests($host_toolchain)",
4144
"//src/lib/diagnostics:tests",
4245

4346
# Disabled due to lack of support in Clang and Rust toolchain;

src/diagnostics/iquery/src/commands/list.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn components_from_inspect_data(inspect_data: Vec<InspectData>) -> Vec<ListResul
100100
}
101101

102102
pub fn list_response_items_from_components(
103-
manifest: &Option<String>,
103+
manifest: Option<&str>,
104104
with_url: bool,
105105
components: Vec<ListResultItem>,
106106
) -> Vec<ListResultItem> {
@@ -146,11 +146,11 @@ pub struct ListCommand {
146146
#[argh(option)]
147147
/// A selector specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to.
148148
/// The selector will be in the form of:
149-
/// <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName
149+
/// <moniker>:fuchsia.diagnostics.ArchiveAccessorName
150150
///
151151
/// Typically this is the output of `iquery list-accessors`.
152152
///
153-
/// For example: `bootstrap/archivist:expose:fuchsia.diagnostics.FeedbackArchiveAccessor`
153+
/// For example: `bootstrap/archivist:fuchsia.diagnostics.FeedbackArchiveAccessor`
154154
/// means that the command will connect to the `FeedbackArchiveAccecssor`
155155
/// exposed by `bootstrap/archivist`.
156156
pub accessor: Option<String>,
@@ -160,10 +160,14 @@ impl Command for ListCommand {
160160
type Result = ListResult;
161161

162162
async fn execute<P: DiagnosticsProvider>(self, provider: &P) -> Result<Self::Result, Error> {
163-
let inspect = provider.snapshot::<Inspect>(&self.accessor, std::iter::empty()).await?;
163+
let inspect =
164+
provider.snapshot::<Inspect>(self.accessor.as_deref(), std::iter::empty()).await?;
164165
let components = components_from_inspect_data(inspect);
165-
let results =
166-
list_response_items_from_components(&self.manifest, self.with_url, components);
166+
let results = list_response_items_from_components(
167+
self.manifest.as_deref(),
168+
self.with_url,
169+
components,
170+
);
167171
Ok(ListResult(results))
168172
}
169173
}

src/diagnostics/iquery/src/commands/selectors.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct SelectorsCommand {
3939
/// A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to.
4040
/// This can be copied from the output of `ffx inspect list-accessors`.
4141
/// The selector will be in the form of:
42-
/// <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName
42+
/// <moniker>:fuchsia.diagnostics.ArchiveAccessorName
4343
pub accessor: Option<String>,
4444
}
4545

@@ -65,16 +65,21 @@ impl Command for SelectorsCommand {
6565
)
6666
.await?
6767
} else if let Some(manifest) = self.manifest {
68-
utils::get_selectors_for_manifest(manifest, self.selectors, &self.accessor, provider)
69-
.await?
68+
utils::get_selectors_for_manifest(
69+
manifest,
70+
self.selectors,
71+
self.accessor.clone(),
72+
provider,
73+
)
74+
.await?
7075
} else {
7176
utils::process_fuzzy_inputs(self.selectors, provider).await?
7277
};
7378

7479
let selectors = utils::expand_selectors(selectors, None)?;
7580

7681
let mut results =
77-
provider.snapshot::<Inspect>(&self.accessor, selectors.into_iter()).await?;
82+
provider.snapshot::<Inspect>(self.accessor.as_deref(), selectors.into_iter()).await?;
7883
for result in results.iter_mut() {
7984
if let Some(hierarchy) = &mut result.payload {
8085
hierarchy.sort();

src/diagnostics/iquery/src/commands/show.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct ShowCommand {
7878
/// A string specifying what `fuchsia.diagnostics.ArchiveAccessor` to connect to.
7979
/// This can be copied from the output of `ffx inspect list-accessors`.
8080
/// The selector will be in the form of:
81-
/// <moniker>:<directory>:fuchsia.diagnostics.ArchiveAccessorName
81+
/// <moniker>:fuchsia.diagnostics.ArchiveAccessorName
8282
pub accessor: Option<String>,
8383

8484
#[argh(option)]
@@ -105,16 +105,21 @@ impl Command for ShowCommand {
105105
)
106106
.await?
107107
} else if let Some(manifest) = self.manifest {
108-
utils::get_selectors_for_manifest(manifest, self.selectors, &self.accessor, provider)
109-
.await?
108+
utils::get_selectors_for_manifest(
109+
manifest,
110+
self.selectors,
111+
self.accessor.clone(),
112+
provider,
113+
)
114+
.await?
110115
} else {
111116
utils::process_fuzzy_inputs(self.selectors, provider).await?
112117
};
113118

114119
let selectors = utils::expand_selectors(selectors, self.name)?;
115120

116121
let inspect_data_iter =
117-
provider.snapshot::<Inspect>(&self.accessor, selectors).await?.into_iter();
122+
provider.snapshot::<Inspect>(self.accessor.as_deref(), selectors).await?.into_iter();
118123

119124
let mut results = inspect_data_iter
120125
.map(|mut d: InspectData| {

0 commit comments

Comments
 (0)