diff --git a/bin/trick-ify b/bin/trick-ify new file mode 100755 index 00000000..9e503fc3 --- /dev/null +++ b/bin/trick-ify @@ -0,0 +1,238 @@ +#!/usr/bin/perl + +$my_path = $0 ; +$my_path =~ s/trick-ify// ; + +$source_dir = "" ; # Base path to build header from +$header_dir = "" ; # Base path to find header files +$source_make_call = "" ; # Make call to build object files +$source_make_args = "" ; # Args to pass into default object make +$trickify_make_args = "" ; # Arguments to pass into the trickify make +$trickify_make_path = "$my_path../share/trick/makefiles/trickify.mk" ; # Path of the trickify make file +$build_s_source = 1 ; # Whether to generate a S_source +$build_trickify_src_list = 1 ; # Whether to generate a trickify_src_list +$build_trickify_obj_list = 1 ; # Whether to generate a trickify_obj_list +$full_build = 1 ; # Whether to build only ICG/Swig artifacts or entire source +$name = "trickified" ; # Name of the library +$build_type = "o" ; # Type of library to be built (o, a , so) +$debug = 0 ; # Debug info flag +$trick_home = $my_path . ".." ; # Trick directory to use for building + +$skip_arg = 0 ; +foreach $argnum (0 .. $#ARGV) +{ + if($skip_arg) + { + $skip_arg = 0 ; + next ; + } + + $arg = $ARGV[$argnum] ; + if($arg eq "-d") # Set both source and header directory + { + $source_dir = $ARGV[$argnum + 1] ; + $header_dir = $source_dir ; + $skip_arg = 1 ; + } + elsif($arg eq "-s") # Set source directory + { + $source_dir = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-h") # Set header directory + { + $header_dir = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-ph") # Preserve S_source.hh + { + $build_s_source = 0 ; + } + elsif($arg eq "-ps") # Preserve trickify_src_list + { + $build_trickify_src_list = 0 ; + } + elsif($arg eq "-po") # Preserve trickify_obj_list + { + $build_trickify_obj_list = 0 ; + } + elsif($arg eq "-t") # Build trick artifacts only + { + $full_build = 0 ; + } + elsif($arg eq "-m") # Make call to build object files + { + $source_make_call = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-ma") # Default make call args to build object files + { + $source_make_args = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-tm") # Trickify make args + { + $trickify_make_args = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-tp") # Set trickify make path + { + $trickify_make_path = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-n") # Set the library name + { + $name = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + elsif($arg eq "-b") # Set library build type + { + $val = $ARGV[$argnum + 1] ; + if( ($val eq "o") or ($val eq "a") or ($val eq "so") ) + { + $build_type = $ARGV[$argnum + 1] ; + } + else + { + print "Invalid build type {$val}, valid build types are {o, a, so}\n" ; + exit 1 ; + } + $skip_arg = 1 ; + } + elsif($arg eq "-v") # Verbose, print debug info + { + $debug = 1 ; + } + elsif($arg eq "-th") # Set trick home directory + { + $trick_home = $ARGV[$argnum + 1] ; + $skip_arg = 1 ; + } + else + { + print "Unrecognized argument: $arg\n" ; + exit 1 ; + } +} + +if($header_dir eq "") +{ + print "Must set a header directory\n" ; + exit 1 ; +} + +if($source_dir eq "" and $full_build) +{ + print "Must set a source directory\n" ; + exit 1 ; +} + +#Set Environment Variables +if ($full_build) +{ + $ENV{'FULL_TRICKIFY_BUILD'} = "1" ; +} +my @src_dirs = split ' ', $source_dir ; +$source_dir_arg = "" ; +foreach $dir (@src_dirs) +{ + $source_dir_arg .= "-I " . $dir . " "; +} +$ENV{'TRICKIFY_CXX_FLAGS'} = "$source_dir_args -I $trick_home" . "/include" ; +$ENV{'TRICKIFY_OBJECT_NAME'} = "$name.$build_type" ; +$ENV{'TRICKIFY_SOURCE'} = "$source_dir" ; +$ENV{'TRICKIFY_HEADER'} = "$header_dir" ; +if ( $build_type eq o ) +{ + $ENV{'TRICKIFY_BUILD_TYPE'} = PLO ; +} +elsif ( $build_type eq a ) +{ + $ENV{'TRICKIFY_BUILD_TYPE'} = STATIC ; +} +elsif ( $build_type eq so ) +{ + $ENV{'TRICKIFY_BUILD_TYPE'} = SHARED ; +} + +#Build the S_source.hh +if ($build_s_source) +{ + print "Building S_source.hh\n" ; + $make_s_source = "python3 $my_path../share/trick/makefiles/build_trickify_S_source_hh.py" ; + print(`$make_s_source`) ; +} + +#Build source file list, only if trickifying the entire library +if ($build_trickify_src_list and $full_build) +{ + print "Building trickify_src_list\n" ; + $make_src_list = "python3 $my_path../share/trick/makefiles/build_trickify_src_list.py" ; + print(`$make_src_list`) ; +} + +#Build array of source files +if ($full_build) +{ + open ($fh, "trickify_src_list") or die "Could not open trickify_src_list: $!" ; + @src_files ; + while (my $line = <$fh>) + { + chomp $line ; + push @src_files, $line ; + } + close (fh) ; +} + +#Build object files from source file list +if ($full_build) +{ + print "Building object files\n" ; + if($source_make_call eq "") + { + foreach $src (@src_files) + { + $file = $src ; + $file =~ s/\Q.cpp\E$// ; + $file =~ s/\Q.c$\E$// ; + $cmd = "g++ $source_make_args -I $trick_home" . "/include -c $src -o $file.o" ; + if($debug) + { + print "Building obj file: $cmd\n" ; + } + print(`$cmd`) ; + } + } + else + { + print(`$source_make_call`) ; + } +} + +#Build object file list, only if trickifying the entire library +if($build_trickify_obj_list and $full_build) +{ + print "Building trickify_obj_list\n" ; + $make_obj_list = "python3 $my_path../share/trick/makefiles/build_trickify_obj_list.py" ; + print(`$make_obj_list`) ; +} + +#Build trickify call +print "Begin Trickification...\n" ; +$trickify_make_call = "make $trickify_make_args -f $trickify_make_path" ; +print(`$trickify_make_call`) ; + +if($debug) { + print + "TRICKIFY BUILD INFO: + header_dir = $header_dir + source_dir = $source_dir_arg + source_make_call = $source_make_call + trickify_make_args = $trickify_make_args + trickify_make_path = $trickify_make_path + build_s_source = $build_s_source + full_build = $full_build + name = $name + build_type = $build_type + trick_home = $trick_home\n" ; +} diff --git a/share/trick/makefiles/build_trickify.py b/share/trick/makefiles/build_trickify.py new file mode 100644 index 00000000..897b5932 --- /dev/null +++ b/share/trick/makefiles/build_trickify.py @@ -0,0 +1,51 @@ +from pathlib import Path +import os + +def_header_ext = ["h", "hh", "hpp", "H", "hxx", "h++"] +def_src_ext = ["cpp", "c"] + +def find_files_by_extension(loc, ext): + path = Path(loc) + files = list(path.rglob(f'*.{ext}')) + return files + +def build_S_source(): + loc = "" + if "TRICKIFY_HEADER" in os.environ: + loc = os.getenv("TRICKIFY_HEADER") + dirs = loc.split() + + s_source = open("S_source.hh", 'w') + + for path in dirs: + for ext in def_header_ext: + files = find_files_by_extension(path, ext) + for i in range(len(files)): + s_source.write('#include "' + str(files[i]) + '"\n') + +def build_obj_list(): + loc = "" + if "TRICKIFY_SOURCE" in os.environ: + loc = os.getenv("TRICKIFY_SOURCE") + dirs = loc.split() + + obj_list = open("trickify_obj_list", 'w') + + for path in dirs: + files = find_files_by_extension(path, "o") + for i in range(len(files)): + obj_list.write(str(files[i]) + '\n') + +def build_src_list(): + loc = "" + if "TRICKIFY_SOURCE" in os.environ: + loc = os.getenv("TRICKIFY_SOURCE") + dirs = loc.split() + + src_list = open("trickify_src_list", 'w') + + for path in dirs: + for ext in def_src_ext: + files = find_files_by_extension(path, ext) + for i in range(len(files)): + src_list.write(str(files[i]) + '\n') diff --git a/share/trick/makefiles/build_trickify_S_source_hh.py b/share/trick/makefiles/build_trickify_S_source_hh.py new file mode 100644 index 00000000..92242d43 --- /dev/null +++ b/share/trick/makefiles/build_trickify_S_source_hh.py @@ -0,0 +1,10 @@ +import os + +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" + +exec(open(path).read()) + +build_S_source() diff --git a/share/trick/makefiles/build_trickify_obj_list.py b/share/trick/makefiles/build_trickify_obj_list.py new file mode 100644 index 00000000..0fa24786 --- /dev/null +++ b/share/trick/makefiles/build_trickify_obj_list.py @@ -0,0 +1,10 @@ +import os + +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" + +exec(open(path).read()) + +build_obj_list() diff --git a/share/trick/makefiles/build_trickify_src_list.py b/share/trick/makefiles/build_trickify_src_list.py new file mode 100644 index 00000000..164733d6 --- /dev/null +++ b/share/trick/makefiles/build_trickify_src_list.py @@ -0,0 +1,10 @@ +import os + +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" + +exec(open(path).read()) + +build_src_list() diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index 68aa90e8..74c9fdcb 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -50,6 +50,8 @@ # The file into which generated Python modules are zipped. The default # value is python (in the current directory). # +# TRICKIFY_SOURCE +# # ----------------------------------------------------------------------------- # # EXAMPLE: @@ -105,17 +107,22 @@ include $(dir $(lastword $(MAKEFILE_LIST)))Makefile.common BUILD_DIR := $(dir $(MAKE_OUT)) PY_LINK_LIST := $(BUILD_DIR)trickify_py_link_list IO_LINK_LIST := $(BUILD_DIR)trickify_io_link_list -LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST) +OBJ_LINK_LIST := trickify_obj_list +ifdef FULL_TRICKIFY_BUILD + LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST) @$(OBJ_LINK_LIST) +else + LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST) +endif ifneq ($(wildcard $(BUILD_DIR)),) - SWIG_OBJECTS := $(shell cat $(PY_LINK_LIST)) - IO_OBJECTS := $(shell cat $(IO_LINK_LIST)) + SWIG_OBJECTS := $(shell cat $(PY_LINK_LIST)) + IO_OBJECTS := $(shell cat $(IO_LINK_LIST)) endif TRICK_CFLAGS += $(TRICKIFY_CXX_FLAGS) TRICK_CXXFLAGS += $(TRICKIFY_CXX_FLAGS) # Ensure we can process all headers -TRICK_EXT_LIB_DIRS := $(TRICKIFY_EXT_LIB_DIRS) +TRICK_EXT_LIB_DIRS := .PHONY: all all: $(TRICKIFY_OBJECT_NAME) $(TRICKIFY_PYTHON_DIR) diff --git a/test/Makefile b/test/Makefile index f60dd273..5f15e1e6 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,8 +6,19 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common SIM_DIRECTORIES = $(wildcard SIM_*) UNIT_TEST_RESULTS = $(addprefix $(TRICK_HOME)/trick_test/, $(addsuffix .xml, $(SIM_DIRECTORIES))) +# The auto-generated makefile for each test does not know to call other makefiles the user may have included. +# User generated clean calls must be directly called here +# Otherwise build artifacts may not be cleaned and give misleading test results +clean_trickify: + for i in $(SIM_DIRECTORIES) ; do \ + if [ -f "$$i/trickified_project/trickified/"[Mm]"akefile" ] ; then \ + $(MAKE) -C $$i/trickified_project/trickified/ clean ; \ + elif [ -f "$$i/models/trickified/"[Mm]"akefile" ] ; then \ + $(MAKE) -C $$i/models/trickified/ clean ; \ + fi \ + done -clean: +clean: clean_trickify rm -f $(UNIT_TEST_RESULTS) - for i in $(SIM_DIRECTORIES) ; do \ if [ -f "$$i/"[Mm]"akefile" ] ; then \ diff --git a/test/SIM_trickified/S_overrides.mk b/test/SIM_trickified/S_overrides.mk deleted file mode 100644 index ad344832..00000000 --- a/test/SIM_trickified/S_overrides.mk +++ /dev/null @@ -1,2 +0,0 @@ -include trickified_project/trickified/myproject.mk -TRICK_CXXFLAGS += -I$(CURDIR)/models diff --git a/test/SIM_trickified/trickified_project/trickified/Makefile b/test/SIM_trickified/trickified_project/trickified/Makefile deleted file mode 100644 index ae6eb310..00000000 --- a/test/SIM_trickified/trickified_project/trickified/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -PROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) -TRICK_HOME := $(abspath $(PROJECT_HOME)/../../..) - -export TRICKIFY_OBJECT_NAME := trickified_myproject.o -export TRICKIFY_CXX_FLAGS := -I$(PROJECT_HOME)/include -I$(TRICK_HOME)/include - -all: - @$(MAKE) -s -f $(TRICK_HOME)/share/trick/makefiles/trickify.mk - -clean: - @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) diff --git a/test/SIM_trickified/trickified_project/trickified/S_source.hh b/test/SIM_trickified/trickified_project/trickified/S_source.hh deleted file mode 100644 index a6dab172..00000000 --- a/test/SIM_trickified/trickified_project/trickified/S_source.hh +++ /dev/null @@ -1,2 +0,0 @@ -#include "Foo.hh" -#include "Bar.hh" diff --git a/test/SIM_trickified/RUN_test/unit_test.py b/test/SIM_trickified_archive/RUN_test/unit_test.py similarity index 100% rename from test/SIM_trickified/RUN_test/unit_test.py rename to test/SIM_trickified_archive/RUN_test/unit_test.py diff --git a/test/SIM_trickified/S_define b/test/SIM_trickified_archive/S_define similarity index 100% rename from test/SIM_trickified/S_define rename to test/SIM_trickified_archive/S_define diff --git a/test/SIM_trickified_archive/S_overrides.mk b/test/SIM_trickified_archive/S_overrides.mk new file mode 100644 index 00000000..e17d8690 --- /dev/null +++ b/test/SIM_trickified_archive/S_overrides.mk @@ -0,0 +1,4 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models +include $(CURDIR)/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified/models/Baz.hh b/test/SIM_trickified_archive/models/Baz.hh similarity index 100% rename from test/SIM_trickified/models/Baz.hh rename to test/SIM_trickified_archive/models/Baz.hh diff --git a/test/SIM_trickified_archive/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.cpp new file mode 100644 index 00000000..55a07a84 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Bar.hh" + + +void Bar::add() {} +void Bar::remove() {} +void Bar::restart() {} + diff --git a/test/SIM_trickified/trickified_project/include/Bar.hh b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.hh similarity index 87% rename from test/SIM_trickified/trickified_project/include/Bar.hh rename to test/SIM_trickified_archive/trickified_project/include_bar/Bar.hh index 5640bfb0..5c497262 100644 --- a/test/SIM_trickified/trickified_project/include/Bar.hh +++ b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.hh @@ -10,8 +10,8 @@ class Bar : public Trick::Event { int process(long long) {return 0;} - void add() {} - void remove() {} - void restart() {} + void add(); + void remove(); + void restart(); }; diff --git a/test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp new file mode 100644 index 00000000..f8c4fe60 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified/trickified_project/include/Foo.hh b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh similarity index 61% rename from test/SIM_trickified/trickified_project/include/Foo.hh rename to test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh index be7e761a..a29d0719 100644 --- a/test/SIM_trickified/trickified_project/include/Foo.hh +++ b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh @@ -8,8 +8,6 @@ class Foo { int i; - void foo() { - std::cout << i++ << '\n'; - } + void foo(); }; diff --git a/test/SIM_trickified/trickified_project/trickified/.gitignore b/test/SIM_trickified_archive/trickified_project/trickified/.gitignore similarity index 100% rename from test/SIM_trickified/trickified_project/trickified/.gitignore rename to test/SIM_trickified_archive/trickified_project/trickified/.gitignore diff --git a/test/SIM_trickified_archive/trickified_project/trickified/Makefile b/test/SIM_trickified_archive/trickified_project/trickified/Makefile new file mode 100644 index 00000000..4cf63573 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/Makefile @@ -0,0 +1,15 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b a -n trickified_myproject -v + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) + @rm -rf $(MYPROJECT_TRICK) + @rm -rf trickify_obj_list + @rm -rf trickify_src_list + @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified_archive/trickified_project/trickified/myproject.mk b/test/SIM_trickified_archive/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..f2f61e8f --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/myproject.mk @@ -0,0 +1,14 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +include $(LOCAL_DIR)/myproject_vars.mk + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified/trickified_project/trickified/myproject.mk b/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk similarity index 59% rename from test/SIM_trickified/trickified_project/trickified/myproject.mk rename to test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk index 7abe9af1..4454d8a7 100644 --- a/test/SIM_trickified/trickified_project/trickified/myproject.mk +++ b/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk @@ -4,14 +4,15 @@ export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) # Specify include paths for your headers. -MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include_foo # Users may set different flags for C and C++, so you should really modify both # to be safe. TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) -MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/trickified_myproject.o +export TRICKIFY_OBJECT_NAME := trickified_myproject.a +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME) # Tell Trick the headers and source at this location are part of a # Trickified project @@ -25,14 +26,3 @@ TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified # Link in the Trickified object TRICK_LDFLAGS += $(MYPROJECT_TRICK) - -# Append a prerequisite to the $(SWIG_SRC) target. This will build the -# Trickified library along with the sim if it does not already exist. Using -# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is -# run on any simulation .i files, which may %import them. Note that this does -# NOT cause the Trickified library to be rebuilt if it already exists, even if -# the Trickified source code has changed. -$(SWIG_SRC): $(MYPROJECT_TRICK) - -$(MYPROJECT_TRICK): - @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified_object/RUN_test/unit_test.py b/test/SIM_trickified_object/RUN_test/unit_test.py new file mode 100644 index 00000000..f74fee0b --- /dev/null +++ b/test/SIM_trickified_object/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_trickified_object/S_define b/test/SIM_trickified_object/S_define new file mode 100644 index 00000000..f770e2a7 --- /dev/null +++ b/test/SIM_trickified_object/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified_object/S_overrides.mk b/test/SIM_trickified_object/S_overrides.mk new file mode 100644 index 00000000..e17d8690 --- /dev/null +++ b/test/SIM_trickified_object/S_overrides.mk @@ -0,0 +1,4 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models +include $(CURDIR)/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified_object/models/Baz.hh b/test/SIM_trickified_object/models/Baz.hh new file mode 100644 index 00000000..fc91c1b2 --- /dev/null +++ b/test/SIM_trickified_object/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp new file mode 100644 index 00000000..55a07a84 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Bar.hh" + + +void Bar::add() {} +void Bar::remove() {} +void Bar::restart() {} + diff --git a/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh b/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh new file mode 100644 index 00000000..5c497262 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh @@ -0,0 +1,17 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +/** + * Induce an `%import sim_services` statement in this class's Python module by inheriting from a + * Trick class. This allows us to test if `sys.path` contains the correct path to `sim_services.py` + * (and other modules generated during a sim build) for Trickified projects. + */ +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add(); + void remove(); + void restart(); + +}; diff --git a/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp new file mode 100644 index 00000000..f8c4fe60 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh new file mode 100644 index 00000000..a29d0719 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh @@ -0,0 +1,13 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo(); + +}; diff --git a/test/SIM_trickified_object/trickified_project/trickified/.gitignore b/test/SIM_trickified_object/trickified_project/trickified/.gitignore new file mode 100644 index 00000000..0259157c --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o diff --git a/test/SIM_trickified_object/trickified_project/trickified/Makefile b/test/SIM_trickified_object/trickified_project/trickified/Makefile new file mode 100644 index 00000000..f087848e --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/Makefile @@ -0,0 +1,15 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b o -n trickified_myproject -v + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) + @rm -rf $(MYPROJECT_TRICK) + @rm -rf trickify_obj_list + @rm -rf trickify_src_list + @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified_object/trickified_project/trickified/myproject.mk b/test/SIM_trickified_object/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..f2f61e8f --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/myproject.mk @@ -0,0 +1,14 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +include $(LOCAL_DIR)/myproject_vars.mk + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified_object/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_object/trickified_project/trickified/myproject_vars.mk new file mode 100644 index 00000000..3f562422 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/myproject_vars.mk @@ -0,0 +1,28 @@ +# We know this file's position relative to the root directory of the project, +# and MAKEFILE_LIST will give us the full path to this file no matter where the +# user has installed this project. +export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) + +# Specify include paths for your headers. +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include_foo + +# Users may set different flags for C and C++, so you should really modify both +# to be safe. +TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) +TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) + +export TRICKIFY_OBJECT_NAME := trickified_myproject.o +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME) + +# Tell Trick the headers and source at this location are part of a +# Trickified project +TRICK_EXT_LIB_DIRS += :$(MYPROJECT_HOME) + +# Tell Trick where to find the Python modules generated by SWIG +TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python + +# Tell SWIG where to find py_*.i files +TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified + +# Link in the Trickified object +TRICK_LDFLAGS += $(MYPROJECT_TRICK) diff --git a/test/SIM_trickified_shared/RUN_test/unit_test.py b/test/SIM_trickified_shared/RUN_test/unit_test.py new file mode 100644 index 00000000..f74fee0b --- /dev/null +++ b/test/SIM_trickified_shared/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_trickified_shared/S_define b/test/SIM_trickified_shared/S_define new file mode 100644 index 00000000..f770e2a7 --- /dev/null +++ b/test/SIM_trickified_shared/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified_shared/S_overrides.mk b/test/SIM_trickified_shared/S_overrides.mk new file mode 100644 index 00000000..e17d8690 --- /dev/null +++ b/test/SIM_trickified_shared/S_overrides.mk @@ -0,0 +1,4 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models +include $(CURDIR)/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified_shared/models/Baz.hh b/test/SIM_trickified_shared/models/Baz.hh new file mode 100644 index 00000000..fc91c1b2 --- /dev/null +++ b/test/SIM_trickified_shared/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp new file mode 100644 index 00000000..55a07a84 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Bar.hh" + + +void Bar::add() {} +void Bar::remove() {} +void Bar::restart() {} + diff --git a/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh new file mode 100644 index 00000000..5c497262 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh @@ -0,0 +1,17 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +/** + * Induce an `%import sim_services` statement in this class's Python module by inheriting from a + * Trick class. This allows us to test if `sys.path` contains the correct path to `sim_services.py` + * (and other modules generated during a sim build) for Trickified projects. + */ +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add(); + void remove(); + void restart(); + +}; diff --git a/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp new file mode 100644 index 00000000..f8c4fe60 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh new file mode 100644 index 00000000..a29d0719 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh @@ -0,0 +1,13 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo(); + +}; diff --git a/test/SIM_trickified_shared/trickified_project/trickified/.gitignore b/test/SIM_trickified_shared/trickified_project/trickified/.gitignore new file mode 100644 index 00000000..0259157c --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o diff --git a/test/SIM_trickified_shared/trickified_project/trickified/Makefile b/test/SIM_trickified_shared/trickified_project/trickified/Makefile new file mode 100644 index 00000000..f4013441 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/Makefile @@ -0,0 +1,15 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b so -n trickified_myproject -v -ma "-fPIC" + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) + @rm -rf $(MYPROJECT_TRICK) + @rm -rf trickify_obj_list + @rm -rf trickify_src_list + @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk b/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..f2f61e8f --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk @@ -0,0 +1,14 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +include $(LOCAL_DIR)/myproject_vars.mk + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk new file mode 100644 index 00000000..8f3a556b --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk @@ -0,0 +1,28 @@ +# We know this file's position relative to the root directory of the project, +# and MAKEFILE_LIST will give us the full path to this file no matter where the +# user has installed this project. +export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) + +# Specify include paths for your headers. +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include_foo + +# Users may set different flags for C and C++, so you should really modify both +# to be safe. +TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) +TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) + +export TRICKIFY_OBJECT_NAME := trickified_myproject.so +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME) + +# Tell Trick the headers and source at this location are part of a +# Trickified project +TRICK_EXT_LIB_DIRS += :$(MYPROJECT_HOME) + +# Tell Trick where to find the Python modules generated by SWIG +TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python + +# Tell SWIG where to find py_*.i files +TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified + +# Link in the Trickified object +TRICK_LDFLAGS += $(MYPROJECT_TRICK) diff --git a/test_sims.yml b/test_sims.yml index a6f56dea..cefeecea 100644 --- a/test_sims.yml +++ b/test_sims.yml @@ -21,8 +21,6 @@ SIM_parse_s_define: path: test/SIM_parse_s_define SIM_target_specific_variables: path: test/SIM_target_specific_variables -SIM_swig_template_scoping: - path: test/SIM_swig_template_scoping SIM_test_abstract: path: test/SIM_test_abstract SIM_test_inherit: @@ -114,8 +112,22 @@ SIM_threads: runs: RUN_test/unit_test.py: returns: 0 -SIM_trickified: - path: test/SIM_trickified +SIM_trickified_object: + path: test/SIM_trickified_object + build_args: "-t" + binary: "T_main_{cpu}_test.exe" + runs: + RUN_test/unit_test.py: + returns: 0 +SIM_trickified_archive: + path: test/SIM_trickified_archive + build_args: "-t" + binary: "T_main_{cpu}_test.exe" + runs: + RUN_test/unit_test.py: + returns: 0 +SIM_trickified_shared: + path: test/SIM_trickified_shared build_args: "-t" binary: "T_main_{cpu}_test.exe" runs: