Skip to content

Commit 5aaf203

Browse files
authored
Warn on loading Geo* archetypes without the map_view feature (#8061)
### What * Closes #8052 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8061?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8061?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/8061) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
1 parent f23a3a2 commit 5aaf203

File tree

6 files changed

+128
-25
lines changed

6 files changed

+128
-25
lines changed

crates/build/re_types_builder/src/codegen/docs/mod.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use itertools::Itertools;
99

1010
use crate::{
1111
codegen::{autogen_warning, common::ExampleInfo, Target},
12-
objects::FieldKind,
12+
objects::{FieldKind, ViewReference},
1313
CodeGenerator, GeneratedFiles, Object, ObjectField, ObjectKind, Objects, Reporter, Type,
14-
ATTR_DOCS_VIEW_TYPES,
1514
};
1615

1716
pub const DATAFRAME_VIEW_FQNAME: &str = "rerun.blueprint.views.DataframeView";
@@ -34,12 +33,6 @@ impl DocsCodeGenerator {
3433
}
3534
}
3635

37-
struct ViewReference {
38-
/// Typename of the view. Not a fully qualified name, just the name as specified on the attribute.
39-
view_name: String,
40-
explanation: Option<String>,
41-
}
42-
4336
type ViewsPerArchetype = BTreeMap<String, Vec<ViewReference>>;
4437

4538
impl CodeGenerator for DocsCodeGenerator {
@@ -144,23 +137,9 @@ on [Entities and Components](../../concepts/entity-component.md).",
144137
fn collect_view_types_per_archetype(objects: &Objects) -> ViewsPerArchetype {
145138
let mut view_types_per_object = ViewsPerArchetype::new();
146139
for object in objects.objects.values() {
147-
let Some(view_types) = object.try_get_attr::<String>(ATTR_DOCS_VIEW_TYPES) else {
148-
continue;
149-
};
150-
151-
let view_types = view_types
152-
.split(',')
153-
.map(|view_type| {
154-
let mut parts = view_type.splitn(2, ':');
155-
let view_name = parts.next().unwrap().trim().to_owned();
156-
let explanation = parts.next().map(|s| s.trim().to_owned());
157-
ViewReference {
158-
view_name,
159-
explanation,
160-
}
161-
})
162-
.collect();
163-
view_types_per_object.insert(object.fqname.clone(), view_types);
140+
if let Some(view_types) = object.archetype_view_types() {
141+
view_types_per_object.insert(object.fqname.clone(), view_types);
142+
}
164143
}
165144

166145
view_types_per_object

crates/build/re_types_builder/src/codegen/rust/reflection.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::{BTreeMap, BTreeSet, HashMap};
22

33
use camino::Utf8PathBuf;
4+
use itertools::Itertools as _;
45
use proc_macro2::TokenStream;
56
use quote::{format_ident, quote};
67

@@ -217,10 +218,24 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
217218
.join("\n");
218219
}
219220

221+
let quoted_view_types = obj
222+
.archetype_view_types()
223+
.unwrap_or_default()
224+
.iter()
225+
.map(|view_type| {
226+
let view_name = &view_type.view_name;
227+
quote! { #view_name }
228+
})
229+
.collect_vec();
230+
220231
let quoted_archetype_reflection = quote! {
221232
ArchetypeReflection {
222233
display_name: #display_name,
223234

235+
view_types: &[
236+
#(#quoted_view_types,)*
237+
],
238+
224239
fields: vec![
225240
#(#quoted_field_reflections,)*
226241
],

crates/build/re_types_builder/src/objects.rs

+26
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ impl ObjectKind {
280280
}
281281
}
282282

283+
pub struct ViewReference {
284+
/// Typename of the view. Not a fully qualified name, just the name as specified on the attribute.
285+
pub view_name: String,
286+
287+
pub explanation: Option<String>,
288+
}
289+
283290
/// A high-level representation of a flatbuffers object, which can be either a struct, a union or
284291
/// an enum.
285292
#[derive(Debug, Clone)]
@@ -531,6 +538,25 @@ impl Object {
531538
self.attrs.has(name)
532539
}
533540

541+
pub fn archetype_view_types(&self) -> Option<Vec<ViewReference>> {
542+
let view_types = self.try_get_attr::<String>(crate::ATTR_DOCS_VIEW_TYPES)?;
543+
544+
Some(
545+
view_types
546+
.split(',')
547+
.map(|view_type| {
548+
let mut parts = view_type.splitn(2, ':');
549+
let view_name = parts.next().unwrap().trim().to_owned();
550+
let explanation = parts.next().map(|s| s.trim().to_owned());
551+
ViewReference {
552+
view_name,
553+
explanation,
554+
}
555+
})
556+
.collect(),
557+
)
558+
}
559+
534560
pub fn is_struct(&self) -> bool {
535561
self.class == ObjectClass::Struct
536562
}

crates/store/re_types_core/src/reflection.rs

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ pub struct ArchetypeReflection {
233233
/// The name of the field in human case.
234234
pub display_name: &'static str,
235235

236+
/// The views that this archetype can be added to.
237+
///
238+
/// e.g. `Spatial3DView`.
239+
pub view_types: &'static [&'static str],
240+
236241
/// All the component fields of the archetype, in the order they appear in the archetype.
237242
pub fields: Vec<ArchetypeFieldReflection>,
238243
}

crates/viewer/re_viewer/src/app.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,8 @@ impl App {
11891189
if let Some(caches) = store_hub.active_caches() {
11901190
caches.on_store_events(&store_events);
11911191
}
1192+
1193+
self.validate_loaded_events(&store_events);
11921194
}
11931195

11941196
Err(err) => {
@@ -1292,6 +1294,32 @@ impl App {
12921294
}
12931295
}
12941296

1297+
/// After loading some data; check if the loaded data makes sense.
1298+
fn validate_loaded_events(&self, store_events: &[re_chunk_store::ChunkStoreEvent]) {
1299+
re_tracing::profile_function!();
1300+
1301+
for event in store_events {
1302+
let chunk = &event.diff.chunk;
1303+
for component in chunk.component_names() {
1304+
if let Some(archetype_name) = component.indicator_component_archetype() {
1305+
if let Some(archetype) = self
1306+
.reflection
1307+
.archetype_reflection_from_short_name(&archetype_name)
1308+
{
1309+
for &view_type in archetype.view_types {
1310+
// TODO(#7876): remove once `map_view` feature is gone
1311+
if !cfg!(feature = "map_view") && view_type == "MapView" {
1312+
re_log::warn_once!("Found map-related archetype, but viewer was not compiled with the `map_view` feature.");
1313+
}
1314+
}
1315+
} else {
1316+
re_log::debug_once!("Unknown archetype: {archetype_name}");
1317+
}
1318+
}
1319+
}
1320+
}
1321+
}
1322+
12951323
fn purge_memory_if_needed(&mut self, store_hub: &mut StoreHub) {
12961324
re_tracing::profile_function!();
12971325

0 commit comments

Comments
 (0)