aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-12 15:25:31 +0800
committercrupest <crupest@outlook.com>2018-11-12 15:25:31 +0800
commit828a48aa387796ce89706ade69d0a6a3bf1e35a9 (patch)
treefd5531251d6c8b9d43a90c7baf005710d908fe0c
parent651106c12769751a87b1175c2c27dd664e31acb3 (diff)
downloadcru-828a48aa387796ce89706ade69d0a6a3bf1e35a9.tar.gz
cru-828a48aa387796ce89706ade69d0a6a3bf1e35a9.tar.bz2
cru-828a48aa387796ce89706ade69d0a6a3bf1e35a9.zip
Develop exclude feature.
-rw-r--r--tools/cppmerge/main.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/tools/cppmerge/main.py b/tools/cppmerge/main.py
index ed7d113a..ed06a2f7 100644
--- a/tools/cppmerge/main.py
+++ b/tools/cppmerge/main.py
@@ -7,6 +7,7 @@ import sys
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", required=True, help="The name of output header and source files excluding extension.")
parser.add_argument("input", nargs="+", help="The input source files or folders to scan.")
+parser.add_argument("-e", "--exclude", nargs="+", help="Filenames that exludes from merging.")
args = parser.parse_args()
input_dirs = []
@@ -32,26 +33,38 @@ for path in args.input:
elif os.path.isfile(path):
file_name = os.path.basename(path)
if cpp_source_file_regex.match(file_name):
- add_source_file(path)
+ if file_name in args.exclude:
+ sys.exit("{} is specified excluding.")
+ else:
+ add_source_file(path)
elif cpp_header_file_regex.match(file_name):
- add_header_file(path)
+ if file_name in args.exclude:
+ sys.exit("{} is specified excluding.")
+ else:
+ add_header_file(path)
else:
sys.exit("{} is a file but it is neither c++ source nor header.".format(path))
else:
sys.exit("{} is neither a file nor a directory.".format(path))
+actual_exclude_count = 0
+
for input_dir in input_dirs:
for root, subdirs, files in os.walk(input_dir):
for f in files:
- if cpp_source_file_regex.match(f):
- path = os.path.join(root, f)
- add_source_file(path)
- elif cpp_header_file_regex.match(f):
- path = os.path.join(root, f)
- add_header_file(path)
+ if f in args.exclude:
+ actual_exclude_count += 1
+ else:
+ if cpp_source_file_regex.match(f):
+ path = os.path.join(root, f)
+ add_source_file(path)
+ elif cpp_header_file_regex.match(f):
+ path = os.path.join(root, f)
+ add_header_file(path)
print()
print("total find {} header file(s)".format(len(header_file_list)))
print("total find {} source file(s)".format(len(source_file_list)))
+print("total actual exclude {} file(s)".format(actual_exclude_count))
print()