From ebbcf072180c4e09c74809af10d3a6d4ed584c86 Mon Sep 17 00:00:00 2001 From: johndebord Date: Mon, 16 Dec 2019 17:57:39 -0500 Subject: [PATCH 1/2] Add `-M` flag --- tools/cc/.#eosio-cpp.cpp.in | 1 + tools/cc/eosio-cc.cpp.in | 17 +++++++++++------ tools/cc/eosio-cpp.cpp.in | 17 +++++++++++------ tools/include/compiler_options.hpp.in | 14 ++++++++++++-- 4 files changed, 35 insertions(+), 14 deletions(-) create mode 120000 tools/cc/.#eosio-cpp.cpp.in diff --git a/tools/cc/.#eosio-cpp.cpp.in b/tools/cc/.#eosio-cpp.cpp.in new file mode 120000 index 0000000000..66805f5f8e --- /dev/null +++ b/tools/cc/.#eosio-cpp.cpp.in @@ -0,0 +1 @@ +john.debord@jdebord.55509 \ No newline at end of file diff --git a/tools/cc/eosio-cc.cpp.in b/tools/cc/eosio-cc.cpp.in index 1d8e220103..11ea0a160b 100644 --- a/tools/cc/eosio-cc.cpp.in +++ b/tools/cc/eosio-cc.cpp.in @@ -45,10 +45,12 @@ int main(int argc, const char **argv) { std::string tmp_file = std::string(res.c_str())+"/"+input+"-tmp.c"; std::string output; - auto src = SmallString<64>(input); - llvm::sys::path::remove_filename(src); - std::string source_path = src.str().empty() ? "." : src.str(); - new_opts.insert(new_opts.begin(), "-I" + source_path); + if (!opts.no_outputs) { + auto src = SmallString<64>(input); + llvm::sys::path::remove_filename(src); + std::string source_path = src.str().empty() ? "." : src.str(); + new_opts.insert(new_opts.begin(), "-I" + source_path); + } output = tmp_file+".o"; @@ -58,8 +60,11 @@ int main(int argc, const char **argv) { output = opts.output_fn.empty() ? "a.out" : opts.output_fn; } - new_opts.insert(new_opts.begin(), "-o"+output); - outputs.push_back(output); + if (!opts.no_outputs) { + new_opts.insert(new_opts.begin(), "-o"+output); + outputs.push_back(output); + } + if (!eosio::cdt::environment::exec_subprogram("clang-7", new_opts)) { llvm::sys::fs::remove(tmp_file); return -1; diff --git a/tools/cc/eosio-cpp.cpp.in b/tools/cc/eosio-cpp.cpp.in index b87c0b3686..845b47da24 100644 --- a/tools/cc/eosio-cpp.cpp.in +++ b/tools/cc/eosio-cpp.cpp.in @@ -191,10 +191,13 @@ int main(int argc, const char **argv) { tool_opts.end()); generate(tool_opts, input, opts.abigen_contract, opts.abigen_resources, opts.abigen); - auto src = SmallString<64>(input); - llvm::sys::path::remove_filename(src); - std::string source_path = src.str().empty() ? "." : src.str(); - new_opts.insert(new_opts.begin(), "-I" + source_path); + if (!opts.no_outputs) { + auto src = SmallString<64>(input); + llvm::sys::path::remove_filename(src); + std::string source_path = src.str().empty() ? "." : src.str(); + new_opts.insert(new_opts.begin(), "-I" + source_path); + } + if (llvm::sys::fs::exists(tmp_file)) { input = tmp_file; @@ -205,8 +208,10 @@ int main(int argc, const char **argv) { output = opts.output_fn.empty() ? "a.out" : opts.output_fn; } - new_opts.insert(new_opts.begin(), {"-o", output}); - outputs.push_back(output); + if (!opts.no_outputs) { + new_opts.insert(new_opts.begin(), {"-o", output}); + outputs.push_back(output); + } } new_opts.insert(new_opts.begin(), input); diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index 873be56bbb..94ee1d22a5 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -151,6 +151,10 @@ static cl::opt MMD_opt( "MMD", cl::desc("Write depfile containing user"), cl::cat(EosioCompilerToolCategory)); +static cl::opt M_opt( + "M", + cl::desc("Like -MD, but also implies -E and writes to stdout by default"), + cl::cat(EosioCompilerToolCategory)); static cl::list resources( "R", cl::Prefix, @@ -355,6 +359,7 @@ struct Options { bool link; bool abigen; bool pp_only; + bool no_outputs; std::string eosio_pp_dir; std::string abigen_output; std::string abigen_contract; @@ -508,6 +513,7 @@ static Options CreateOptions(bool add_defaults=true) { std::vector agopts; bool link = true; bool debug = false; + bool no_outputs = false; std::string pp_dir; std::string abigen_output; std::string abigen_contract; @@ -633,6 +639,10 @@ static Options CreateOptions(bool add_defaults=true) { if (!MT_opt.empty()) { copts.emplace_back("-MT "+MT_opt); } + if (M_opt) { + copts.emplace_back("-M "); + no_outputs = true; + } if (finline_functions_opt) { copts.emplace_back("-finline-functions"); } @@ -862,8 +872,8 @@ static Options CreateOptions(bool add_defaults=true) { #endif #ifndef ONLY_LD - return {output_fn, inputs, link, abigen, pp_only, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; + return {output_fn, inputs, link, abigen, pp_only, no_outputs, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; #else - return {output_fn, {}, link, abigen, pp_only, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; + return {output_fn, {}, link, abigen, pp_only, no_outputs, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; #endif } From c07fd045340f1cc1e06f03cd8fd2e3b93ac23135 Mon Sep 17 00:00:00 2001 From: johndebord Date: Mon, 16 Dec 2019 17:59:15 -0500 Subject: [PATCH 2/2] Remove file --- tools/cc/.#eosio-cpp.cpp.in | 1 - 1 file changed, 1 deletion(-) delete mode 120000 tools/cc/.#eosio-cpp.cpp.in diff --git a/tools/cc/.#eosio-cpp.cpp.in b/tools/cc/.#eosio-cpp.cpp.in deleted file mode 120000 index 66805f5f8e..0000000000 --- a/tools/cc/.#eosio-cpp.cpp.in +++ /dev/null @@ -1 +0,0 @@ -john.debord@jdebord.55509 \ No newline at end of file