mirror of
https://github.com/nasa/trick.git
synced 2025-04-07 11:26:47 +00:00
Implmented trick-ify
This commit is contained in:
parent
f9d9d6ea00
commit
be8a772362
238
bin/trick-ify
Executable file
238
bin/trick-ify
Executable file
@ -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" ;
|
||||
}
|
51
share/trick/makefiles/build_trickify.py
Normal file
51
share/trick/makefiles/build_trickify.py
Normal file
@ -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')
|
10
share/trick/makefiles/build_trickify_S_source_hh.py
Normal file
10
share/trick/makefiles/build_trickify_S_source_hh.py
Normal file
@ -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()
|
10
share/trick/makefiles/build_trickify_obj_list.py
Normal file
10
share/trick/makefiles/build_trickify_obj_list.py
Normal file
@ -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()
|
10
share/trick/makefiles/build_trickify_src_list.py
Normal file
10
share/trick/makefiles/build_trickify_src_list.py
Normal file
@ -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()
|
@ -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)
|
||||
|
@ -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 \
|
||||
|
@ -1,2 +0,0 @@
|
||||
include trickified_project/trickified/myproject.mk
|
||||
TRICK_CXXFLAGS += -I$(CURDIR)/models
|
@ -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)
|
@ -1,2 +0,0 @@
|
||||
#include "Foo.hh"
|
||||
#include "Bar.hh"
|
4
test/SIM_trickified_archive/S_overrides.mk
Normal file
4
test/SIM_trickified_archive/S_overrides.mk
Normal file
@ -0,0 +1,4 @@
|
||||
LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models
|
||||
include $(CURDIR)/trickified_project/trickified/myproject.mk
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Bar.hh"
|
||||
|
||||
|
||||
void Bar::add() {}
|
||||
void Bar::remove() {}
|
||||
void Bar::restart() {}
|
||||
|
@ -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();
|
||||
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Foo.hh"
|
||||
|
||||
|
||||
|
||||
void Foo::foo() {
|
||||
std::cout << i++ << '\n';
|
||||
}
|
@ -8,8 +8,6 @@ class Foo {
|
||||
|
||||
int i;
|
||||
|
||||
void foo() {
|
||||
std::cout << i++ << '\n';
|
||||
}
|
||||
void foo();
|
||||
|
||||
};
|
@ -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
|
@ -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
|
@ -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
|
4
test/SIM_trickified_object/RUN_test/unit_test.py
Normal file
4
test/SIM_trickified_object/RUN_test/unit_test.py
Normal file
@ -0,0 +1,4 @@
|
||||
sandbox.foo.i = 5
|
||||
assert sandbox.foo.i == 5
|
||||
foo = trick.Foo()
|
||||
trick.stop(10)
|
21
test/SIM_trickified_object/S_define
Normal file
21
test/SIM_trickified_object/S_define
Normal file
@ -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;
|
4
test/SIM_trickified_object/S_overrides.mk
Normal file
4
test/SIM_trickified_object/S_overrides.mk
Normal file
@ -0,0 +1,4 @@
|
||||
LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models
|
||||
include $(CURDIR)/trickified_project/trickified/myproject.mk
|
9
test/SIM_trickified_object/models/Baz.hh
Normal file
9
test/SIM_trickified_object/models/Baz.hh
Normal file
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
class Baz {
|
||||
|
||||
public:
|
||||
int i;
|
||||
int j;
|
||||
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Bar.hh"
|
||||
|
||||
|
||||
void Bar::add() {}
|
||||
void Bar::remove() {}
|
||||
void Bar::restart() {}
|
||||
|
@ -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();
|
||||
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Foo.hh"
|
||||
|
||||
|
||||
|
||||
void Foo::foo() {
|
||||
std::cout << i++ << '\n';
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Foo {
|
||||
|
||||
public:
|
||||
|
||||
int i;
|
||||
|
||||
void foo();
|
||||
|
||||
};
|
4
test/SIM_trickified_object/trickified_project/trickified/.gitignore
vendored
Normal file
4
test/SIM_trickified_object/trickified_project/trickified/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
python
|
||||
trick
|
||||
*.o
|
@ -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
|
@ -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
|
@ -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)
|
4
test/SIM_trickified_shared/RUN_test/unit_test.py
Normal file
4
test/SIM_trickified_shared/RUN_test/unit_test.py
Normal file
@ -0,0 +1,4 @@
|
||||
sandbox.foo.i = 5
|
||||
assert sandbox.foo.i == 5
|
||||
foo = trick.Foo()
|
||||
trick.stop(10)
|
21
test/SIM_trickified_shared/S_define
Normal file
21
test/SIM_trickified_shared/S_define
Normal file
@ -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;
|
4
test/SIM_trickified_shared/S_overrides.mk
Normal file
4
test/SIM_trickified_shared/S_overrides.mk
Normal file
@ -0,0 +1,4 @@
|
||||
LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models
|
||||
include $(CURDIR)/trickified_project/trickified/myproject.mk
|
9
test/SIM_trickified_shared/models/Baz.hh
Normal file
9
test/SIM_trickified_shared/models/Baz.hh
Normal file
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
class Baz {
|
||||
|
||||
public:
|
||||
int i;
|
||||
int j;
|
||||
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Bar.hh"
|
||||
|
||||
|
||||
void Bar::add() {}
|
||||
void Bar::remove() {}
|
||||
void Bar::restart() {}
|
||||
|
@ -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();
|
||||
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include "Foo.hh"
|
||||
|
||||
|
||||
|
||||
void Foo::foo() {
|
||||
std::cout << i++ << '\n';
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
// @trick_parse{everything}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Foo {
|
||||
|
||||
public:
|
||||
|
||||
int i;
|
||||
|
||||
void foo();
|
||||
|
||||
};
|
4
test/SIM_trickified_shared/trickified_project/trickified/.gitignore
vendored
Normal file
4
test/SIM_trickified_shared/trickified_project/trickified/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
python
|
||||
trick
|
||||
*.o
|
@ -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
|
@ -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
|
@ -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)
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user