@@ -267,20 +267,24 @@ def add_file_ref(self, file_type, file_name, file_path):
267
267
self ._file_refs [file_type ].add (FileRef (file_name , file_path ))
268
268
269
269
def _include_file (self , ref ):
270
+ """Determine if a given file ref should be included in the build
271
+
272
+ Files may be part of a library if a parent directory contains an
273
+ mbed_lib.json. If a file is part of a library, include or exclude
274
+ it based on the library it's part of.
275
+ If a file is not part of a library, it's included.
276
+ """
270
277
_ , path = ref
271
- starts_with_excluded = [
272
- len (dirname (e .path )) for e in self ._excluded_libs
273
- if path .startswith (dirname (e .path ))
274
- ]
275
- if not starts_with_excluded :
276
- return True
277
- starts_with_included = [
278
- len (dirname (e .path )) for e in self ._libs_filtered
279
- if path .startswith (dirname (e .path ))
280
- ]
281
- if not starts_with_included :
282
- return False
283
- return max (starts_with_included ) > max (starts_with_excluded )
278
+ cur_dir = dirname (path )
279
+ included_lib_paths = [dirname (e .path ) for e in self ._libs_filtered ]
280
+ excluded_lib_paths = [dirname (e .path ) for e in self ._excluded_libs ]
281
+ while dirname (cur_dir ) != cur_dir :
282
+ if cur_dir in included_lib_paths :
283
+ return True
284
+ elif cur_dir in excluded_lib_paths :
285
+ return False
286
+ cur_dir = dirname (cur_dir )
287
+ return True
284
288
285
289
def get_file_refs (self , file_type ):
286
290
"""Return a list of FileRef for every file of the given type"""
0 commit comments