Skip to content

Commit

Permalink
Compiler warning support
Browse files Browse the repository at this point in the history
  • Loading branch information
vector-of-bool committed Oct 13, 2019
1 parent 00190c7 commit 12cf2b4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/dds/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/dds/build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/dds/ddslim.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)) {
Expand Down
15 changes: 11 additions & 4 deletions src/dds/toolchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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

Expand All @@ -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(""),
};
}

Expand Down Expand Up @@ -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());
Expand All @@ -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()));
}
Expand Down
19 changes: 11 additions & 8 deletions src/dds/toolchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,27 +33,29 @@ 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,
const std::string& cxx_compile,
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);

Expand Down
5 changes: 5 additions & 0 deletions src/dds/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 12cf2b4

Please sign in to comment.