Skip to content

Commit

Permalink
adressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 14, 2023
1 parent 68464a8 commit 3112d07
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 290 deletions.
14 changes: 9 additions & 5 deletions crates/re_types_builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use xshell::{cmd, Shell};

use re_build_tools::{
compute_file_hash, is_tracked_env_var_set, read_versioning_hash, rerun_if_changed,
rerun_if_changed_or_doesnt_exist, write_versioning_hash,
compute_file_hash, is_tracked_env_var_set, read_versioning_hash, write_versioning_hash,
};

// ---
Expand Down Expand Up @@ -33,9 +32,14 @@ fn main() {
return;
}

rerun_if_changed_or_doesnt_exist(SOURCE_HASH_PATH);
rerun_if_changed(FBS_REFLECTION_DEFINITION_PATH);

// We're building an actual build graph here, and Cargo has no idea about it.
//
// Worse: some nodes in our build graph actually output artifacts into the src/ directory,
// which Cargo always interprets as "need to rebuild everything ASAP", leading to an infinite
// feedback loop.
//
// For these reasons, we manually compute and track signature hashes for the graph nodes we
// depend on, and make sure to exit early if everything's already up to date.
let cur_hash = read_versioning_hash(SOURCE_HASH_PATH);
let new_hash = compute_file_hash(FBS_REFLECTION_DEFINITION_PATH);

Expand Down
3 changes: 3 additions & 0 deletions crates/re_types_builder/definitions/reflection.fbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copied verbatim from the official flatbuffers source tree:
// https://github.com/google/flatbuffers/blob/63b7b25289447313ab6e79191fa1733748dca0da/reflection/reflection.fbs

// This schema defines objects that represent a parsed schema, like
// the binary version of a .fbs file.
// This could be used to operate on unknown FlatBuffers at runtime.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
72d936d50287d6c16d0c1b91f86bd74120642c8fc08e885f08dd2b92bb52e8a4
674450e64722effea9b29a84c34fab81b9d57497136a8f161561b8e19f7441b2
9 changes: 2 additions & 7 deletions crates/re_types_builder/src/arrow_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ use anyhow::Context as _;
use arrow2::datatypes::{DataType, Field, UnionMode};
use std::collections::{BTreeMap, HashMap};

use crate::{ElementType, Object, Type};

// ---

pub const ARROW_ATTR_TRANSPARENT: &str = "arrow.attr.transparent";
pub const ARROW_ATTR_SPARSE_UNION: &str = "arrow.attr.sparse_union";
use crate::{ElementType, Object, Type, ARROW_ATTR_SPARSE_UNION, ARROW_ATTR_TRANSPARENT};

// --- Registry ---

Expand Down Expand Up @@ -59,7 +54,7 @@ impl ArrowRegistry {
let num_fields = obj.fields.len();

assert!(
!(is_transparent && (!is_struct || num_fields != 1)),
!is_transparent || (is_struct && num_fields == 1),
"cannot have a transparent arrow object with any number of fields but 1: {:?} has {num_fields}",
obj.fqname,
);
Expand Down
19 changes: 19 additions & 0 deletions crates/re_types_builder/src/codegen/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ pub fn quote_doc_from_docs(docs: &Docs, tags: &[&str]) -> Vec<String> {

lines
}

pub trait StringExt {
fn push_text(&mut self, text: impl AsRef<str>, linefeeds: usize, indent: usize) -> &mut Self;
fn push_unindented_text(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self;
}

impl StringExt for String {
fn push_text(&mut self, text: impl AsRef<str>, linefeeds: usize, indent: usize) -> &mut Self {
self.push_str(&indent::indent_all_by(indent, text.as_ref()));
self.push_str(&vec!["\n"; linefeeds].join(""));
self
}

fn push_unindented_text(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self {
self.push_str(&unindent::unindent(text.as_ref()));
self.push_str(&vec!["\n"; linefeeds].join(""));
self
}
}
6 changes: 1 addition & 5 deletions crates/re_types_builder/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ pub trait CodeGenerator {
pub const AUTOGEN_WARNING: &str =
"NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT.";

pub const RERUN_ATTR_COMPONENT_REQUIRED: &str = "rerun.attr.component_required";
pub const RERUN_ATTR_COMPONENT_RECOMMENDED: &str = "rerun.attr.component_recommended";
pub const RERUN_ATTR_COMPONENT_OPTIONAL: &str = "rerun.attr.component_optional";

// ---

mod common;
use self::common::quote_doc_from_docs;
use self::common::{quote_doc_from_docs, StringExt};

mod python;
mod rust;
Expand Down
Loading

0 comments on commit 3112d07

Please sign in to comment.