1
- //! Helper binary for running the codegen manually. Useful during development!
1
+ //! This binary runs the codegen manually.
2
+ //!
3
+ //! It is easiest to call this using `just codegen`,
4
+ //! which will set up the necessary tools.
2
5
3
- use camino:: Utf8Path ;
4
6
use re_build_tools:: {
5
7
read_versioning_hash, set_output_cargo_build_instructions, write_versioning_hash,
6
8
} ;
7
- use re_types_builder:: { compute_re_types_builder_hash, compute_re_types_hash, SourceLocations } ;
9
+ use re_types_builder:: { compute_re_types_hash, SourceLocations } ;
10
+
11
+ use camino:: Utf8Path ;
8
12
9
- const RE_TYPES_BUILDER_SOURCE_HASH_PATH : & str = "crates/re_types_builder/source_hash.txt" ;
10
13
const RE_TYPES_SOURCE_HASH_PATH : & str = "crates/re_types/source_hash.txt" ;
11
14
const DEFINITIONS_DIR_PATH : & str = "crates/re_types/definitions" ;
12
15
const ENTRYPOINT_PATH : & str = "crates/re_types/definitions/rerun/archetypes.fbs" ;
@@ -31,6 +34,7 @@ macro_rules! join {
31
34
32
35
fn main ( ) {
33
36
re_log:: setup_native_logging ( ) ;
37
+
34
38
// This isn't a build.rs script, so opt out of cargo build instrctinsr
35
39
set_output_cargo_build_instructions ( false ) ;
36
40
@@ -40,13 +44,17 @@ fn main() {
40
44
. unwrap ( ) ;
41
45
42
46
let mut profiler = re_tracing:: Profiler :: default ( ) ;
47
+ let mut always_run = false ;
43
48
44
49
for arg in std:: env:: args ( ) . skip ( 1 ) {
45
50
match arg. as_str ( ) {
46
51
"--help" => {
47
- println ! ( "Usage: [--help] [--profile]" ) ;
52
+ println ! ( "Usage: [--help] [--force] [-- profile]" ) ;
48
53
return ;
49
54
}
55
+ "--force" => {
56
+ always_run = true ;
57
+ }
50
58
"--profile" => profiler. start ( ) ,
51
59
_ => {
52
60
eprintln ! ( "Unknown argument: {arg:?}" ) ;
@@ -61,28 +69,41 @@ fn main() {
61
69
. unwrap ( ) ;
62
70
63
71
let re_types_source_hash_path = workspace_dir. join ( RE_TYPES_SOURCE_HASH_PATH ) ;
64
- let re_types_builder_source_hash_path = workspace_dir. join ( RE_TYPES_BUILDER_SOURCE_HASH_PATH ) ;
65
72
let definitions_dir_path = workspace_dir. join ( DEFINITIONS_DIR_PATH ) ;
66
73
let entrypoint_path = workspace_dir. join ( ENTRYPOINT_PATH ) ;
67
- let doc_examples_dir_path = workspace_dir. join ( DOC_EXAMPLES_DIR_PATH ) ;
68
74
let cpp_output_dir_path = workspace_dir. join ( CPP_OUTPUT_DIR_PATH ) ;
69
75
let rust_output_dir_path = workspace_dir. join ( RUST_OUTPUT_DIR_PATH ) ;
70
76
let python_output_dir_path = workspace_dir. join ( PYTHON_OUTPUT_DIR_PATH ) ;
71
77
let python_testing_output_dir_path = workspace_dir. join ( PYTHON_TESTING_OUTPUT_DIR_PATH ) ;
72
78
let docs_content_dir_path = workspace_dir. join ( DOCS_CONTENT_DIR_PATH ) ;
73
79
74
80
let cur_hash = read_versioning_hash ( & re_types_source_hash_path) ;
75
- eprintln ! ( "cur_hash: {cur_hash:?}" ) ;
76
-
77
- let builder_hash = compute_re_types_builder_hash ( ) ;
81
+ re_log:: debug!( "cur_hash: {cur_hash:?}" ) ;
78
82
79
83
let new_hash = compute_re_types_hash ( & SourceLocations {
80
- definitions_dir : definitions_dir_path . as_str ( ) ,
81
- doc_examples_dir : doc_examples_dir_path . as_str ( ) ,
82
- python_output_dir : python_output_dir_path . as_str ( ) ,
83
- cpp_output_dir : cpp_output_dir_path . as_str ( ) ,
84
+ definitions_dir : DEFINITIONS_DIR_PATH ,
85
+ doc_examples_dir : DOC_EXAMPLES_DIR_PATH ,
86
+ python_output_dir : PYTHON_OUTPUT_DIR_PATH ,
87
+ cpp_output_dir : CPP_OUTPUT_DIR_PATH ,
84
88
} ) ;
85
89
90
+ if let Some ( cur_hash) = cur_hash {
91
+ if cur_hash == new_hash {
92
+ if always_run {
93
+ re_log:: info!(
94
+ "The hash hasn't changed, but --force was passed, so we'll run anyway."
95
+ ) ;
96
+ } else {
97
+ re_log:: info!( "Returning early: no changes detected (and --force wasn't set)." ) ;
98
+ return ;
99
+ }
100
+ } else {
101
+ re_log:: info!( "Change detected" ) ;
102
+ }
103
+ } else {
104
+ re_log:: info!( "Missing {re_types_source_hash_path:?} (first time running codegen)" ) ;
105
+ }
106
+
86
107
re_log:: info!( "Running codegen…" ) ;
87
108
let ( report, reporter) = re_types_builder:: report:: init ( ) ;
88
109
@@ -121,7 +142,6 @@ fn main() {
121
142
report. finalize ( ) ;
122
143
123
144
write_versioning_hash ( re_types_source_hash_path, new_hash) ;
124
- write_versioning_hash ( re_types_builder_source_hash_path, builder_hash) ;
125
145
126
146
re_log:: info!( "Done." ) ;
127
147
}
0 commit comments