22
22
from time import time , sleep
23
23
from types import ListType
24
24
from shutil import copyfile
25
- from os .path import join , splitext , exists , relpath , dirname , basename , split , abspath
25
+ from os .path import join , splitext , exists , relpath , dirname , basename , split , abspath , isfile , isdir
26
26
from inspect import getmro
27
27
from copy import deepcopy
28
28
from tools .config import Config
@@ -431,13 +431,21 @@ def is_ignored(self, file_path):
431
431
return False
432
432
433
433
def scan_resources (self , path , exclude_paths = None , base_path = None ):
434
- labels = self .get_labels ()
435
-
436
434
resources = Resources (path )
437
435
if not base_path :
438
- base_path = path
436
+ if isfile (path ):
437
+ base_path = dirname (path )
438
+ else :
439
+ base_path = path
439
440
resources .base_path = base_path
440
441
442
+ if isfile (path ):
443
+ self .add_file (path , resources , base_path , exclude_paths = exclude_paths )
444
+ else :
445
+ self .add_dir (path , resources , base_path , exclude_paths = exclude_paths )
446
+ return resources
447
+
448
+ def add_dir (self , path , resources , base_path , exclude_paths = None ):
441
449
""" os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
442
450
When topdown is True, the caller can modify the dirnames list in-place
443
451
(perhaps using del or slice assignment), and walk() will only recurse into
@@ -448,6 +456,7 @@ def scan_resources(self, path, exclude_paths=None, base_path=None):
448
456
bottom-up mode the directories in dirnames are generated before dirpath
449
457
itself is generated.
450
458
"""
459
+ labels = self .get_labels ()
451
460
for root , dirs , files in walk (path , followlinks = True ):
452
461
# Check if folder contains .mbedignore
453
462
if ".mbedignore" in files :
@@ -469,7 +478,7 @@ def scan_resources(self, path, exclude_paths=None, base_path=None):
469
478
if d == '.hg' :
470
479
resources .repo_dirs .append (dir_path )
471
480
resources .repo_files .extend (self .scan_repository (dir_path ))
472
-
481
+
473
482
if ((d .startswith ('.' ) or d in self .legacy_ignore_dirs ) or
474
483
# Ignore targets that do not match the TARGET in extra_labels list
475
484
(d .startswith ('TARGET_' ) and d [7 :] not in labels ['TARGET' ]) or
@@ -497,58 +506,59 @@ def scan_resources(self, path, exclude_paths=None, base_path=None):
497
506
498
507
for file in files :
499
508
file_path = join (root , file )
509
+ self .add_file (file_path , resources , base_path )
500
510
501
- resources .file_basepath [file_path ] = base_path
511
+ def add_file (self , file_path , resources , base_path , exclude_paths = None ):
512
+ resources .file_basepath [file_path ] = base_path
502
513
503
- if self .is_ignored (file_path ):
504
- continue
514
+ if self .is_ignored (file_path ):
515
+ return
505
516
506
- _ , ext = splitext (file )
507
- ext = ext .lower ()
517
+ _ , ext = splitext (file_path )
518
+ ext = ext .lower ()
508
519
509
- if ext == '.s' :
510
- resources .s_sources .append (file_path )
520
+ if ext == '.s' :
521
+ resources .s_sources .append (file_path )
511
522
512
- elif ext == '.c' :
513
- resources .c_sources .append (file_path )
523
+ elif ext == '.c' :
524
+ resources .c_sources .append (file_path )
514
525
515
- elif ext == '.cpp' :
516
- resources .cpp_sources .append (file_path )
526
+ elif ext == '.cpp' :
527
+ resources .cpp_sources .append (file_path )
517
528
518
- elif ext == '.h' or ext == '.hpp' :
519
- resources .headers .append (file_path )
529
+ elif ext == '.h' or ext == '.hpp' :
530
+ resources .headers .append (file_path )
520
531
521
- elif ext == '.o' :
522
- resources .objects .append (file_path )
532
+ elif ext == '.o' :
533
+ resources .objects .append (file_path )
523
534
524
- elif ext == self .LIBRARY_EXT :
525
- resources .libraries .append (file_path )
526
- resources .lib_dirs .add (root )
535
+ elif ext == self .LIBRARY_EXT :
536
+ resources .libraries .append (file_path )
537
+ resources .lib_dirs .add (dirname ( file_path ) )
527
538
528
- elif ext == self .LINKER_EXT :
529
- if resources .linker_script is not None :
530
- self .info ("Warning: Multiple linker scripts detected: %s -> %s" % (resources .linker_script , file_path ))
531
- resources .linker_script = file_path
539
+ elif ext == self .LINKER_EXT :
540
+ if resources .linker_script is not None :
541
+ self .info ("Warning: Multiple linker scripts detected: %s -> %s" % (resources .linker_script , file_path ))
542
+ resources .linker_script = file_path
532
543
533
- elif ext == '.lib' :
534
- resources .lib_refs .append (file_path )
544
+ elif ext == '.lib' :
545
+ resources .lib_refs .append (file_path )
535
546
536
- elif ext == '.bld' :
537
- resources .lib_builds .append (file_path )
547
+ elif ext == '.bld' :
548
+ resources .lib_builds .append (file_path )
538
549
539
- elif file == '.hgignore' :
540
- resources .repo_files .append (file_path )
550
+ elif file == '.hgignore' :
551
+ resources .repo_files .append (file_path )
541
552
542
- elif ext == '.hex' :
543
- resources .hex_files .append (file_path )
553
+ elif ext == '.hex' :
554
+ resources .hex_files .append (file_path )
544
555
545
- elif ext == '.bin' :
546
- resources .bin_files .append (file_path )
556
+ elif ext == '.bin' :
557
+ resources .bin_files .append (file_path )
547
558
548
- elif ext == '.json' :
549
- resources .json_files .append (file_path )
559
+ elif ext == '.json' :
560
+ resources .json_files .append (file_path )
550
561
551
- return resources
552
562
553
563
def scan_repository (self , path ):
554
564
resources = []
0 commit comments