summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-14 12:05:23 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-14 12:10:58 +0100
commit321f25af1ba33d8409cd294b4f50d0d3e79cf3bd (patch)
tree586c8297ca89e477ae8dfc228dd71f0b15f96faa
parentd5c88fedf517e738490c32fa95097e03178903fe (diff)
Add ar_flag support for ar tool, replacing hardcoded values.HEADmaster
-rw-r--r--src/ctor.h5
-rw-r--r--src/task_ar.cc8
-rw-r--r--src/tools.cc18
-rw-r--r--test/tools_test.cc40
4 files changed, 65 insertions, 6 deletions
diff --git a/src/ctor.h b/src/ctor.h
index 36aa46a..b8b3ae6 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -120,6 +120,11 @@ enum class ld_opt
enum class ar_opt
{
// gcc/clang
+ replace, // -r
+ add_index, // -s
+ create, // -c
+ output, // <arg>
+
custom, // entire option taken verbatim from <arg>
};
diff --git a/src/task_ar.cc b/src/task_ar.cc
index 81ced0f..426a576 100644
--- a/src/task_ar.cc
+++ b/src/task_ar.cc
@@ -78,9 +78,13 @@ bool TaskAR::dirtyInner()
int TaskAR::runInner()
{
+ auto toolchain = getToolChain(config.system);
+
std::vector<std::string> args;
- args.push_back("rcs");
- args.push_back(targetFile().string());
+ append(args, ar_option(toolchain, ctor::ar_opt::replace));
+ append(args, ar_option(toolchain, ctor::ar_opt::add_index));
+ append(args, ar_option(toolchain, ctor::ar_opt::create));
+ append(args, ar_option(toolchain, ctor::ar_opt::output, targetFile().string()));
for(const auto& task : getDependsTasks())
{
args.push_back(task->targetFile().string());
diff --git a/src/tools.cc b/src/tools.cc
index 476386b..28d3903 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -80,6 +80,10 @@ std::ostream& operator<<(std::ostream& stream, const ctor::ar_opt& opt)
// Adding to this enum should also imply adding to the unit-tests below
switch(opt)
{
+ case ctor::ar_opt::replace: stream << "ctor::ar_opt::replace"; break;
+ case ctor::ar_opt::add_index: stream << "ctor::ar_opt::add_index"; break;
+ case ctor::ar_opt::create: stream << "ctor::ar_opt::create"; break;
+ case ctor::ar_opt::output: stream << "ctor::ar_opt::output"; break;
case ctor::ar_opt::custom: stream << "ctor::ar_opt::custom"; break;
}
@@ -174,6 +178,11 @@ ctor::ld_flag ld_option(const std::string& flag)
return { ctor::ld_opt::custom, flag };
}
+ctor::ar_flag ar_option(const std::string& flag)
+{
+ return { ctor::ar_opt::custom, flag };
+}
+
std::vector<std::string> cxx_option(ctor::cxx_opt opt, const std::string& arg)
{
switch(opt)
@@ -280,6 +289,14 @@ std::vector<std::string> ar_option(ctor::ar_opt opt, const std::string& arg)
{
switch(opt)
{
+ case ctor::ar_opt::replace:
+ return {"-r"};
+ case ctor::ar_opt::add_index:
+ return {"-s"};
+ case ctor::ar_opt::create:
+ return {"-c"};
+ case ctor::ar_opt::output:
+ return {arg};
case ctor::ar_opt::custom:
return {arg};
}
@@ -494,6 +511,7 @@ ctor::ar_flag ar_option(const std::string& flag, ctor::toolchain toolchain)
{
case ctor::toolchain::gcc:
case ctor::toolchain::clang:
+ return gcc::ar_option(flag);
case ctor::toolchain::any:
case ctor::toolchain::none:
break;
diff --git a/test/tools_test.cc b/test/tools_test.cc
index 1d377b7..7127b8d 100644
--- a/test/tools_test.cc
+++ b/test/tools_test.cc
@@ -666,22 +666,54 @@ public:
//
// gcc
//
+ exp = { "-r" };
+ act = ar_option(ctor::toolchain::gcc, ctor::ar_opt::replace);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-s" };
+ act = ar_option(ctor::toolchain::gcc, ctor::ar_opt::add_index);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-c" };
+ act = ar_option(ctor::toolchain::gcc, ctor::ar_opt::create);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "foo" };
+ act = ar_option(ctor::toolchain::gcc, ctor::ar_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
exp = { "-foo" };
- act = asm_option(ctor::toolchain::gcc, ctor::asm_opt::custom, "-foo");
+ act = ar_option(ctor::toolchain::gcc, ctor::ar_opt::custom, "-foo");
uASSERT_EQUAL(exp, act);
//
// clang
//
+ exp = { "-r" };
+ act = ar_option(ctor::toolchain::clang, ctor::ar_opt::replace);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-s" };
+ act = ar_option(ctor::toolchain::clang, ctor::ar_opt::add_index);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-c" };
+ act = ar_option(ctor::toolchain::clang, ctor::ar_opt::create);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "foo" };
+ act = ar_option(ctor::toolchain::clang, ctor::ar_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
exp = { "-foo" };
- act = asm_option(ctor::toolchain::clang, ctor::asm_opt::custom, "-foo");
+ act = ar_option(ctor::toolchain::clang, ctor::ar_opt::custom, "-foo");
uASSERT_EQUAL(exp, act);
//
// any
//
- exp = { "{ctor::asm_opt::custom, \"-foo\"}" };
- act = asm_option(ctor::toolchain::any, ctor::asm_opt::custom, "-foo");
+ exp = { "{ctor::ar_opt::custom, \"-foo\"}" };
+ act = ar_option(ctor::toolchain::any, ctor::ar_opt::custom, "-foo");
uASSERT_EQUAL(exp, act);
}