From 2c06ae6eaf873d8d81e8e2dc986f1c0a56b6fd30 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Wed, 19 May 2021 17:21:21 -0500 Subject: [PATCH] Rename SIM_*/trick to SIM_*/.trick Hide the non-zipped Python modules to indicate to users that changing them will have no effect on the sim. Refs #1144 --- bin/trick-CP | 2 +- .../Trickified-Project-Libraries.md | 12 ++++---- libexec/trick/make_makefile_swig | 30 +++++++++++-------- share/trick/makefiles/trickify.mk | 12 ++++---- test/.gitignore | 2 +- trick_sims/.gitignore | 3 +- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/bin/trick-CP b/bin/trick-CP index 9f8ef66d..f537fe5a 100755 --- a/bin/trick-CP +++ b/bin/trick-CP @@ -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 diff --git a/docs/documentation/building_a_simulation/Trickified-Project-Libraries.md b/docs/documentation/building_a_simulation/Trickified-Project-Libraries.md index 913ac34e..b4e3a938 100644 --- a/docs/documentation/building_a_simulation/Trickified-Project-Libraries.md +++ b/docs/documentation/building_a_simulation/Trickified-Project-Libraries.md @@ -59,9 +59,9 @@ The result should be: trickified.o python build/ - trick/ + .trick/ -`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) @@ -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/ + .trick/ ```make ifndef TRICK_HOME @@ -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. @@ -117,7 +117,7 @@ The only Trickification-related files you want under version control are `S_sour ```git build/ -trick/ +.trick/ python *.o ``` @@ -168,7 +168,7 @@ While the above is sufficient to use a Trickified project, it's awfully inconven trickified_myproject.o python build/ - trick/ + .trick/ Here's the contents of `myproject.mk`. It's everything from the previous section plus some other things you might find useful. diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 3046a5a8..a5fa5647 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -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" ; @@ -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 ; @@ -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" ; @@ -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" ; diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index 5a2511f2..b7416fea 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -81,7 +81,7 @@ # $(MAKE) -f $(TRICKIFY) # # clean: -# rm -rf $(TRICKIFY_OBJECT_NAME) build python trick +# rm -rf $(TRICKIFY_OBJECT_NAME) build python .trick # # ----------------------------------------------------------------------------- # @@ -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 @@ -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): ; @@ -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 diff --git a/test/.gitignore b/test/.gitignore index 883ab8dd..38e6eddd 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -20,7 +20,7 @@ S_sie.resource S_source.cpp S_source.hh T_main_* -trick +.trick trick.zip jitlib build diff --git a/trick_sims/.gitignore b/trick_sims/.gitignore index 18797f68..60d1a30c 100644 --- a/trick_sims/.gitignore +++ b/trick_sims/.gitignore @@ -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