8
8
import logging
9
9
import pathlib
10
10
import sys
11
+ import os
11
12
12
- def generate_crates (srctree , objtree , sysroot_src ):
13
+ def generate_crates (srctree , objtree , sysroot_src , external_src ):
13
14
# Generate the configuration list.
14
15
cfg = []
15
16
with open (objtree / "include" / "generated" / "rustc_cfg" ) as fd :
@@ -65,7 +66,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
65
66
[],
66
67
is_proc_macro = True ,
67
68
)
68
- crates [- 1 ]["proc_macro_dylib_path" ] = " rust/libmacros.so"
69
+ crates [- 1 ]["proc_macro_dylib_path" ] = f" { objtree } / rust/libmacros.so"
69
70
70
71
append_crate (
71
72
"build_error" ,
@@ -98,13 +99,15 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
98
99
# Then, the rest outside of `rust/`.
99
100
#
100
101
# We explicitly mention the top-level folders we want to cover.
101
- for folder in ("samples" , "drivers" ):
102
+ extra_src_dirs = ["samples" , "drivers" ] if external_src is None else [external_src ]
103
+
104
+ for folder in extra_src_dirs :
102
105
for path in (srctree / folder ).rglob ("*.rs" ):
103
106
logging .info ("Checking %s" , path )
104
107
name = path .name .replace (".rs" , "" )
105
108
106
109
# Skip those that are not crate roots.
107
- if f"{ name } .o" not in open (path .parent / "Makefile" ).read ():
110
+ if os . path . exists ( path . parent / "Makefile" ) and f"{ name } .o" not in open (path .parent / "Makefile" ).read ():
108
111
continue
109
112
110
113
logging .info ("Adding %s" , name )
@@ -123,6 +126,7 @@ def main():
123
126
parser .add_argument ("srctree" , type = pathlib .Path )
124
127
parser .add_argument ("objtree" , type = pathlib .Path )
125
128
parser .add_argument ("sysroot_src" , type = pathlib .Path )
129
+ parser .add_argument ("exttree" , type = pathlib .Path , nargs = '?' )
126
130
args = parser .parse_args ()
127
131
128
132
logging .basicConfig (
@@ -131,7 +135,7 @@ def main():
131
135
)
132
136
133
137
rust_project = {
134
- "crates" : generate_crates (args .srctree , args .objtree , args .sysroot_src ),
138
+ "crates" : generate_crates (args .srctree , args .objtree , args .sysroot_src , args . exttree ),
135
139
"sysroot_src" : str (args .sysroot_src ),
136
140
}
137
141
0 commit comments