summaryrefslogtreecommitdiffhomepage
path: root/yscan.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2024-05-04 14:43:48 +0200
committerRoland Reichwein <mail@reichwein.it>2024-05-04 14:43:48 +0200
commit44479895f325cbbc283553dcb10b29a0af3b480b (patch)
treef29b9da1c782554ec3cef375d7cc771a0d56756e /yscan.cpp
parent45983abe664be648b513202c8c12578c9a85784f (diff)
Added yscan
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;
+}
+