aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-01-12 16:46:53 +0800
committerLi Jin <dragon-fly@qq.com>2023-01-12 16:49:23 +0800
commitc1cc934e55ca88117599121841301783d29aac32 (patch)
tree9f0e4e69f93585ac5707d0561712a141939b1dae /src
parent0cc452c7cf2301e75bab1069c9da6ee73c7c5cfd (diff)
downloadyuescript-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 'src')
-rw-r--r--src/yue.cpp13
1 files changed, 13 insertions, 0 deletions
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
24using namespace std::string_view_literals; 24using namespace std::string_view_literals;
25using namespace std::string_literals; 25using namespace std::string_literals;
26using namespace std::chrono_literals; 26using 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
143static std::string compileFile(const fs::path& file, yue::YueConfig conf, const fs::path& workPath, const fs::path& targetPath) { 146static 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
238int main(int narg, const char** args) { 242int 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, [=]() {