diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-11-06 11:05:45 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-11-06 11:05:45 +0100 |
commit | dbd68011363b01f22ab85e11ad52a8e90da9611a (patch) | |
tree | 6d1bec44119ab3fa99ace9298f0ac3575fcdc15a | |
parent | 92cc25c10bcba1f14cbf28bd0298311b8e81a2ea (diff) |
Use std::source_location instead of __FILE__.
-rw-r--r-- | src/libctor.cc | 2 | ||||
-rw-r--r-- | src/libctor.h | 10 | ||||
-rw-r--r-- | src/rebuild.cc | 33 | ||||
-rw-r--r-- | src/rebuild.h | 2 |
4 files changed, 34 insertions, 13 deletions
diff --git a/src/libctor.cc b/src/libctor.cc index c752192..1fe1298 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -200,7 +200,7 @@ Options: no_default_build = true; for(const auto& add_file : add_files) { - reg(add_file.data(), [](){ return std::vector<BuildConfiguration>{};}); + reg(add_file.data()); } for(const auto& remove_file : remove_files) diff --git a/src/libctor.h b/src/libctor.h index 2a10c53..6d3becf 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -3,6 +3,7 @@ // See accompanying file LICENSE for details. #pragma once +#include <source_location> #include <string> #include <vector> #include <map> @@ -61,7 +62,9 @@ struct BuildConfiguration using BuildConfigurations = std::vector<BuildConfiguration>; -int reg(const char* location, BuildConfigurations (*cb)()); +int reg(BuildConfigurations (*cb)(), + const std::source_location location = std::source_location::current()); + struct ExternalConfiguration { @@ -74,13 +77,14 @@ struct ExternalConfiguration using ExternalConfigurations = std::vector<ExternalConfiguration>; -int reg(const char* location, ExternalConfigurations (*cb)()); +int reg(ExternalConfigurations (*cb)(), + const std::source_location location = std::source_location::current()); // Convenience macro - ugly but keeps things simple(r) #define CONCAT(a, b) CONCAT_INNER(a, b) #define CONCAT_INNER(a, b) a ## b #define UNIQUE_NAME(base) CONCAT(base, __LINE__) -#define REG(cb) namespace { int UNIQUE_NAME(unique) = reg(__FILE__, cb); } +#define REG(cb) namespace { int UNIQUE_NAME(unique) = reg(cb); } // Predefined configuration keys namespace cfg diff --git a/src/rebuild.cc b/src/rebuild.cc index a03f5e3..fc95b16 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -6,6 +6,7 @@ #include <iostream> #include <filesystem> #include <algorithm> +#include <source_location> #include "configure.h" #include "settings.h" @@ -16,9 +17,8 @@ std::array<BuildConfigurationEntry, 1024> configFiles; std::size_t numConfigFiles{0}; -// TODO: Use c++20 when ready, somehing like this: -//int reg(const std::source_location location = std::source_location::current()) -int reg(const char* location, std::vector<BuildConfiguration> (*cb)()) +int reg(std::vector<BuildConfiguration> (*cb)(), + const std::source_location location) { // NOTE: std::cout cannot be used here if(numConfigFiles >= configFiles.size()) @@ -28,13 +28,31 @@ int reg(const char* location, std::vector<BuildConfiguration> (*cb)()) exit(1); } - configFiles[numConfigFiles].file = location; + configFiles[numConfigFiles].file = location.file_name(); configFiles[numConfigFiles].cb = cb; ++numConfigFiles; return 0; } +int reg(const char* location) +{ + // NOTE: std::cout cannot be used here + if(numConfigFiles >= configFiles.size()) + { + fprintf(stderr, "Max %d build configurations currently supported.\n", + (int)configFiles.size()); + exit(1); + } + + configFiles[numConfigFiles].file = location; + configFiles[numConfigFiles].cb = + [](){ return std::vector<BuildConfiguration>{}; }; + ++numConfigFiles; + + return 0; +} + int unreg(const char* location) { std::size_t found{0}; @@ -78,9 +96,8 @@ int unreg(const char* location) std::array<ExternalConfigurationEntry, 1024> externalConfigFiles; std::size_t numExternalConfigFiles{0}; -// TODO: Use c++20 when ready, somehing like this: -//int reg(const std::source_location location = std::source_location::current()) -int reg(const char* location, std::vector<ExternalConfiguration> (*cb)()) +int reg(std::vector<ExternalConfiguration> (*cb)(), + const std::source_location location) { // NOTE: std::cout cannot be used here if(numExternalConfigFiles >= externalConfigFiles.size()) @@ -90,7 +107,7 @@ int reg(const char* location, std::vector<ExternalConfiguration> (*cb)()) exit(1); } - externalConfigFiles[numExternalConfigFiles].file = location; + externalConfigFiles[numExternalConfigFiles].file = location.file_name(); externalConfigFiles[numExternalConfigFiles].cb = cb; ++numExternalConfigFiles; diff --git a/src/rebuild.h b/src/rebuild.h index 020df6b..f14236e 100644 --- a/src/rebuild.h +++ b/src/rebuild.h @@ -28,7 +28,7 @@ extern std::size_t numConfigFiles; extern std::array<ExternalConfigurationEntry, 1024> externalConfigFiles; extern std::size_t numExternalConfigFiles; -//int reg(const char* location, std::vector<BuildConfiguration> (*cb)()); +int reg(const char* location); int unreg(const char* location); void recompileCheck(const Settings& settings, int argc, char* argv[], |