Skip to content

Commit

Permalink
Rename SIM_*/trick to SIM_*/.trick
Browse files Browse the repository at this point in the history
Hide the non-zipped Python modules to indicate to users that changing
them will have no effect on the sim.

Refs #1144
  • Loading branch information
dbankieris committed May 19, 2021
1 parent 8d314fa commit 2c06ae6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bin/trick-CP
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ tidy:
clean: tidy
-rm -f DP_Product/DP_rt_frame DP_Product/DP_rt_itimer
-rm -f DP_Product/DP_rt_jobs DP_Product/DP_rt_timeline DP_Product/DP_mem_stats
-rm -rf build trick trick.zip
-rm -rf build .trick trick.zip
-rm -f makefile
spotless: clean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ The result should be:
<b>trickified.o
python
build/
trick/</b></pre>
.trick/</b></pre>

`trickified.o` contains all of the compiled `io_*.cpp` and `*_py.cpp` code. The name is configurable via the `TRICKIFY_OBJECT_NAME` variable, which can include directories, which will automatically be created if necessary. `build` contains a lot of ICG and SWIG artifacts. You can't change its name or location at this time, but it's useful to keep around as it will allow you to rebuild only the parts of the project that change in the future, and sims that build against your project will need the `*_py.i` files within. `trick` includes a bunch of crazily-named Python modules which serve as the input file interface to the content of the header files. Those modules are compiled and zipped into `python`. The zip file name is configurable via the `TRICKIFY_PYTHON_DIR` variable, which can include directories, which will automatically be created if necessary.
`trickified.o` contains all of the compiled `io_*.cpp` and `*_py.cpp` code. The name is configurable via the `TRICKIFY_OBJECT_NAME` variable, which can include directories, which will automatically be created if necessary. `build` contains a lot of ICG and SWIG artifacts. You can't change its name or location at this time, but it's useful to keep around as it will allow you to rebuild only the parts of the project that change in the future, and sims that build against your project will need the `*_py.i` files within. `.trick` includes a bunch of crazily-named Python modules which serve as the input file interface to the content of the header files. Those modules are compiled and zipped into `python`. The zip file name is configurable via the `TRICKIFY_PYTHON_DIR` variable, which can include directories, which will automatically be created if necessary.

Your Trickified library can be produced in three different formats based on the value of `TRICKIFY_BUILD_TYPE`:
1. `STATIC` (.a)
Expand All @@ -87,7 +87,7 @@ Let's be honest. You're not going to remember that command line. And who wants t
trickified.o
python
build/
trick/</pre>
.trick/</pre>

```make
ifndef TRICK_HOME
Expand All @@ -107,7 +107,7 @@ all:
@$(MAKE) -s -f $(TRICKIFY)

clean:
@rm -rf build python trick $(TRICKIFY_OBJECT_NAME)
@rm -rf build python .trick $(TRICKIFY_OBJECT_NAME)
```

Now just type `make` in `trickified` and everything is taken care of. I even added a check to make sure you're using a recent enough version of Trick. I've silenced a lot of make's output because I prefer to see echoed commands only when debugging, but you're welcome to get rid of the `@` and `-s` if you enjoy such verbosity. Note that I've used `TRICKIFY_OBJECT_NAME` to rename the default `trickified.o` to something a little less generic. If you're following along, you can remove the `trickified.o` we built earlier.
Expand All @@ -117,7 +117,7 @@ The only Trickification-related files you want under version control are `S_sour

```git
build/
trick/
.trick/
python
*.o
```
Expand Down Expand Up @@ -168,7 +168,7 @@ While the above is sufficient to use a Trickified project, it's awfully inconven
trickified_myproject.o
python
build/
trick/</pre>
.trick/</pre>

Here's the contents of `myproject.mk`. It's everything from the previous section plus some other things you might find useful.

Expand Down
30 changes: 17 additions & 13 deletions libexec/trick/make_makefile_swig
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ sub purge_swig_no_files() {

sub write_makefile_swig() {
my $s_source_md5 = md5_hex(abs_path("S_source.hh")) ;
my $swig_sim_dir = "trick" ;
my $swig_sim_dir = ".trick" ;
my $swig_sim_zip = "trick.zip" ;
my $swig_src_dir = "build" ;

open MAKEFILE , ">build/Makefile_swig" or die "Could not open build/Makefile_swig for writing" ;
Expand Down Expand Up @@ -217,15 +218,18 @@ SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o
LINK_LISTS += \$(LD_FILELIST)build/py_link_list
# trick.zip ====================================================================
# $swig_sim_zip ===================================================================
trick.zip: \$(SWIG_SRC) \$(TRICK_FIXED_PYTHON) $swig_sim_dir/__init__.py
$swig_sim_zip: \$(SWIG_SRC) \$(TRICK_FIXED_PYTHON) $swig_sim_dir/__init__.py
\t\$(info \$(call COLOR,Compiling) Python modules)
\t\$(call ECHO_AND_LOG,\$(PYTHON) -m compileall -q $swig_sim_dir)
\t\$(info \$(call COLOR,Zipping) Python modules into $swig_sim_dir.zip)
\t\$(call ECHO_AND_LOG,zip -rq $swig_sim_dir $swig_sim_dir)
\t\$(info \$(call COLOR,Zipping) Python modules into \$@)
\t\$(call ECHO_AND_LOG,ln -sf $swig_sim_dir trick)
\t\$(call ECHO_AND_LOG,zip -rq $swig_sim_zip trick)
\t\$(call ECHO_AND_LOG,rm -f trick)
all: $swig_sim_dir.zip
all: $swig_sim_zip
" ;

close MAKEFILE ;
Expand Down Expand Up @@ -293,18 +297,18 @@ all: $swig_sim_dir.zip
print INITSWIGFILE "#endif\n" ;
close INITSWIGFILE ;

if ( ! -e "trick") {
mkdir "trick" ;
if ( ! -e $swig_sim_dir) {
mkdir $swig_sim_dir ;
}
open INITFILE , ">trick/__init__.py" or die "Could not open trick/__init__.py for writing" ;
open INITFILE , ">$swig_sim_dir/__init__.py" or die "Could not open $swig_sim_dir/__init__.py for writing" ;

print INITFILE "from pkgutil import extend_path\n" ;
print INITFILE "__path__ = extend_path(__path__, __name__)\n" ;
print INITFILE "import sys\n" ;
print INITFILE "import os\n" ;
print INITFILE "sys.path.append(os.getcwd() + \"/trick.zip/trick\")\n" ;
print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick\")\n" ;
foreach my $dir ( keys %python_module_dirs ) {
print INITFILE "sys.path.append(os.getcwd() + \"/trick.zip/trick/$dir\")\n" ;
print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick/$dir\")\n" ;
}

print INITFILE "\n" ;
Expand Down Expand Up @@ -350,8 +354,8 @@ all: $swig_sim_dir.zip
close INITFILE ;

foreach my $dir ( keys %python_module_dirs ) {
system("mkdir -p trick/$dir");
open MODULE_INITFILE, ">trick/$dir/__init__.py";
system("mkdir -p $swig_sim_dir/$dir");
open MODULE_INITFILE, ">$swig_sim_dir/$dir/__init__.py";
foreach my $file ( @files_to_process ) {
if ( exists $trick_headers{$file}{python_module_dir} and $trick_headers{$file}{python_module_dir} eq $dir ) {
print MODULE_INITFILE "# $file\n" ;
Expand Down
12 changes: 6 additions & 6 deletions share/trick/makefiles/trickify.mk
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
# $(MAKE) -f $(TRICKIFY)
#
# clean:
# rm -rf $(TRICKIFY_OBJECT_NAME) build python trick
# rm -rf $(TRICKIFY_OBJECT_NAME) build python .trick
#
# -----------------------------------------------------------------------------
#
Expand Down Expand Up @@ -129,7 +129,7 @@ else ifeq ($(TRICKIFY_BUILD_TYPE),STATIC)
$(call ECHO_AND_LOG,ar rcs $@ $^)
endif

$(dir $(TRICKIFY_OBJECT_NAME)) $(BUILD_DIR) $(dir $(TRICKIFY_PYTHON_DIR)) trick:
$(dir $(TRICKIFY_OBJECT_NAME)) $(BUILD_DIR) $(dir $(TRICKIFY_PYTHON_DIR)) .trick:
@mkdir -p $@

$(IO_OBJECTS): %.o: %.cpp
Expand All @@ -144,9 +144,9 @@ $(SWIG_OBJECTS): %.o: %.cpp
$(info $(call COLOR,Compiling) $<)
$(call ECHO_AND_LOG,$(TRICK_CXX) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(PYTHON_INCLUDES) -Wno-unused-parameter -Wno-shadow -c -o $@ $<)

$(SWIG_OBJECTS:.o=.cpp): %.cpp: %.i | %.d trick $(SWIG_OBJECTS:.o=.i)
$(SWIG_OBJECTS:.o=.cpp): %.cpp: %.i | %.d .trick $(SWIG_OBJECTS:.o=.i)
$(info $(call COLOR,SWIGing) $<)
$(call ECHO_AND_LOG,$(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201 -w303 -w315 -w325 -w362 -w389 -w401 -w451 -MMD -MP -outdir trick -o $@ $<)
$(call ECHO_AND_LOG,$(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201 -w303 -w315 -w325 -w362 -w389 -w401 -w451 -MMD -MP -outdir .trick -o $@ $<)

$(SWIG_OBJECTS:.o=.d): ;

Expand All @@ -161,9 +161,9 @@ $(foreach EXTENSION,H h hh hxx h++ hpp,$(eval $(call create_convert_swig_rule,$(

$(TRICKIFY_PYTHON_DIR): $(SWIG_OBJECTS:.o=.cpp) | $(dir $(TRICKIFY_PYTHON_DIR))
$(info $(call COLOR,Compiling) Python modules)
$(call ECHO_AND_LOG,$(PYTHON) -m compileall -q trick)
$(call ECHO_AND_LOG,$(PYTHON) -m compileall -q .trick)
$(info $(call COLOR,Zipping) Python modules into $@)
$(call ECHO_AND_LOG,cd trick && zip -Arq $@ .)
$(call ECHO_AND_LOG,cd .trick && zip -Arq $@ .)

# SWIG_OBJECTS and IO_OBJECTS are meant to contain all of the *_py and io_*
# object file names, respectively, by looking at products of ICG and
Expand Down
2 changes: 1 addition & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ S_sie.resource
S_source.cpp
S_source.hh
T_main_*
trick
.trick
trick.zip
jitlib
build
Expand Down
3 changes: 2 additions & 1 deletion trick_sims/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ S_sie.json
S_source.cpp
S_source.hh
T_main_*
**/SIM_*/trick
**/SIM_*/.trick
**/SIM_*/trick.zip
**/graphics/dist
**/graphics/manifest
**/graphics/build
Expand Down

0 comments on commit 2c06ae6

Please sign in to comment.