Sfoglia il codice sorgente

Compiler warning support

default_compile_flags
vector-of-bool 5 anni fa
parent
commit
12cf2b41a2
6 ha cambiato i file con 39 aggiunte e 12 eliminazioni
  1. +5
    -0
      src/dds/build.cpp
  2. +1
    -0
      src/dds/build.hpp
  3. +6
    -0
      src/dds/ddslim.main.cpp
  4. +11
    -4
      src/dds/toolchain.cpp
  5. +11
    -8
      src/dds/toolchain.hpp
  6. +5
    -0
      src/dds/util.hpp

+ 5
- 0
src/dds/build.cpp Vedi File

@@ -111,6 +111,7 @@ fs::path compile_file(fs::path src_path,
spdlog::info("Compile file: {}", fs::relative(src_path, params.root).string());

compile_file_spec spec{src_path, obj_path};
spec.enable_warnings = params.enable_warnings;

spec.include_dirs.push_back(params.root / "src");
spec.include_dirs.push_back(params.root / "include");
@@ -135,6 +136,10 @@ fs::path compile_file(fs::path src_path,
throw compile_failure("Compilation failed.");
}

if (!compile_res.output.empty()) {
spdlog::warn("While compiling file {}:\n{}", spec.source_path.string(), compile_res.output);
}

return obj_path;
}


+ 1
- 0
src/dds/build.hpp Vedi File

@@ -15,6 +15,7 @@ struct build_params {
std::string export_name;
bool do_export = false;
bool build_tests = false;
bool enable_warnings = false;
};

void build(const build_params&, const library_manifest& man);

+ 6
- 0
src/dds/ddslim.main.cpp Vedi File

@@ -52,6 +52,11 @@ struct cli_build {
args::Flag build_tests{cmd, "build_tests", "Build the tests", {"tests"}};
args::Flag export_{cmd, "export_dir", "Generate a library export", {"export", 'E'}};

args::Flag enable_warnings{cmd,
"enable_warnings",
"Enable compiler warnings",
{"--warnings", 'W'}};

int run() {
dds::build_params params;
params.root = lib_dir.Get();
@@ -60,6 +65,7 @@ struct cli_build {
params.export_name = export_name.Get();
params.do_export = export_.Get();
params.build_tests = build_tests.Get();
params.enable_warnings = enable_warnings.Get();
dds::library_manifest man;
const auto man_filepath = params.root / "manifest.dds";
if (exists(man_filepath)) {

+ 11
- 4
src/dds/toolchain.cpp Vedi File

@@ -29,6 +29,7 @@ toolchain toolchain::load_from_file(fs::path p) {
opt_string c_compile_template;
opt_string cxx_compile_template;
opt_string create_archive_template;
opt_string warning_flags;

opt_string archive_suffix;

@@ -64,6 +65,7 @@ toolchain toolchain::load_from_file(fs::path p) {
|| try_single("Compile-C++-Template", cxx_compile_template)
|| try_single("Create-Archive-Template", create_archive_template)
|| try_single("Archive-Suffix", archive_suffix)
|| try_single("Warning-Flags", warning_flags)
|| false;
// clang-format on

@@ -88,6 +90,7 @@ toolchain toolchain::load_from_file(fs::path p) {
def_template.value(),
create_archive_template.value(),
archive_suffix.value(),
warning_flags.value_or(""),
};
}

@@ -183,18 +186,22 @@ vector<string> toolchain::create_compile_command(const compile_file_spec& spec)

for (auto&& inc_dir : spec.include_dirs) {
auto inc_args = include_args(inc_dir);
flags.insert(flags.end(), inc_args.begin(), inc_args.end());
extend(flags, inc_args);
}

for (auto&& def : spec.definitions) {
auto def_args = definition_args(def);
flags.insert(flags.end(), def_args.begin(), def_args.end());
extend(flags, def_args);
}

if (spec.enable_warnings) {
extend(flags, _warning_flags);
}

vector<string> command;
for (auto arg : _cxx_compile) {
if (arg == "<FLAGS>") {
command.insert(command.end(), flags.begin(), flags.end());
extend(command, flags);
} else {
arg = replace(arg, "<FILE>", spec.source_path.string());
arg = replace(arg, "<OUT>", spec.out_path.string());
@@ -208,7 +215,7 @@ vector<string> toolchain::create_archive_command(const archive_spec& spec) const
vector<string> cmd;
for (auto& arg : _archive_template) {
if (arg == "<OBJECTS>") {
cmd.insert(cmd.end(), spec.input_files.begin(), spec.input_files.end());
extend(cmd, spec.input_files);
} else {
cmd.push_back(replace(arg, "<ARCHIVE>", spec.out_path.string()));
}

+ 11
- 8
src/dds/toolchain.hpp Vedi File

@@ -22,6 +22,7 @@ struct compile_file_spec {
std::vector<std::string> definitions = {};
std::vector<fs::path> include_dirs = {};
language lang = language::automatic;
bool enable_warnings = false;
};

struct archive_spec {
@@ -32,13 +33,13 @@ struct archive_spec {
class toolchain {
using string_seq = std::vector<std::string>;

string_seq _c_compile;
string_seq _cxx_compile;
string_seq _inc_template;
string_seq _def_template;
string_seq _archive_template;

string_seq _c_compile;
string_seq _cxx_compile;
string_seq _inc_template;
string_seq _def_template;
string_seq _archive_template;
std::string _archive_suffix;
string_seq _warning_flags;

public:
toolchain(const std::string& c_compile,
@@ -46,13 +47,15 @@ public:
const std::string& inc_template,
const std::string& def_template,
const std::string& archive_template,
const std::string& archive_suffix)
const std::string& archive_suffix,
const std::string& warning_flags)
: _c_compile(split_shell_string(c_compile))
, _cxx_compile(split_shell_string(cxx_compile))
, _inc_template(split_shell_string(inc_template))
, _def_template(split_shell_string(def_template))
, _archive_template(split_shell_string(archive_template))
, _archive_suffix(archive_suffix) {}
, _archive_suffix(archive_suffix)
, _warning_flags(split_shell_string(warning_flags)) {}

static toolchain load_from_file(fs::path);


+ 5
- 0
src/dds/util.hpp Vedi File

@@ -41,6 +41,11 @@ void erase_if(Container& c, Predicate&& p) {
c.erase(erase_point, c.end());
}

template <typename Container, typename Other>
void extend(Container& c, const Other& o) {
c.insert(c.end(), o.begin(), o.end());
}

} // namespace dds

#endif // DDS_UTIL_HPP_INCLUDED

Loading…
Annulla
Salva