summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--README.md2
-rw-r--r--bootstrap.bat44
-rwxr-xr-xclbootstrap.sh50
-rwxr-xr-xclrun.sh22
-rw-r--r--ctor.cc29
-rw-r--r--src/bootstrap.cc22
-rw-r--r--src/configure.cc176
-rw-r--r--src/execute.cc139
-rw-r--r--src/execute.h4
-rw-r--r--src/libctor.cc9
-rw-r--r--src/libctor.h1
-rw-r--r--src/rebuild.cc41
-rw-r--r--src/rebuild.h3
-rw-r--r--src/task.cc23
-rw-r--r--src/task.h1
-rw-r--r--src/task_ar.cc12
-rw-r--r--src/task_cc.cc31
-rw-r--r--src/task_fn.cc2
-rw-r--r--src/task_ld.cc15
-rw-r--r--src/task_ld.h4
-rw-r--r--src/task_so.cc3
-rw-r--r--src/tasks.cc14
-rw-r--r--src/tasks.h9
-rw-r--r--src/tools.cc63
-rw-r--r--src/tools.h1
-rw-r--r--src/unittest.cc3
-rw-r--r--src/unittest.h2
-rw-r--r--src/util.cc1
-rw-r--r--test/ctor.cc78
-rw-r--r--test/execute_test.cc6
-rw-r--r--test/source_type_test.cc8
-rw-r--r--test/tasks_test.cc76
-rw-r--r--test/tools_test.cc24
34 files changed, 182 insertions, 741 deletions
diff --git a/.gitignore b/.gitignore
index 393e55a..4a8a9cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,8 @@
drumgizmo/
build/
ctor
-ctor.exe
+*.a
+*.o
+*.d
configuration.cc
config.h
-examples
diff --git a/README.md b/README.md
index caad51d..8319a59 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Introduction
+ # Introduction
Have you ever wondered, if you want to compile a C++ program, why you always
need to learn another language to make it build properly with dependency
diff --git a/bootstrap.bat b/bootstrap.bat
deleted file mode 100644
index 2a8820a..0000000
--- a/bootstrap.bat
+++ /dev/null
@@ -1,44 +0,0 @@
-@echo off
-:: Run with:
-:: WINEDEBUG=-all wine start bootstrap.bat
-
-set BASE=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133
-set ONECORELIB="%BASE%\lib\onecore\x86"
-set path=%path%;%BASE%\bin\Hostx86\x86
-set INCLUDE="%BASE%\include"
-set UCRT="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt"
-set UCRTLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86"
-set UM="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um"
-set UMLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86"
-set SHARED="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared"
-echo Bootstrapping...
-
-set CL=/I"%BASE%\include" /I%UCRT% /I%UM% /I%SHARED% /link /LIBPATH:%UMLIB% /LIBPATH:%ONECORELIB% /LIBPATH:%UCRTLIB%
-set LINK=/LIBPATH:%UMLIB% /LIBPATH:%ONECORELIB% /LIBPATH:%UCRTLIB%
-set LIB=/LIBPATH:%UMLIB% /LIBPATH:%ONECORELIB% /LIBPATH:%UCRTLIB%
-
-:: https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170
-
-:: set INCLUDE="%BASE%\include";%UCRT%;%UM%;%SHARED%
-:: set LIB=
-:: set LIBPATH=%UMLIB%;%ONECORELIB%;%UCRTLIB%
-
-set CXX=cl.exe
-set CC=cl.exe
-set AR=lib.exe
-set LD=link.exe
-cl /nologo /std:c++20 /D_X86_ /EHsc /Isrc src/bootstrap.cc /link /SUBSYSTEM:CONSOLE /out:ctor.exe
-
-set /p DUMMY=Hit ENTER to continue...
-
-ctor.exe
-
-set /p DUMMY=Hit ENTER to continue...
-
-cl /nologo /std:c++20 /D_X86_ /EHsc /Isrc ctor.cc build/libctor.lib /link /SUBSYSTEM:CONSOLE /out:ctor.exe
-
-set /p DUMMY=Hit ENTER to continue...
-
-ctor.exe configure --name ctor.exe --ctor-includedir=src --ctor-libdir=build --cxx=cl.exe --cc=cl.exe --ar=lib.exe --ld=link.exe
-
-set /p DUMMY=!!!!!!!!!!!!!!!!!Hit ENTER to continue...
diff --git a/clbootstrap.sh b/clbootstrap.sh
deleted file mode 100755
index e3a420f..0000000
--- a/clbootstrap.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/bash
-set -e
-set -x
-export WINEDEBUG=-all
-
-rm -f ~/.wine/drive_c/number
-
-export BASE='C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133'
-export ONECORELIB="$BASE\lib\onecore\x86"
-export WINEPATH="$BASE\bin\Hostx86\x86"
-export INCLUDE="$BASE\include"
-export UCRT="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt"
-export UCRTLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86"
-export UM="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um"
-export UMLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86"
-export SHARED="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared"
-echo Bootstrapping...
-
-export CL="/I\"$BASE\include\" /I\"$UCRT\" /I\"$UM\" /I\"$SHARED\" /link /LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-export LINK="/LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-export LIB="/LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-
-# https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170
-
-# set INCLUDE="$BASE\include";$UCRT;$UM;$SHARED
-# set LIB=
-# set LIBPATH=$UMLIB;$ONECORELIB;$UCRTLIB
-
-rm -Rf ctor.exe build/ configuration.cc
-
-export CXX="cl.exe"
-export CC="cl.exe"
-export AR="lib.exe"
-export LD="link.exe"
-wine cl /nologo /std:c++20 /D_X86_ /EHsc /Isrc src/bootstrap.cc /link /SUBSYSTEM:CONSOLE /out:ctor.exe
-
-#echo -e "\n\n\nHit ENTER to continue...\n\n\n"; read
-
-wine ctor.exe
-
-#echo -e "\n\n\nHit ENTER to continue...\n\n\n"; read
-
-wine cl /nologo /std:c++20 /D_X86_ /EHsc /Isrc ctor.cc build/libctor.lib /link /SUBSYSTEM:CONSOLE /out:ctor.exe
-
-#echo -e "\n\n\nHit ENTER to continue...\n\n\n"; read
-
-wine ctor.exe configure --ctor-includedir=src --ctor-libdir=build --cxx=cl.exe --cc=cl.exe --ar=lib.exe --ld=link.exe
-
-#echo -e "\n\n\nHit ENTER to continue...\n\n\n"; read
-
diff --git a/clrun.sh b/clrun.sh
deleted file mode 100755
index e920372..0000000
--- a/clrun.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-set -e
-set -x
-export WINEDEBUG=-all
-
-rm -f ~/.wine/drive_c/number
-
-export BASE='C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133'
-export ONECORELIB="$BASE\lib\onecore\x86"
-export WINEPATH="$BASE\bin\Hostx86\x86"
-export INCLUDE="$BASE\include"
-export UCRT="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt"
-export UCRTLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86"
-export UM="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um"
-export UMLIB="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86"
-export SHARED="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared"
-
-export CL="/I\"$BASE\include\" /I\"$UCRT\" /I\"$UM\" /I\"$SHARED\" /link /LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-export LINK="/LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-export LIB="/LIBPATH:\"$UMLIB\" /LIBPATH:\"$ONECORELIB\" /LIBPATH:\"$UCRTLIB\""
-wine ctor.exe
-
diff --git a/ctor.cc b/ctor.cc
index baf22c1..445f18a 100644
--- a/ctor.cc
+++ b/ctor.cc
@@ -11,7 +11,7 @@ BuildConfigurations ctorConfigs(const Settings& settings)
{
{
.type = TargetType::StaticLibrary,
- .target = "libctor.lib",
+ .target = "libctor.a",
.sources = {
"src/build.cc",
"src/configure.cc",
@@ -29,30 +29,15 @@ BuildConfigurations ctorConfigs(const Settings& settings)
"src/tools.cc",
"src/util.cc",
"src/unittest.cc",
- "getopt-for-windows/getopt.c",
},
.flags = {
.cxxflags = {
- "/std:c++20",
-// "/O2",
-// "/Wall",
-// "/WX",
- "/Isrc",
- "/nologo",
- "/EHsc",
- "/D_X86_",
- "/Igetopt-for-windows",
- },
- .cflags = {
- "/std:c++20",
-// "/O2",
-// "/Wall",
-// "/WX",
- "/Isrc",
- "/nologo",
- "/EHsc",
- "/D_X86_",
- "/Igetopt-for-windows",
+ "-std=c++20",
+ "-O3",
+ "-g",
+ "-Wall",
+ "-Werror",
+ "-Isrc",
},
},
}
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()
diff --git a/src/task.h b/src/task.h
index 0e2a9f7..be3995f 100644
--- a/src/task.h
+++ b/src/task.h
@@ -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 {};
diff --git a/test/ctor.cc b/test/ctor.cc
index 9a6ec91..9b690a2 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -19,16 +19,11 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
},
.flags = {
.cxxflags = {
- "/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src", "/Iuunit",
- "/Isrc", "/Itest/uunit",
- "/DOUTPUT=\\\"execute\\\"",
- "/nologo",
- "/EHsc",
- "/D_X86_",
+ "-std=c++20", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"execute\"",
},
- //.ldflags = { "/pthread" },
- .ldflags = { "/nologo" },
+ .ldflags = { "-pthread" },
},
},
{
@@ -38,19 +33,14 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
"tasks_test.cc",
"testmain.cc",
},
- .depends = { "libctor_nomain.lib" },
+ .depends = { "libctor_nomain.a" },
.flags = {
.cxxflags = {
- "/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src", "/Iuunit",
- "/Isrc", "/Itest/uunit",
- "/DOUTPUT=\\\"tasks\\\"",
- "/nologo",
- "/EHsc",
- "/D_X86_",
+ "-std=c++20", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"tasks\"",
},
- //.ldflags = { "/pthread" },
- .ldflags = { "/nologo" },
+ .ldflags = { "-pthread" },
},
},
{
@@ -60,19 +50,14 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
"source_type_test.cc",
"testmain.cc",
},
- .depends = { "libctor_nomain.lib" },
+ .depends = { "libctor_nomain.a" },
.flags = {
.cxxflags = {
- "/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src", "/Iuunit",
- "/Isrc", "/Itest/uunit",
- "/DOUTPUT=\\\"source_type\\\"",
- "/nologo",
- "/EHsc",
- "/D_X86_",
+ "-std=c++20", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"source_type\"",
},
- //.ldflags = { "/pthread" },
- .ldflags = { "/nologo" },
+ .ldflags = { "-pthread" },
},
},
{
@@ -86,20 +71,15 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
//.depends = { "libctor_nomain.a" },
.flags = {
.cxxflags = {
- "/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src", "/Iuunit",
- "/Isrc", "/Itest/uunit",
- "/DOUTPUT=\\\"tools\\\"",
- "/nologo",
- "/EHsc",
- "/D_X86_",
+ "-std=c++20", "-O3", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"tools\"",
},
- .ldflags = { "/nologo" },
},
},
{
.type = TargetType::UnitTestLib,
- .target = "libctor_nomain.lib",
+ .target = "libctor_nomain.a",
.sources = {
"../src/build.cc",
"../src/configure.cc",
@@ -115,29 +95,13 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
"../src/tools.cc",
"../src/util.cc",
"../src/externals_manual.cc",
- "../getopt-for-windows/getopt.c",
},
.flags = {
.cxxflags = {
- "/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src",
- "/Isrc",
- "/nologo",
- "/EHsc",
- "/D_X86_",
- "/Igetopt-for-windows",
+ "-std=c++20", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src",
},
- .cflags = {
- //"/std:c++20", "/O2",// "/Wall",// "/WX",
- "/I../src",
- "/Isrc",
- "/nologo",
- "/EHsc",
- "/D_X86_",
- "/Igetopt-for-windows",
- },
- //.ldflags = { "/pthread" },
- .ldflags = { "/nologo" },
+ .ldflags = { "-pthread" },
},
},
};
diff --git a/test/execute_test.cc b/test/execute_test.cc
index 739156f..9da18dc 100644
--- a/test/execute_test.cc
+++ b/test/execute_test.cc
@@ -13,9 +13,9 @@ public:
void runit()
{
- uUNIT_ASSERT_EQUAL(0, execute("/bin/true", {}, {}, false));
- uUNIT_ASSERT_EQUAL(1, execute("/bin/false", {}, {}, false));
- uUNIT_ASSERT_EQUAL(1, execute("no-such-binary", {}, {}, false));
+ uASSERT_EQUAL(0, execute("/bin/true", {}, false));
+ uASSERT_EQUAL(1, execute("/bin/false", {}, false));
+ uASSERT_EQUAL(1, execute("no-such-binary", {}, false));
}
};
diff --git a/test/source_type_test.cc b/test/source_type_test.cc
index c4d12e3..ed7e783 100644
--- a/test/source_type_test.cc
+++ b/test/source_type_test.cc
@@ -50,22 +50,22 @@ public:
{
{ // c++
TestableTaskCC task("hello.cc");
- uUNIT_ASSERT_EQUAL(Language::Cpp, task.language());
+ uASSERT_EQUAL(Language::Cpp, task.language());
}
{ // c
TestableTaskCC task("hello.c");
- uUNIT_ASSERT_EQUAL(Language::C, task.language());
+ uASSERT_EQUAL(Language::C, task.language());
}
{ // asm
TestableTaskCC task("hello.s");
- uUNIT_ASSERT_EQUAL(Language::Asm, task.language());
+ uASSERT_EQUAL(Language::Asm, task.language());
}
{ // custom/explicit language
TestableTaskCC task( {"hello.foo", Language::Asm} );
- uUNIT_ASSERT_EQUAL(Language::Asm, task.language());
+ uASSERT_EQUAL(Language::Asm, task.language());
}
// Note: Failure state will result in exit(1) so cannot be tested
diff --git a/test/tasks_test.cc b/test/tasks_test.cc
index f74ef37..2e0ffc7 100644
--- a/test/tasks_test.cc
+++ b/test/tasks_test.cc
@@ -93,17 +93,17 @@ public:
using namespace std::string_literals;
Settings settings{};
const auto& targets = getTargets(settings);
- uUNIT_ASSERT_EQUAL(4u, targets.size());
+ uASSERT_EQUAL(4u, targets.size());
- uUNIT_ASSERT_EQUAL("target1"s, targets[0].config.target);
- uUNIT_ASSERT_EQUAL("target2"s, targets[1].config.target);
- uUNIT_ASSERT_EQUAL("target3"s, targets[2].config.target);
- uUNIT_ASSERT_EQUAL("target4"s, targets[3].config.target);
+ uASSERT_EQUAL("target1"s, targets[0].config.target);
+ uASSERT_EQUAL("target2"s, targets[1].config.target);
+ uASSERT_EQUAL("target3"s, targets[2].config.target);
+ uASSERT_EQUAL("target4"s, targets[3].config.target);
- uUNIT_ASSERT_EQUAL("test"s, targets[0].path);
- uUNIT_ASSERT_EQUAL("test"s, targets[1].path);
- uUNIT_ASSERT_EQUAL("test"s, targets[2].path);
- uUNIT_ASSERT_EQUAL("test"s, targets[3].path);
+ uASSERT_EQUAL("test"s, targets[0].path);
+ uASSERT_EQUAL("test"s, targets[1].path);
+ uASSERT_EQUAL("test"s, targets[2].path);
+ uASSERT_EQUAL("test"s, targets[3].path);
}
void getTasks_test()
@@ -112,27 +112,27 @@ public:
Settings settings{ .builddir = "foo" };
{
auto tasks = getTasks(settings);
- uUNIT_ASSERT_EQUAL(6u, tasks.size());
+ uASSERT_EQUAL(6u, tasks.size());
// Note: count() is used here because the order of
// std::set<std::shared_ptr<T>> is not deterministic.
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target1"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target2"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target3"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target4"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s));
+ uASSERT_EQUAL(1u, count(tasks, "target1"s));
+ uASSERT_EQUAL(1u, count(tasks, "target2"s));
+ uASSERT_EQUAL(1u, count(tasks, "target3"s));
+ uASSERT_EQUAL(1u, count(tasks, "target4"s));
+ uASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s));
+ uASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s));
}
{
auto tasks = getTasks(settings, {"target1", "target3"});
- uUNIT_ASSERT_EQUAL(4u, tasks.size());
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target1"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "target3"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s));
- uUNIT_ASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s));
+ uASSERT_EQUAL(4u, tasks.size());
+ uASSERT_EQUAL(1u, count(tasks, "target1"s));
+ uASSERT_EQUAL(1u, count(tasks, "target3"s));
+ uASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s));
+ uASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s));
}
{
auto tasks = getTasks(settings, {"no-such-target"});
- uUNIT_ASSERT_EQUAL(0u, tasks.size());
+ uASSERT_EQUAL(0u, tasks.size());
}
}
@@ -147,10 +147,10 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(nullptr, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(nullptr, getNextTask(allTasks, dirtyTasks));
}
{ // Zero (One task, no dirty)
@@ -163,10 +163,10 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(nullptr, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(nullptr, getNextTask(allTasks, dirtyTasks));
}
{ // One (One task, one dirty)
@@ -180,11 +180,11 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(task1, getNextTask(allTasks, dirtyTasks));
- uUNIT_ASSERT_EQUAL(0u, dirtyTasks.size());
+ uASSERT_EQUAL(task1, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(0u, dirtyTasks.size());
}
{ // One (Two tasks, one dirty)
@@ -200,11 +200,11 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(task2, getNextTask(allTasks, dirtyTasks));
- uUNIT_ASSERT_EQUAL(0u, dirtyTasks.size());
+ uASSERT_EQUAL(task2, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(0u, dirtyTasks.size());
}
{ // One (Two tasks, one dirty which depends on the other)
@@ -222,11 +222,11 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(task2, getNextTask(allTasks, dirtyTasks));
- uUNIT_ASSERT_EQUAL(0u, dirtyTasks.size());
+ uASSERT_EQUAL(task2, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(0u, dirtyTasks.size());
}
{ // One (Two tasks, Both dirty, one depends on the other)
@@ -245,11 +245,11 @@ public:
for(auto& task : dirtyTasks)
{
- uUNIT_ASSERT_EQUAL(0, task->registerDepTasks(allTasks));
+ uASSERT_EQUAL(0, task->registerDepTasks(allTasks));
}
- uUNIT_ASSERT_EQUAL(task1, getNextTask(allTasks, dirtyTasks));
- uUNIT_ASSERT_EQUAL(1u, dirtyTasks.size());
+ uASSERT_EQUAL(task1, getNextTask(allTasks, dirtyTasks));
+ uASSERT_EQUAL(1u, dirtyTasks.size());
}
}
diff --git a/test/tools_test.cc b/test/tools_test.cc
index 4000665..3e9de1b 100644
--- a/test/tools_test.cc
+++ b/test/tools_test.cc
@@ -116,41 +116,41 @@ public:
{
// host
conf_host_cxx = "/usr/bin/g++";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
conf_host_cxx = "/usr/bin/g++-10";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
conf_host_cxx = "/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Host));
conf_host_cxx = "/usr/bin/clang++";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
conf_host_cxx = "/usr/bin/clang++-10";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
conf_host_cxx = "/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Host));
// build
conf_build_cxx = "/usr/bin/g++";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
conf_build_cxx = "/usr/bin/g++-10";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
conf_build_cxx = "/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0";
- uUNIT_ASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::gcc, getToolChain(OutputSystem::Build));
conf_build_cxx = "/usr/bin/clang++";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
conf_build_cxx = "/usr/bin/clang++-10";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
conf_build_cxx = "/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12";
- uUNIT_ASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
+ uASSERT_EQUAL(ToolChain::clang, getToolChain(OutputSystem::Build));
}
void getOption_toolchain_test()