diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-01-12 16:46:53 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-01-12 16:49:23 +0800 |
| commit | c1cc934e55ca88117599121841301783d29aac32 (patch) | |
| tree | 9f0e4e69f93585ac5707d0561712a141939b1dae | |
| parent | 0cc452c7cf2301e75bab1069c9da6ee73c7c5cfd (diff) | |
| download | yuescript-c1cc934e55ca88117599121841301783d29aac32.tar.gz yuescript-c1cc934e55ca88117599121841301783d29aac32.tar.bz2 yuescript-c1cc934e55ca88117599121841301783d29aac32.zip | |
fix issue #122, add option to build yue tool without file watcher function.
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/.vuepress/config.js | 7 | ||||
| -rw-r--r-- | makefile | 15 | ||||
| -rw-r--r-- | src/yue.cpp | 13 |
3 files changed, 25 insertions, 10 deletions
diff --git a/doc/docs/.vuepress/config.js b/doc/docs/.vuepress/config.js index c6f8f39..bd89428 100755 --- a/doc/docs/.vuepress/config.js +++ b/doc/docs/.vuepress/config.js | |||
| @@ -43,13 +43,6 @@ module.exports = { | |||
| 43 | } | 43 | } |
| 44 | }; | 44 | }; |
| 45 | `], | 45 | `], |
| 46 | ['script', {}, ` | ||
| 47 | var Module = { | ||
| 48 | onRuntimeInitialized: function() { | ||
| 49 | window.yue = Module; | ||
| 50 | } | ||
| 51 | }; | ||
| 52 | `], | ||
| 53 | ['script', { src: '/js/yuescript.js' }], | 46 | ['script', { src: '/js/yuescript.js' }], |
| 54 | ], | 47 | ], |
| 55 | 48 | ||
| @@ -54,6 +54,9 @@ endif | |||
| 54 | INCLUDES += -I $(SRC_PATH)/3rdParty/lua | 54 | INCLUDES += -I $(SRC_PATH)/3rdParty/lua |
| 55 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl | 55 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl |
| 56 | endif | 56 | endif |
| 57 | ifeq ($(NO_WATCHER),true) | ||
| 58 | COMPILE_FLAGS += -DYUE_NO_WATCHER | ||
| 59 | endif | ||
| 57 | 60 | ||
| 58 | # Add platform related linker flag | 61 | # Add platform related linker flag |
| 59 | ifneq ($(UNAME_S),Darwin) | 62 | ifneq ($(UNAME_S),Darwin) |
| @@ -137,7 +140,9 @@ OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) | |||
| 137 | # Set the dependency files that will be used to add header dependencies | 140 | # Set the dependency files that will be used to add header dependencies |
| 138 | DEPS = $(OBJECTS:.o=.d) | 141 | DEPS = $(OBJECTS:.o=.d) |
| 139 | 142 | ||
| 140 | SOURCES += $(SRC_PATH)/3rdParty/efsw/Debug.cpp $(SRC_PATH)/3rdParty/efsw/DirectorySnapshot.cpp $(SRC_PATH)/3rdParty/efsw/DirectorySnapshotDiff.cpp $(SRC_PATH)/3rdParty/efsw/DirWatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/FileInfo.cpp $(SRC_PATH)/3rdParty/efsw/FileSystem.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcher.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherCWrapper.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherImpl.cpp $(SRC_PATH)/3rdParty/efsw/Log.cpp $(SRC_PATH)/3rdParty/efsw/Mutex.cpp $(SRC_PATH)/3rdParty/efsw/String.cpp $(SRC_PATH)/3rdParty/efsw/System.cpp $(SRC_PATH)/3rdParty/efsw/Thread.cpp $(SRC_PATH)/3rdParty/efsw/Watcher.cpp $(SRC_PATH)/3rdParty/efsw/WatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/FileSystemImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/MutexImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/SystemImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/ThreadImpl.cpp | 143 | ifneq ($(NO_WATCHER),true) |
| 144 | SOURCES += $(SRC_PATH)/3rdParty/efsw/Debug.cpp $(SRC_PATH)/3rdParty/efsw/DirectorySnapshot.cpp $(SRC_PATH)/3rdParty/efsw/DirectorySnapshotDiff.cpp $(SRC_PATH)/3rdParty/efsw/DirWatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/FileInfo.cpp $(SRC_PATH)/3rdParty/efsw/FileSystem.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcher.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherCWrapper.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherImpl.cpp $(SRC_PATH)/3rdParty/efsw/Log.cpp $(SRC_PATH)/3rdParty/efsw/Mutex.cpp $(SRC_PATH)/3rdParty/efsw/String.cpp $(SRC_PATH)/3rdParty/efsw/System.cpp $(SRC_PATH)/3rdParty/efsw/Thread.cpp $(SRC_PATH)/3rdParty/efsw/Watcher.cpp $(SRC_PATH)/3rdParty/efsw/WatcherGeneric.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/FileSystemImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/MutexImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/SystemImpl.cpp $(SRC_PATH)/3rdParty/efsw/platform/posix/ThreadImpl.cpp | ||
| 145 | endif | ||
| 141 | 146 | ||
| 142 | # Macros for timing compilation | 147 | # Macros for timing compilation |
| 143 | ifeq ($(UNAME_S),Darwin) | 148 | ifeq ($(UNAME_S),Darwin) |
| @@ -148,7 +153,9 @@ ifeq ($(UNAME_S),Darwin) | |||
| 148 | $(RM) $(TIME_FILE) ; \ | 153 | $(RM) $(TIME_FILE) ; \ |
| 149 | st=$$((`$(CUR_TIME)` - $$st)) ; \ | 154 | st=$$((`$(CUR_TIME)` - $$st)) ; \ |
| 150 | echo $$st | 155 | echo $$st |
| 151 | SOURCES += $(SRC_PATH)/3rdParty/efsw/FileWatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/WatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/WatcherKqueue.cpp | 156 | ifneq ($(NO_WATCHER),true) |
| 157 | SOURCES += $(SRC_PATH)/3rdParty/efsw/FileWatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/WatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/WatcherKqueue.cpp | ||
| 158 | endif | ||
| 152 | else | 159 | else |
| 153 | TIME_FILE = $(dir $@).$(notdir $@)_time | 160 | TIME_FILE = $(dir $@).$(notdir $@)_time |
| 154 | START_TIME = date '+%s' > $(TIME_FILE) | 161 | START_TIME = date '+%s' > $(TIME_FILE) |
| @@ -156,7 +163,9 @@ else | |||
| 156 | $(RM) $(TIME_FILE) ; \ | 163 | $(RM) $(TIME_FILE) ; \ |
| 157 | st=$$((`date '+%s'` - $$st - 86400)) ; \ | 164 | st=$$((`date '+%s'` - $$st - 86400)) ; \ |
| 158 | echo `date -u -d @$$st '+%H:%M:%S'` | 165 | echo `date -u -d @$$st '+%H:%M:%S'` |
| 159 | SOURCES += $(SRC_PATH)/3rdParty/efsw/FileWatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/WatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/WatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherInotify.cpp $(SRC_PATH)/3rdParty/efsw/WatcherInotify.cpp | 166 | ifneq ($(NO_WATCHER),true) |
| 167 | SOURCES += $(SRC_PATH)/3rdParty/efsw/FileWatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/WatcherFSEvents.cpp $(SRC_PATH)/3rdParty/efsw/WatcherKqueue.cpp $(SRC_PATH)/3rdParty/efsw/FileWatcherInotify.cpp $(SRC_PATH)/3rdParty/efsw/WatcherInotify.cpp | ||
| 168 | endif | ||
| 160 | endif | 169 | endif |
| 161 | 170 | ||
| 162 | # Version macros | 171 | # Version macros |
diff --git a/src/yue.cpp b/src/yue.cpp index 95dd920..3a61271 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -24,7 +24,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
| 24 | using namespace std::string_view_literals; | 24 | using namespace std::string_view_literals; |
| 25 | using namespace std::string_literals; | 25 | using namespace std::string_literals; |
| 26 | using namespace std::chrono_literals; | 26 | using namespace std::chrono_literals; |
| 27 | #ifndef YUE_NO_WATCHER | ||
| 27 | #include "efsw/efsw.hpp" | 28 | #include "efsw/efsw.hpp" |
| 29 | #endif // YUE_NO_WATCHER | ||
| 28 | #include "ghc/fs_std.hpp" | 30 | #include "ghc/fs_std.hpp" |
| 29 | #include "linenoise.hpp" | 31 | #include "linenoise.hpp" |
| 30 | 32 | ||
| @@ -140,6 +142,7 @@ fs::path getTargetFileDirty(const fs::path& file, const fs::path& workPath, cons | |||
| 140 | return fs::path(); | 142 | return fs::path(); |
| 141 | } | 143 | } |
| 142 | 144 | ||
| 145 | #ifndef YUE_NO_WATCHER | ||
| 143 | static std::string compileFile(const fs::path& file, yue::YueConfig conf, const fs::path& workPath, const fs::path& targetPath) { | 146 | static std::string compileFile(const fs::path& file, yue::YueConfig conf, const fs::path& workPath, const fs::path& targetPath) { |
| 144 | auto srcFile = fs::absolute(file); | 147 | auto srcFile = fs::absolute(file); |
| 145 | auto targetFile = getTargetFileDirty(srcFile, workPath, targetPath); | 148 | auto targetFile = getTargetFileDirty(srcFile, workPath, targetPath); |
| @@ -234,6 +237,7 @@ public: | |||
| 234 | fs::path workPath; | 237 | fs::path workPath; |
| 235 | fs::path targetPath; | 238 | fs::path targetPath; |
| 236 | }; | 239 | }; |
| 240 | #endif // YUE_NO_WATCHER | ||
| 237 | 241 | ||
| 238 | int main(int narg, const char** args) { | 242 | int main(int narg, const char** args) { |
| 239 | const char* help = | 243 | const char* help = |
| @@ -250,7 +254,9 @@ int main(int narg, const char** args) { | |||
| 250 | " -b Dump compile time (doesn't write output)\n" | 254 | " -b Dump compile time (doesn't write output)\n" |
| 251 | " -g Dump global variables used in NAME LINE COLUMN\n" | 255 | " -g Dump global variables used in NAME LINE COLUMN\n" |
| 252 | " -l Write line numbers from source codes\n" | 256 | " -l Write line numbers from source codes\n" |
| 257 | #ifndef YUE_NO_WATCHER | ||
| 253 | " -w path Watch changes and compile every file under directory\n" | 258 | " -w path Watch changes and compile every file under directory\n" |
| 259 | #endif // YUE_NO_WATCHER | ||
| 254 | " -v Print version\n" | 260 | " -v Print version\n" |
| 255 | #ifndef YUE_COMPILER_ONLY | 261 | #ifndef YUE_COMPILER_ONLY |
| 256 | " -- Read from standard in, print to standard out\n" | 262 | " -- Read from standard in, print to standard out\n" |
| @@ -550,7 +556,12 @@ int main(int narg, const char** args) { | |||
| 550 | return 1; | 556 | return 1; |
| 551 | } | 557 | } |
| 552 | } else if (arg == "-w"sv) { | 558 | } else if (arg == "-w"sv) { |
| 559 | #ifndef YUE_NO_WATCHER | ||
| 553 | watchFiles = true; | 560 | watchFiles = true; |
| 561 | #else | ||
| 562 | std::cout << "Error: -w is not supported\n"sv; | ||
| 563 | return 1; | ||
| 564 | #endif // YUE_NO_WATCHER | ||
| 554 | } else if (arg.size() > 2 && arg.substr(0, 2) == "--"sv && arg.substr(2, 1) != "-"sv) { | 565 | } else if (arg.size() > 2 && arg.substr(0, 2) == "--"sv && arg.substr(2, 1) != "-"sv) { |
| 555 | auto argStr = arg.substr(2); | 566 | auto argStr = arg.substr(2); |
| 556 | yue::Utils::trim(argStr); | 567 | yue::Utils::trim(argStr); |
| @@ -593,6 +604,7 @@ int main(int narg, const char** args) { | |||
| 593 | std::cout << "Error: -o can not be used with multiple input files\n"sv; | 604 | std::cout << "Error: -o can not be used with multiple input files\n"sv; |
| 594 | return 1; | 605 | return 1; |
| 595 | } | 606 | } |
| 607 | #ifndef YUE_NO_WATCHER | ||
| 596 | if (watchFiles) { | 608 | if (watchFiles) { |
| 597 | auto fullWorkPath = fs::absolute(fs::path(workPath)).string(); | 609 | auto fullWorkPath = fs::absolute(fs::path(workPath)).string(); |
| 598 | auto fullTargetPath = fullWorkPath; | 610 | auto fullTargetPath = fullWorkPath; |
| @@ -624,6 +636,7 @@ int main(int narg, const char** args) { | |||
| 624 | } | 636 | } |
| 625 | return 0; | 637 | return 0; |
| 626 | } | 638 | } |
| 639 | #endif // YUE_NO_WATCHER | ||
| 627 | std::list<std::future<std::tuple<int, std::string, std::string>>> results; | 640 | std::list<std::future<std::tuple<int, std::string, std::string>>> results; |
| 628 | for (const auto& file : files) { | 641 | for (const auto& file : files) { |
| 629 | auto task = std::async(std::launch::async, [=]() { | 642 | auto task = std::async(std::launch::async, [=]() { |
