summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-10 16:00:36 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-11 17:13:24 +0100
commit1484d74c1dfd24cfe5b6f13f76d58ff395e4d253 (patch)
tree2f71f2aa6d6dd29eda51924f985de7f9caee78c0 /src
parentf31661d392c1332ceb0edcbc9fd35f4cb49bb50d (diff)
Put ctor.h contents in ctor namespace.
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap.cc10
-rw-r--r--src/build.cc2
-rw-r--r--src/build.h8
-rw-r--r--src/configure.cc11
-rw-r--r--src/configure.h6
-rw-r--r--src/ctor.h4
-rw-r--r--src/externals_manual.cc2
-rw-r--r--src/externals_manual.h7
-rw-r--r--src/libctor.cc2
-rw-r--r--src/rebuild.cc6
-rw-r--r--src/rebuild.h6
-rw-r--r--src/task.cc2
-rw-r--r--src/task.h22
-rw-r--r--src/task_ar.cc2
-rw-r--r--src/task_ar.h11
-rw-r--r--src/task_cc.cc2
-rw-r--r--src/task_cc.h15
-rw-r--r--src/task_fn.cc2
-rw-r--r--src/task_fn.h13
-rw-r--r--src/task_ld.cc2
-rw-r--r--src/task_ld.h11
-rw-r--r--src/task_so.cc2
-rw-r--r--src/task_so.h11
-rw-r--r--src/tasks.cc2
-rw-r--r--src/tasks.h13
-rw-r--r--src/tools.cc2
-rw-r--r--src/tools.h2
-rw-r--r--src/unittest.cc2
-rw-r--r--src/unittest.h5
-rw-r--r--src/util.cc2
-rw-r--r--src/util.h2
31 files changed, 110 insertions, 79 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc
index d473689..3a73cc6 100644
--- a/src/bootstrap.cc
+++ b/src/bootstrap.cc
@@ -22,8 +22,9 @@
std::filesystem::path configurationFile("configuration.cc");
std::filesystem::path configHeaderFile("config.h");
-const Configuration default_configuration{};
-const Configuration& configuration()
+namespace ctor {
+const ctor::Configuration default_configuration{};
+const ctor::Configuration& configuration()
{
return default_configuration;
}
@@ -50,6 +51,7 @@ const std::string& getConfiguration(const std::string& key,
return defaultValue;
}
+} // namespace ctor::
int main(int argc, char* argv[])
{
@@ -60,9 +62,9 @@ int main(int argc, char* argv[])
return 1;
}
- Settings settings{};
+ ctor::Settings settings{};
- settings.builddir = getConfiguration(cfg::builddir, settings.builddir);
+ settings.builddir = ctor::getConfiguration(cfg::builddir, settings.builddir);
settings.parallel_processes =
std::max(1u, std::thread::hardware_concurrency() * 2 - 1);
settings.verbose = 0;
diff --git a/src/build.cc b/src/build.cc
index 5ea1a13..ab520d2 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -13,6 +13,8 @@
#include "ctor.h"
+using namespace ctor;
+
using namespace std::chrono_literals;
int build(const Settings& settings,
diff --git a/src/build.h b/src/build.h
index caf7a68..97bcfc6 100644
--- a/src/build.h
+++ b/src/build.h
@@ -10,23 +10,25 @@
#include "task.h"
#include "tasks.h"
+namespace ctor {
struct Settings;
+} // namespace ctor::
//! Dry-run returns number of dirty tasks but otherwise does nothing.
-int build(const Settings& settings,
+int build(const ctor::Settings& settings,
const std::string& name,
const std::set<std::shared_ptr<Task>>& tasks,
const std::set<std::shared_ptr<Task>>& all_tasks,
bool dryrun = false);
//! Dry-run returns number of dirty tasks but otherwise does nothing.
-int build(const Settings& settings,
+int build(const ctor::Settings& settings,
const std::string& name,
const std::set<std::shared_ptr<Task>>& all_tasks,
bool dryrun = false);
//! Dry-run returns number of dirty tasks but otherwise does nothing.
-int build(const Settings& settings,
+int build(const ctor::Settings& settings,
const std::string& name,
const std::vector<Target>& targets,
const std::set<std::shared_ptr<Task>>& all_tasks,
diff --git a/src/configure.cc b/src/configure.cc
index 25403f7..28049ae 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -16,25 +16,25 @@
#include "rebuild.h"
#include "externals.h"
+using namespace ctor;
+
std::filesystem::path configurationFile("configuration.cc");
std::filesystem::path configHeaderFile("config.h");
std::map<std::string, std::string> external_includedir;
std::map<std::string, std::string> external_libdir;
+namespace ctor {
const Configuration default_configuration{};
const Configuration& __attribute__((weak)) configuration()
{
return default_configuration;
}
-namespace ctor
-{
std::optional<std::string> includedir;
std::optional<std::string> libdir;
std::optional<std::string> builddir;
std::map<std::string, std::string> conf_values;
-}
bool hasConfiguration(const std::string& key)
{
@@ -93,6 +93,7 @@ const std::string& getConfiguration(const std::string& key,
return defaultValue;
}
+} // namespace ctor::
std::string locate(const std::string& arch, const std::string& app)
{
@@ -419,6 +420,7 @@ int regenerateCache(Settings& settings,
{
std::ofstream istr(configurationFile);
istr << "#include <ctor.h>\n\n";
+ istr << "namespace ctor {\n";
istr << "const Configuration& configuration()\n";
istr << "{\n";
istr << " static Configuration cfg =\n";
@@ -528,7 +530,8 @@ int regenerateCache(Settings& settings,
istr << " },\n";
istr << " };\n";
istr << " return cfg;\n";
- istr << "}\n\n";
+ istr << "}\n";
+ istr << "} // namespace ctor::\n\n";
}
{
diff --git a/src/configure.h b/src/configure.h
index 16499d6..cc20707 100644
--- a/src/configure.h
+++ b/src/configure.h
@@ -8,10 +8,12 @@
#include <map>
#include <vector>
+namespace ctor {
struct Settings;
+} // namespace ctor::
extern std::filesystem::path configurationFile;;
extern std::filesystem::path configHeaderFile;
-int configure(const Settings& settings, int argc, char* argv[]);
-int reconfigure(const Settings& settings, int argc, char* argv[]);
+int configure(const ctor::Settings& settings, int argc, char* argv[]);
+int reconfigure(const ctor::Settings& settings, int argc, char* argv[]);
diff --git a/src/ctor.h b/src/ctor.h
index 96e1115..9770c09 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -11,6 +11,8 @@
#include <cstddef>
#include <functional>
+namespace ctor {
+
enum class TargetType
{
Auto, // Default - deduce from target name and sources extensions
@@ -152,3 +154,5 @@ const Configuration& configuration();
bool hasConfiguration(const std::string& key);
const std::string& getConfiguration(const std::string& key,
const std::string& defaultValue = {});
+
+} // namespace ctor::
diff --git a/src/externals_manual.cc b/src/externals_manual.cc
index 3f00698..4c1c540 100644
--- a/src/externals_manual.cc
+++ b/src/externals_manual.cc
@@ -10,6 +10,8 @@
#include "util.h"
#include "tools.h"
+using namespace ctor;
+
extern std::map<std::string, std::string> external_includedir;
extern std::map<std::string, std::string> external_libdir;
diff --git a/src/externals_manual.h b/src/externals_manual.h
index 7bd968d..422f279 100644
--- a/src/externals_manual.h
+++ b/src/externals_manual.h
@@ -3,10 +3,13 @@
// See accompanying file LICENSE for details.
#pragma once
+namespace ctor {
struct Settings;
struct ExternalConfiguration;
struct ExternalManual;
struct Flags;
+} // namespace ctor::
-int resolv(const Settings& settings, const ExternalConfiguration& name,
- const ExternalManual& ext, Flags& flags);
+int resolv(const ctor::Settings& settings,
+ const ctor::ExternalConfiguration& name,
+ const ctor::ExternalManual& ext, ctor::Flags& flags);
diff --git a/src/libctor.cc b/src/libctor.cc
index 45fc94d..83002db 100644
--- a/src/libctor.cc
+++ b/src/libctor.cc
@@ -26,6 +26,8 @@
#include "build.h"
#include "unittest.h"
+using namespace ctor;
+
int main(int argc, char* argv[])
{
Settings settings{};
diff --git a/src/rebuild.cc b/src/rebuild.cc
index 7155984..c40a18c 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -17,9 +17,12 @@
#include "tools.h"
#include "util.h"
+using namespace ctor;
+
std::array<BuildConfigurationEntry, 1024> configFiles;
std::size_t numConfigFiles{0};
+namespace ctor {
int reg(BuildConfigurations (*cb)(const Settings&),
const std::source_location location)
{
@@ -47,6 +50,7 @@ int reg(BuildConfigurations (*cb)(const Settings&),
return 0;
}
+} // namespace ctor::
int reg(const char* location)
{
@@ -109,6 +113,7 @@ int unreg(const char* location)
std::array<ExternalConfigurationEntry, 1024> externalConfigFiles;
std::size_t numExternalConfigFiles{0};
+namespace ctor {
int reg(ExternalConfigurations (*cb)(const Settings&),
const std::source_location location)
{
@@ -126,6 +131,7 @@ int reg(ExternalConfigurations (*cb)(const Settings&),
return 0;
}
+} // namespace ctor::
namespace
{
diff --git a/src/rebuild.h b/src/rebuild.h
index 284aeb2..6d0f6a8 100644
--- a/src/rebuild.h
+++ b/src/rebuild.h
@@ -11,13 +11,13 @@
struct BuildConfigurationEntry
{
const char* file;
- BuildConfigurations (*cb)(const Settings&);
+ ctor::BuildConfigurations (*cb)(const ctor::Settings&);
};
struct ExternalConfigurationEntry
{
const char* file;
- ExternalConfigurations (*cb)(const Settings&);
+ ctor::ExternalConfigurations (*cb)(const ctor::Settings&);
};
extern std::array<BuildConfigurationEntry, 1024> configFiles;
@@ -30,5 +30,5 @@ int reg(const char* location);
int unreg(const char* location);
//! Returns true of recompilation was needed.
-bool recompileCheck(const Settings& settings, int argc, char* argv[],
+bool recompileCheck(const ctor::Settings& settings, int argc, char* argv[],
bool relaunch_allowed = true);
diff --git a/src/task.cc b/src/task.cc
index fb50765..5e3bbb8 100644
--- a/src/task.cc
+++ b/src/task.cc
@@ -6,6 +6,8 @@
#include <unistd.h>
#include <iostream>
+using namespace ctor;
+
Task::Task(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir)
: config(config)
diff --git a/src/task.h b/src/task.h
index 4efbfff..b4f37a5 100644
--- a/src/task.h
+++ b/src/task.h
@@ -21,12 +21,10 @@ enum class State
Error,
};
-struct Settings;
-
class Task
{
public:
- Task(const BuildConfiguration& config, const Settings& settings,
+ Task(const ctor::BuildConfiguration& config, const ctor::Settings& settings,
const std::string& sourceDir);
virtual ~Task() = default;
@@ -59,11 +57,11 @@ public:
//! Returns a reference to the originating build config.
//! Note: the build config of a derived task will be that of its parent
//! (target) task.
- const BuildConfiguration& buildConfig() const;
+ const ctor::BuildConfiguration& buildConfig() const;
- TargetType targetType() const;
- Language sourceLanguage() const;
- OutputSystem outputSystem() const;
+ ctor::TargetType targetType() const;
+ ctor::Language sourceLanguage() const;
+ ctor::OutputSystem outputSystem() const;
std::string compiler() const;
std::set<std::shared_ptr<Task>> getDependsTasks();
@@ -77,10 +75,10 @@ protected:
std::vector<std::string> dependsStr;
std::set<std::shared_ptr<Task>> dependsTasks;
- const BuildConfiguration& config;
- TargetType target_type{TargetType::Auto};
- Language source_language{Language::Auto};
- OutputSystem output_system{OutputSystem::Host};
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ ctor::TargetType target_type{ctor::TargetType::Auto};
+ ctor::Language source_language{ctor::Language::Auto};
+ ctor::OutputSystem output_system{ctor::OutputSystem::Host};
+ const ctor::Settings& settings;
std::string sourceDir;
};
diff --git a/src/task_ar.cc b/src/task_ar.cc
index 39a8c6d..024755f 100644
--- a/src/task_ar.cc
+++ b/src/task_ar.cc
@@ -10,6 +10,8 @@
#include "execute.h"
#include "util.h"
+using namespace ctor;
+
TaskAR::TaskAR(const BuildConfiguration& config,
const Settings& settings,
const std::string& target,
diff --git a/src/task_ar.h b/src/task_ar.h
index c76a852..9e8ca8b 100644
--- a/src/task_ar.h
+++ b/src/task_ar.h
@@ -10,15 +10,12 @@
#include <future>
#include <filesystem>
-struct BuildConfiguration;
-struct Settings;
-
class TaskAR
: public Task
{
public:
- TaskAR(const BuildConfiguration& config,
- const Settings& settings,
+ TaskAR(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
const std::string& target,
const std::vector<std::string>& objects,
const std::string& sourceDir);
@@ -44,7 +41,7 @@ private:
std::filesystem::path _targetFile;
std::filesystem::path flagsFile;
- const BuildConfiguration& config;
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ const ctor::Settings& settings;
std::string sourceDir;
};
diff --git a/src/task_cc.cc b/src/task_cc.cc
index 29aeefb..9ec3e01 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -12,6 +12,8 @@
#include "util.h"
#include "tools.h"
+using namespace ctor;
+
TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir, const Source& source)
: Task(config, settings, sourceDir)
diff --git a/src/task_cc.h b/src/task_cc.h
index 0a0d96a..cdde84b 100644
--- a/src/task_cc.h
+++ b/src/task_cc.h
@@ -10,16 +10,13 @@
#include <future>
#include <filesystem>
-struct BuildConfiguration;
-struct Settings;
-
class TaskCC
: public Task
{
public:
- TaskCC(const BuildConfiguration& config,
- const Settings& settings,
- const std::string& sourceDir, const Source& source);
+ TaskCC(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
+ const std::string& sourceDir, const ctor::Source& source);
virtual ~TaskCC() = default;
int registerDepTasksInner(const std::set<std::shared_ptr<Task>>& tasks) override;
@@ -51,8 +48,8 @@ protected:
std::filesystem::path depsFile;
std::filesystem::path flagsFile;
- const BuildConfiguration& config;
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ const ctor::Settings& settings;
std::filesystem::path sourceDir;
- const Source& _source;
+ const ctor::Source& _source;
};
diff --git a/src/task_fn.cc b/src/task_fn.cc
index b8932de..f633704 100644
--- a/src/task_fn.cc
+++ b/src/task_fn.cc
@@ -11,6 +11,8 @@
#include "execute.h"
#include "util.h"
+using namespace ctor;
+
TaskFn::TaskFn(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir, const Source& source)
: Task(config, settings, sourceDir)
diff --git a/src/task_fn.h b/src/task_fn.h
index e350395..654241c 100644
--- a/src/task_fn.h
+++ b/src/task_fn.h
@@ -10,16 +10,13 @@
#include <future>
#include <filesystem>
-struct BuildConfiguration;
-struct Settings;
-
class TaskFn
: public Task
{
public:
- TaskFn(const BuildConfiguration& config,
- const Settings& settings,
- const std::string& sourceDir, const Source& source);
+ TaskFn(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
+ const std::string& sourceDir, const ctor::Source& source);
virtual ~TaskFn() = default;
bool dirtyInner() override;
@@ -41,7 +38,7 @@ protected:
std::filesystem::path sourceFile;
std::filesystem::path _targetFile;
- const BuildConfiguration& config;
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ const ctor::Settings& settings;
std::filesystem::path sourceDir;
};
diff --git a/src/task_ld.cc b/src/task_ld.cc
index 5c27d3f..acd733b 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -11,6 +11,8 @@
#include "util.h"
#include "tools.h"
+using namespace ctor;
+
TaskLD::TaskLD(const BuildConfiguration& config,
const Settings& settings,
const std::string& target,
diff --git a/src/task_ld.h b/src/task_ld.h
index 8625075..8667d65 100644
--- a/src/task_ld.h
+++ b/src/task_ld.h
@@ -10,15 +10,12 @@
#include <future>
#include <filesystem>
-struct BuildConfiguration;
-struct Settings;
-
class TaskLD
: public Task
{
public:
- TaskLD(const BuildConfiguration& config,
- const Settings& settings,
+ TaskLD(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
const std::string& target,
const std::vector<std::string>& objects,
const std::string& _sourceDir);
@@ -44,7 +41,7 @@ private:
std::filesystem::path _targetFile;
std::filesystem::path flagsFile;
- const BuildConfiguration& config;
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ const ctor::Settings& settings;
std::string sourceDir;
};
diff --git a/src/task_so.cc b/src/task_so.cc
index ed4bd18..fc5ef4a 100644
--- a/src/task_so.cc
+++ b/src/task_so.cc
@@ -11,6 +11,8 @@
#include "util.h"
#include "tools.h"
+using namespace ctor;
+
TaskSO::TaskSO(const BuildConfiguration& config,
const Settings& settings,
const std::string& target,
diff --git a/src/task_so.h b/src/task_so.h
index fe5d2fd..a751226 100644
--- a/src/task_so.h
+++ b/src/task_so.h
@@ -10,15 +10,12 @@
#include <future>
#include <filesystem>
-struct BuildConfiguration;
-struct Settings;
-
class TaskSO
: public Task
{
public:
- TaskSO(const BuildConfiguration& config,
- const Settings& settings,
+ TaskSO(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
const std::string& target,
const std::vector<std::string>& objects,
const std::string& sourceDir);
@@ -44,7 +41,7 @@ private:
std::filesystem::path _targetFile;
std::filesystem::path flagsFile;
- const BuildConfiguration& config;
- const Settings& settings;
+ const ctor::BuildConfiguration& config;
+ const ctor::Settings& settings;
std::string sourceDir;
};
diff --git a/src/tasks.cc b/src/tasks.cc
index 12ff399..2d83349 100644
--- a/src/tasks.cc
+++ b/src/tasks.cc
@@ -19,6 +19,8 @@
#include "rebuild.h"
#include "configure.h"
+using namespace ctor;
+
const std::deque<Target>& getTargets(const Settings& settings,
bool resolve_externals)
{
diff --git a/src/tasks.h b/src/tasks.h
index 403a954..26cd757 100644
--- a/src/tasks.h
+++ b/src/tasks.h
@@ -10,17 +10,14 @@
#include "task.h"
-struct BuildConfiguration;
-struct Settings;
-
struct Target
{
- BuildConfiguration config;
+ ctor::BuildConfiguration config;
std::string path;
};
//! Get list of all registered targets
-const std::deque<Target>& getTargets(const Settings& settings,
+const std::deque<Target>& getTargets(const ctor::Settings& settings,
bool resolve_externals = true);
//! Returns next dirty task from the dirtyTasks list that has all its dependencies
@@ -32,12 +29,12 @@ std::shared_ptr<Task> getNextTask(const std::set<std::shared_ptr<Task>>& allTask
//! Get list of tasks filtered by name including each of their direct
//! dependency tasks (ie. objects tasks from their sources).
-std::set<std::shared_ptr<Task>> getTasks(const Settings& settings,
+std::set<std::shared_ptr<Task>> getTasks(const ctor::Settings& settings,
const std::vector<std::string> names = {},
bool resolve_externals = true);
//! Generate list of targets from a single configuration, including the final
//! link target and all its objects files (if any).
-std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
- const Settings& settings,
+std::set<std::shared_ptr<Task>> taskFactory(const ctor::BuildConfiguration& config,
+ const ctor::Settings& settings,
const std::string& sourceDir);
diff --git a/src/tools.cc b/src/tools.cc
index 7e8ac78..f0b6d4e 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -8,6 +8,8 @@
#include <cassert>
+using namespace ctor;
+
ToolChain getToolChain(OutputSystem system)
{
std::string compiler;
diff --git a/src/tools.h b/src/tools.h
index c346cbf..0b5b211 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -37,7 +37,7 @@ enum class opt
};
//! Get tool-chain type from output system (via configuration)
-ToolChain getToolChain(OutputSystem system);
+ToolChain getToolChain(ctor::OutputSystem system);
//! Get tool argument(s) for specific option type matching the supplied
//! tool-chain
diff --git a/src/unittest.cc b/src/unittest.cc
index 942be3e..cceaec7 100644
--- a/src/unittest.cc
+++ b/src/unittest.cc
@@ -8,6 +8,8 @@
#include "execute.h"
#include "task.h"
+using namespace ctor;
+
int runUnitTests(std::set<std::shared_ptr<Task>>& tasks,
const Settings& settings)
{
diff --git a/src/unittest.h b/src/unittest.h
index 5118689..1ea90dd 100644
--- a/src/unittest.h
+++ b/src/unittest.h
@@ -7,7 +7,10 @@
#include <memory>
class Task;
+
+namespace ctor {
struct Settings;
+} // namespace ctor::
int runUnitTests(std::set<std::shared_ptr<Task>>& tasks,
- const Settings& settings);
+ const ctor::Settings& settings);
diff --git a/src/util.cc b/src/util.cc
index 92560b6..47cb5c4 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -6,6 +6,8 @@
#include <iostream>
#include <fstream>
+using namespace ctor;
+
std::string readFile(const std::string& fileName)
{
std::ifstream ifs(fileName.c_str(),
diff --git a/src/util.h b/src/util.h
index 0cb01ce..1b41823 100644
--- a/src/util.h
+++ b/src/util.h
@@ -10,7 +10,7 @@
std::string readFile(const std::string& fileName);
std::vector<std::string> readDeps(const std::string& depFile);
-Language languageFromExtension(const std::filesystem::path& file);
+ctor::Language languageFromExtension(const std::filesystem::path& file);
std::string cleanUp(const std::string& path);
template<typename T>