diff options
| author | Roland Reichwein <mail@reichwein.it> | 2024-05-04 14:43:48 +0200 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2024-05-04 14:43:48 +0200 | 
| commit | 44479895f325cbbc283553dcb10b29a0af3b480b (patch) | |
| tree | f29b9da1c782554ec3cef375d7cc771a0d56756e | |
| parent | 45983abe664be648b513202c8c12578c9a85784f (diff) | |
Added yscan
| -rw-r--r-- | Builder.cpp | 8 | ||||
| -rw-r--r-- | Makefile | 15 | ||||
| -rw-r--r-- | YMakefile | 9 | ||||
| -rw-r--r-- | file.cpp | 24 | ||||
| -rw-r--r-- | file.h | 8 | ||||
| -rw-r--r-- | ymake.cpp | 3 | ||||
| -rw-r--r-- | yscan-main.cpp | 6 | ||||
| -rw-r--r-- | yscan.cpp | 55 | ||||
| -rw-r--r-- | yscan.h | 4 | 
9 files changed, 120 insertions, 12 deletions
diff --git a/Builder.cpp b/Builder.cpp index 1f6fbb2..58176d4 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -1,5 +1,7 @@  #include "Builder.h" +#include "file.h" +  #include <algorithm>  #include <chrono>  #include <cstdlib> @@ -107,12 +109,6 @@ namespace {    return deps_from_depfile(depfile);   } - // type of file can be built from dependencies - bool is_buildable_by_extension(const fs::path& p) { -  fs::path ext{p.extension()}; -  return ext.empty() || ext == ".o"; - } -   std::unordered_map<fs::path, std::vector<fs::path>> get_dependencies(const pt::ptree& ptree) {    std::unordered_map<fs::path, std::vector<fs::path>> dependencies;    dependencies.emplace(get_target(ptree), get_objects(ptree)); @@ -1,10 +1,13 @@  PROJECTNAME=ymake -SRC=main.cpp ymake.cpp Builder.cpp ProcessRunner.cpp - +SRC=main.cpp ymake.cpp Builder.cpp ProcessRunner.cpp file.cpp  OBJ=$(SRC:.cpp=.o) -all: $(PROJECTNAME) +YSCAN=yscan +YSCAN_SRC=yscan-main.cpp yscan.cpp file.cpp +YSCAN_OBJ=$(YSCAN_SRC:.cpp=.o) + +all: $(PROJECTNAME) $(YSCAN)  LDLIBS += -lfmt -lreichwein  CXXFLAGS += -std=c++17 @@ -12,15 +15,19 @@ CXXFLAGS += -std=c++17  $(PROJECTNAME): $(OBJ)  	$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ +$(YSCAN): $(YSCAN_OBJ) +	$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ +  %.o: %.cpp  	$(CXX) $(CXXFLAGS) -c $< -o $@  install:  	mkdir -p $(DESTDIR)/usr/bin  	cp $(PROJECTNAME) $(DESTDIR)/usr/bin/ +	cp $(YSCAN) $(DESTDIR)/usr/bin/  clean: -	-rm -f *.o $(PROJECTNAME) +	-rm -f *.o $(PROJECTNAME) $(YSCAN)  	-dh_clean  deb: @@ -6,4 +6,13 @@    <source>ProcessRunner.cpp</source>    <source>ymake.cpp</source>   </build> + <build> +  <name>yscan</name> +  <source>yscan.cpp</source> +  <source>yscan-main.cpp</source> + </build> + <test> +  <name>test-ymake</name> +  <source>test-ymake.cpp</source> + </test>  </ymake> diff --git a/file.cpp b/file.cpp new file mode 100644 index 0000000..823d723 --- /dev/null +++ b/file.cpp @@ -0,0 +1,24 @@ +#include "file.h" + +#include <unordered_set> + +namespace fs = std::filesystem; + +const fs::path YMakefile{"YMakefile"}; + +// type of file can be built from dependencies +bool is_buildable_by_extension(const fs::path& p) { + fs::path ext{p.extension()}; + return ext.empty() || ext == ".o"; +} + +namespace { + std::unordered_set<fs::path> compile_unit_source_types{".cpp", ".c"}; +} + +// type of file is source of compile unit (no included types like headers) +bool is_compile_unit_source_by_extension(const fs::path& p) { + fs::path ext{p.extension()}; + return compile_unit_source_types.find(ext) != compile_unit_source_types.end(); +} + @@ -0,0 +1,8 @@ +#pragma once + +#include <filesystem> + +extern const std::filesystem::path YMakefile; + +bool is_buildable_by_extension(const std::filesystem::path& p); +bool is_compile_unit_source_by_extension(const std::filesystem::path& p); @@ -1,5 +1,6 @@  #include "ymake.h" +#include "file.h"  #include "Builder.h"  #include <algorithm> @@ -30,8 +31,6 @@ namespace pt = boost::property_tree;  using namespace std::string_literals;  namespace { - const fs::path YMakefile{"YMakefile"}; -   void usage()   {    std::cout << "Usage: ymake <target>" << std::endl; diff --git a/yscan-main.cpp b/yscan-main.cpp new file mode 100644 index 0000000..f0d2930 --- /dev/null +++ b/yscan-main.cpp @@ -0,0 +1,6 @@ +#include "yscan.h" + +int main(int argc, char* argv[]) +{ + return yscan(argc, argv); +} 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; +} + @@ -0,0 +1,4 @@ +#pragma once + +int yscan(int argc, char* argv[]); +  | 
