diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bootstrap.cc | 22 | ||||
-rw-r--r-- | src/configure.cc | 176 | ||||
-rw-r--r-- | src/execute.cc | 139 | ||||
-rw-r--r-- | src/execute.h | 4 | ||||
-rw-r--r-- | src/libctor.cc | 9 | ||||
-rw-r--r-- | src/libctor.h | 1 | ||||
-rw-r--r-- | src/rebuild.cc | 41 | ||||
-rw-r--r-- | src/rebuild.h | 3 | ||||
-rw-r--r-- | src/task.cc | 23 | ||||
-rw-r--r-- | src/task.h | 1 | ||||
-rw-r--r-- | src/task_ar.cc | 12 | ||||
-rw-r--r-- | src/task_cc.cc | 31 | ||||
-rw-r--r-- | src/task_fn.cc | 2 | ||||
-rw-r--r-- | src/task_ld.cc | 15 | ||||
-rw-r--r-- | src/task_ld.h | 4 | ||||
-rw-r--r-- | src/task_so.cc | 3 | ||||
-rw-r--r-- | src/tasks.cc | 14 | ||||
-rw-r--r-- | src/tasks.h | 9 | ||||
-rw-r--r-- | src/tools.cc | 63 | ||||
-rw-r--r-- | src/tools.h | 1 | ||||
-rw-r--r-- | src/unittest.cc | 3 | ||||
-rw-r--r-- | src/unittest.h | 2 | ||||
-rw-r--r-- | src/util.cc | 1 |
23 files changed, 93 insertions, 486 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 97fe6fa..9a3c321 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -3,7 +3,6 @@ // See accompanying file LICENSE for details. #include <iostream> #include <array> -#include <cstdlib> #define BOOTSTRAP @@ -18,7 +17,6 @@ #include "tasks.cc" #include "build.cc" #include "tools.cc" -#include "../ctor.cc" std::filesystem::path configurationFile("configuration.cc"); std::filesystem::path configHeaderFile("config.h"); @@ -37,24 +35,6 @@ bool hasConfiguration(const std::string& key) const std::string& getConfiguration(const std::string& key, const std::string& defaultValue) { - if(key == cfg::host_cxx && std::getenv("CXX")) - { - static std::string s = std::getenv("CXX"); - return s; - } - - if(key == cfg::host_cc && std::getenv("CC")) - { - static std::string s = std::getenv("CC"); - return s; - } - - if(key == cfg::host_ar && std::getenv("AR")) - { - static std::string s = std::getenv("AR"); - return s; - } - return defaultValue; } @@ -71,7 +51,7 @@ int main(int argc, char* argv[]) settings.builddir = getConfiguration(cfg::builddir, "build"); settings.parallel_processes = - (std::max)(1u, std::thread::hardware_concurrency() * 2 - 1); + std::max(1u, std::thread::hardware_concurrency() * 2 - 1); settings.verbose = 0; auto all_tasks = getTasks(settings, {}, false); for(auto task : all_tasks) diff --git a/src/configure.cc b/src/configure.cc index 8348c19..a81f8ad 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -23,39 +23,15 @@ std::map<std::string, std::string> external_includedir; std::map<std::string, std::string> external_libdir; const Configuration default_configuration{}; -#if !defined(_WIN32) const Configuration& __attribute__((weak)) configuration() { return default_configuration; } -#else -//extern const char * pWeakValue; -//extern const char * pDefaultWeakValue = NULL; -// -//#pragma comment(linker, "/alternatename:_pWeakValue=_pDefaultWeakValue") -const Configuration& defConfiguration() -{ - return default_configuration; -} -#pragma comment(linker, "/alternatename:?configuration@@YAABUConfiguration@@XZ=?defConfiguration@@YAABUConfiguration@@XZ") -//https://stackoverflow.com/questions/2290587/gcc-style-weak-linking-in-visual-studio -//https://devblogs.microsoft.com/oldnewthing/20200731-00/?p=104024 - -//extern "C" -//{ -//void default_error_log() { /* do nothing */ } -//} -//// For expository simplification: assume x86 cdecl -//#pragma comment(linker, "/alternatename:_error_log=_default_error_log") - - -#endif namespace ctor { std::optional<std::string> includedir; std::optional<std::string> libdir; -std::map<std::string, std::string> conf_values; } bool hasConfiguration(const std::string& key) @@ -70,11 +46,6 @@ bool hasConfiguration(const std::string& key) return true; } - if(ctor::conf_values.find(key) != ctor::conf_values.end()) - { - return true; - } - const auto& c = configuration(); return c.tools.find(key) != c.tools.end(); } @@ -92,11 +63,6 @@ const std::string& getConfiguration(const std::string& key, return *ctor::libdir; } - if(ctor::conf_values.find(key) != ctor::conf_values.end()) - { - return ctor::conf_values[key]; - } - const auto& c = configuration(); if(hasConfiguration(key)) { @@ -122,24 +88,11 @@ std::string locate(const std::string& arch, const std::string& app) { std::stringstream ss(path_env); std::string path; - while (std::getline(ss, path, ';')) + while (std::getline(ss, path, ':')) { paths.push_back(path); } } - { - const auto& cfg = configuration(); - auto it = cfg.env.find("ctorPATH"); - if(it != cfg.env.end()) - { - std::stringstream ss(it->second); - std::string path; - while (std::getline(ss, path, ';')) - { - paths.push_back(path); - } - } - } for(const auto& path_str : paths) { std::filesystem::path path(path_str); @@ -174,10 +127,10 @@ class Args : public std::vector<char*> { public: - Args(const std::string& name, const std::vector<std::string>& args) + Args(const std::vector<std::string>& args) { resize(args.size() + 1); - (*this)[0] = strdup(name.data()); + (*this)[0] = strdup("./ctor"); for(std::size_t i = 0; i < size() - 1; ++i) { (*this)[i + 1] = strdup(args[i].data()); @@ -193,32 +146,15 @@ public: } }; -std::string esc(const std::string& in) -{ - std::string out; - for(auto c : in) - { - switch(c) - { - case '\\': out += "\\\\"; break; - case '"': out += "\\\""; break; - default: - out += c; - break; - } - } - return out; -} - // helper constant for the visitor template<class> inline constexpr bool always_false_v = false; -int regenerateCache(Settings& settings, - const std::string& name, +int regenerateCache(const Settings& default_settings, const std::vector<std::string>& args, const std::map<std::string, std::string>& env) { - Args vargs(name, args); + Settings settings{default_settings}; + Args vargs(args); dg::Options opt; int key{128}; @@ -249,13 +185,6 @@ int regenerateCache(Settings& settings, return 0; }); - opt.add("name", required_argument, 'n', - "Set the output name of the ctor command to override the current one.", - [&]() { - settings.name = optarg; - return 0; - }); - opt.add("cc", required_argument, key++, "Use specified c-compiler instead of gcc.", [&]() { @@ -382,19 +311,6 @@ int regenerateCache(Settings& settings, opt.process(vargs.size(), vargs.data()); - std::filesystem::path settings_file(settings.name); - std::filesystem::path argv0_file(vargs[0]); - - if(settings_file.is_relative()) - { - settings_file = std::filesystem::current_path() / settings_file; - } - if(argv0_file.is_relative()) - { - argv0_file = std::filesystem::current_path() / argv0_file; - } - - if(host_arch.empty()) { host_arch = build_arch; @@ -460,20 +376,6 @@ int regenerateCache(Settings& settings, std::string build_ar = locate(build_arch, ar_prog); std::string build_ld = locate(build_arch, ld_prog); - // Store current values for execution in this execution context. - if(!ctor_includedir.empty()) - { - ctor::conf_values[cfg::ctor_includedir] = ctor_includedir; - } - if(!ctor_libdir.empty()) - { - ctor::conf_values[cfg::ctor_libdir] = ctor_libdir; - } - ctor::conf_values[cfg::host_cxx] = host_cxx; - ctor::conf_values[cfg::build_cxx] = build_cxx; - ctor::conf_values[cfg::host_ld] = host_ld; - ctor::conf_values[cfg::build_ld] = build_ld; - std::cout << "Writing results to: " << configurationFile.string() << "\n"; { std::ofstream istr(configurationFile); @@ -485,34 +387,34 @@ int regenerateCache(Settings& settings, istr << " .args = {"; for(const auto& arg : args) { - istr << "\"" << esc(arg) << "\","; + istr << "\"" << arg << "\","; } istr << "},\n"; - istr << " .env = {\n"; + istr << " .env = {"; for(const auto& e : env) { - istr << " {\"" << e.first << "\", \"" << esc(e.second) << "\"},\n"; + istr << "{\"" << e.first << "\", \"" << e.second << "\"}, "; } - istr << " },\n"; + istr << "},\n"; istr << " .tools = {\n"; - istr << " { \"" << cfg::builddir << "\", \"" << esc(settings.builddir) << "\" },\n"; - istr << " { \"" << cfg::host_cc << "\", \"" << esc(host_cc) << "\" },\n"; - istr << " { \"" << cfg::host_cxx << "\", \"" << esc(host_cxx) << "\" },\n"; - istr << " { \"" << cfg::host_ar << "\", \"" << esc(host_ar) << "\" },\n"; - istr << " { \"" << cfg::host_ld << "\", \"" << esc(host_ld) << "\" },\n"; - istr << " { \"" << cfg::build_cc << "\", \"" << esc(build_cc) << "\" },\n"; - istr << " { \"" << cfg::build_cxx << "\", \"" << esc(build_cxx) << "\" },\n"; - istr << " { \"" << cfg::build_ar << "\", \"" << esc(build_ar) << "\" },\n"; - istr << " { \"" << cfg::build_ld << "\", \"" << esc(build_ld) << "\" },\n"; + istr << " { \"" << cfg::builddir << "\", \"" << settings.builddir << "\" },\n"; + istr << " { \"" << cfg::host_cc << "\", \"" << host_cc << "\" },\n"; + istr << " { \"" << cfg::host_cxx << "\", \"" << host_cxx << "\" },\n"; + istr << " { \"" << cfg::host_ar << "\", \"" << host_ar << "\" },\n"; + istr << " { \"" << cfg::host_ld << "\", \"" << host_ld << "\" },\n"; + istr << " { \"" << cfg::build_cc << "\", \"" << build_cc << "\" },\n"; + istr << " { \"" << cfg::build_cxx << "\", \"" << build_cxx << "\" },\n"; + istr << " { \"" << cfg::build_ar << "\", \"" << build_ar << "\" },\n"; + istr << " { \"" << cfg::build_ld << "\", \"" << build_ld << "\" },\n"; if(!ctor_includedir.empty()) { - istr << " { \"" << cfg::ctor_includedir << "\", \"" << esc(ctor_includedir) << "\" },\n"; + istr << " { \"" << cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n"; ctor::includedir = ctor_includedir; } if(!ctor_libdir.empty()) { - istr << " { \"" << cfg::ctor_libdir << "\", \"" << esc(ctor_libdir) << "\" },\n"; + istr << " { \"" << cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n"; ctor::libdir = ctor_libdir; } @@ -606,7 +508,7 @@ int configure(const Settings& global_settings, int argc, char* argv[]) args.push_back(argv[i]); } - auto env = configuration().env; + std::map<std::string, std::string> env; auto cc_env = getenv("CC"); if(cc_env) { @@ -631,32 +533,7 @@ int configure(const Settings& global_settings, int argc, char* argv[]) env["LD"] = ld_env; } - // Env vars for msvc - auto cl_env = getenv("CL"); - if(cl_env) - { - env["CL"] = cl_env; - } - - auto lib_env = getenv("LIB"); - if(lib_env) - { - env["LIB"] = lib_env; - } - - auto link_env = getenv("LINK"); - if(link_env) - { - env["LINK"] = link_env; - } - - auto path_env = getenv("PATH"); - if(path_env) - { - env["ctorPATH"] = path_env; - } - - auto ret = regenerateCache(settings, argv[0], args, env); + auto ret = regenerateCache(settings, args, env); if(ret != 0) { return ret; @@ -667,9 +544,8 @@ int configure(const Settings& global_settings, int argc, char* argv[]) return 0; } -int reconfigure(const Settings& global_settings, int argc, char* argv[]) +int reconfigure(const Settings& settings, int argc, char* argv[]) { - Settings settings{global_settings}; bool no_rerun{false}; std::vector<std::string> args; @@ -697,7 +573,7 @@ int reconfigure(const Settings& global_settings, int argc, char* argv[]) } std::cout << "\n"; - auto ret = regenerateCache(settings, argv[0], cfg.args, cfg.env); + auto ret = regenerateCache(settings, cfg.args, cfg.env); if(ret != 0) { return ret; @@ -710,5 +586,5 @@ int reconfigure(const Settings& global_settings, int argc, char* argv[]) return 0; // this was originally invoked by configure, don't loop } - return execute(argv[0], args, {}); + return execute(argv[0], args); } diff --git a/src/execute.cc b/src/execute.cc index 85c1da1..610ccdd 100644 --- a/src/execute.cc +++ b/src/execute.cc @@ -3,17 +3,11 @@ // See accompanying file LICENSE for details. #include "execute.h" -#include <cstring> -#if !defined(_WIN32) #include <unistd.h> +#include <cstring> #include <sys/types.h> #include <sys/wait.h> #include <spawn.h> -#else -#include <processthreadsapi.h> -#include <synchapi.h> -#include <processenv.h> -#endif #include <iostream> /* @@ -24,7 +18,6 @@ https://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork- */ -#if !defined(_WIN32) namespace { int parent_waitpid(pid_t pid) @@ -39,12 +32,10 @@ int parent_waitpid(pid_t pid) return WEXITSTATUS(status); } } // namespace :: -#endif int execute(const std::string& command, const std::vector<std::string>& args, - const std::map<std::string, std::string>& env, - bool verbose, bool terminate) + bool verbose) { std::vector<const char*> argv; argv.push_back(command.data()); @@ -54,138 +45,46 @@ int execute(const std::string& command, } argv.push_back(nullptr); - std::string cmd; - for(const auto& arg : argv) + if(verbose) { - if(arg == nullptr) - { - break; - } - if(!cmd.empty()) + std::string cmd; + for(const auto& arg : argv) { - cmd += " "; + if(arg == nullptr) + { + break; + } + if(!cmd.empty()) + { + cmd += " "; + } + cmd += arg; } - cmd += arg; - } - if(verbose) - { std::cout << cmd << "\n"; } -#if !defined(_WIN32) - #if 1 auto pid = vfork(); if(pid == 0) { - for(const auto& [key, value] : env) - { - setenv(key, value); - } - // TODO: use execvpe to set LD_LIBRARY_PATH execv(command.data(), (char**)argv.data()); std::cout << "Could not execute " << command << ": " << strerror(errno) << "\n"; _exit(1); // execv only returns if an error occurred } - - return parent_waitpid(pid); + auto ret = parent_waitpid(pid); #elif 0 pid_t pid; - const char * envp[] = {nullptr}; // TODO: use this to set LD_LIBRARY_PATH if(posix_spawn(&pid, command.data(), nullptr, nullptr, - (char**)argv.data(), envp)) + (char**)argv.data(), nullptr)) { return 1; } - return parent_waitpid(pid); + auto ret = parent_waitpid(pid); #else - return system(cmd.data()); + auto ret = system(cmd.data()); #endif -#else - std::map<std::string, std::string> new_env; - auto env_strings = GetEnvironmentStrings(); - const char* ptr = env_strings; - std::string key; - std::string value; - bool key_state{true}; - while(true) - { - if(key_state) // searching for key - { - if(*ptr == '\0') - { - break; - } - - if(*ptr != '=') - { - key += *ptr; - } - else - { - key_state = false; - } - } - else - { - if(*ptr != '\0') - { - value += *ptr; - } - else - { - new_env.insert({key, value}); - key = {}; - value = {}; - key_state = true; - } - } - ++ptr; - } - FreeEnvironmentStrings(env_strings); - - // add new env vars (if any) - for(const auto& [key, value] : env) - { - //if(key == "CL" || key == "LINK" || key == "LIB") - { - new_env[key] = value; - } - } - - std::string env_str; - for(const auto& [k,v] : new_env) - { - env_str += k + "=" + v; - env_str += '\0'; - } - env_str += '\0'; - STARTUPINFO si; - PROCESS_INFORMATION pi; - ZeroMemory(&si,sizeof(si)); - si.cb=sizeof(si); - ZeroMemory(&pi,sizeof(pi)); - // TODO: Use SetDllDirectory(...) to set DLL search directory - if(!CreateProcess(nullptr, //"C:/WINDOWS/notepad.exe", - //"notepad.exe c:/readme.txt",0,0,0,0,0,0,&si,&pi)) - (char*)cmd.data(),0,0,0,0,env_str.data(),0,&si,&pi)) - { - return 1; // Could not start process; - } - - if(terminate) - { - ExitProcess(0); - } - // Now 'pi.hProcess' contains the process HANDLE, which you can use to - // wait for it like this: - const DWORD infinite = 0xFFFFFFFF; - WaitForSingleObject(pi.hProcess, infinite); - DWORD exitCode{0}; - GetExitCodeProcess(pi.hProcess, &exitCode); - return exitCode; -#endif + return ret; } diff --git a/src/execute.h b/src/execute.h index e0626ab..c750a83 100644 --- a/src/execute.h +++ b/src/execute.h @@ -5,9 +5,7 @@ #include <string> #include <vector> -#include <map> int execute(const std::string& command, const std::vector<std::string>& args, - const std::map<std::string, std::string>& env, - bool verbose = true, bool terminate = false); + bool verbose = true); diff --git a/src/libctor.cc b/src/libctor.cc index bfa09d6..d188771 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -33,7 +33,6 @@ int main(int argc, char* argv[]) settings.builddir = getConfiguration(cfg::builddir, settings.builddir); settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency()) * 2 - 1; - settings.name = argv[0]; if(argc > 1 && std::string(argv[1]) == "configure") { @@ -97,14 +96,6 @@ int main(int argc, char* argv[]) return 0; }); - opt.add("name", required_argument, 'n', - "Set the output name of the ctor command to override the current one.", - [&]() { - std::this_thread::sleep_for(std::chrono::seconds(3)); - settings.name = optarg; - return 0; - }); - opt.add("add", required_argument, 'a', "Add specified file to the build configurations.", [&]() { diff --git a/src/libctor.h b/src/libctor.h index e4ea7e7..96e1115 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -69,7 +69,6 @@ struct Settings std::string builddir{"build"}; std::size_t parallel_processes{1}; int verbose{0}; // -1: completely silent, 0: normal, 1: verbose, ... - std::string name; }; struct BuildConfiguration; diff --git a/src/rebuild.cc b/src/rebuild.cc index cfbe790..9ddf5ba 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -152,63 +152,40 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], { std::cout << "Recompile check (" << numConfigFiles << "):\n"; } - std::filesystem::path settings_file(global_settings.name); - std::filesystem::path argv0_file(argv[0]); - - if(settings_file.is_relative()) - { - settings_file = std::filesystem::current_path() / settings_file; - } - if(argv0_file.is_relative()) - { - argv0_file = std::filesystem::current_path() / argv0_file; - } BuildConfiguration config; - config.type = TargetType::Executable; config.name = "ctor"; config.system = OutputSystem::Build; auto tool_chain = getToolChain(config.system); append(config.flags.cxxflags, - getOption(tool_chain, opt::optimization, "2")); + getOption(tool_chain, opt::optimization, "3")); append(config.flags.cxxflags, getOption(tool_chain, opt::cpp_std, "c++20")); - config.flags.cxxflags.push_back("/nologo"); if(hasConfiguration(cfg::ctor_includedir)) { append(config.flags.cxxflags, getOption(tool_chain, opt::include_path, getConfiguration(cfg::ctor_includedir))); } - if(hasConfiguration(cfg::ctor_libdir)) { append(config.flags.ldflags, getOption(tool_chain, opt::library_path, getConfiguration(cfg::ctor_libdir))); } -// append(config.flags.ldflags, getOption(tool_chain, opt::link, "ctor")); - config.flags.ldflags.push_back("build/libctor.lib"); + append(config.flags.ldflags, getOption(tool_chain, opt::link, "ctor")); append(config.flags.ldflags, getOption(tool_chain, opt::threads)); - config.flags.ldflags.push_back("/nologo"); - config.flags.ldflags.push_back("/SUBSYSTEM:CONSOLE"); - Settings settings{global_settings}; - settings.parallel_processes = 1; - settings.verbose = 2;//-1; // Make check completely silent. + settings.verbose = -1; // Make check completely silent. settings.builddir += "/ctor"; // override builddir to use ctor subdir + { std::filesystem::path buildfile = settings.builddir; - std::filesystem::path currentfile = settings.name; - - if(currentfile.is_relative()) - { - currentfile = std::filesystem::current_path() / currentfile; - } + std::filesystem::path currentfile = argv[0]; config.target = std::filesystem::relative(currentfile, buildfile).string(); } @@ -247,7 +224,7 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], } } - auto tasks = taskFactory({config}, settings, {}, true); + auto tasks = taskFactory({config}, settings, {}); for(auto task : tasks) { @@ -270,8 +247,6 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], } auto dirty_tasks = build(settings, "ctor", tasks, true); // dryrun - - bool was_rebuilt{false}; if(dirty_tasks) { std::cout << "Rebuilding config.\n"; @@ -280,7 +255,6 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], { return ret; } - was_rebuilt = true; } if(reconfigure) @@ -295,11 +269,12 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], { args.push_back(argv[i]); } - auto ret = execute(settings.name, args, {}); + auto ret = execute(argv[0], args); //if(ret != 0) { exit(ret); } + } return dirty_tasks; diff --git a/src/rebuild.h b/src/rebuild.h index 7b0ebb8..f1255c6 100644 --- a/src/rebuild.h +++ b/src/rebuild.h @@ -7,7 +7,8 @@ #include <array> #include "libctor.h" -//class Settings; + +class Settings; struct BuildConfigurationEntry { diff --git a/src/task.cc b/src/task.cc index 4736565..fb50765 100644 --- a/src/task.cc +++ b/src/task.cc @@ -3,7 +3,7 @@ // See accompanying file LICENSE for details. #include "task.h" -//#include <unistd.h> +#include <unistd.h> #include <iostream> Task::Task(const BuildConfiguration& config, const Settings& settings, @@ -147,24 +147,11 @@ std::string Task::compiler() const case OutputSystem::Build: return getConfiguration(cfg::build_cxx, "/usr/bin/g++"); } + default: + std::cerr << "Unknown CC target type\n"; + exit(1); + break; } - - std::cerr << "Unknown CC target type\n"; - exit(1); -} - -std::string Task::linker() const -{ - switch(outputSystem()) - { - case OutputSystem::Host: - return getConfiguration(cfg::host_ld, "/usr/bin/ld"); - case OutputSystem::Build: - return getConfiguration(cfg::build_ld, "/usr/bin/ld"); - } - - std::cerr << "Unknown CC target type\n"; - exit(1); } std::set<std::shared_ptr<Task>> Task::getDependsTasks() @@ -64,7 +64,6 @@ public: Language sourceLanguage() const; OutputSystem outputSystem() const; std::string compiler() const; - std::string linker() const; std::set<std::shared_ptr<Task>> getDependsTasks(); diff --git a/src/task_ar.cc b/src/task_ar.cc index 3fcfcf4..3e1746c 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -78,16 +78,13 @@ bool TaskAR::dirtyInner() int TaskAR::runInner() { std::vector<std::string> args; - //args.push_back("rcs"); + args.push_back("rcs"); + args.push_back(targetFile().string()); for(const auto& task : getDependsTasks()) { args.push_back(task->targetFile().string()); } - args.push_back("/nologo"); - args.push_back("/SUBSYSTEM:CONSOLE"); - args.push_back("/out:"+targetFile().string()); - { // Write flags to file. std::ofstream flagsStream(flagsFile); flagsStream << flagsString(); @@ -109,8 +106,7 @@ int TaskAR::runInner() break; } - const auto& cfg = configuration(); - return execute(tool, args, cfg.env, settings.verbose > 0); + return execute(tool, args, settings.verbose > 0); } int TaskAR::clean() @@ -172,7 +168,7 @@ std::string TaskAR::flagsString() const } flagsStr += flag; } - //flagsStr += "\n"; + flagsStr += "\n"; for(const auto& dep : config.depends) { diff --git a/src/task_cc.cc b/src/task_cc.cc index e9ef590..c4343b6 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -24,6 +24,7 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings, sourceFile /= source.file; std::filesystem::path base = sourceFile.parent_path(); + std::filesystem::create_directories(std::filesystem::path(settings.builddir) / base); base /= cleanUp(config.target); base += "-"; @@ -55,17 +56,14 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings, if(source.output.empty()) { _targetFile = base; - _targetFile += ".obj"; + _targetFile += ".o"; } else { _targetFile = source.output; } - - std::filesystem::create_directories(targetFile().parent_path()); - depsFile = targetFile().parent_path() / targetFile().stem(); - depsFile += ".deps"; + depsFile += ".d"; flagsFile = targetFile().parent_path() / targetFile().stem(); flagsFile += ".flags"; } @@ -187,8 +185,7 @@ int TaskCC::runInner() targetFile().lexically_normal().string() << "\n"; } - const auto& cfg = configuration(); - return execute(compiler(), args, cfg.env, settings.verbose > 0); + return execute(compiler(), args, settings.verbose > 0); } int TaskCC::clean() @@ -288,26 +285,8 @@ std::vector<std::string> TaskCC::getCompilerArgs() const auto compiler_flags = flags(); - // cl.exe (compiler - gcc/g++) - // https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-170 - - // /c Compiles without linking. - // /Fo Object File Name (or path if .cc basename is re-used) - // /F Output-File - // /Fe (Name EXE File) - // /sourceDependencies <file> json file with dependenciy tree - // /I<dir> include path - // /LD Creates a dynamic-link library. - // /link <option> Passes the specified option to LINK. - - // link.exe (exe and dll linker - ld) - // https://docs.microsoft.com/en-us/cpp/build/reference/linker-options?view=msvc-170 - - // lib.exe (lib linker - ar) - // https://docs.microsoft.com/en-us/cpp/build/reference/overview-of-lib?view=msvc-170 std::vector<std::string> args; - append(args, getOption(tool_chain, opt::generate_dep_tree, depsFile.string())); -// args.push_back("-MMD"); // https://github.com/ninja-build/ninja/issues/1806 + append(args, getOption(tool_chain, opt::generate_dep_tree)); if(std::filesystem::path(config.target).extension() == ".so") { diff --git a/src/task_fn.cc b/src/task_fn.cc index 9ef8f96..ab00fae 100644 --- a/src/task_fn.cc +++ b/src/task_fn.cc @@ -97,7 +97,7 @@ std::vector<std::string> TaskFn::depends() const std::string TaskFn::target() const { - return _targetFile.string(); + return _targetFile; } std::filesystem::path TaskFn::targetFile() const diff --git a/src/task_ld.cc b/src/task_ld.cc index 3d89f90..20e823d 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -15,12 +15,11 @@ TaskLD::TaskLD(const BuildConfiguration& config, const Settings& settings, const std::string& target, const std::vector<std::string>& objects, - const std::string& sourceDir, bool is_self) + const std::string& sourceDir) : Task(config, settings, sourceDir) , config(config) , settings(settings) , sourceDir(sourceDir) - , is_self(is_self) { target_type = config.type; if(target_type == TargetType::Auto) @@ -96,15 +95,14 @@ int TaskLD::runInner() auto lib = depFile.stem().string().substr(3); // strip 'lib' prefix append(args, getOption(tool_chain, opt::link, lib)); } - else if(depFile.extension() == ".lib" || depFile.extension() == ".obj") + else if(depFile.extension() == ".a" || depFile.extension() == ".o") { args.push_back(depFile.string()); } } append(args, config.flags.ldflags); -// append(args, getOption(tool_chain, opt::output, targetFile().string())); - args.push_back("/out:"+targetFile().string()); + append(args, getOption(tool_chain, opt::output, targetFile().string())); { // Write flags to file. std::ofstream flagsStream(flagsFile); @@ -116,9 +114,8 @@ int TaskLD::runInner() std::cout << "LD => " << targetFile().string() << "\n"; } - auto tool = linker(); - const auto& cfg = configuration(); - return execute(tool, args, cfg.env, settings.verbose > 0, is_self); + auto tool = compiler(); + return execute(tool, args, settings.verbose > 0); } int TaskLD::clean() @@ -180,7 +177,7 @@ std::string TaskLD::flagsString() const } flagsStr += flag; } - //flagsStr += "\n"; break on win32 + flagsStr += "\n"; for(const auto& dep : config.depends) { diff --git a/src/task_ld.h b/src/task_ld.h index 348d23b..8625075 100644 --- a/src/task_ld.h +++ b/src/task_ld.h @@ -21,8 +21,7 @@ public: const Settings& settings, const std::string& target, const std::vector<std::string>& objects, - const std::string& _sourceDir, - bool is_self); + const std::string& _sourceDir); virtual ~TaskLD() = default; bool dirtyInner() override; @@ -48,5 +47,4 @@ private: const BuildConfiguration& config; const Settings& settings; std::string sourceDir; - bool is_self; }; diff --git a/src/task_so.cc b/src/task_so.cc index 98057ea..8c6dbd4 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -106,8 +106,7 @@ int TaskSO::runInner() } auto tool = compiler(); - const auto& cfg = configuration(); - return execute(tool, args, cfg.env, settings.verbose > 0); + return execute(tool, args, settings.verbose > 0); } int TaskSO::clean() diff --git a/src/tasks.cc b/src/tasks.cc index 435bef1..68b2476 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -79,8 +79,7 @@ const std::deque<Target>& getTargets(const Settings& settings, std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, const Settings& settings, - const std::string& sourceDir, - bool is_self) + const std::string& sourceDir) { std::set<std::shared_ptr<Task>> tasks; @@ -93,16 +92,15 @@ std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, { target_type = TargetType::Function; } - else if(targetFile.extension() == ".lib") + else if(targetFile.extension() == ".a") { target_type = TargetType::StaticLibrary; } - else if(targetFile.extension() == ".dll") + else if(targetFile.extension() == ".so") { target_type = TargetType::DynamicLibrary; } - else if(targetFile.extension() == "" || - targetFile.extension() == ".exe") + else if(targetFile.extension() == "") { target_type = TargetType::Executable; } @@ -162,7 +160,7 @@ std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, case TargetType::Executable: case TargetType::UnitTest: tasks.insert(std::make_shared<TaskLD>(config, settings, config.target, - objects, sourceDir, is_self)); + objects, sourceDir)); break; case TargetType::Object: @@ -208,7 +206,7 @@ std::set<std::shared_ptr<Task>> getTasks(const Settings& settings, std::find(std::begin(names), std::end(names), target.config.target) != std::end(names)) { std::vector<std::string> objects; - auto t = taskFactory(target.config, settings, target.path, false); + auto t = taskFactory(target.config, settings, target.path); tasks.insert(t.begin(), t.end()); } } diff --git a/src/tasks.h b/src/tasks.h index 97b115c..c547432 100644 --- a/src/tasks.h +++ b/src/tasks.h @@ -9,9 +9,9 @@ #include <deque> #include "task.h" -#include "libctor.h" -//class BuildConfiguration; -//class Settings; + +class BuildConfiguration; +class Settings; struct Target { @@ -40,5 +40,4 @@ std::set<std::shared_ptr<Task>> getTasks(const Settings& settings, //! link target and all its objects files (if any). std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, const Settings& settings, - const std::string& sourceDir, - bool is_self); + const std::string& sourceDir); diff --git a/src/tools.cc b/src/tools.cc index cd00f89..7e8ac78 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -8,14 +8,6 @@ #include <cassert> -/* -https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-170 -/TC Specifies all source files are C. -/Tc Specifies a C source file. -/TP Specifies all source files are C++. -/Tp Specifies a C++ source file. -*/ - ToolChain getToolChain(OutputSystem system) { std::string compiler; @@ -41,11 +33,6 @@ ToolChain getToolChain(OutputSystem system) { return ToolChain::gcc; } - else if(cc_cmd.find("cl") != std::string::npos || - cc_cmd.find("CL") != std::string::npos) - { - return ToolChain::msvc; - } std::cerr << "Unsupported output system.\n"; return ToolChain::gcc; @@ -68,7 +55,7 @@ std::vector<std::string> getOptionGcc(opt option, const std::string& arg) case opt::warnings_as_errors: return {"-Werror"}; case opt::generate_dep_tree: - return {"-MMD", "-MF" + arg}; + return {"-MMD"}; case opt::no_link: return {"-c"}; case opt::include_path: @@ -96,50 +83,6 @@ std::vector<std::string> getOptionGcc(opt option, const std::string& arg) std::cerr << "Unsupported compiler option.\n"; return {}; } - -std::vector<std::string> getOptionMsvc(opt option, const std::string& arg) -{ - switch(option) - { - case opt::output: - return {"/Fo\""+arg+"\""}; - case opt::debug: - return {"/DEBUG"}; - case opt::strip: - return {};//{"-s"}; TODO - case opt::warn_all: - return {"/Wall"}; - case opt::warnings_as_errors: - return {"/WX"}; - case opt::generate_dep_tree: - return {"/sourceDependencies", arg}; - case opt::no_link: - return {"/c"}; - case opt::include_path: - return {"/I" + arg}; - case opt::library_path: - return {"/LIBPATH:" + arg}; - case opt::link: - return {}; //{"-l" + arg}; TODO - case opt::cpp_std: - return {"/std:" + arg}; - case opt::build_shared: - return {};//{"-shared"}; TODO - case opt::threads: - return {};// {"-pthread"}; TODO - case opt::optimization: - return {"/O" + arg}; // TODO: max 2 - case opt::position_independent_code: - return {};//{"-fPIC"}; TODO - case opt::position_independent_executable: - return {};//{"-fPIE"}; TODO - case opt::custom: - return {arg}; - } - - std::cerr << "Unsupported compiler option.\n"; - return {}; -} } std::vector<std::string> getOption(ToolChain tool_chain, @@ -151,8 +94,6 @@ std::vector<std::string> getOption(ToolChain tool_chain, case ToolChain::gcc: case ToolChain::clang: return getOptionGcc(option, arg); - case ToolChain::msvc: - return getOptionMsvc(option, arg); } std::cerr << "Unsupported tool-chain.\n"; @@ -188,8 +129,6 @@ std::pair<opt, std::string> getOption(const std::string& flag, case ToolChain::gcc: case ToolChain::clang: return getOptionGcc(flag); - case ToolChain::msvc: - break; // TODO } std::cerr << "Unsupported tool-chain.\n"; diff --git a/src/tools.h b/src/tools.h index 37282e1..39118d2 100644 --- a/src/tools.h +++ b/src/tools.h @@ -12,7 +12,6 @@ enum class ToolChain { gcc, clang, - msvc, }; enum class opt diff --git a/src/unittest.cc b/src/unittest.cc index 5524ea5..f18de47 100644 --- a/src/unittest.cc +++ b/src/unittest.cc @@ -7,7 +7,6 @@ #include "execute.h" #include "task.h" -#include "libctor.h" int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, const Settings& settings) @@ -25,7 +24,7 @@ int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, name = task->target(); } std::cout << name << ": " << std::flush; - auto ret = execute(task->targetFile().string(), {}, {}, settings.verbose > 0); + auto ret = execute(task->targetFile(), {}, settings.verbose > 0); ok &= ret == 0; if(ret == 0) { diff --git a/src/unittest.h b/src/unittest.h index 5118689..8dee33c 100644 --- a/src/unittest.h +++ b/src/unittest.h @@ -7,7 +7,7 @@ #include <memory> class Task; -struct Settings; +class Settings; int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, const Settings& settings); diff --git a/src/util.cc b/src/util.cc index 7aedad1..92560b6 100644 --- a/src/util.cc +++ b/src/util.cc @@ -22,7 +22,6 @@ std::string readFile(const std::string& fileName) std::vector<std::string> readDeps(const std::string& depFile) { - return {};// TODO: parse json if(!std::filesystem::exists(depFile)) { return {}; |