diff --git a/src/tools/cmake.h b/src/tools/cmake.h new file mode 100644 index 0000000..aa01c14 --- /dev/null +++ b/src/tools/cmake.h @@ -0,0 +1,79 @@ +#pragma once + +namespace mob +{ + +class cmake : public basic_process_runner +{ +public: + enum generators + { + vs = 0x01, + jom = 0x02 + }; + + enum ops + { + generate =1 , + clean + }; + + cmake(ops o=generate); + + static fs::path binary(); + + cmake& generator(generators g); + cmake& generator(const std::string& g); + cmake& root(const fs::path& p); + cmake& output(const fs::path& p); + cmake& prefix(const fs::path& s); + cmake& def(const std::string& name, const std::string& value); + cmake& def(const std::string& name, const fs::path& p); + cmake& def(const std::string& name, const char* s); + cmake& architecture(arch a); + cmake& cmd(const std::string& s); + + // returns the path given in output(), if it was set + // + // if not, returns the build path based on the parameters (for example, + // `vsbuild_32/` for a 32-bit arch with the VS generator + // + fs::path build_path() const; + + // returns build_path(), used by task::run_tool() + // + fs::path result() const; + +protected: + void do_run() override; + +private: + struct gen_info + { + std::string dir; + std::string name; + std::string x86; + std::string x64; + + std::string get_arch(arch a) const; + std::string output_dir(arch a) const; + }; + + ops op_; + fs::path root_; + generators gen_; + std::string genstring_; + fs::path prefix_; + std::vector> def_; + fs::path output_; + arch arch_; + std::string cmd_; + + void do_clean(); + void do_generate(); + + static const std::map& all_generators(); + static const gen_info& get_generator(generators g); +}; + +} // namespace diff --git a/src/tools/git.h b/src/tools/git.h index f590804..d6310e6 100644 --- a/src/tools/git.h +++ b/src/tools/git.h @@ -128,4 +128,44 @@ private: const std::string& url_pattern={}); }; + +class git_submodule_adder : public instrumentable<2> +{ +public: + enum class times + { + add_submodule_wait, + add_submodule + }; + + ~git_submodule_adder(); + + static git_submodule_adder& instance(); + + void queue(git g); + void stop(); + +private: + struct sleeper + { + std::mutex m; + std::condition_variable cv; + bool ready = false; + }; + + context cx_; + std::thread thread_; + std::vector queue_; + mutable std::mutex queue_mutex_; + std::atomic quit_; + sleeper sleeper_; + + git_submodule_adder(); + void run(); + + void thread_fun(); + void wakeup(); + void process(); +}; + } // namespace diff --git a/src/tools/msbuild.h b/src/tools/msbuild.h new file mode 100644 index 0000000..b317b11 --- /dev/null +++ b/src/tools/msbuild.h @@ -0,0 +1,58 @@ +#pragma once + +namespace mob +{ + +class msbuild : public basic_process_runner +{ +public: + enum flags_t + { + noflags = 0x00, + single_job = 0x01, + allow_failure = 0x02 + }; + + enum ops + { + build = 1, + clean + }; + + msbuild(ops o=build); + + static fs::path binary(); + + msbuild& solution(const fs::path& sln); + msbuild& targets(const std::vector& names); + msbuild& parameters(const std::vector& params); + msbuild& config(const std::string& s); + msbuild& platform(const std::string& s); + msbuild& architecture(arch a); + msbuild& flags(flags_t f); + msbuild& prepend_path(const fs::path& p); + + int result() const; + +protected: + void do_run() override; + +private: + ops op_; + fs::path sln_; + std::vector targets_; + std::vector params_; + std::string config_; + std::string platform_; + arch arch_; + flags_t flags_; + std::vector prepend_path_; + + void do_clean(); + void do_build(); + void do_run(const std::vector& targets); +}; + +MOB_ENUM_OPERATORS(msbuild::flags_t); + +} // namespace diff --git a/src/tools/tools.h b/src/tools/tools.h index 1624a96..72b2c49 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -152,48 +152,6 @@ private: }; - - -class git_submodule_adder : public instrumentable<2> -{ -public: - enum class times - { - add_submodule_wait, - add_submodule - }; - - ~git_submodule_adder(); - - static git_submodule_adder& instance(); - - void queue(git g); - void stop(); - -private: - struct sleeper - { - std::mutex m; - std::condition_variable cv; - bool ready = false; - }; - - context cx_; - std::thread thread_; - std::vector queue_; - mutable std::mutex queue_mutex_; - std::atomic quit_; - sleeper sleeper_; - - git_submodule_adder(); - void run(); - - void thread_fun(); - void wakeup(); - void process(); -}; - - class extractor : public basic_process_runner { public: @@ -252,80 +210,6 @@ private: }; -class cmake : public basic_process_runner -{ -public: - enum generators - { - vs = 0x01, - jom = 0x02 - }; - - enum ops - { - generate =1 , - clean - }; - - cmake(ops o=generate); - - static fs::path binary(); - - cmake& generator(generators g); - cmake& generator(const std::string& g); - cmake& root(const fs::path& p); - cmake& output(const fs::path& p); - cmake& prefix(const fs::path& s); - cmake& def(const std::string& name, const std::string& value); - cmake& def(const std::string& name, const fs::path& p); - cmake& def(const std::string& name, const char* s); - cmake& architecture(arch a); - cmake& cmd(const std::string& s); - - // returns the path given in output(), if it was set - // - // if not, returns the build path based on the parameters (for example, - // `vsbuild_32/` for a 32-bit arch with the VS generator - // - fs::path build_path() const; - - // returns build_path(), used by task::run_tool() - // - fs::path result() const; - -protected: - void do_run() override; - -private: - struct gen_info - { - std::string dir; - std::string name; - std::string x86; - std::string x64; - - std::string get_arch(arch a) const; - std::string output_dir(arch a) const; - }; - - ops op_; - fs::path root_; - generators gen_; - std::string genstring_; - fs::path prefix_; - std::vector> def_; - fs::path output_; - arch arch_; - std::string cmd_; - - void do_clean(); - void do_generate(); - - static const std::map& all_generators(); - static const gen_info& get_generator(generators g); -}; - - class jom : public basic_process_runner { public: @@ -360,59 +244,6 @@ private: }; -class msbuild : public basic_process_runner -{ -public: - enum flags_t - { - noflags = 0x00, - single_job = 0x01, - allow_failure = 0x02 - }; - - enum ops - { - build = 1, - clean - }; - - msbuild(ops o=build); - - static fs::path binary(); - - msbuild& solution(const fs::path& sln); - msbuild& targets(const std::vector& names); - msbuild& parameters(const std::vector& params); - msbuild& config(const std::string& s); - msbuild& platform(const std::string& s); - msbuild& architecture(arch a); - msbuild& flags(flags_t f); - msbuild& prepend_path(const fs::path& p); - - int result() const; - -protected: - void do_run() override; - -private: - ops op_; - fs::path sln_; - std::vector targets_; - std::vector params_; - std::string config_; - std::string platform_; - arch arch_; - flags_t flags_; - std::vector prepend_path_; - - void do_clean(); - void do_build(); - void do_run(const std::vector& targets); -}; - -MOB_ENUM_OPERATORS(msbuild::flags_t); - - class vs : public basic_process_runner { public: @@ -599,3 +430,5 @@ private: #include "git.h" +#include "cmake.h" +#include "msbuild.h" diff --git a/vs/mob.vcxproj b/vs/mob.vcxproj index a7f04b8..ee8309e 100644 --- a/vs/mob.vcxproj +++ b/vs/mob.vcxproj @@ -136,7 +136,9 @@ + + diff --git a/vs/mob.vcxproj.filters b/vs/mob.vcxproj.filters index f2ef1ac..8f1418b 100644 --- a/vs/mob.vcxproj.filters +++ b/vs/mob.vcxproj.filters @@ -272,5 +272,11 @@ src\tools + + src\tools + + + src\tools + \ No newline at end of file