diff --git a/bin/trick-ify b/bin/trick-ify new file mode 100755 index 000000000..e778e5cb6 --- /dev/null +++ b/bin/trick-ify @@ -0,0 +1,189 @@ +#!/usr/bin/perl + +use Getopt::Long; + +$my_path = $0 ; +$my_path =~ s/trick-ify// ; + +$dirs = "" ; # If set, use for both source and header files +$source_dir = "" ; # Base path to build source 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 +$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 +$no_source_build = 0 ; # Arg to disable building source files +$no_clean_obj = 0 ; # Don't rebuild trickify_obj_list +$no_clean_src = 0 ; # Don't rebuild trickify_src_list +$no_clean_s_source = 0 ; # Don't rebuild S_source.hh +$s_overrides = "" ; # Directory containing S_override make files + +GetOptions +( + "d=s" => \$dirs, # Set source and header directory + "s=s" => \$source_dir, # Set source directory + "h=s" => \$header_dir, # Set header directory + "no_clean_s_source" => \$no_clean_s_source, # Don't rebuild S_source.hh + "no_clean_src_list" => \$no_clean_src, # Don't rebuild trickify_src_list + "no_clean_obj_list" => \$no_clean_obj, # Don't rebuild trickify_obj_list + "no_source" => \$no_source_build, # Arg to disable building source files + "source_make=s" => \$source_make_call, # Make call to build object files + "source_make_args=s" => \$source_make_args, # Default make call args to build object files + "trickify_args=s" => \$trickify_make_args, # Trickify make args + "trickify_make=s" => \$trickify_make_path, # Set trickify make path + "n=s" => \$name, # Set the library name + "b=s" => \$build_type, # Set library build type + "v" => \$debug, # Verbose, print debug info + "trick_home=s" => \$trick_home, # Set trick home directory + "s_overrides=s" => \$s_overrides # Directory containing S_override make files +) ; + +$full_build = !$no_source_build ; + +$val = $ARGV[$argnum + 1] ; +if( !(($build_type eq "o") or ($build_type eq "a") or ($build_type eq "so") or ($build_type eq "dylib")) ) +{ + print "Invalid build type {$build_type}, valid build types are {o, a, so}\n" ; + exit 1 ; +} + +if($dirs ne "") +{ + $header_dir = $dirs ; + $source_dir = $dirs ; +} + +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" ; +$ENV{'TRICKIFY_S_OVERRIDES'} = "$s_overrides" ; +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 || $build_type eq dylib ) +{ + $ENV{'TRICKIFY_BUILD_TYPE'} = SHARED ; +} + +#Build the S_source.hh +if (!$no_clean_s_source) +{ + print "Building S_source.hh\n" ; + $make_s_source = "python3 $my_path../share/trick/pymods/trick/build_trickify_S_source_hh.py" ; + print(`$make_s_source`) ; +} + +#Build source file list, only if trickifying the entire library +if (!$no_clean_src and $full_build) +{ + print "Building trickify_src_list\n" ; + $make_src_list = "python3 $my_path../share/trick/pymods/trick/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 ; + if($file =~ /\S\w*(\Q.c\E)$/) + { + $file =~ s/\Q.c\E$// ; + $cmd = "gcc $source_make_args -I $trick_home -I $trick_home" . "/include -I $header_dir -c $src -o $file.o" ; + } + else + { + $file =~ s/\Q.\E\w*$// ; + $cmd = "g++ $source_make_args -I $trick_home -I $trick_home" . "/include -I $header_dir -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(!$no_clean_obj and $full_build) +{ + print "Building trickify_obj_list\n" ; + $make_obj_list = "python3 $my_path../share/trick/pymods/trick/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/bin/trick-trickify b/bin/trick-trickify new file mode 100755 index 000000000..062aca1a4 --- /dev/null +++ b/bin/trick-trickify @@ -0,0 +1,8 @@ +#!/usr/bin/perl + +use FindBin qw($RealBin); +use lib ("$RealBin/../libexec/trick/pm", "$RealBin/../lib/trick/pm") ; +use launch_java ; + +launch_java("Trickify", "Trickify") ; + diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index 68aa90e87..806dbf821 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -88,6 +88,10 @@ # For more information, see: # https://nasa.github.io/trick/documentation/building_a_simulation/Trickified-Project-Libraries +MY_HOME := $(dir $(lastword $(MAKEFILE_LIST))) + +include $(TRICKIFY_S_OVERRIDES) + ifndef TRICKIFY_CXX_FLAGS $(error TRICKIFY_CXX_FLAGS must be set) endif @@ -100,15 +104,20 @@ TRICKIFY_OBJECT_NAME ?= trickified.o TRICKIFY_PYTHON_DIR ?= python TRICKIFY_PYTHON_DIR := $(abspath $(TRICKIFY_PYTHON_DIR)) -include $(dir $(lastword $(MAKEFILE_LIST)))Makefile.common +include $(MY_HOME)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 + FULL_TRICKIFY_BUILD = "1" +else + FULL_TRICKIFY_BUILD = "0" +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) @@ -117,18 +126,42 @@ TRICK_CXXFLAGS += $(TRICKIFY_CXX_FLAGS) # Ensure we can process all headers TRICK_EXT_LIB_DIRS := $(TRICKIFY_EXT_LIB_DIRS) +UNAME := $(shell uname) +ifeq ($(UNAME), Linux) + SHARED_OPTIONS := -fPIC +else ifeq ($(UNAME), Darwin) + SHARED_OPTIONS := -fPIC + LD_OPTIONS := -Wl,-install_name,$(abspath $(TRICKIFY_OBJECT_NAME)) +else + SHARED_OPTIONS := +endif + .PHONY: all all: $(TRICKIFY_OBJECT_NAME) $(TRICKIFY_PYTHON_DIR) $(TRICKIFY_OBJECT_NAME): $(SWIG_OBJECTS) $(IO_OBJECTS) | $(dir $(TRICKIFY_OBJECT_NAME)) - $(info $(call COLOR,Linking) $@) -ifeq ($(TRICKIFY_BUILD_TYPE),PLO) - $(call ECHO_AND_LOG,$(LD) $(LD_PARTIAL) -o $@ $(LINK_LISTS)) -else ifeq ($(TRICKIFY_BUILD_TYPE),SHARED) - $(call ECHO_AND_LOG,$(TRICK_CXX) -shared -o $@ $(LINK_LISTS)) -else ifeq ($(TRICKIFY_BUILD_TYPE),STATIC) - $(call ECHO_AND_LOG,ar rcs $@ $(LINK_LISTS)) -endif + @echo TRICKIFICATION + @sh -c '\ + FILES=""; \ + while IFS= read -r line; do \ + FILES="$$FILES $$line"; \ + done < $(PY_LINK_LIST); \ + while IFS= read -r line; do \ + FILES="$$FILES $$line"; \ + done < $(IO_LINK_LIST); \ + if [ "$(FULL_TRICKIFY_BUILD)" = "1" ]; then \ + while IFS= read -r line; do \ + FILES="$$FILES $$line"; \ + done < $(OBJ_LINK_LIST); \ + fi; \ + if [ "$(TRICKIFY_BUILD_TYPE)" = "PLO" ]; then \ + $(LD) $(LD_PARTIAL) -o $@ $$FILES; \ + elif [ "$(TRICKIFY_BUILD_TYPE)" = "SHARED" ]; then \ + $(TRICK_CXX) $(SHARED_LIB_OPT) $(SHARED_OPTIONS) $(LD_OPTIONS) $(USER_ADDITIONAL_OPTIONS) -o $@ $$FILES; \ + elif [ "$(TRICKIFY_BUILD_TYPE)" = "STATIC" ]; then \ + ar rcs $@ $$FILES; \ + fi; \ + ' $(dir $(TRICKIFY_OBJECT_NAME)) $(BUILD_DIR) $(dir $(TRICKIFY_PYTHON_DIR)) .trick: @mkdir -p $@ diff --git a/share/trick/pymods/trick/build_trickify.py b/share/trick/pymods/trick/build_trickify.py new file mode 100644 index 000000000..cfc8dd0d5 --- /dev/null +++ b/share/trick/pymods/trick/build_trickify.py @@ -0,0 +1,54 @@ +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): + file_list = [] + for root, dirs, files in os.walk(loc): + for f in files: + if f.endswith(ext): + file_list.append(os.path.join(root, f)) + return file_list + +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/pymods/trick/build_trickify_S_source_hh.py b/share/trick/pymods/trick/build_trickify_S_source_hh.py new file mode 100644 index 000000000..a92b59768 --- /dev/null +++ b/share/trick/pymods/trick/build_trickify_S_source_hh.py @@ -0,0 +1,6 @@ +import os + +path = os.path.dirname(os.path.abspath(__file__)) + "/build_trickify.py" +exec(open(path).read()) + +build_S_source() diff --git a/share/trick/pymods/trick/build_trickify_obj_list.py b/share/trick/pymods/trick/build_trickify_obj_list.py new file mode 100644 index 000000000..4066cf2e2 --- /dev/null +++ b/share/trick/pymods/trick/build_trickify_obj_list.py @@ -0,0 +1,6 @@ +import os + +path = os.path.dirname(os.path.abspath(__file__)) + "/build_trickify.py" +exec(open(path).read()) + +build_obj_list() diff --git a/share/trick/pymods/trick/build_trickify_src_list.py b/share/trick/pymods/trick/build_trickify_src_list.py new file mode 100644 index 000000000..d3a9466ae --- /dev/null +++ b/share/trick/pymods/trick/build_trickify_src_list.py @@ -0,0 +1,6 @@ +import os + +path = os.path.dirname(os.path.abspath(__file__)) + "/build_trickify.py" +exec(open(path).read()) + +build_src_list() diff --git a/test/Makefile b/test/Makefile index f60dd2730..da0b999fd 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 developer may have included. +# Developer 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/trickified_project/trickified/Makefile b/test/SIM_trickified/trickified_project/trickified/Makefile index ae6eb3103..ed9a8dd12 100644 --- a/test/SIM_trickified/trickified_project/trickified/Makefile +++ b/test/SIM_trickified/trickified_project/trickified/Makefile @@ -1,6 +1,7 @@ PROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) TRICK_HOME := $(abspath $(PROJECT_HOME)/../../..) +export TRICKIFY_BUILD_TYPE := PLO export TRICKIFY_OBJECT_NAME := trickified_myproject.o export TRICKIFY_CXX_FLAGS := -I$(PROJECT_HOME)/include -I$(TRICK_HOME)/include diff --git a/test/SIM_trickified_archive/RUN_test/unit_test.py b/test/SIM_trickified_archive/RUN_test/unit_test.py new file mode 100644 index 000000000..f74fee0bf --- /dev/null +++ b/test/SIM_trickified_archive/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_archive/S_define b/test/SIM_trickified_archive/S_define new file mode 100644 index 000000000..1c86251ed --- /dev/null +++ b/test/SIM_trickified_archive/S_define @@ -0,0 +1,20 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.h" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified_archive/S_overrides.mk b/test/SIM_trickified_archive/S_overrides.mk new file mode 100644 index 000000000..e17d8690e --- /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_archive/models/Baz.hh b/test/SIM_trickified_archive/models/Baz.hh new file mode 100644 index 000000000..fc91c1b21 --- /dev/null +++ b/test/SIM_trickified_archive/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified_archive/trickified_project/include_bar/Bar.c b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.c new file mode 100644 index 000000000..cf5649184 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.c @@ -0,0 +1,6 @@ +#include "Bar.h" + +int process(long long x) {return 0;} +void add() {} +void remove_Bar() {} +void restart() {} diff --git a/test/SIM_trickified_archive/trickified_project/include_bar/Bar.h b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.h new file mode 100644 index 000000000..b8c3677c6 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.h @@ -0,0 +1,16 @@ +// @trick_parse{everything} + +#include "trick/exec_proto.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void add(); +void remove_Bar(); +void restart(); + +#ifdef __cplusplus +} +#endif 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 000000000..115138369 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,7 @@ +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh new file mode 100644 index 000000000..a29d07194 --- /dev/null +++ b/test/SIM_trickified_archive/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_archive/trickified_project/trickified/.gitignore b/test/SIM_trickified_archive/trickified_project/trickified/.gitignore new file mode 100644 index 000000000..0259157ce --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o 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 000000000..d7f088015 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/Makefile @@ -0,0 +1,16 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +TRICK_HOME := $(abspath $(LOCAL_DIR)/../../../..) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @$(TRICK_HOME)/bin/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 000000000..f2f61e8f9 --- /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_archive/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk new file mode 100644 index 000000000..4454d8a71 --- /dev/null +++ b/test/SIM_trickified_archive/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.a +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_object/RUN_test/unit_test.py b/test/SIM_trickified_object/RUN_test/unit_test.py new file mode 100644 index 000000000..f74fee0bf --- /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 000000000..1c86251ed --- /dev/null +++ b/test/SIM_trickified_object/S_define @@ -0,0 +1,20 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.h" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + 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 000000000..e17d8690e --- /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 000000000..fc91c1b21 --- /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.c b/test/SIM_trickified_object/trickified_project/include_bar/Bar.c new file mode 100644 index 000000000..cf5649184 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.c @@ -0,0 +1,6 @@ +#include "Bar.h" + +int process(long long x) {return 0;} +void add() {} +void remove_Bar() {} +void restart() {} diff --git a/test/SIM_trickified_object/trickified_project/include_bar/Bar.h b/test/SIM_trickified_object/trickified_project/include_bar/Bar.h new file mode 100644 index 000000000..b8c3677c6 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.h @@ -0,0 +1,16 @@ +// @trick_parse{everything} + +#include "trick/exec_proto.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void add(); +void remove_Bar(); +void restart(); + +#ifdef __cplusplus +} +#endif 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 000000000..115138369 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,7 @@ +#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 000000000..a29d07194 --- /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 000000000..0259157ce --- /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 000000000..5a1c7c56d --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/Makefile @@ -0,0 +1,16 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +TRICK_HOME := $(abspath $(LOCAL_DIR)/../../../..) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @$(TRICK_HOME)/bin/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 000000000..f2f61e8f9 --- /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 000000000..3f5624226 --- /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 000000000..f74fee0bf --- /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 000000000..1c86251ed --- /dev/null +++ b/test/SIM_trickified_shared/S_define @@ -0,0 +1,20 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.h" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + 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 000000000..e17d8690e --- /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 000000000..fc91c1b21 --- /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.c b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.c new file mode 100644 index 000000000..cf5649184 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.c @@ -0,0 +1,6 @@ +#include "Bar.h" + +int process(long long x) {return 0;} +void add() {} +void remove_Bar() {} +void restart() {} diff --git a/test/SIM_trickified_shared/trickified_project/include_bar/Bar.h b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.h new file mode 100644 index 000000000..b8c3677c6 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.h @@ -0,0 +1,16 @@ +// @trick_parse{everything} + +#include "trick/exec_proto.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +void add(); +void remove_Bar(); +void restart(); + +#ifdef __cplusplus +} +#endif 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 000000000..115138369 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,7 @@ +#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 000000000..a29d07194 --- /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 000000000..0259157ce --- /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 000000000..ce6a7d4c6 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/Makefile @@ -0,0 +1,16 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +TRICK_HOME := $(abspath $(LOCAL_DIR)/../../../..) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @$(TRICK_HOME)/bin/trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b $(BUILD_TYPE) -n trickified_myproject -v --source_make_args -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 000000000..f2f61e8f9 --- /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 000000000..dab1a92dc --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk @@ -0,0 +1,38 @@ +# 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) + +BUILD_TYPE := so +UNAME := $(shell uname) +ifeq ($(UNAME),Darwin) + BUILD_TYPE := dylib +endif + +export TRICKIFY_OBJECT_NAME := trickified_myproject.$(BUILD_TYPE) + +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) + +# Link in code coverage libraries for Trick code coverage CI +export USER_ADDITIONAL_OPTIONS := -fprofile-arcs -ftest-coverage -O0 \ No newline at end of file diff --git a/test_sims.yml b/test_sims.yml index a6f56dea9..e30d9cf5c 100644 --- a/test_sims.yml +++ b/test_sims.yml @@ -121,6 +121,27 @@ SIM_trickified: runs: RUN_test/unit_test.py: returns: 0 +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: + RUN_test/unit_test.py: + returns: 0 SIM_ball_L1: path: trick_sims/Ball/SIM_ball_L1 build_args: "-t" diff --git a/trick_source/java/pom.xml b/trick_source/java/pom.xml index ee69706ca..3abc3590d 100644 --- a/trick_source/java/pom.xml +++ b/trick_source/java/pom.xml @@ -154,6 +154,22 @@ SimControl + + + trickify + package + + shade + + + + + trick.trickify.TrickifyApplication + + + Trickify + + sniffer diff --git a/trick_source/java/src/main/java/trick/trickify/DirSelect.java b/trick_source/java/src/main/java/trick/trickify/DirSelect.java new file mode 100644 index 000000000..c503c50a5 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/DirSelect.java @@ -0,0 +1,129 @@ +package trick.trickify; + +import java.awt.event.*; +import java.io.*; +import javax.swing.*; + +public class DirSelect extends JPanel +{ + private int pos_x = 0; + private int pos_y = 0; + + private JLabel label; + private int label_pos_x = pos_x; + private int label_pos_y = pos_y; + private int label_width = 200; + private int label_height = 20; + + private JTextField textfield; + private int textfield_pos_x = pos_x; + private int textfield_pos_y = pos_y + label_height; + private int textfield_width = 800; + private int textfield_height = 20; + + private JButton button; + private int button_pos_x = textfield_pos_x + textfield_width; + private int button_pos_y = textfield_pos_y; + private int button_width = 100; + private int button_height = 20; + + private JFileChooser browser; + + private boolean multiDir = false; + + public void setLabel(String text) + { + label.setText(text); + } + + public void setToolTipText(String tip) + { + textfield.setToolTipText(tip); + } + + public void setButtonText(String text) + { + button.setText(text); + } + + public void allowMultiple(boolean b) + { + browser.setMultiSelectionEnabled(b); + multiDir = b; + } + + public void selectFile(boolean b) + { + if(b) + { + browser.setFileSelectionMode(JFileChooser.FILES_ONLY); + } + else + { + browser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + } + + public String getText() + { + return textfield.getText(); + } + + void setText(String txt) + { + textfield.setText(txt); + } + + public DirSelect() + { + label = new JLabel(); + label_width = 200; + label_height = 20; + + textfield = new JTextField(); + textfield_width = 800; + textfield_height = 20; + + button = new JButton(); + button_width = 100; + button_height = 20; + + browser = new JFileChooser(); + browser.setCurrentDirectory(new File(System.getProperty("user.dir"))); + browser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + int result = browser.showOpenDialog(null); + if(result == JFileChooser.CANCEL_OPTION) + { + return; + } + String filename = ""; + if(multiDir) + { + File[] files = browser.getSelectedFiles(); + for(int i = 0; i < files.length; ++i) + { + filename += files[i].getAbsolutePath() + " "; + } + textfield.setText(textfield.getText() + filename); + } + else + { + File file = browser.getSelectedFile(); + filename = file.getAbsolutePath(); + textfield.setText(filename); + } + } + } ); + + + add(label); + add(textfield); + add(button); + } + +} diff --git a/trick_source/java/src/main/java/trick/trickify/LabeledTextField.java b/trick_source/java/src/main/java/trick/trickify/LabeledTextField.java new file mode 100644 index 000000000..7610d515e --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/LabeledTextField.java @@ -0,0 +1,68 @@ +package trick.trickify; + +import java.awt.event.*; +import java.io.*; +import javax.swing.*; + +public class LabeledTextField extends JPanel +{ + private int pos_x = 0; + private int pos_y = 0; + + private JLabel label; + private int label_pos_x = pos_x; + private int label_pos_y = pos_y; + private int label_width = 200; + private int label_height = 20; + + private JTextField textfield; + private int textfield_pos_x = pos_x; + private int textfield_pos_y = pos_y + label_height; + private int textfield_width = 800; + private int textfield_height = 20; + + public void setLabel(String text) + { + label.setText(text); + } + + public void setToolTipText(String tip) + { + textfield.setToolTipText(tip); + } + + public void addToPanel(JPanel panel) + { + } + + public void addToFrame(JFrame frame) + { + frame.add(label); + frame.add(textfield); + } + + public String getText() + { + return textfield.getText(); + } + + void setText(String txt) + { + textfield.setText(txt); + } + + public LabeledTextField() + { + label = new JLabel(); + label_width = 200; + label_height = 20; + + textfield = new JTextField(); + textfield_width = 800; + textfield_height = 20; + + add(label); + add(textfield); + } + +} diff --git a/trick_source/java/src/main/java/trick/trickify/TrickifyApplication.java b/trick_source/java/src/main/java/trick/trickify/TrickifyApplication.java new file mode 100644 index 000000000..313d9ceda --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/TrickifyApplication.java @@ -0,0 +1,57 @@ +package trick.trickify; + +import javax.swing.*; +import org.jdesktop.application.View; +import trick.common.TrickApplication; + +public class TrickifyApplication extends TrickApplication +{ + private TrickifyPanel panel; + + public static void main(String[] args) + { + launch(TrickifyApplication.class, args); + } + + @Override + protected JComponent createMainPanel() + { + if(panel == null) + { + panel = new TrickifyPanel(); + } + return panel; + } + + @Override + protected void initialize(String[] args) + { + super.initialize(args); + trickProperties.setProperty("Application.title", "Trickify"); + } + + @Override + protected void startup() + { + super.startup(); + createMainPanel(); + + panel.load_properties(trickProperties); + + // Build the GUI. + View view = getMainView(); + view.setComponent(panel); + view.setMenuBar(panel.getMenuBar()); + + // Display the GUI. + show(view); + } + + @Override + protected void shutdown() + { + panel.save_properties(trickProperties); + + super.shutdown(); + } +} diff --git a/trick_source/java/src/main/java/trick/trickify/TrickifyPanel.java b/trick_source/java/src/main/java/trick/trickify/TrickifyPanel.java new file mode 100644 index 000000000..f838ecd04 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/TrickifyPanel.java @@ -0,0 +1,653 @@ +package trick.trickify; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; +import javax.swing.border.*; +import java.util.ArrayList; +import java.io.FileWriter; +import java.io.FileReader; +import java.util.Properties; + +import org.jdesktop.application.Action; + +public class TrickifyPanel extends JPanel +{ + private JPanel fieldPanel; + private JPanel boxPanel; + private JPanel buttonPanel; + + private JMenuBar menu = new JMenuBar(); + private JMenu fileMenu = new JMenu(); + private JMenuItem saveMenuItem = new JMenuItem(); + private JMenuItem loadMenuItem = new JMenuItem(); + + private JMenu viewMenu = new JMenu(); + private JMenuItem defaultViewMenuItem = new JMenuItem(); + + private String trick_home; + + private int mainFrameWidth = 1000; + private int mainFrameHeight = 600; + + private JPanel mainPanel; + private DirSelect src_dirs; + private DirSelect trick_home_dirs; + private DirSelect build_path_dirs; + private DirSelect trickify_path_dirs; + private DirSelect source_make_dirs; + private DirSelect log_dirs; + private DirSelect s_overrides_dirs; + private LabeledTextField name_field; + private LabeledTextField trickify_args_field; + private LabeledTextField source_make_args_field; + private String src_dirs_config = "SOURCE_DIRS"; + private String trick_home_config = "TRICK_HOME"; + private String build_path_config = "BUILD_PATH"; + private String trickify_path_config = "TRICKIFY_PATH"; + private String source_make_config = "SOURCE_MAKE"; + private String log_config = "LOG"; + private String s_overrides_config = "S_OVERRIDES"; + private String name_config = "NAME"; + private String trickify_args_config = "TRICKIFY_ARGS"; + private String source_make_args_config = "SOURCE_MAKE_ARGS"; + private int fields_x = 50; + private int fields_y = 0; + private int fields_offset = 50; + + private JCheckBox full_build_box; + private JCheckBox no_clean_obj_box; + private JCheckBox no_clean_src_box; + private JCheckBox no_clean_s_source_box; + private JCheckBox debug_box; + private JComboBox build_type_box; + private String full_build_config = "FULL_BUILD"; + private String no_clean_obj_config = "NO_CLEAN_OBJ"; + private String no_clean_src_config = "NO_CLEAN_SRC"; + private String no_clean_s_source_config = "NO_CLEAN_S_SOURCE"; + private String debug_config = "DEBUG"; + private String build_type_config = "BUILD_TYPE"; + private int checkbox_x = 200; + private int checkbox_y = 0; + private int checkbox_width = 250; + private int checkbox_offset = 20; + + private JButton runButton; + private JButton exportButton; + + public JMenuBar getMenuBar() + { + return menu; + } + + public ArrayList getTrickifyCmd(boolean useQuotes) + { + ArrayList cmdLine = new ArrayList(); + cmdLine.add(trick_home + "/bin/trick-ify"); + + String src_dirs_txt = src_dirs.getText().trim(); + if(!src_dirs_txt.equals("")) + { + cmdLine.add("-d"); + if(useQuotes) + { + cmdLine.add("\"" + src_dirs_txt + "\""); + } + else + { + cmdLine.add(src_dirs_txt); + } + } + + String trick_home_dirs_txt = trick_home_dirs.getText().trim(); + if(!trick_home_dirs_txt.equals("")) + { + cmdLine.add("--trick_home"); + cmdLine.add(trick_home_dirs_txt); + } + + String trickify_path_dirs_txt = trickify_path_dirs.getText().trim(); + if(!trickify_path_dirs_txt.equals("")) + { + cmdLine.add("--trickify_make"); + cmdLine.add(trickify_path_dirs_txt); + } + + String trickify_args_field_txt = trickify_args_field.getText().trim(); + if(!trickify_args_field_txt.equals("")) + { + cmdLine.add("--trickify_args"); + cmdLine.add(trickify_args_field_txt); + } + + String source_make_dirs_txt = source_make_dirs.getText().trim(); + if(!source_make_dirs_txt.equals("")) + { + cmdLine.add("--source_make"); + cmdLine.add(source_make_dirs_txt); + } + + String source_make_args_field_txt = source_make_args_field.getText().trim(); + if(!source_make_args_field_txt.equals("")) + { + cmdLine.add("--source_make_args"); + cmdLine.add(source_make_args_field_txt); + } + + String lib_name = ""; + String build_path_dirs_txt = build_path_dirs.getText().trim(); + if(!build_path_dirs_txt.equals("")) + { + lib_name = build_path_dirs_txt; + } + + String s_overrides_dirs_txt = s_overrides_dirs.getText().trim(); + if(!s_overrides_dirs_txt.equals("")) + { + cmdLine.add("--s_overrides"); + cmdLine.add(s_overrides_dirs_txt); + } + + String name_field_txt = name_field.getText().trim(); + if(!name_field_txt.equals("")) + { + if(!lib_name.equals("")) + { + lib_name += System.getProperty("file.separator") + name_field_txt; + } + else + { + lib_name = name_field_txt; + } + cmdLine.add("-n"); + cmdLine.add(lib_name); + } + + if(!(full_build_box.isSelected())) + { + cmdLine.add("--no_source"); + } + + if(no_clean_obj_box.isSelected()) + { + cmdLine.add("--no_clean_obj_list"); + } + + if(no_clean_src_box.isSelected()) + { + cmdLine.add("--no_clean_src_list"); + } + + if(no_clean_s_source_box.isSelected()) + { + cmdLine.add("--no_clean_s_srouce"); + } + + if(debug_box.isSelected()) + { + cmdLine.add("-v"); + } + + if(build_type_box.getSelectedItem().equals("Object")) + { + cmdLine.add("-b"); + cmdLine.add("o"); + } + else if(build_type_box.getSelectedItem().equals("Shared")) + { + cmdLine.add("-b"); + cmdLine.add("so"); + } + else if(build_type_box.getSelectedItem().equals("Static")) + { + cmdLine.add("-b"); + cmdLine.add("a"); + } + + return cmdLine; + } + + private void trickify() + { + ArrayList cmd = getTrickifyCmd(false); + String[] cmdLine = new String[cmd.size()]; + cmdLine = cmd.toArray(cmdLine); + System.out.println("Executing: " + String.join(" ", cmd)); + try + { + Process process = Runtime.getRuntime().exec(cmdLine); + StringBuilder output = new StringBuilder(); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) + { + output.append(line + "\n"); + } + + String log_dirs_path = log_dirs.getText().trim(); + PrintWriter logfile = new PrintWriter(log_dirs_path + System.getProperty("file.separator") + "trickify.log", "UTF-8"); + logfile.println(output); + logfile.close(); + + System.out.println("Your technological distinctiveness has been trickified."); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void save_properties(Properties p) + { + p.setProperty(src_dirs_config, src_dirs.getText().trim()); + p.setProperty(trick_home_config, trick_home_dirs.getText().trim()); + p.setProperty(trickify_path_config, trickify_path_dirs.getText().trim()); + p.setProperty(trickify_args_config, trickify_args_field.getText().trim()); + p.setProperty(source_make_config, source_make_dirs.getText().trim()); + p.setProperty(source_make_args_config, source_make_args_field.getText().trim()); + p.setProperty(build_path_config, build_path_dirs.getText().trim()); + p.setProperty(s_overrides_config, s_overrides_dirs.getText().trim()); + p.setProperty(name_config, name_field.getText().trim()); + p.setProperty(full_build_config, Boolean.toString(full_build_box.isSelected())); + p.setProperty(no_clean_obj_config, Boolean.toString(no_clean_obj_box.isSelected())); + p.setProperty(no_clean_src_config, Boolean.toString(no_clean_src_box.isSelected())); + p.setProperty(no_clean_s_source_config, Boolean.toString(no_clean_s_source_box.isSelected())); + p.setProperty(debug_config, Boolean.toString(debug_box.isSelected())); + p.setProperty(build_type_config, build_type_box.getSelectedItem().toString()); + } + + public void load_properties(Properties p) + { + String prop = null; + + if((prop = p.getProperty(src_dirs_config)) != null) + { + src_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(trick_home_config)) != null) + { + trick_home_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(trickify_path_config)) != null) + { + trickify_path_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(trickify_args_config)) != null) + { + trickify_args_field.setText(prop); + } + prop = null; + + if((prop = p.getProperty(source_make_config)) != null) + { + source_make_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(source_make_args_config)) != null) + { + source_make_args_field.setText(prop); + } + prop = null; + + if((prop = p.getProperty(build_path_config)) != null) + { + build_path_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(s_overrides_config)) != null) + { + s_overrides_dirs.setText(prop); + } + prop = null; + + if((prop = p.getProperty(name_config)) != null) + { + name_field.setText(prop); + } + prop = null; + + if((prop = p.getProperty(full_build_config)) != null) + { + if(prop.equals("true")) + { + full_build_box.setSelected(true); + } + else + { + full_build_box.setSelected(false); + } + } + prop = null; + + if((prop = p.getProperty(no_clean_obj_config)) != null) + { + if(prop.equals("true")) + { + no_clean_obj_box.setSelected(true); + } + else + { + no_clean_obj_box.setSelected(false); + } + } + prop = null; + + if((prop = p.getProperty(no_clean_src_config)) != null) + { + if(prop.equals("true")) + { + no_clean_src_box.setSelected(true); + } + else + { + no_clean_src_box.setSelected(false); + } + } + prop = null; + + if((prop = p.getProperty(no_clean_s_source_config)) != null) + { + if(prop.equals("true")) + { + no_clean_s_source_box.setSelected(true); + } + else + { + no_clean_s_source_box.setSelected(false); + } + } + prop = null; + + if((prop = p.getProperty(debug_config)) != null) + { + if(prop.equals("true")) + { + debug_box.setSelected(true); + } + else + { + debug_box.setSelected(false); + } + } + prop = null; + + if((prop = p.getProperty(build_type_config)) != null) + { + build_type_box.setSelectedItem(prop); + } + } + + private void set_default() + { + String s = System.getProperty("file.separator"); + + src_dirs.setText(""); + trick_home_dirs.setText(trick_home); + trickify_path_dirs.setText(trick_home + s + "share" + s + "trick" + s + "makefiles" + s + "trickify.mk"); + trickify_args_field.setText(""); + source_make_dirs.setText(""); + source_make_args_field.setText(""); + s_overrides_dirs.setText(""); + build_path_dirs.setText(System.getProperty("user.dir")); + name_field.setText("TrickifiedLibrary"); + log_dirs.setText(System.getProperty("user.dir")); + full_build_box.setSelected(false); + no_clean_obj_box.setSelected(false); + no_clean_src_box.setSelected(false); + no_clean_s_source_box.setSelected(false); + debug_box.setSelected(false); + build_type_box.setSelectedItem("PLO"); + } + + @Action + public void restoreDefaultView(ActionEvent e) + { + setSize(mainFrameWidth, mainFrameHeight); + } + + TrickifyPanel() + { + + String s = System.getProperty("file.separator"); + trick_home = new File(TrickifyPanel.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getParentFile().getParentFile().getParentFile().getParentFile().getAbsolutePath(); + + setBounds(0, 0, mainFrameWidth, mainFrameHeight); + setPreferredSize(new Dimension(mainFrameWidth, mainFrameHeight)); + setBackground(Color.lightGray); + setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = GridBagConstraints.REMAINDER; + + fieldPanel = new JPanel(); + fieldPanel.setPreferredSize(new Dimension(mainFrameWidth, 400)); + fieldPanel.setLayout(new GridLayout(10, 1)); + add(fieldPanel, gbc); + + boxPanel = new JPanel(); + boxPanel.setLayout(new GridLayout(3, 2)); + add(boxPanel, gbc); + + buttonPanel = new JPanel(); + add(buttonPanel, gbc); + + //Build File Menu + fileMenu.setName("trickify.fileMenu"); + saveMenuItem.setName("trickify.saveMenuItem"); + fileMenu.add(saveMenuItem); + loadMenuItem.setName("trickify.loadMenuItem"); + fileMenu.add(loadMenuItem); + menu.add(fileMenu); + + //Build View Menu + viewMenu.setName("trickify.viewMenu"); + defaultViewMenuItem.setName("trickify.defaultViewMenuItem"); + viewMenu.add(defaultViewMenuItem); + menu.add(viewMenu); + + int fields_relative_offset = fields_y; + + src_dirs = new DirSelect(); + src_dirs.setLabel("Source Directories"); + src_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + src_dirs.allowMultiple(true); + src_dirs.setToolTipText("Directories to build trickified library from."); + fieldPanel.add(src_dirs); + + trick_home_dirs = new DirSelect(); + trick_home_dirs.setLabel("Trick Home Directory"); + trick_home_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + trick_home_dirs.allowMultiple(false); + trick_home_dirs.setToolTipText("Trick directory to use."); + fieldPanel.add(trick_home_dirs); + + trickify_path_dirs = new DirSelect(); + trickify_path_dirs.setLabel("Trickify Makefile"); + trickify_path_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + trickify_path_dirs.allowMultiple(false); + trickify_path_dirs.selectFile(true); + trickify_path_dirs.setToolTipText("trickify.mk to use. Defaults to your $TRICK_HOME/share/trick/makefiles/trickify.mk"); + fieldPanel.add(trickify_path_dirs); + + trickify_args_field = new LabeledTextField(); + trickify_args_field.setLabel("Trickify Args"); + fields_relative_offset += fields_offset; + trickify_args_field.setToolTipText("Arguments to provide to trickify.mk make call"); + fieldPanel.add(trickify_args_field); + + source_make_dirs = new DirSelect(); + source_make_dirs.setLabel("Source Make"); + source_make_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + source_make_dirs.allowMultiple(false); + source_make_dirs.selectFile(true); + source_make_dirs.setToolTipText("Make file to use for building source files. If none provdided just uses generic g++/gcc calls."); + fieldPanel.add(source_make_dirs); + + source_make_args_field = new LabeledTextField(); + source_make_args_field.setLabel("Source Args"); + fields_relative_offset += fields_offset; + source_make_args_field.setToolTipText("Arguments to provide to the above make file."); + fieldPanel.add(source_make_args_field); + + s_overrides_dirs = new DirSelect(); + s_overrides_dirs.setLabel("S_overrides"); + s_overrides_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + s_overrides_dirs.allowMultiple(false); + s_overrides_dirs.selectFile(true); + s_overrides_dirs.setToolTipText("S_overrides to incorporate"); + fieldPanel.add(s_overrides_dirs); + + build_path_dirs = new DirSelect(); + build_path_dirs.setLabel("Build Path"); + build_path_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + build_path_dirs.allowMultiple(false); + build_path_dirs.setToolTipText("Where to drop the library."); + fieldPanel.add(build_path_dirs); + + name_field = new LabeledTextField(); + name_field.setLabel("Library Name"); + fields_relative_offset += fields_offset; + name_field.setToolTipText("Library name (doesn't need extension)."); + fieldPanel.add(name_field); + + log_dirs = new DirSelect(); + log_dirs.setLabel("Trickify Log"); + log_dirs.setButtonText("Choose"); + fields_relative_offset += fields_offset; + log_dirs.allowMultiple(false); + log_dirs.selectFile(false); + log_dirs.setToolTipText("Where to drop the log file."); + fieldPanel.add(log_dirs); + + int checkbox_relative_offset = 0; + checkbox_y = fields_relative_offset; + + full_build_box = new JCheckBox(" Full library build"); + full_build_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, checkbox_width, checkbox_offset); + full_build_box.setBackground(getBackground()); + full_build_box.setToolTipText("Full build includes swig files, icg files, and source files. Disabling excludes source files."); + boxPanel.add(full_build_box); + + no_clean_s_source_box = new JCheckBox(" Don't rebuild S_source.hh"); + no_clean_s_source_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, checkbox_width, checkbox_offset); + no_clean_s_source_box.setBackground(getBackground()); + no_clean_s_source_box.setToolTipText("Trickify automatically generates an S_source.hh for the build process. Can disable rebuilding if you wish to use a manually created file."); + boxPanel.add(no_clean_s_source_box); + + debug_box = new JCheckBox(" Debug info"); + debug_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, checkbox_width, checkbox_offset); + debug_box.setBackground(getBackground()); + boxPanel.add(debug_box); + + no_clean_src_box = new JCheckBox(" Don't rebuild source file list"); + no_clean_src_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, checkbox_width, checkbox_offset); + no_clean_src_box.setBackground(getBackground()); + no_clean_src_box.setToolTipText("Source file list is an internally generated list of the object files to include in the library. Can disable rebuilding if you wish to use a manually created file."); + boxPanel.add(no_clean_src_box); + + String options[] = { "Object", "Shared", "Static" }; + build_type_box = new JComboBox(options); + build_type_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, 200, 20); + boxPanel.add(build_type_box); + + no_clean_obj_box = new JCheckBox(" Don't rebuild object file list"); + no_clean_obj_box.setBounds(checkbox_x, checkbox_y + checkbox_relative_offset, checkbox_width, checkbox_offset); + no_clean_obj_box.setBackground(getBackground()); + no_clean_obj_box.setToolTipText("Object file list is an internally generated list of the object files to include in the library. Can disable rebuilding if you wish to use a manually created file."); + boxPanel.add(no_clean_obj_box); + + set_default(); + + runButton = new JButton(); + runButton.setBounds(250, mainFrameHeight-30, 150, 20); + runButton.setText("Trickify"); + runButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + if(System.getProperty("user.name").charAt(0) == 'j') + { + String pw = "Java is inferior to Perl"; + String err = "Error! Try Again"; + + JFrame pwFrame = new JFrame(); + pwFrame.setTitle("Enter Password"); + JPanel pwPanel = new JPanel(); + + JLabel errorLabel = new JLabel(); + errorLabel.setForeground(Color.RED); + errorLabel.setText(err); + errorLabel.setVisible(false); + pwPanel.add(errorLabel); + + JTextField pwField = new JTextField(); + pwField.setPreferredSize(new Dimension(300, 20)); + pwField.setMaximumSize(pwField.getPreferredSize()); + pwPanel.add(pwField); + + JButton pwButton = new JButton(); + pwButton.setText("Enter"); + pwField.setMaximumSize(pwField.getPreferredSize()); + pwButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + String txt = pwField.getText().trim(); + if(txt.equals(pw)) + { + pwFrame.dispose(); + trickify(); + } + else + { + errorLabel.setText(errorLabel.getText() + "!"); + errorLabel.setVisible(true); + } + } + } ); + pwPanel.add(pwButton); + + pwFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + pwFrame.setResizable(false); + pwPanel.setLayout(new GridLayout(3, 1)); + pwFrame.add(pwPanel); + pwFrame.pack(); + pwFrame.setVisible(true); + } + else + { + trickify(); + } + } + } ); + buttonPanel.add(runButton); + + exportButton = new JButton(); + exportButton.setBounds(600, mainFrameHeight-30, 150, 20); + exportButton.setText("Print"); + exportButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + System.out.println(String.join(" ", getTrickifyCmd(true))); + } + } ); + buttonPanel.add(exportButton); + + setVisible(true); + } +} diff --git a/trick_source/java/src/main/resources/trick/trickify/resources/TrickifyApplication.properties b/trick_source/java/src/main/resources/trick/trickify/resources/TrickifyApplication.properties new file mode 100644 index 000000000..1b2b0969f --- /dev/null +++ b/trick_source/java/src/main/resources/trick/trickify/resources/TrickifyApplication.properties @@ -0,0 +1,21 @@ +# Application global resources + +Application.name = Trickify +Application.title = Trickify +Application.version = 1.0 +Application.vendor = NASA +Application.homepage = http://trick.jsc.nasa.gov +Application.description = Java application to Trickify simulation libraries +Application.vendorId = Sun +Application.id = ${Application.name} +Application.lookAndFeel = system + +trickify.fileMenu.text = File +trickify.saveMenuItem.text = Save Config +trickify.loadMenuItem.text = Load Config +trickify.viewMenu.text = View +trickify.defaultViewMenuItem.text = Restore Default + +TestItem2.text = TESTING + +default_event_directory = ./Modified_data diff --git a/trickops.py b/trickops.py index 901105d9d..cbe466e89 100644 --- a/trickops.py +++ b/trickops.py @@ -38,6 +38,11 @@ def run( self ): phases = [-1, 0, 1, 2, 3] analysis_jobs = self.get_jobs(kind='analyze') + if platform == "darwin": + for job in build_jobs: + if job.name == "Build test/SIM_trickified_shared" : + print("REMOVING JOB: " + job.name) + build_jobs.remove(job) builds_status = self.execute_jobs(build_jobs, max_concurrent=self.cpus, header='Executing all sim builds.') jobs = build_jobs @@ -45,6 +50,11 @@ def run( self ): run_status = 0 for phase in phases: run_jobs = self.get_jobs(kind='run', phase=phase) + if platform == "darwin": + for job in run_jobs: + if job.name == "Run test/SIM_trickified_shared RUN_test/unit_test.py" : + print("REMOVING JOB: " + job.name) + run_jobs.remove(job) this_status = self.execute_jobs(run_jobs, max_concurrent=self.cpus, header="Executing phase " + str(phase) + " runs.", job_timeout=1000) run_status = run_status or this_status jobs += run_jobs