From: Florent Kermarrec Date: Fri, 1 Aug 2014 10:50:38 +0000 (+0200) Subject: mibuild/generic_platform: add recursive parameter to add_source_dir X-Git-Tag: 24jan2021_ls180~2099^2~334 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a0d07426641ce6902ce00b441d41f0807b891f25;p=litex.git mibuild/generic_platform: add recursive parameter to add_source_dir --- diff --git a/mibuild/generic_platform.py b/mibuild/generic_platform.py index d972ee26..1ede87a4 100644 --- a/mibuild/generic_platform.py +++ b/mibuild/generic_platform.py @@ -222,12 +222,20 @@ class GenericPlatform: for f in filenames: self.add_source(os.path.join(path, f), language) - def add_source_dir(self, path): - for root, dirs, files in os.walk(path): - for filename in files: - language = tools.language_by_filename(filename) - if language is not None: - self.add_source(os.path.join(root, filename), language) + def add_source_dir(self, path, recursive=True): + dir_files = [] + if recursive: + for root, dirs, files in os.walk(path): + for filename in files: + dir_files.append(os.path.join(root, filename)) + else: + for item in os.listdir(path): + if os.path.isfile(os.path.join(path, item)): + dir_files.append(os.path.join(path, item)) + for filename in dir_files: + language = tools.language_by_filename(filename) + if language is not None: + self.add_source(filename, language) def add_verilog_include_path(self, path): self.verilog_include_paths.append(os.path.abspath(path))