From 67decaed245abdbc61598c2b2ea3fe3d7d5ea6b7 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Thu, 20 Jun 2019 10:12:33 -0500 Subject: [PATCH] Add support for -isystem Closes #407 --- libexec/trick/pm/get_paths.pm | 2 +- test/SIM_isystem/S_define | 6 ++++++ test/SIM_isystem/S_overrides.mk | 2 ++ test/SIM_isystem/models/my_code/Foo.cpp | 3 +++ test/SIM_isystem/models/my_code/Foo.hh | 1 + .../SIM_isystem/models/third_party/Warning.cpp | 1 + test/SIM_isystem/models/third_party/Warning.hh | 7 +++++++ test/makefile | 3 ++- .../Interface_Code_Gen/HeaderSearchDirs.cpp | 18 ++++++++++++++++-- .../Interface_Code_Gen/HeaderSearchDirs.hh | 11 ++++++++--- .../codegen/Interface_Code_Gen/main.cpp | 7 ++----- 11 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 test/SIM_isystem/S_define create mode 100644 test/SIM_isystem/S_overrides.mk create mode 100644 test/SIM_isystem/models/my_code/Foo.cpp create mode 100644 test/SIM_isystem/models/my_code/Foo.hh create mode 100644 test/SIM_isystem/models/third_party/Warning.cpp create mode 100644 test/SIM_isystem/models/third_party/Warning.hh diff --git a/libexec/trick/pm/get_paths.pm b/libexec/trick/pm/get_paths.pm index 413d08f0..5943412d 100644 --- a/libexec/trick/pm/get_paths.pm +++ b/libexec/trick/pm/get_paths.pm @@ -13,7 +13,7 @@ sub get_paths { } sub get_include_paths { - return "$ENV{TRICK_CFLAGS} $ENV{TRICK_CXXFLAGS}" =~ /-I(\S+)/g + return "$ENV{TRICK_CFLAGS} $ENV{TRICK_CXXFLAGS}" =~ /-(?:I|isystem)(\S+)/g } sub get_defines { diff --git a/test/SIM_isystem/S_define b/test/SIM_isystem/S_define new file mode 100644 index 00000000..2d610164 --- /dev/null +++ b/test/SIM_isystem/S_define @@ -0,0 +1,6 @@ +#include "sim_objects/default_trick_sys.sm" + +##include "Foo.hh" +##include "Warning.hh" + +class Sandbox : public Trick::SimObject {}; diff --git a/test/SIM_isystem/S_overrides.mk b/test/SIM_isystem/S_overrides.mk new file mode 100644 index 00000000..ad74f232 --- /dev/null +++ b/test/SIM_isystem/S_overrides.mk @@ -0,0 +1,2 @@ +MODELS := $(CURDIR)/models +TRICK_CXXFLAGS += -Wall -Wextra -I$(MODELS)/my_code -isystem$(MODELS)/third_party diff --git a/test/SIM_isystem/models/my_code/Foo.cpp b/test/SIM_isystem/models/my_code/Foo.cpp new file mode 100644 index 00000000..c70664db --- /dev/null +++ b/test/SIM_isystem/models/my_code/Foo.cpp @@ -0,0 +1,3 @@ +// @trick_link_dependency{Warning.cpp} + +#include "Warning.hh" diff --git a/test/SIM_isystem/models/my_code/Foo.hh b/test/SIM_isystem/models/my_code/Foo.hh new file mode 100644 index 00000000..2954fa7f --- /dev/null +++ b/test/SIM_isystem/models/my_code/Foo.hh @@ -0,0 +1 @@ +// @trick_link_dependency{Foo.cpp} diff --git a/test/SIM_isystem/models/third_party/Warning.cpp b/test/SIM_isystem/models/third_party/Warning.cpp new file mode 100644 index 00000000..87a48933 --- /dev/null +++ b/test/SIM_isystem/models/third_party/Warning.cpp @@ -0,0 +1 @@ +#include diff --git a/test/SIM_isystem/models/third_party/Warning.hh b/test/SIM_isystem/models/third_party/Warning.hh new file mode 100644 index 00000000..b774fb94 --- /dev/null +++ b/test/SIM_isystem/models/third_party/Warning.hh @@ -0,0 +1,7 @@ +// @trick_link_dependency{Warning.cpp} + +/* This comment has an embedded /*, which causes a warning. */ + +static void foo() { + int i = 1 / 0; +} diff --git a/test/makefile b/test/makefile index 2936432b..79f46a36 100644 --- a/test/makefile +++ b/test/makefile @@ -8,7 +8,6 @@ COMPILE_DIRS = \ SIM_python_namespace \ SIM_rti \ SIM_stls \ - SIM_target_specific_variables \ SIM_test_dp \ SIM_test_dr \ SIM_test_io \ @@ -20,8 +19,10 @@ COMPILE_DIRS = \ SIMS_NEEDING_TEST = \ SIM_alloc_test \ SIM_demo_inputfile \ + SIM_isystem \ SIM_measurement_units \ SIM_parse_s_define \ + SIM_target_specific_variables \ SIM_test_abstract \ SIM_test_inherit \ SIM_test_ip2 \ diff --git a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp index f6ad1b25..5ee3aa23 100644 --- a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp +++ b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp @@ -106,10 +106,22 @@ void HeaderSearchDirs::AddUserSearchDirs ( std::vector & include_di if ( resolved_path != NULL ) { //std::cout << "adding resolved_path = " << resolved_path << std::endl ; hso.AddPath(resolved_path , clang::frontend::Angled, false, true); - // Add the path as a system path as well for those included files that are erroneously in <> } } +} +void HeaderSearchDirs::AddSystemSearchDirs ( std::vector & isystem_dirs ) { + //std::cout << "num isystem dirs " << isystem_dirs.size() << std::endl ; + int ii ; + + for ( ii = 0 ; ii < isystem_dirs.size() ; ii++ ) { + //std::cout << "isystem dirs " << isystem_dirs[ii] << std::endl ; + char * resolved_path = almostRealPath(isystem_dirs[ii].c_str()) ; + if ( resolved_path != NULL ) { + //std::cout << "adding resolved_path = " << resolved_path << std::endl ; + hso.AddPath(resolved_path , clang::frontend::System, false, true); + } + } } void HeaderSearchDirs::AddTrickSearchDirs () { @@ -186,8 +198,10 @@ void HeaderSearchDirs::ApplyHeaderSearchOptions () { */ } -void HeaderSearchDirs::addSearchDirs ( std::vector & include_dirs ) { +void HeaderSearchDirs::addSearchDirs ( std::vector & include_dirs, + std::vector & isystem_dirs) { AddUserSearchDirs( include_dirs ) ; + AddSystemSearchDirs( isystem_dirs ) ; AddTrickSearchDirs() ; AddCompilerBuiltInSearchDirs() ; ApplyHeaderSearchOptions() ; diff --git a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh index c3d31cb6..897987a0 100644 --- a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh +++ b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh @@ -32,9 +32,11 @@ class HeaderSearchDirs { bool in_sim_services ) ; /** Add all search directories to the preprocessor. - @param include_dirs = directories incuded on the command line + @param include_dirs = directories included via -I on the command line + @param isystem_dirs = directories included via -isystem on the command line */ - void addSearchDirs ( std::vector & include_dirs ) ; + void addSearchDirs ( std::vector & include_dirs, + std::vector & isystem_dirs ) ; /** Returns true if the path argument is in a user model directory @param path = directory path to be checked @@ -133,9 +135,12 @@ class HeaderSearchDirs { /** Adds all of the built-in system paths contained in the TRICK_CXX compiler */ void AddCompilerBuiltInSearchDirs () ; - /** Adds all of the paths specified on the command line */ + /** Adds -I include paths */ void AddUserSearchDirs ( std::vector & include_dirs ) ; + /** Adds -isystem include paths */ + void AddSystemSearchDirs ( std::vector & isystem_dirs ) ; + /** Adds ${TRICK_HOME}/trick_source to the search directories */ void AddTrickSearchDirs () ; diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index 504075e3..743476c7 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -29,6 +29,7 @@ /* Command line arguments. These work better as globals, as suggested in llvm/CommandLine documentation */ llvm::cl::list include_dirs("I", llvm::cl::Prefix, llvm::cl::desc("Include directory"), llvm::cl::value_desc("directory")); +llvm::cl::list isystem_dirs("isystem", llvm::cl::Prefix, llvm::cl::desc("Include directory, suppress all warnings"), llvm::cl::value_desc("directory")); llvm::cl::list defines("D", llvm::cl::Prefix, llvm::cl::desc("Defines"), llvm::cl::value_desc("define")); // TODO: remove units_truth_is_scary in 2021. llvm::cl::opt units_truth_is_scary("units-truth-is-scary", llvm::cl::desc("DEPRECATED: Don't print units conversion messages")); @@ -75,10 +76,6 @@ int main(int argc, char * argv[]) { */ llvm::cl::ParseCommandLineOptions(argc, argv); - /*if (!validAttributesVersion(attr_version)) { - return -1; - }*/ - if (input_file_names.empty()) { std::cerr << "No header file specified" << std::endl; return 1; @@ -149,7 +146,7 @@ int main(int argc, char * argv[]) { // Add all of the include directories to the preprocessor HeaderSearchDirs hsd(ci.getPreprocessor().getHeaderSearchInfo(), ci.getHeaderSearchOpts(), pp, sim_services_flag); - hsd.addSearchDirs(include_dirs); + hsd.addSearchDirs(include_dirs, isystem_dirs); // Add a preprocessor callback to search for TRICK_ICG #if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 6))