From c1cc934e55ca88117599121841301783d29aac32 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 12 Jan 2023 16:46:53 +0800 Subject: fix issue #122, add option to build yue tool without file watcher function. --- doc/docs/.vuepress/config.js | 7 ------- makefile | 15 ++++++++++++--- 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 = { } }; `], - ['script', {}, ` - var Module = { - onRuntimeInitialized: function() { - window.yue = Module; - } - }; - `], ['script', { src: '/js/yuescript.js' }], ], diff --git a/makefile b/makefile index 3978d96..6bd5f16 100644 --- a/makefile +++ b/makefile @@ -54,6 +54,9 @@ endif INCLUDES += -I $(SRC_PATH)/3rdParty/lua LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl endif +ifeq ($(NO_WATCHER),true) + COMPILE_FLAGS += -DYUE_NO_WATCHER +endif # Add platform related linker flag ifneq ($(UNAME_S),Darwin) @@ -137,7 +140,9 @@ OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) # Set the dependency files that will be used to add header dependencies DEPS = $(OBJECTS:.o=.d) -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 +ifneq ($(NO_WATCHER),true) + 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 +endif # Macros for timing compilation ifeq ($(UNAME_S),Darwin) @@ -148,7 +153,9 @@ ifeq ($(UNAME_S),Darwin) $(RM) $(TIME_FILE) ; \ st=$$((`$(CUR_TIME)` - $$st)) ; \ echo $$st - 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 + ifneq ($(NO_WATCHER),true) + 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 + endif else TIME_FILE = $(dir $@).$(notdir $@)_time START_TIME = date '+%s' > $(TIME_FILE) @@ -156,7 +163,9 @@ else $(RM) $(TIME_FILE) ; \ st=$$((`date '+%s'` - $$st - 86400)) ; \ echo `date -u -d @$$st '+%H:%M:%S'` - 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 + ifneq ($(NO_WATCHER),true) + 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 + endif endif # 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 using namespace std::string_view_literals; using namespace std::string_literals; using namespace std::chrono_literals; +#ifndef YUE_NO_WATCHER #include "efsw/efsw.hpp" +#endif // YUE_NO_WATCHER #include "ghc/fs_std.hpp" #include "linenoise.hpp" @@ -140,6 +142,7 @@ fs::path getTargetFileDirty(const fs::path& file, const fs::path& workPath, cons return fs::path(); } +#ifndef YUE_NO_WATCHER static std::string compileFile(const fs::path& file, yue::YueConfig conf, const fs::path& workPath, const fs::path& targetPath) { auto srcFile = fs::absolute(file); auto targetFile = getTargetFileDirty(srcFile, workPath, targetPath); @@ -234,6 +237,7 @@ public: fs::path workPath; fs::path targetPath; }; +#endif // YUE_NO_WATCHER int main(int narg, const char** args) { const char* help = @@ -250,7 +254,9 @@ int main(int narg, const char** args) { " -b Dump compile time (doesn't write output)\n" " -g Dump global variables used in NAME LINE COLUMN\n" " -l Write line numbers from source codes\n" +#ifndef YUE_NO_WATCHER " -w path Watch changes and compile every file under directory\n" +#endif // YUE_NO_WATCHER " -v Print version\n" #ifndef YUE_COMPILER_ONLY " -- Read from standard in, print to standard out\n" @@ -550,7 +556,12 @@ int main(int narg, const char** args) { return 1; } } else if (arg == "-w"sv) { +#ifndef YUE_NO_WATCHER watchFiles = true; +#else + std::cout << "Error: -w is not supported\n"sv; + return 1; +#endif // YUE_NO_WATCHER } else if (arg.size() > 2 && arg.substr(0, 2) == "--"sv && arg.substr(2, 1) != "-"sv) { auto argStr = arg.substr(2); yue::Utils::trim(argStr); @@ -593,6 +604,7 @@ int main(int narg, const char** args) { std::cout << "Error: -o can not be used with multiple input files\n"sv; return 1; } +#ifndef YUE_NO_WATCHER if (watchFiles) { auto fullWorkPath = fs::absolute(fs::path(workPath)).string(); auto fullTargetPath = fullWorkPath; @@ -624,6 +636,7 @@ int main(int narg, const char** args) { } return 0; } +#endif // YUE_NO_WATCHER std::list>> results; for (const auto& file : files) { auto task = std::async(std::launch::async, [=]() { -- cgit v1.2.3-55-g6feb