Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trick ify #1808

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
be8a772
Implmented trick-ify
Pherring04 Nov 25, 2024
ba693dc
Cleaning up code
Pherring04 Nov 25, 2024
1e7f5db
CI Fix
Pherring04 Nov 25, 2024
377e8c8
Shared library test fix
Pherring04 Nov 26, 2024
d290eeb
CI Fix
Pherring04 Nov 26, 2024
8afa83a
CI Fix
Pherring04 Nov 26, 2024
973a473
Added old trickify test
Pherring04 Nov 26, 2024
f285e2a
Added S_source.hh
Pherring04 Dec 2, 2024
df19738
Changed old trickified test to generate an archive
Pherring04 Dec 2, 2024
5960500
Added support for archive trickify builds on mac
Pherring04 Dec 2, 2024
ffb2e34
Trickify MAC fixes
Pherring04 Dec 3, 2024
573211e
Trickify shared on mac fix
Pherring04 Dec 3, 2024
d0316b5
Moved the py files to their appropriate directory
Pherring04 Dec 9, 2024
c5e044a
CI fix
Pherring04 Jan 2, 2025
2b4054f
Improved trick-ify arguments
Pherring04 Jan 3, 2025
fc96481
CI
Pherring04 Jan 6, 2025
1e9a2e1
CI
Pherring04 Jan 6, 2025
f420dca
CI
Pherring04 Jan 7, 2025
e25aaa3
CI
Pherring04 Jan 7, 2025
c3cd94e
CI
Pherring04 Jan 9, 2025
a2d4455
CI
Pherring04 Jan 13, 2025
04c0fea
CI
Pherring04 Jan 13, 2025
74c7512
Added C support
Pherring04 Jan 14, 2025
4af3fc3
Removed trickified shared test from MAC CI
Pherring04 Jan 15, 2025
ae86640
Start of trickify GUI
Pherring04 Jan 22, 2025
2e46a84
Checkpoint
Pherring04 Jan 22, 2025
e30ebf8
Trickify GUI
Pherring04 Feb 3, 2025
9578258
Merge branch 'master' into Trick-ify
Pherring04 Feb 3, 2025
7f4c78d
Test fix
Pherring04 Feb 3, 2025
9b44b2d
CI
Pherring04 Feb 3, 2025
c2f32a2
CI
Pherring04 Feb 4, 2025
011c4e7
CI
Pherring04 Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions bin/trick-ify
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/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

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
) ;

$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" ;
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*(\Q.c\E)$/)
{
$file =~ s/\Q.c\E$// ;
$cmd = "gcc $source_make_args -I $trick_home" . "/include -c $src -o $file.o" ;
}
else
{
$file =~ s/\Q.cpp\E$// ;
$cmd = "g++ $source_make_args -I $trick_home" . "/include -c $src -o $file.o" ;
}
if($debug)
{
print "Building obj file: $cmd\n" ;
}
print(`$cmd`) ;
}
}
else
{
print(`$source_make_call`) ;
}
}

#Build object file list, only if trickifying the entire library
if(!$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" ;
}
8 changes: 8 additions & 0 deletions bin/trick-trickify
Original file line number Diff line number Diff line change
@@ -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") ;

52 changes: 41 additions & 11 deletions share/trick/makefiles/trickify.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ include $(dir $(lastword $(MAKEFILE_LIST)))Makefile.common
BUILD_DIR := $(dir $(MAKE_OUT))
PY_LINK_LIST := $(BUILD_DIR)trickify_py_link_list
IO_LINK_LIST := $(BUILD_DIR)trickify_io_link_list
LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST)
OBJ_LINK_LIST := trickify_obj_list
ifdef FULL_TRICKIFY_BUILD
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)
Expand All @@ -117,18 +122,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 $@
Expand Down
51 changes: 51 additions & 0 deletions share/trick/pymods/trick/build_trickify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from pathlib import Path
import os

def_header_ext = ["h", "hh", "hpp", "H", "hxx", "h++"]
def_src_ext = ["cpp", "c"]

def find_files_by_extension(loc, ext):
path = Path(loc)
files = list(path.rglob(f'*.{ext}'))
return files

def build_S_source():
loc = ""
if "TRICKIFY_HEADER" in os.environ:
loc = os.getenv("TRICKIFY_HEADER")
dirs = loc.split()

s_source = open("S_source.hh", 'w')

for path in dirs:
for ext in def_header_ext:
files = find_files_by_extension(path, ext)
for i in range(len(files)):
s_source.write('#include "' + str(files[i]) + '"\n')

def build_obj_list():
loc = ""
if "TRICKIFY_SOURCE" in os.environ:
loc = os.getenv("TRICKIFY_SOURCE")
dirs = loc.split()

obj_list = open("trickify_obj_list", 'w')

for path in dirs:
files = find_files_by_extension(path, "o")
for i in range(len(files)):
obj_list.write(str(files[i]) + '\n')

def build_src_list():
loc = ""
if "TRICKIFY_SOURCE" in os.environ:
loc = os.getenv("TRICKIFY_SOURCE")
dirs = loc.split()

src_list = open("trickify_src_list", 'w')

for path in dirs:
for ext in def_src_ext:
files = find_files_by_extension(path, ext)
for i in range(len(files)):
src_list.write(str(files[i]) + '\n')
10 changes: 10 additions & 0 deletions share/trick/pymods/trick/build_trickify_S_source_hh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

path = ""
if "TRICK_HOME" in os.environ:
path = os.getenv("TRICK_HOME")
path += "/share/trick/pymods/trick/build_trickify.py"

exec(open(path).read())

build_S_source()
10 changes: 10 additions & 0 deletions share/trick/pymods/trick/build_trickify_obj_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

path = ""
if "TRICK_HOME" in os.environ:
path = os.getenv("TRICK_HOME")
path += "/share/trick/pymods/trick/build_trickify.py"

exec(open(path).read())

build_obj_list()
10 changes: 10 additions & 0 deletions share/trick/pymods/trick/build_trickify_src_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

path = ""
if "TRICK_HOME" in os.environ:
path = os.getenv("TRICK_HOME")
path += "/share/trick/pymods/trick/build_trickify.py"

exec(open(path).read())

build_src_list()
13 changes: 12 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions test/SIM_trickified/trickified_project/trickified/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/SIM_trickified_archive/RUN_test/unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sandbox.foo.i = 5
assert sandbox.foo.i == 5
foo = trick.Foo()
trick.stop(10)
Loading
Loading