From 173611700e9e544d5d8bb14582698be8290ea75d Mon Sep 17 00:00:00 2001 From: Du Yanning Date: Mon, 22 Jul 2019 20:06:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=EF=BC=9B=E5=A2=9E=E5=8A=A0=E5=9B=9E?= =?UTF-8?q?=E5=BD=92=E6=B5=8B=E8=AF=95=E4=B8=80=E6=9E=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scan.cpp | 2 +- test/helloworld/main.cpp | 12 ------------ test/multiple-srcs/{hello.cpp => main.cpp} | 2 +- test/using-a-cpp-many-times/bar.cpp | 6 ++++++ test/using-a-cpp-many-times/bar.h | 7 +++++++ test/using-a-cpp-many-times/foo.cpp | 10 ++++++++++ test/using-a-cpp-many-times/foo.h | 8 ++++++++ test/using-a-cpp-many-times/main.cpp | 16 ++++++++++++++++ test/using-a-cpp-many-times/run-gcc.sh | 7 +++++++ test/using-a-cpp-many-times/run-mingw.bat | 7 +++++++ test/using-a-cpp-many-times/run-vc.bat | 8 ++++++++ 11 files changed, 71 insertions(+), 14 deletions(-) delete mode 100644 test/helloworld/main.cpp rename test/multiple-srcs/{hello.cpp => main.cpp} (87%) mode change 100755 => 100644 create mode 100644 test/using-a-cpp-many-times/bar.cpp create mode 100644 test/using-a-cpp-many-times/bar.h create mode 100644 test/using-a-cpp-many-times/foo.cpp create mode 100644 test/using-a-cpp-many-times/foo.h create mode 100644 test/using-a-cpp-many-times/main.cpp create mode 100644 test/using-a-cpp-many-times/run-gcc.sh create mode 100644 test/using-a-cpp-many-times/run-mingw.bat create mode 100644 test/using-a-cpp-many-times/run-vc.bat diff --git a/src/scan.cpp b/src/scan.cpp index 038cd3c..e3b9ac3 100644 --- a/src/scan.cpp +++ b/src/scan.cpp @@ -19,7 +19,7 @@ void scan(fs::path src_path) string line; regex usingcpp_pat{ R"(^\s*#include\s+"([\w\./]+)\.h"\s+//\s+usingcpp)" }; - regex using_pat{ R"(using\s+([\w\./]+\.(c|cpp|cxx|c\+\+|C|cc|cp|CPP)))" }; + regex using_pat{ R"(using\s+([\w\./]+\.(cpp|cxx|c\+\+|cc|c)))" }; // | 或的顺序还挺重要,把长的排前边。免得前缀就匹配。 regex linklib_pat{ R"(//\s+linklib\s+([\w\-\.]+))" }; string compiler_specific_linklib_string = R"(//\s+)" + cc_info[cc].compiler_name; compiler_specific_linklib_string += R"(-linklib\s+([\w\-\.]+))"; diff --git a/test/helloworld/main.cpp b/test/helloworld/main.cpp deleted file mode 100644 index bc2f10c..0000000 --- a/test/helloworld/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "foo.h" - -using namespace std; - -int main(int argc, char* argv[]) -{ - cout << "hello"<< endl; - cout << "world"<< endl; - - return 0; -} diff --git a/test/multiple-srcs/hello.cpp b/test/multiple-srcs/main.cpp old mode 100755 new mode 100644 similarity index 87% rename from test/multiple-srcs/hello.cpp rename to test/multiple-srcs/main.cpp index 5bb9295..ade18e1 --- a/test/multiple-srcs/hello.cpp +++ b/test/multiple-srcs/main.cpp @@ -2,7 +2,7 @@ #include #include -#include "foo.h" // using foo.cpp +#include "foo.h" // using foo.cpp #include "bar.h" // using bar.cpp using namespace std; diff --git a/test/using-a-cpp-many-times/bar.cpp b/test/using-a-cpp-many-times/bar.cpp new file mode 100644 index 0000000..50a4f75 --- /dev/null +++ b/test/using-a-cpp-many-times/bar.cpp @@ -0,0 +1,6 @@ +#include "bar.h" + +int bar() +{ + return 3; +} diff --git a/test/using-a-cpp-many-times/bar.h b/test/using-a-cpp-many-times/bar.h new file mode 100644 index 0000000..45b7405 --- /dev/null +++ b/test/using-a-cpp-many-times/bar.h @@ -0,0 +1,7 @@ +#ifndef BAR_H +#define BAR_H + +int bar(); + + +#endif // BAR_H diff --git a/test/using-a-cpp-many-times/foo.cpp b/test/using-a-cpp-many-times/foo.cpp new file mode 100644 index 0000000..040239d --- /dev/null +++ b/test/using-a-cpp-many-times/foo.cpp @@ -0,0 +1,10 @@ +#include +#include "foo.h" +#include "bar.h" // using bar.cpp + +using namespace std; + +void foo() +{ + bar(); +} diff --git a/test/using-a-cpp-many-times/foo.h b/test/using-a-cpp-many-times/foo.h new file mode 100644 index 0000000..7bfaf7c --- /dev/null +++ b/test/using-a-cpp-many-times/foo.h @@ -0,0 +1,8 @@ +#ifndef FOO_H +#define FOO_H + +void foo(); + + + +#endif // FOO_H diff --git a/test/using-a-cpp-many-times/main.cpp b/test/using-a-cpp-many-times/main.cpp new file mode 100644 index 0000000..6b18acf --- /dev/null +++ b/test/using-a-cpp-many-times/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "foo.h" // using foo.cpp +#include "bar.h" // using bar.cpp + +using namespace std; + +int main() +{ + foo(); + bar(); + + return 0; +} diff --git a/test/using-a-cpp-many-times/run-gcc.sh b/test/using-a-cpp-many-times/run-gcc.sh new file mode 100644 index 0000000..7ee0159 --- /dev/null +++ b/test/using-a-cpp-many-times/run-gcc.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +cpps --clear -c gcc -v main.cpp +# CHECK: compiling main.cpp +# CHECK-NEXT: compiling foo.cpp +# CHECK-NEXT: compiling bar.cpp +# CHECK-NEXT: linking main.cpp.gcc.exe diff --git a/test/using-a-cpp-many-times/run-mingw.bat b/test/using-a-cpp-many-times/run-mingw.bat new file mode 100644 index 0000000..4232d2c --- /dev/null +++ b/test/using-a-cpp-many-times/run-mingw.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +cpps --clear -c mingw -v main.cpp +rem CHECK: compiling main.cpp +rem CHECK-NEXT: compiling foo.cpp +rem CHECK-NEXT: compiling bar.cpp +rem CHECK-NEXT: linking main.cpp.mingw.exe diff --git a/test/using-a-cpp-many-times/run-vc.bat b/test/using-a-cpp-many-times/run-vc.bat new file mode 100644 index 0000000..eae6713 --- /dev/null +++ b/test/using-a-cpp-many-times/run-vc.bat @@ -0,0 +1,8 @@ +@ECHO OFF + +cpps --clear -c vc -v main.cpp +rem CHECK: compiling main.cpp +rem CHECK-NEXT: compiling foo.cpp +rem CHECK-NEXT: compiling bar.cpp +rem CHECK-NEXT: linking main.cpp.vc.exe +