summaryrefslogtreecommitdiffhomepage
path: root/yscan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'yscan.cpp')
-rw-r--r--yscan.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/yscan.cpp b/yscan.cpp
new file mode 100644
index 0000000..8dad6bf
--- /dev/null
+++ b/yscan.cpp
@@ -0,0 +1,55 @@
+#include "yscan.h"
+
+#include "file.h"
+
+#include <filesystem>
+#include <iostream>
+#include <string>
+
+#include <fmt/format.h>
+
+#include <libreichwein/file.h>
+
+namespace fs = std::filesystem;
+using namespace std::string_literals;
+
+int yscan(int argc, char* argv[])
+{
+ try {
+ std::string name {fs::current_path().stem().string()};
+
+ std::string sources;
+ std::string test_sources;
+ for (const auto& i: fs::directory_iterator(".")) {
+ fs::path p{i.path().filename()};
+ if (is_compile_unit_source_by_extension(p)) {
+ if (p.string().substr(0, 4) == "test") {
+ test_sources += " <source>" + p.string() + "</source>\n";
+ } else {
+ sources += " <source>" + p.string() + "</source>\n";
+ }
+ }
+ }
+
+ if (!test_sources.empty()) {
+ test_sources = fmt::format(R"( <test>
+ <name>{}</name>
+{} </test>
+)", "test-"s + name, test_sources);
+ }
+
+ std::string contents {R"(<ymake>
+ <build>
+ <name>{}</name>
+{} </build>
+{}</ymake>
+)"};
+ contents = fmt::format(contents, name, sources, test_sources);
+ std::cout << contents << std::endl;
+ } catch (const std::exception& ex) {
+ std::cerr << "yscan: " << ex.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+