From 5285f1a72ee8d172acd7b698534549a4c3b64abd Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 12 Dec 2017 10:14:23 -0600 Subject: [PATCH] Symbolic links rise again #530 Found more places where symbolic links cause havoc. Also added back a #define that was removed in parameter_types.h and added back the messaging routines to the list swig processes. --- include/trick/parameter_types.h | 3 ++ libexec/trick/convert_swig | 27 +++++++++++-- libexec/trick/make_makefile_swig | 10 ++++- .../Interface_Code_Gen/FieldVisitor.cpp | 2 +- .../Interface_Code_Gen/PrintAttributes.cpp | 39 +++++++++++++++++++ trick_source/trick_swig/sim_services.i | 1 + 6 files changed, 76 insertions(+), 6 deletions(-) diff --git a/include/trick/parameter_types.h b/include/trick/parameter_types.h index e88347a8..e65a73f4 100644 --- a/include/trick/parameter_types.h +++ b/include/trick/parameter_types.h @@ -45,6 +45,9 @@ extern "C" { const char* trickTypeCharString( TRICK_TYPE type, const char* name); +/* here for backwards compatibility */ +#define TRICK_USER_DEFINED_TYPE TRICK_OPAQUE_TYPE + /* Define int_64t and uint_64t depending on compiler options */ #if __linux # include diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index e3bac711..ab1664c6 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -128,7 +128,27 @@ if ( $help ) { @include_dirs = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS @exclude_paths = map abs_path($_), split /:/ , $ENV{"TRICK_EXCLUDE"} ; +if (scalar @exclude_paths) { + @exclude_paths = sort(@exclude_paths ); + # Error check - delete any element that is null + # (note: sort forced all blank names to front of array + @exclude_paths = map { s/(^\s+|\s+$)//g ; $_ } @exclude_paths ; + while ( not length @exclude_paths[0] ) { + # Delete an element from the left side of an array (element zero) + shift @exclude_paths ; + } +} @swig_exclude_paths = map abs_path($_), split /:/ , $ENV{"TRICK_SWIG_EXCLUDE"} ; +if (scalar @swig_exclude_paths) { + @swig_exclude_paths = sort(@swig_exclude_paths ); + # Error check - delete any element that is null + # (note: sort forced all blank names to front of array + @swig_exclude_paths = map { s/(^\s+|\s+$)//g ; $_ } @swig_exclude_paths ; + while ( not length @swig_exclude_paths[0] ) { + # Delete an element from the left side of an array (element zero) + shift @swig_exclude_paths ; + } +} @ext_lib_paths = map abs_path($_), split /:/ , $ENV{"TRICK_EXT_LIB_DIRS"} ; @defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS if ( $ENV{"TRICK_CFLAGS"} !~ /DTRICK_VER=/ ) { @@ -211,8 +231,8 @@ sub process_file() { # remove all comments, they can cause all kinds of trouble # leave the line continuation character if present - $raw_contents =~ s/\/\/(?:.*?)(\\)?(\n)/$1\n/sg ; - $raw_contents =~ s/\/\*(?:.*?)\*\/(\s*\\\n)?/$1/sg ; + $raw_contents =~ s/\/\*(?:.*?)\*\/|\/\/(?:.*?)(\\)?(\n)/$1\n/sg ; + ## The init_attr functions cause problems when we try and wrap them with SWIG. ## We can safely remove them from the header files. @@ -258,7 +278,7 @@ sub process_file() { } # Get the canonical path (resolve ., .., and symbolic links) - $file_name = abs_path($file_name) ; + $file_name = abs_path(dirname($file_name)) . "/" . basename($file_name) ; # Skip excluded paths foreach my $i ( @exclude_paths, @swig_exclude_paths ) { @@ -266,7 +286,6 @@ sub process_file() { next outer ; } } - $file_name = "build" . $file_name ; $file_name =~ s/\.[^\.]+?$/\_py.i/ ; $contents .= "\%import \"$file_name\"\n" ; diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index d296dee9..f1dcf438 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -95,6 +95,10 @@ sub read_files_to_process() { print "SWIG Skip TRICK_EXCLUDE: $path$1\n" if $verbose_build ; next outer ; } + if ( abs_path($word) =~ /^\Q$path\E(.*)/ ) { + print "SWIG Skip TRICK_EXCLUDE: $path$1\n" if $verbose_build ; + next outer ; + } } # skip paths in TRICK_SWIG_EXCLUDE @@ -103,6 +107,10 @@ sub read_files_to_process() { print "SWIG Skip TRICK_SWIG_EXCLUDE: $path$1\n" if $verbose_build ; next outer ; } + if ( abs_path($word) =~ /^\Q$path\E(.*)/ ) { + print "SWIG Skip TRICK_SWIG_EXCLUDE: $path$1\n" if $verbose_build ; + next outer ; + } } # we'll be needing this later @@ -161,7 +169,7 @@ sub write_makefile_swig() { print PY_LINK_LIST "build/init_swig_modules.o\n" ; print PY_LINK_LIST "build/top.o\n" ; - print MAKEFILE "SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers + print MAKEFILE "SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers -Wno-unused-but-set-variable ifeq (\$(IS_CC_CLANG), 1) SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized -Wno-deprecated-register diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index d670ef79..ea115422 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -426,7 +426,7 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { tst_string.erase(pos , 7) ; } // clang changes bool to _Bool. We need to change it back - if ((pos = tst_string.find("<_Bool")) != std::string::npos ) { + while ((pos = tst_string.find("<_Bool")) != std::string::npos ) { tst_string.replace(pos , 6, "printClassMap(class_map_outfile, cv); + } +/* char* realPath = almostRealPath(fileName.c_str()); if (realPath) { if (isFileIncluded(fileName) or hsd.isPathInExtLib(realPath)) { @@ -247,6 +251,7 @@ void PrintAttributes::printClass( ClassValues * cv ) { } free(realPath); } +*/ } void PrintAttributes::printEnum(EnumValues* ev) { @@ -270,9 +275,14 @@ void PrintAttributes::printEnum(EnumValues* ev) { outfile.close() ; } + if (!isHeaderExcluded(fileName)) { + printer->printEnumMap(enum_map_outfile, ev); + } +/* if (isFileIncluded(fileName)) { printer->printEnumMap(enum_map_outfile, ev) ; } +*/ } void PrintAttributes::createMapFiles() { @@ -531,6 +541,35 @@ bool PrintAttributes::isHeaderExcluded(const std::string& header, bool exclude_e return true; } + temp = realpath(header.c_str(),NULL); + if ( temp ) { + const std::string real_path = std::string(temp); + free(temp) ; + if ( real_path.compare(path) ) { + if (hsd.isPathInExclude(real_path)) { + if (verboseBuild) { + std::cout << skipping << "TRICK_EXCLUDE: " << underline(real_path, hsd.getPathInExclude(real_path).size()) << std::endl; + } + return true; + } + + if (hsd.isPathInICGExclude(real_path)) { + if (verboseBuild) { + std::cout << skipping << "TRICK_ICG_EXCLUDE: " << underline(real_path, hsd.getPathInICGExclude(real_path).size()) << std::endl; + } + return true; + } + + if (hsd.isPathInExtLib(real_path) && exclude_ext_libs) { + if (verboseBuild) { + std::cout << skipping << "TRICK_EXT_LIB_DIRS: " << underline(real_path, hsd.getPathInExtLib(real_path).size()) << std::endl; + } + ext_lib_io_files.insert(header) ; + return true; + } + } + } + return false; } diff --git a/trick_source/trick_swig/sim_services.i b/trick_source/trick_swig/sim_services.i index 9a4360d3..3dd5ac86 100644 --- a/trick_source/trick_swig/sim_services.i +++ b/trick_source/trick_swig/sim_services.i @@ -120,6 +120,7 @@ #include "trick/MessagePublisher.hh" #include "trick/MessageSubscriber.hh" #include "trick/MessageTCDevice.hh" +#include "trick/Message_proto.hh" #include "trick/message_proto.h" #include "trick/MonteCarlo.hh" #include "trick/montecarlo_c_intf.h"