Merge branch 'master' into VERBOSE-synonym

This commit is contained in:
Scott Fennell 2019-04-02 13:34:52 -05:00 committed by GitHub
commit 49e243b54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 350 additions and 41 deletions

View File

@ -18,7 +18,11 @@ my @ext_lib_paths ;
my @files_to_process ; my @files_to_process ;
my @ext_lib_files ; my @ext_lib_files ;
my %md5s ; my %md5s ;
my $verbose_build = (exists($ENV{'TRICK_VERBOSE_BUILD'}) or exists($ENV{'VERBOSE'})) ; my $verbose_build = (exists($ENV{'TRICK_VERBOSE_BUILD'}) or exists($ENV{'VERBOSE'})) ;
my %trick_headers ;
my %python_modules ;
my %python_module_dirs ;
sub get_paths { sub get_paths {
my @paths = split /:/ , $ENV{$_[0]} ; my @paths = split /:/ , $ENV{$_[0]} ;
@ -140,9 +144,21 @@ sub write_makefile_swig_deps() {
close DEPENDENCIES_FILE ; close DEPENDENCIES_FILE ;
} }
sub get_trick_headers() {
foreach my $f ( @files_to_process, @ext_lib_files) {
my %trick_header = extract_trick_header( $f, do { local( @ARGV, $/ ) = $f ; <> }, 0, 0 ) ;
if ( exists $trick_header{python_module} ) {
$trick_headers{$f}{python_module} = $trick_header{python_module};
($trick_headers{$f}{python_module_dir} = $trick_header{python_module}) =~ s/\./\//g;
$python_modules{$trick_headers{$f}{python_module}} = 1;
$python_module_dirs{$trick_headers{$f}{python_module_dir}} = 1;
}
$trick_headers{$f}{swig} = $trick_header{swig} if ( exists $trick_header{swig} );
}
}
sub has_swig_no($) { sub has_swig_no($) {
my %trick_header = extract_trick_header( $_[0], do { local( @ARGV, $/ ) = $_[0] ; <> }, 0, 0 ) ; my $result = $trick_headers{$_[0]}{swig} =~ /^NO$/i ;
my $result = $trick_header{swig} =~ /^NO$/i ;
print "SWIG Skip SWIG: (NO): $_[0]\n" if $verbose_build and $result ; print "SWIG Skip SWIG: (NO): $_[0]\n" if $verbose_build and $result ;
return $result ; return $result ;
} }
@ -208,11 +224,26 @@ all: \$(TRICK_FIXED_PYTHON)
SWIG_I =" ; SWIG_I =" ;
foreach my $file ( @files_to_process ) { foreach my $file ( @files_to_process ) {
if ( !exists $trick_headers{$file}{python_module_dir} ) {
(my $swig_file = $file) =~ s/\.[^.]*$/_py.i/ ; (my $swig_file = $file) =~ s/\.[^.]*$/_py.i/ ;
print MAKEFILE " \\\n build$swig_file" ; print MAKEFILE " \\\n build$swig_file" ;
$swig_file =~ s/i$/o/ ; $swig_file =~ s/i$/o/ ;
print PY_LINK_LIST "build$swig_file\n" ; print PY_LINK_LIST "build$swig_file\n" ;
} }
}
print MAKEFILE "
SWIG_I_CUSTOM_OUTDIR =" ;
foreach my $file ( @files_to_process ) {
if ( exists $trick_headers{$file}{python_module_dir} ) {
(my $swig_file = $file) =~ s/\.[^.]*$/_py.i/ ;
print MAKEFILE " \\\n build$swig_file" ;
$swig_file =~ s/i$/o/ ;
print PY_LINK_LIST "build$swig_file\n" ;
}
}
print MAKEFILE " print MAKEFILE "
@ -238,9 +269,24 @@ SWIG_SRC = \$(subst .i,.cpp,\$(SWIG_I)) $swig_src_dir/top.cpp
\t\@echo \$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick -o \$@ \$< >> \$(MAKE_OUT) \t\@echo \$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick -o \$@ \$< >> \$(MAKE_OUT)
\t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick -o \$@ \$< 2>&1 | \$(TEE) -a \$(MAKE_OUT) ; exit \$\${PIPESTATUS[0]} \t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick -o \$@ \$< 2>&1 | \$(TEE) -a \$(MAKE_OUT) ; exit \$\${PIPESTATUS[0]}
SWIG_SRC_CUSTOM_OUTDIR = \$(subst .i,.cpp,\$(SWIG_I_CUSTOM_OUTDIR))\n" ;
foreach my $file ( @files_to_process ) {
if ( exists $trick_headers{$file}{python_module_dir} ) {
(my $swig_file = $file) =~ s/\.[^.]*$/_py.i/ ;
(my $cpp_file = $file) =~ s/\.[^.]*$/_py.cpp/ ;
print MAKEFILE "
build$cpp_file : build$swig_file | trick/$trick_headers{$file}{python_module_dir}
\t\$(PRINT_SWIG)
\t\@echo \$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick/$trick_headers{$file}{python_module_dir} -o \$@ \$< >> \$(MAKE_OUT)
\t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick/$trick_headers{$file}{python_module_dir} -o \$@ \$< 2>&1 | \$(TEE) -a \$(MAKE_OUT) ; exit \$\${PIPESTATUS[0]}\n";
}
}
print MAKEFILE "
# SWIG_OBJECTS ================================================================= # SWIG_OBJECTS =================================================================
SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) \$(subst .cpp,.o,\$(SWIG_SRC_CUSTOM_OUTDIR)) $swig_src_dir/init_swig_modules.o
\$(SWIG_OBJECTS): %.o: %.cpp \$(SWIG_OBJECTS): %.o: %.cpp
\t\$(PRINT_COMPILE_SWIG) \t\$(PRINT_COMPILE_SWIG)
@ -327,6 +373,9 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list
print INITFILE "import sys\n" ; print INITFILE "import sys\n" ;
print INITFILE "import os\n" ; print INITFILE "import os\n" ;
print INITFILE "sys.path.append(os.getcwd() + \"/trick\")\n" ; print INITFILE "sys.path.append(os.getcwd() + \"/trick\")\n" ;
foreach my $dir ( keys %python_module_dirs ) {
print INITFILE "sys.path.append(os.getcwd() + \"/trick/$dir\")\n" ;
}
print INITFILE "\n" ; print INITFILE "\n" ;
print INITFILE "import _sim_services\n" ; print INITFILE "import _sim_services\n" ;
@ -339,12 +388,16 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list
foreach $f ( @files_to_process, @ext_lib_files ) { foreach $f ( @files_to_process, @ext_lib_files ) {
print INITFILE "# $f\n" ; print INITFILE "# $f\n" ;
print INITFILE "import _m$md5s{$f}\n" ;
print INITFILE "from m$md5s{$f} import *\n" ; print INITFILE "from m$md5s{$f} import *\n" ;
print INITFILE "combine_cvars(all_cvars, cvar)\n" ; print INITFILE "combine_cvars(all_cvars, cvar)\n" ;
print INITFILE "cvar = None\n\n" ; print INITFILE "cvar = None\n\n" ;
} }
foreach my $mod ( keys %python_modules ) {
print INITFILE "import trick.$mod\n" ;
}
print INITFILE "\n" ;
print INITFILE "# S_source.hh\n" ; print INITFILE "# S_source.hh\n" ;
print INITFILE "import _m${s_source_md5}\n" ; print INITFILE "import _m${s_source_md5}\n" ;
print INITFILE "from m${s_source_md5} import *\n\n" ; print INITFILE "from m${s_source_md5} import *\n\n" ;
@ -361,6 +414,17 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list
print INITFILE "cvar = all_cvars\n\n" ; print INITFILE "cvar = all_cvars\n\n" ;
close INITFILE ; close INITFILE ;
foreach my $dir ( keys %python_module_dirs ) {
system("mkdir -p trick/$dir");
open MODULE_INITFILE, ">trick/$dir/__init__.py";
foreach my $file ( @files_to_process ) {
if ( exists $trick_headers{$file}{python_module_dir} and $trick_headers{$file}{python_module_dir} eq $dir ) {
print MODULE_INITFILE "from m$md5s{$file} import *\n" ;
}
}
close MODULE_INITFILE;
}
return ; return ;
} }
@ -370,6 +434,7 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list
read_files_to_process() ; read_files_to_process() ;
write_makefile_swig_deps() ; write_makefile_swig_deps() ;
get_trick_headers() ;
# Remove SWIG: (NO) files, but not before they're written to the dependency file. # Remove SWIG: (NO) files, but not before they're written to the dependency file.
# If SWIG: (NO) is removed, Makefile_swig needs to be regenerated. # If SWIG: (NO) is removed, Makefile_swig needs to be regenerated.
purge_swig_no_files() ; purge_swig_no_files() ;

View File

@ -31,7 +31,7 @@ sub extract_trick_header($$$$) {
$header{icg_ignore} = $2 if $trick_header =~ /ICG[ _]IGNORE[ _]TYPE(S)?:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{icg_ignore} = $2 if $trick_header =~ /ICG[ _]IGNORE[ _]TYPE(S)?:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
$header{swig} = $1 if $trick_header =~ /SWIG:[^(]*\((.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{swig} = $1 if $trick_header =~ /SWIG:[^(]*\((.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
$header{default_data} = $1 if $trick_header =~ /DEFAULT[ _]DATA:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{default_data} = $1 if $trick_header =~ /DEFAULT[ _]DATA:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
$header{python_module} = $1 if $trick_header =~ /PYTHON[ _]MODULE:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{python_module} = $1 if $trick_header =~ /PYTHON[ _]MODULE:[^(]*\((.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
$header{programmers} = $1 if $trick_header =~ /PROGRAMMERS:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{programmers} = $1 if $trick_header =~ /PROGRAMMERS:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
$header{language} = $1 if $trick_header =~ /LANGUAGE:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{language} = $1 if $trick_header =~ /LANGUAGE:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
@ -55,6 +55,9 @@ sub extract_trick_header($$$$) {
# save doxygen style trick_lib_dependency fields in field = liblist. # save doxygen style trick_lib_dependency fields in field = liblist.
$header{liblist} = [@lib_list] ; $header{liblist} = [@lib_list] ;
} }
if ( $contents =~ /(?:@|\\)python_module\s*{\s*(.*?)\s*}/) {
$header{python_module} = $1;
}
$header{language} = "CPP" if ( $header{language} =~ /c[p\+]+/i ) ; $header{language} = "CPP" if ( $header{language} =~ /c[p\+]+/i ) ;

View File

@ -1,6 +1,6 @@
# This file can be used to create an object file containing the io_* and py_* # This file can be used to create an object file or library containing the io_*
# code that Trick would normally generate during the simulation build process. # and py_* code that Trick would normally generate during the simulation build
# Sims can then link against this object file, reducing compilation time. # process. Sims can then link against that, reducing compilation time.
# #
# To use it, create a directory that includes a file named S_source.hh that # To use it, create a directory that includes a file named S_source.hh that
# includes all header files for which you want io_* and py_* code generated. # includes all header files for which you want io_* and py_* code generated.
@ -25,9 +25,26 @@
# paths to the header files included by your S_source.hh. For instance: # paths to the header files included by your S_source.hh. For instance:
# -I$(HOME)/myproject/foo/include -I$(HOME)/myproject/bar/include # -I$(HOME)/myproject/foo/include -I$(HOME)/myproject/bar/include
# #
# TRICKIFY_BUILD_TYPE (optional)
# Valid options are:
# 1. STATIC (.a)
# Create a static library. This will require the use of --whole-archive (on
# Linux) or -all_load/-force_load (on Mac) when linking the sim executeable.
# Trick uses dlsym to dynamically load symbols at run time, but the linker,
# by default, will not include symbols from static libraries that are not
# known to be needed at compile time.
# 2. SHARED (.so)
# Create a shared object (dynamically linked library). This may require the
# use of -rpath to ensure the linker can find the shared object at runtime
# unless you explicitly link against it (as opposed to using -L and -l)
# during compilation.
# 3. PLO (.o) [default]
# Create a partially-linked object. No special linker options are required.
#
# TRICKIFY_OBJECT_NAME (optional) # TRICKIFY_OBJECT_NAME (optional)
# The name of the generated object file. The default value is trickified.o. # The name of the generated object file or library. The default value is
# You should choose something more meaningful, like trickified_myproject.o. # trickified.o. You should choose something more meaningful, especially if
# you're using another build type.
# #
# TRICKIFY_PTYON_DIR (optional) # TRICKIFY_PTYON_DIR (optional)
# The directory into which generated Python modules are placed. The default # The directory into which generated Python modules are placed. The default
@ -74,9 +91,11 @@ ifndef TRICKIFY_CXX_FLAGS
$(error TRICKIFY_CXX_FLAGS must be set) $(error TRICKIFY_CXX_FLAGS must be set)
endif endif
TRICKIFY_BUILD_TYPE ?= PLO
TRICKIFY_OBJECT_NAME ?= trickified.o TRICKIFY_OBJECT_NAME ?= trickified.o
TRICKIFY_PYTHON_DIR ?= python TRICKIFY_PYTHON_DIR ?= python
TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../../..) TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../../..)
MAKE_OUT ?= build/MAKE_out
ifneq ($(wildcard build),) ifneq ($(wildcard build),)
SWIG_OBJECTS := $(shell cat build/S_library_swig) SWIG_OBJECTS := $(shell cat build/S_library_swig)
@ -92,30 +111,26 @@ TRICK_CXXFLAGS += $(TRICKIFY_CXX_FLAGS)
# Ensure we can process all headers # Ensure we can process all headers
TRICK_EXT_LIB_DIRS := TRICK_EXT_LIB_DIRS :=
# When given a library, the linker will only link in objects that are known to
# be needed at link time. However, Trick uses dlsym to dynamically load the
# objects we'll be creating here. It cannot be known which objects will be
# needed at link time, so the sim has to link them all. In that case, we might
# as well create an object (which will be fully linked in by the sim) instead
# of a library (which would require the use of the -whole-archive option).
#
# One disadvantage of this approach is that we have to link all of the objects
# in this rule no matter how many have changed, whereas ar would allow us to
# replace only the changed objects. However, Trickified projects are
# necessarily used as third-party libraries, and so would be expected to
# change infrequently. Moreover, the methods for force-linking a library differ
# between Linux and Mac, so obviating the need for it simplifies a Trickified
# project's user-facing makefile.
$(TRICKIFY_OBJECT_NAME): $(SWIG_OBJECTS) $(IO_OBJECTS) | $(dir $(TRICKIFY_OBJECT_NAME)) $(TRICKIFY_OBJECT_NAME): $(SWIG_OBJECTS) $(IO_OBJECTS) | $(dir $(TRICKIFY_OBJECT_NAME))
$(info $(call COLOR,Linking) $@) $(info $(call COLOR,Linking) $@)
@ld -r -o $@ $^ ifeq ($(TRICKIFY_BUILD_TYPE),PLO)
@echo $(LD) $(LD_PARTIAL) -o $@ $^ >> $(MAKE_OUT)
$(ECHO_CMD)ld -r -o $@ $^ 2>&1 | $(TEE) -a $(MAKE_OUT); exit $${PIPESTATUS[0]}
else ifeq ($(TRICKIFY_BUILD_TYPE),SHARED)
@echo $(TRICK_CPPC) -shared -o $@ $^ >> $(MAKE_OUT)
$(ECHO_CMD)c++ -shared -o $@ $^ 2>&1 | $(TEE) -a $(MAKE_OUT); exit $${PIPESTATUS[0]}
else ifeq ($(TRICKIFY_BUILD_TYPE),STATIC)
@echo ar rcs $@ $^ >> $(MAKE_OUT)
$(ECHO_CMD)ar rcs $@ $^ 2>&1 | $(TEE) -a $(MAKE_OUT); exit $${PIPESTATUS[0]}
endif
$(dir $(TRICKIFY_OBJECT_NAME)) $(TRICKIFY_PYTHON_DIR) build: $(dir $(TRICKIFY_OBJECT_NAME)) $(TRICKIFY_PYTHON_DIR) build:
@mkdir -p $@ @mkdir -p $@
$(IO_OBJECTS): %.o: %.cpp $(IO_OBJECTS): %.o: %.cpp
$(info $(call COLOR,Compiling) $<) $(info $(call COLOR,Compiling) $<)
@$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -std=c++11 -Wno-invalid-offsetof -MMD -MP -c -o $@ $< @echo $(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -std=c++11 -Wno-invalid-offsetof -MMD -MP -c -o $@ $< >> $(MAKE_OUT)
$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -std=c++11 -Wno-invalid-offsetof -MMD -MP -c -o $@ $< 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $${PIPESTATUS[0]}
$(IO_OBJECTS:.o=.d): %.d: ; $(IO_OBJECTS:.o=.d): %.d: ;
@ -123,16 +138,19 @@ $(IO_OBJECTS:.o=.d): %.d: ;
$(SWIG_OBJECTS): %.o: %.cpp $(SWIG_OBJECTS): %.o: %.cpp
$(info $(call COLOR,Compiling) $<) $(info $(call COLOR,Compiling) $<)
@$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(PYTHON_INCLUDES) -Wno-unused-parameter -Wno-shadow -c -o $@ $< @echo $(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(PYTHON_INCLUDES) -Wno-unused-parameter -Wno-shadow -c -o $@ $< >> $(MAKE_OUT)
$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(PYTHON_INCLUDES) -Wno-unused-parameter -Wno-shadow -c -o $@ $< 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $${PIPESTATUS[0]}
$(SWIG_OBJECTS:.o=.cpp): %.cpp: %.i | $(TRICKIFY_PYTHON_DIR) $(SWIG_OBJECTS:.o=.i) $(SWIG_OBJECTS:.o=.cpp): %.cpp: %.i | $(TRICKIFY_PYTHON_DIR) $(SWIG_OBJECTS:.o=.i)
$(info $(call COLOR,SWIGing) $<) $(info $(call COLOR,SWIGing) $<)
@$(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir $(TRICKIFY_PYTHON_DIR) -o $@ $< @echo $(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir $(TRICKIFY_PYTHON_DIR) -o $@ $< >> $(MAKE_OUT)
$(ECHO_CMD)$(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir $(TRICKIFY_PYTHON_DIR) -o $@ $< 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $${PIPESTATUS[0]}
define create_convert_swig_rule define create_convert_swig_rule
build/%_py.i: /%.$1 build/%_py.i: /%.$1
$$(info $$(call COLOR,Converting) $$<) $$(info $$(call COLOR,Converting) $$<)
${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} $$< @echo ${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} $$< >> $(MAKE_OUT)
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} $$< 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $$${PIPESTATUS[0]}
endef endef
EXTENSIONS := H h hh hxx h++ hpp EXTENSIONS := H h hh hxx h++ hpp
@ -170,8 +188,9 @@ $(foreach EXTENSION,$(EXTENSIONS),$(eval $(call create_convert_swig_rule,$(EXTEN
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
build/S_source.d: | $(dir $@) build/S_source.d: | $(dir $@)
@$(TRICK_HOME)/bin/trick-ICG $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_ICGFLAGS) S_source.hh $(ECHO_CMD)$(TRICK_HOME)/bin/trick-ICG $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_ICGFLAGS) S_source.hh
@$(TRICK_HOME)/$(LIBEXEC)/trick/make_makefile_swig $(ECHO_CMD)$(TRICK_HOME)/$(LIBEXEC)/trick/make_makefile_swig 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $${PIPESTATUS[0]}
@$(TRICK_CC) -MM -MP -MT $@ -MF $@ $(TRICKIFY_CXX_FLAGS) S_source.hh @echo $(TRICK_CC) -MM -MP -MT $@ -MF $@ $(TRICKIFY_CXX_FLAGS) S_source.hh >> $(MAKE_OUT)
$(ECHO_CMD) $(TRICK_CC) -MM -MP -MT $@ -MF $@ $(TRICKIFY_CXX_FLAGS) S_source.hh 2>&1 | $(TEE) -a $(MAKE_OUT) ; exit $${PIPESTATUS[0]}
-include build/S_source.d -include build/S_source.d

View File

@ -18,6 +18,10 @@ if hasattr(top.cvar, 'trick_sys'):
# from monte carlo # from monte carlo
mc_add_range = top.cvar.trick_sys.sched.add_range mc_add_range = top.cvar.trick_sys.sched.add_range
# from Monte Carlo
if hasattr(top.cvar, 'trick_mc'):
mc_add_variable = top.cvar.trick_mc.mc.add_variable
# from the memory manager wrapper # from the memory manager wrapper
if hasattr(top.cvar, 'trick_mm'): if hasattr(top.cvar, 'trick_mm'):
read_checkpoint_from_string = top.cvar.trick_mm.mm.read_checkpoint_from_string read_checkpoint_from_string = top.cvar.trick_mm.mm.read_checkpoint_from_string

View File

@ -0,0 +1,49 @@
from trick.unit_test import *
def main():
trick.stop(1.0)
trick_utest.unit_tests.enable()
trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_python_namespace.xml" )
trick_utest.unit_tests.set_test_name( "PythonNamespace" )
test_suite = "python_namespace"
# normal class methods from S_define
ball.foo_food.print_me()
ball.foo_inner_food.print_me()
ball.bar_food.print_me()
ball.foo_yummyfood.print_me()
print
# new class from Foo.Food
food = trick.Foo.Food()
food.print_me()
TRICK_EXPECT_EQ( food.fast , 0, test_suite , "first level python namespace" )
food.fast = trick.Foo.Burger
TRICK_EXPECT_EQ( food.fast , 2, test_suite , "first level python namespace" )
# new class from Foo.Food.Inner
foodinner = trick.Foo.Inner.Food()
foodinner.print_me()
TRICK_EXPECT_EQ( foodinner.fast , 1, test_suite , "second level python namespace" )
foodinner.fast = trick.Foo.Inner.Burger
TRICK_EXPECT_EQ( foodinner.fast , 0, test_suite , "second level python namespace" )
# new class from Foo.Food.Inner
bar = trick.Bar.Food()
bar.print_me()
TRICK_EXPECT_EQ( bar.fast , 2, test_suite , "another first level python namespace" )
bar.fast = trick.Bar.Burger
TRICK_EXPECT_EQ( bar.fast , 1, test_suite , "another first level python namespace" )
# new class from Foo.Food.Inner
yummy = trick.Foo.YummyFood()
yummy.print_me()
TRICK_EXPECT_EQ( yummy.yummy , 1, test_suite , "additional file in same namespace" )
yummy.yummy = trick.Foo.Doughnuts
TRICK_EXPECT_EQ( yummy.yummy , 2, test_suite , "additional file in same namespace" )
if __name__ == "__main__":
main()

View File

@ -0,0 +1,28 @@
/************************TRICK HEADER*************************
PURPOSE:
(blah blah blah)
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "FooFood.hh"
##include "FooInnerFood.hh"
##include "BarFood.hh"
##include "FooYummyFood.hh"
class SimObj : public Trick::SimObject {
public:
Foo::Food foo_food ;
Foo::Inner::Food foo_inner_food ;
Bar::Food bar_food ;
Foo::YummyFood foo_yummyfood ;
/** Constructor to add the jobs */
SimObj() {
}
} ;
// Instantiations
SimObj ball ;

View File

@ -0,0 +1,4 @@
TRICK_CFLAGS += -I./models
TRICK_CXXFLAGS += -I./models

View File

@ -0,0 +1,33 @@
/**
@file
@verbatim
PURPOSE: (Namespace Test)
PYTHON_MODULE: (Bar)
@endverbatim
*******************************************************************************/
#ifndef BARFOOD_HH
#define BARFOOD_HH
#include <iostream>
namespace Bar {
enum Fast {
Pizza,
Burger,
Taco
};
class Food {
public:
Food() : fast(Taco) {}
void print_me() { std::cout << "Bar::Food::print_me!" << std::endl; }
Fast fast;
};
}
#endif /* _BALL_HH_ */

View File

@ -0,0 +1,33 @@
/**
@file
@verbatim
PURPOSE: (Namespace Test)
PYTHON_MODULE: (Foo)
@endverbatim
*******************************************************************************/
#ifndef FOOFOOD_HH
#define FOOFOOD_HH
#include <iostream>
namespace Foo {
enum Fast {
Taco,
Pizza,
Burger
};
class Food {
public:
Food() : fast(Taco) {}
void print_me() { std::cout << "Foo::Food::print_me!" << std::endl; }
Fast fast;
};
}
#endif /* _BALL_HH_ */

View File

@ -0,0 +1,31 @@
/**
@file
@verbatim
PURPOSE: (Namespace Test)
PYTHON_MODULE: (Foo.Inner)
@endverbatim
*******************************************************************************/
#ifndef FOOINNERFOOD_HH
#define FOOINNERFOOD_HH
namespace Foo {
namespace Inner {
enum Fast {
Burger,
Taco,
Pizza
};
class Food {
public:
Food() : fast(Taco) {}
void print_me() { std::cout << "Foo::Inner::Food::print_me!" << std::endl; }
Fast fast;
};
}
}
#endif /* _BALL_HH_ */

View File

@ -0,0 +1,33 @@
/**
@file
@verbatim
PURPOSE: (Namespace Test)
PYTHON_MODULE: (Foo)
@endverbatim
*******************************************************************************/
#ifndef FOOYUMMYFOOD_HH
#define FOOYUMMYFOOD_HH
#include <iostream>
namespace Foo {
enum Yummy {
Butter,
Bacon,
Doughnuts
};
class YummyFood {
public:
YummyFood() : yummy(Bacon) {}
void print_me() { std::cout << "Foo::YummyFood::print_me!" << std::endl; }
Yummy yummy;
};
}
#endif /* _BALL_HH_ */

View File

@ -5,6 +5,7 @@ export TRICK_HOST_CPU := $(shell $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)
COMPILE_DIRS = \ COMPILE_DIRS = \
SIM_demo_sdefine \ SIM_demo_sdefine \
SIM_events \ SIM_events \
SIM_python_namespace \
SIM_rti \ SIM_rti \
SIM_stls \ SIM_stls \
SIM_test_dp \ SIM_test_dp \

View File

@ -7,4 +7,10 @@
#define RBRACELOC getRBraceLoc #define RBRACELOC getRBraceLoc
#endif #endif
#if (LIBCLANG_MAJOR >=8)
#define GETLOCEND getEndLoc
#else
#define GETLOCEND getLocEnd
#endif
#endif #endif

View File

@ -63,7 +63,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
if (is_forward_declaration) { if (is_forward_declaration) {
// These are forward declarations. Insert this into the set of fwd declares keyed by the current file. // These are forward declarations. Insert this into the set of fwd declares keyed by the current file.
if ( ! crd->getNameAsString().empty() ) { if ( ! crd->getNameAsString().empty() ) {
fwd_declared_classes[getFileName(ci , d->getLocEnd(), hsd)].insert(crd->getNameAsString()) ; fwd_declared_classes[getFileName(ci , d->GETLOCEND(), hsd)].insert(crd->getNameAsString()) ;
} }
} }
else { else {
@ -84,7 +84,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
typedef struct Astruct {} Bstruct ; typedef struct Astruct {} Bstruct ;
*/ */
std::set< std::string >::iterator it ; std::set< std::string >::iterator it ;
std::string file_name = getFileName(ci , d->getLocEnd(), hsd) ; std::string file_name = getFileName(ci , d->GETLOCEND(), hsd) ;
std::string source_type = cvis.get_class_data()->getName() ; std::string source_type = cvis.get_class_data()->getName() ;
it = fwd_declared_classes[file_name].find(source_type) ; it = fwd_declared_classes[file_name].find(source_type) ;
if ( it != fwd_declared_classes[file_name].end() ) { if ( it != fwd_declared_classes[file_name].end() ) {
@ -126,14 +126,14 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
case clang::Decl::Typedef : { case clang::Decl::Typedef : {
clang::TypedefDecl * td = static_cast<clang::TypedefDecl *>(d) ; clang::TypedefDecl * td = static_cast<clang::TypedefDecl *>(d) ;
if ( isInUserCode(ci, td->getSourceRange().getBegin(), hsd) ) { if ( isInUserCode(ci, td->getSourceRange().getBegin(), hsd) ) {
TypedefVisitor tv(ci , cs, hsd, pa, fwd_declared_classes[getFileName(ci , d->getLocEnd(), hsd)]) ; TypedefVisitor tv(ci , cs, hsd, pa, fwd_declared_classes[getFileName(ci , d->GETLOCEND(), hsd)]) ;
tv.TraverseDecl(d) ; tv.TraverseDecl(d) ;
} }
} }
break ; break ;
case clang::Decl::Var : { case clang::Decl::Var : {
if ( isInUserCode(ci, d->getSourceRange().getBegin(), hsd) ) { if ( isInUserCode(ci, d->getSourceRange().getBegin(), hsd) ) {
VariableVisitor tv(ci , cs, hsd, pa, fwd_declared_classes[getFileName(ci , d->getLocEnd(), hsd)]) ; VariableVisitor tv(ci , cs, hsd, pa, fwd_declared_classes[getFileName(ci , d->GETLOCEND(), hsd)]) ;
tv.TraverseDecl(d) ; tv.TraverseDecl(d) ;
} }
} }