diff --git a/bin/trick-ify b/bin/trick-ify new file mode 100755 index 000000000..83b7e98ac --- /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")) ) +{ + 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 ) +{ + $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..839f8a2de 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,43 @@ 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 -lgcov +else + SHARED_OPTIONS := +endif + .PHONY: all all: $(TRICKIFY_OBJECT_NAME) $(TRICKIFY_PYTHON_DIR) +.ONESHELL: $(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 STEP A + @while read -r line ; do \ + export FILES="$$FILES $$line" ; \ + done < $(PY_LINK_LIST) + echo TRICKIFICATION STEP B + @while read -r line ; do \ + export FILES="$$FILES $$line" ; \ + done < $(IO_LINK_LIST) + echo TRICKIFICATION STEP C + @if [ "$(FULL_TRICKIFY_BUILD)" = "1" ] ; then \ + while read -r line ; do \ + export FILES="$$FILES $$line" ; \ + done < $(OBJ_LINK_LIST) ; \ + fi + echo TRICKIFICATION STEP D + @if [ "$(TRICKIFY_BUILD_TYPE)" = "PLO" ] ; then \ + $(LD) $(LD_PARTIAL) -o $@ $$FILES ; \ + elif [ "$(TRICKIFY_BUILD_TYPE)" = "SHARED" ] ; then \ + $(TRICK_CXX) $(SHARED_LIB_OPT) $(SHARED_OPTIONS) -o $@ $$FILES ; \ + elif [ "$(TRICKIFY_BUILD_TYPE)" = "STATIC" ] ; then \ + ar rcs $@ $ $$FILES ; \ + fi + echo TRICKIFICATION STEP E $(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..7d809864e --- /dev/null +++ b/share/trick/pymods/trick/build_trickify.py @@ -0,0 +1,55 @@ +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)) + print(file_list) + 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..4838b1b5c --- /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 so -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..8f3a556b0 --- /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 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..fe8ba9790 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/DirSelect.java @@ -0,0 +1,168 @@ +package trick.trickify; + +import java.awt.event.*; +import java.io.*; +import javax.swing.*; + +public class DirSelect +{ + 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; + + private void updatePosition() + { + label_pos_x = pos_x; + label_pos_y = pos_y; + + textfield_pos_x = pos_x; + textfield_pos_y = pos_y + label_height; + + button_pos_x = textfield_pos_x + textfield_width; + button_pos_y = textfield_pos_y; + } + + private void redraw() + { + label.setBounds(label_pos_x, label_pos_y, label_width, label_height); + textfield.setBounds(textfield_pos_x, textfield_pos_y, textfield_width, textfield_height); + button.setBounds(button_pos_x, button_pos_y, button_width, button_height); + } + + public void setPosition(int x, int y) + { + pos_x = x; + pos_y = y; + + updatePosition(); + redraw(); + } + + 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 addToPanel(JPanel panel) + { + panel.add(label); + panel.add(textfield); + panel.add(button); + } + + public void addToFrame(JFrame frame) + { + frame.add(label); + frame.add(textfield); + frame.add(button); + } + + 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 getDirs() + { + return textfield.getText(); + } + + void setDirs(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); + + setPosition(pos_x, pos_y); + + 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); + } + } + } ); + } + +} 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..ea77503f0 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/LabeledTextField.java @@ -0,0 +1,94 @@ +package trick.trickify; + +import java.awt.event.*; +import java.io.*; +import javax.swing.*; + +public class LabeledTextField +{ + 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 void updatePosition() + { + label_pos_x = pos_x; + label_pos_y = pos_y; + + textfield_pos_x = pos_x; + textfield_pos_y = pos_y + label_height; + } + + private void redraw() + { + label.setBounds(label_pos_x, label_pos_y, label_width, label_height); + textfield.setBounds(textfield_pos_x, textfield_pos_y, textfield_width, textfield_height); + } + + public void setPosition(int x, int y) + { + pos_x = x; + pos_y = y; + + updatePosition(); + redraw(); + } + + public void setLabel(String text) + { + label.setText(text); + } + + public void setToolTipText(String tip) + { + textfield.setToolTipText(tip); + } + + + public void addToPanel(JPanel panel) + { + panel.add(label); + panel.add(textfield); + } + + 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; + + setPosition(pos_x, pos_y); + } + +} 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..7304e54c5 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/TrickifyApplication.java @@ -0,0 +1,10 @@ +package trick.trickify; + +public class TrickifyApplication +{ + public static void main(String[] args) + { + TrickifyFrame trickifyFrame = new TrickifyFrame(); + } + +} diff --git a/trick_source/java/src/main/java/trick/trickify/TrickifyFrame.java b/trick_source/java/src/main/java/trick/trickify/TrickifyFrame.java new file mode 100644 index 000000000..63c002cb1 --- /dev/null +++ b/trick_source/java/src/main/java/trick/trickify/TrickifyFrame.java @@ -0,0 +1,448 @@ +package trick.trickify; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; +import javax.swing.border.*; +import java.util.ArrayList; + +public class TrickifyFrame +{ + private String trick_home; + + private JFrame mainFrame; + 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 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 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 ArrayList getTrickifyCmd(boolean useQuotes) + { + ArrayList cmdLine = new ArrayList(); + cmdLine.add(trick_home + "/bin/trick-ify"); + + String src_dirs_txt = src_dirs.getDirs().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.getDirs().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.getDirs().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.getDirs().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.getDirs().trim(); + if(!build_path_dirs_txt.equals("")) + { + lib_name = build_path_dirs_txt; + } + + String s_overrides_dirs_txt = s_overrides_dirs.getDirs().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_src_list"); + } + + 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 update_checkbox_pos() + { + if(checkbox_x >= mainFrameWidth/2) + { + checkbox_y += checkbox_offset; + } + checkbox_x = mainFrameWidth - checkbox_width - checkbox_x; + } + + 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.getDirs().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(); + } + } + + TrickifyFrame() + { + String s = System.getProperty("file.separator"); + trick_home = new File(TrickifyFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getParentFile().getParentFile().getParentFile().getParentFile().getAbsolutePath(); + + mainFrame = new JFrame(); + + mainPanel = new JPanel(); + mainFrame.setTitle("Trickify"); + mainPanel.setBounds(0, 0, mainFrameWidth, mainFrameHeight); + mainPanel.setPreferredSize(new Dimension(mainFrameWidth, mainFrameHeight)); + mainPanel.setBackground(Color.lightGray); + mainPanel.setLayout(null); + + int fields_relative_offset = fields_y; + + src_dirs = new DirSelect(); + src_dirs.setLabel("Source Directories"); + src_dirs.setButtonText("Choose"); + src_dirs.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + src_dirs.allowMultiple(true); + src_dirs.setToolTipText("Directories to build trickified library from."); + src_dirs.addToPanel(mainPanel); + + trick_home_dirs = new DirSelect(); + trick_home_dirs.setLabel("Trick Home Directory"); + trick_home_dirs.setDirs(trick_home); + trick_home_dirs.setButtonText("Choose"); + trick_home_dirs.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + trick_home_dirs.allowMultiple(false); + trick_home_dirs.setToolTipText("Trick directory to use."); + trick_home_dirs.addToPanel(mainPanel); + + trickify_path_dirs = new DirSelect(); + trickify_path_dirs.setLabel("Trickify Makefile"); + trickify_path_dirs.setDirs(trick_home + s + "share" + s + "trick" + s + "makefiles" + s + "trickify.mk"); + trickify_path_dirs.setButtonText("Choose"); + trickify_path_dirs.setPosition(fields_x, fields_relative_offset); + 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"); + trickify_path_dirs.addToPanel(mainPanel); + + trickify_args_field = new LabeledTextField(); + trickify_args_field.setLabel("Trickify Args"); + trickify_args_field.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + trickify_args_field.setToolTipText("Arguments to provide to trickify.mk make call"); + trickify_args_field.addToPanel(mainPanel); + + source_make_dirs = new DirSelect(); + source_make_dirs.setLabel("Source Make"); + source_make_dirs.setButtonText("Choose"); + source_make_dirs.setPosition(fields_x, fields_relative_offset); + 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."); + source_make_dirs.addToPanel(mainPanel); + + source_make_args_field = new LabeledTextField(); + source_make_args_field.setLabel("Source Args"); + source_make_args_field.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + source_make_args_field.setToolTipText("Arguments to provide to the above make file."); + source_make_args_field.addToPanel(mainPanel); + + s_overrides_dirs = new DirSelect(); + s_overrides_dirs.setLabel("S_overrides"); + s_overrides_dirs.setButtonText("Choose"); + s_overrides_dirs.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + s_overrides_dirs.allowMultiple(false); + s_overrides_dirs.selectFile(true); + s_overrides_dirs.setToolTipText("S_overrides to incorporate"); + s_overrides_dirs.addToPanel(mainPanel); + + build_path_dirs = new DirSelect(); + build_path_dirs.setLabel("Build Path"); + build_path_dirs.setDirs(System.getProperty("user.dir")); + build_path_dirs.setButtonText("Choose"); + build_path_dirs.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + build_path_dirs.allowMultiple(false); + build_path_dirs.setToolTipText("Where to drop the library."); + build_path_dirs.addToPanel(mainPanel); + + name_field = new LabeledTextField(); + name_field.setLabel("Library Name"); + name_field.setText("TrickifiedLibrary"); + name_field.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + name_field.setToolTipText("Library name (doesn't need extension)."); + name_field.addToPanel(mainPanel); + + log_dirs = new DirSelect(); + log_dirs.setLabel("Trickify Log"); + log_dirs.setDirs(System.getProperty("user.dir")); + log_dirs.setButtonText("Choose"); + log_dirs.setPosition(fields_x, fields_relative_offset); + fields_relative_offset += fields_offset; + log_dirs.allowMultiple(false); + log_dirs.selectFile(false); + log_dirs.setToolTipText("Where to drop the log file."); + log_dirs.addToPanel(mainPanel); + + 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(mainPanel.getBackground()); + full_build_box.setToolTipText("Full build includes swig files, icg files, and source files. Disabling excludes source files."); + full_build_box.setSelected(true); + update_checkbox_pos(); + mainPanel.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(mainPanel.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."); + update_checkbox_pos(); + mainPanel.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(mainPanel.getBackground()); + update_checkbox_pos(); + mainPanel.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(mainPanel.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."); + update_checkbox_pos(); + mainPanel.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); + update_checkbox_pos(); + mainPanel.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(mainPanel.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."); + update_checkbox_pos(); + mainPanel.add(no_clean_obj_box); + + 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(); + } + } + } ); + mainPanel.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))); + } + } ); + mainPanel.add(exportButton); + + mainFrame.add(mainPanel); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainFrame.pack(); + mainFrame.setResizable(false); + mainFrame.setVisible(true); + } +} 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