@@ -81,12 +81,21 @@ pub fn build_kconfig_mod() {
81
81
}
82
82
83
83
/// Parse the finalized DTS file, generating the Rust devicetree file.
84
- pub fn build_dts ( ) {
84
+ fn import_dt ( ) -> DeviceTree {
85
85
let zephyr_dts = env:: var ( "ZEPHYR_DTS" ) . expect ( "ZEPHYR_DTS must be set" ) ;
86
- let outdir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR must be set" ) ;
87
86
let gen_include = env:: var ( "BINARY_DIR_INCLUDE_GENERATED" )
88
87
. expect ( "BINARY_DIR_INCLUDE_GENERATED" ) ;
89
- let builddir = env:: var ( "BUILD_DIR" ) . expect ( "BUILD_DIR" ) ;
88
+
89
+ let generated = format ! ( "{}/devicetree_generated.h" , gen_include) ;
90
+ DeviceTree :: new ( & zephyr_dts, generated)
91
+ }
92
+
93
+ pub fn build_dts ( ) {
94
+ let dt = import_dt ( ) ;
95
+
96
+ let outdir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR must be set" ) ;
97
+ let out_path = Path :: new ( & outdir) . join ( "devicetree.rs" ) ;
98
+ let mut out = File :: create ( & out_path) . expect ( "Unable to create devicetree.rs" ) ;
90
99
91
100
let augments = env:: var ( "DT_AUGMENTS" ) . expect ( "DT_AUGMENTS must be set" ) ;
92
101
let augments: Vec < String > = augments. split_whitespace ( ) . map ( String :: from) . collect ( ) ;
@@ -110,40 +119,21 @@ pub fn build_dts() {
110
119
. map ( |aug| Box :: new ( aug) as Box < dyn Augment > )
111
120
. collect ( ) ;
112
121
113
- let generated = format ! ( "{}/devicetree_generated.h" , gen_include) ;
114
- let dt = DeviceTree :: new ( & zephyr_dts, generated) ;
115
-
116
- let out_path = Path :: new ( & outdir) . join ( "devicetree.rs" ) ;
117
- let mut out = File :: create ( & out_path) . expect ( "Unable to create devicetree.rs" ) ;
118
-
119
122
let tokens = dt. to_tokens ( & augs) ;
120
123
if has_rustfmt ( ) {
121
124
write_formatted ( out, tokens) ;
122
125
} else {
123
126
writeln ! ( out, "{}" , tokens) . unwrap ( ) ;
124
127
} ;
125
-
126
- // Output all of the node names in the discovered tree.
127
- let all_nodes_path = Path :: new ( & builddir)
128
- . join ( "rust" )
129
- . join ( "all-dt-nodes.txt" ) ;
130
- let mut out = File :: create ( & all_nodes_path) . expect ( "Unable to create all-dt-nodex.txt" ) ;
131
- dt. output_node_paths ( & mut out) . expect ( "Unable to write to all-dt-nodes.txt" ) ;
132
128
}
133
129
134
130
/// Generate cfg directives for each of the nodes in the generated device tree.
135
131
///
136
132
/// This assumes that build_dts was already run by the `zephyr` crate, which should happen if this
137
133
/// is called from a user application.
138
134
pub fn dt_cfgs ( ) {
139
- let builddir = env:: var ( "BUILD_DIR" ) . expect ( "BUILD_DIR" ) ;
140
- let path = Path :: new ( & builddir)
141
- . join ( "rust" )
142
- . join ( "all-dt-nodes.txt" ) ;
143
- for line in BufReader :: new ( File :: open ( & path) . expect ( "Unable to open all-dt-nodes" ) ) . lines ( ) {
144
- let line = line. expect ( "Error reading line from all-dt-nodes" ) ;
145
- println ! ( "cargo:rustc-cfg=dt=\" {}\" " , line) ;
146
- }
135
+ let dt = import_dt ( ) ;
136
+ dt. output_node_paths ( & mut std:: io:: stdout ( ) ) . unwrap ( ) ;
147
137
}
148
138
149
139
/// Determine if `rustfmt` is in the path, and can be excecuted. Returns false on any kind of error.
0 commit comments