diff options
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | par/output_source.par | 9 | ||||
-rw-r--r-- | schedule.ccl | 2 | ||||
-rw-r--r-- | src/connection.cc | 3 | ||||
-rw-r--r-- | src/make.code.deps | 30 | ||||
-rw-r--r-- | src/make.configuration.deps | 152 | ||||
-rw-r--r-- | src/output_source.c | 76 | ||||
-rw-r--r-- | src/util/makeblob.c | 102 | ||||
-rw-r--r-- | src/util/makemetablob.c | 41 |
9 files changed, 292 insertions, 133 deletions
@@ -17,14 +17,14 @@ number of iterations, an efficiency summary, etc. TODO: unique IDs for all output files -store ThornList and config-info as well -BSD tar: nonrecursive: - read files from file: -I filename +BSD tar: read files from file: -I filename don't use -z; use tar and gzip -find: don't emit directories -find: quote ! character + + +IOUtil should not depend on anything +MoL should not depend on NaNChecker diff --git a/par/output_source.par b/par/output_source.par index 83c4fd1..40a5f87 100644 --- a/par/output_source.par +++ b/par/output_source.par @@ -1,7 +1,16 @@ # $Header$ Cactus::cctk_run_title = "Write out the stored source tree" + +Cactus::cctk_show_banners = no +Cactus::cctk_show_schedule = no + Cactus::cctk_itlast = 0 +ActiveThorns = "CoordBase" + +ActiveThorns = "IOUtil" +IO::out_dir = "cactus-source" + ActiveThorns = "Formaline" Formaline::announce_to_portal = no diff --git a/schedule.ccl b/schedule.ccl index 68289c5..c2a771e 100644 --- a/schedule.ccl +++ b/schedule.ccl @@ -3,7 +3,7 @@ if (output_source) { - SCHEDULE Formaline_OutputSource AT wragh + SCHEDULE Formaline_OutputSource AT startup { LANG: C } "Output Cactus source tree" diff --git a/src/connection.cc b/src/connection.cc index e38f43c..8acaee5 100644 --- a/src/connection.cc +++ b/src/connection.cc @@ -33,7 +33,8 @@ connection (char const * const id) addr.sin_port = portal_port; addr.sin_addr = * (struct in_addr *) hostinfo->h_addr; - int const ierr = connect (sock, & addr, sizeof addr); + int const ierr + = connect (sock, (struct sockaddr const *) (& addr), sizeof addr); #warning "TODO: handle errors" assert (! ERROR_CHECK (ierr)); diff --git a/src/make.code.deps b/src/make.code.deps index fc52179..71e8266 100644 --- a/src/make.code.deps +++ b/src/make.code.deps @@ -1,13 +1,29 @@ # make.code.deps file for thorn Formaline -*-Makefile-*- # $Header$ -# Create the "makeblob" utility whenever this thorn is compiled -# Store it in the scratch directory of this configuration +# Create the "makeblob" utility whenever this thorn is compiled. +# Store it in the scratch directory of this configuration. -$(CCTK_TARGET): $(SCRATCH_BUILD)/makeblob +# This has to live here in the file make.code.deps instead of in the +# file make.configuration.deps because only here the location of the +# source file makeblob.c is known. -$(SCRATCH_BUILD)/makeblob: $(SCRATCH_BUILD)/makeblob.o - cd $(SCRATCH_BUILD) && $(LD) $(LDFLAGS) -o $@ $^ +TARBALL_DIR = $(SCRATCH_BUILD) -$(SCRATCH_BUILD)/makeblob.o: $(SRCDIR)/util/makeblob.c - cd $(SCRATCH_BUILD) && $(CC) $(CFLAGS) -c $^ +$(CCTK_TARGET): $(TARBALL_DIR)/makeblob $(TARBALL_DIR)/makemetablob + + + +$(TARBALL_DIR)/makeblob: $(TARBALL_DIR)/makeblob.o + cd $(TARBALL_DIR) && $(LD) $(LDFLAGS) -o $@ $^ + +$(TARBALL_DIR)/makeblob.o: $(SRCDIR)/util/makeblob.c + cd $(TARBALL_DIR) && $(CC) $(CFLAGS) -c $^ + + + +$(TARBALL_DIR)/makemetablob: $(TARBALL_DIR)/makemetablob.o + cd $(TARBALL_DIR) && $(LD) $(LDFLAGS) -o $@ $^ + +$(TARBALL_DIR)/makemetablob.o: $(SRCDIR)/util/makemetablob.c + cd $(TARBALL_DIR) && $(CC) $(CFLAGS) -c $^ diff --git a/src/make.configuration.deps b/src/make.configuration.deps index fa7954b..a4179fc 100644 --- a/src/make.configuration.deps +++ b/src/make.configuration.deps @@ -6,42 +6,128 @@ # Create a tarball of the source code whenever this thorn is linked # into an executable -$(EXEDIR)$(DIRSEP)$(EXE): make-tarball +TARBALL_DIR = $(SCRATCH_BUILD) -CACTUSLIBLINKLINE += $(SCRATCH_BUILD)/cactus-source.a +CACTUSLIBLINKLINE += $(TARBALL_DIR)/cactus-source.a -# 1. Create a list of files that should be in the tarball -# 2. Create the tarball -# 3. Use the makeblob utility (from this thorn; see make.code.deps) -# to create C source code from the tarball -# 4. Compile C code and create an archive +$(EXEDIR)$(DIRSEP)$(EXE): $(TARBALL_DIR)/cactus-source.a -.PHONY: make-tarball -make-tarball: - @echo "Creating source tarball..." && \ +$(TARBALL_DIR)/cactus-source.a: $(TARBALL_DIR)/cactus-meta-source.o $(TARBALL_DIR)/cactus-flesh-source.o $(patsubst %,$(TARBALL_DIR)/cactus-thorn-source-%.o,$(notdir $(THORNS))) + $(AR) $(ARFLAGS) $@ $^ + +## Cache optimisation: +## Build the thorns' tarballs already while the thorns are compiled +## (does not work) +# +#$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX): $(TARBALL_DIR)/cactus-thorn-source-%.o + + + +# Meta information +$(TARBALL_DIR)/cactus-meta-source.o: $(TARBALL_DIR)/cactus-meta-source.c + $(CC) $(CFLAGS) -c -o $@ $^ + +$(TARBALL_DIR)/cactus-meta-source.c: $(TARBALL_DIR)/cactus-flesh-source.c $(patsubst %,$(TARBALL_DIR)/cactus-thorn-source-%.c,$(notdir $(THORNS))) + $(TARBALL_DIR)/makemetablob Cactus $(notdir $(THORNS)) > $@ + + + +# Flesh + +$(TARBALL_DIR)/cactus-flesh-source.o: $(TARBALL_DIR)/cactus-flesh-source.c + $(CC) $(CFLAGS) -c -o $@ $^ + +$(TARBALL_DIR)/cactus-flesh-source.c: $(TARBALL_DIR)/cactus-flesh-source.tar.gz + $(TARBALL_DIR)/makeblob '' Cactus < $< > $@ + +#$(TARBALL_DIR)/cactus-flesh-source.d: $(TARBALL_DIR)/cactus-flesh-source.files +# echo "$(@:%.d=%.c):" `cat $^` > $@ +#-include $(TARBALL_DIR)/cactus-flesh-source.d + +$(TARBALL_DIR)/cactus-flesh-source.tar.gz: $(TARBALL_DIR)/cactus-flesh-source.files + cd $(CCTK_HOME) && \ + tar czf $@ -T $< + +# This dependency means that the tarball for a thorn is only updated +# if the thorn is actually recompiled. This does not catch changes to +# files that do not influence the executable, but that is okay. +$(TARBALL_DIR)/cactus-flesh-source.files: $(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)Cactus$(LIBNAME_SUFFIX) cd $(CCTK_HOME) && \ - files="CONTRIBUTORS COPYRIGHT Makefile" && \ - dirs="lib src" && \ - thorns="$(THORNS:%=arrangements/%)" && \ - filelist=$(SCRATCH_BUILD)/source-file-list && \ - find $$files $$dirs $$thorns \ - -path 'arrangements/*/*/doc' -prune \ - -o -path 'arrangements/*/*/test' -prune \ - -o -path 'arrangements/*/*/par' -prune \ - -o -print > $$filelist && \ - echo "Adding" `cat $$filelist | wc -l` "files..." && \ - tar czf "$(SCRATCH_BUILD)/cactus-source.tar.gz" \ - --no-recursion -T $$filelist && \ - echo "Created tarball with" `cat $(SCRATCH_BUILD)/cactus-source.tar.gz | wc -c` "bytes..." && \ - cd $(SCRATCH_BUILD) && \ - rm -rf cactus-source && \ - mkdir cactus-source && \ - cd cactus-source && \ - ../makeblob < ../cactus-source.tar.gz && \ - $(CC) $(CFLAGS) -c *.c && \ - cd .. && \ - $(AR) $(ARFLAGS) cactus-source.a cactus-source/*.o && \ - echo "Added tarball to executable." && \ - echo $(DIVIDER) + find CONTRIBUTORS COPYRIGHT Makefile lib src \ + configs/$(notdir $(TOP))/config-info \ + configs/$(notdir $(TOP))/ThornList \ + -name '.*' -prune -o \ + -name '*~' -prune -o \ + -not -type d \ + -print > $@ + + + +# Thorns + +$(TARBALL_DIR)/cactus-thorn-source-%.o: $(TARBALL_DIR)/cactus-thorn-source-%.c + @echo "Creating tarball for thorn $(@:$(TARBALL_DIR)/cactus-thorn-source-%.o=%)" + $(CC) $(CFLAGS) -c -o $@ $^ + +$(TARBALL_DIR)/cactus-thorn-source-%.c: $(TARBALL_DIR)/cactus-thorn-source-%.tar.gz + $(TARBALL_DIR)/makeblob $(patsubst %/,%,$(dir $(filter %/$(@:$(TARBALL_DIR)/cactus-thorn-source-%.c=%),$(THORNS)))) $(@:$(TARBALL_DIR)/cactus-thorn-source-%.c=%) < $< > $@ + +#$(TARBALL_DIR)/cactus-thorn-source-%.d: $(TARBALL_DIR)/cactus-thorn-source-%.files +# echo "$(@:%.d=%.c):" `cat $^` > $@ +#-include $(patsubst %,$(TARBALL_DIR)/cactus-thorn-source-%.d,$(notdir $(THORNS))) + +$(TARBALL_DIR)/cactus-thorn-source-%.tar.gz: $(TARBALL_DIR)/cactus-thorn-source-%.files + cd $(CCTK_HOME) && \ + tar czf $@ -T $< + +# This dependency means that the tarball for a thorn is only updated +# if the thorn is actually recompiled. This does not catch changes to +# files that do not influence the executable, but that is okay. +$(TARBALL_DIR)/cactus-thorn-source-%.files: $(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX) + cd $(CCTK_HOME) && \ + find arrangements/$(filter %/$(@:$(TARBALL_DIR)/cactus-thorn-source-%.files=%),$(THORNS)) \ + -path 'arrangements/*/*/doc' -prune -o \ + -path 'arrangements/*/*/par' -prune -o \ + -path 'arrangements/*/*/test' -prune -o \ + -name '.*' -prune -o \ + -name '*~' -prune -o \ + -not -type d \ + -print > $@ + + + +## 1. Create a list of files that should be in the tarball +## 2. Create the tarball +## 3. Use the makeblob utility (from this thorn; see make.code.deps) +## to create C source code from the tarball +## 4. Compile C code and create an archive +# +#.PHONY: make-tarball +#make-tarball: +# @echo "Creating source tarball..." && \ +# cd $(CCTK_HOME) && \ +# files="CONTRIBUTORS COPYRIGHT Makefile" && \ +# dirs="lib src" && \ +# thorns="$(THORNS:%=arrangements/%)" && \ +# filelist=$(TARBALL_DIR)/source-file-list && \ +# find $$files $$dirs $$thorns \ +# -path 'arrangements/*/*/doc' -prune \ +# -o -path 'arrangements/*/*/test' -prune \ +# -o -path 'arrangements/*/*/par' -prune \ +# -o -print > $$filelist && \ +# echo "Adding" `cat $$filelist | wc -l` "files..." && \ +# tar czf "$(TARBALL_DIR)/cactus-source.tar.gz" \ +# --no-recursion -T $$filelist && \ +# echo "Created tarball with" `cat $(TARBALL_DIR)/cactus-source.tar.gz | wc -c` "bytes..." && \ +# cd $(TARBALL_DIR) && \ +# rm -rf cactus-source && \ +# mkdir cactus-source && \ +# cd cactus-source && \ +# ../makeblob < ../cactus-source.tar.gz && \ +# $(CC) $(CFLAGS) -c *.c && \ +# cd .. && \ +# $(AR) $(ARFLAGS) cactus-source.a cactus-source/*.o && \ +# echo "Added tarball to executable." && \ +# echo $(DIVIDER) diff --git a/src/output_source.c b/src/output_source.c index 45bfb6a..db70022 100644 --- a/src/output_source.c +++ b/src/output_source.c @@ -12,49 +12,75 @@ -struct chunkinfo +struct sourceinfo { char const * data; - size_t const * length; + size_t length; + char const * arrangement; + char const * thorn; }; -extern struct chunkinfo cactus_source_chunks []; -extern size_t cactus_source_chunks_length; +extern struct sourceinfo const * const cactus_source []; +extern size_t const cactus_source_length; -void -Formaline_OutputSource (CCTK_ARGUMENTS) +int +Formaline_OutputSource () { - DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - char const sourcename [] = "cactus-source.tar.gz"; - size_t filenamelength; - char * filename; + char filename [10000]; FILE * file; - size_t chunk; + int count; - if (CCTK_MyProc (cctkGH) != 0) return; - - filenamelength = strlen (out_dir) + strlen (sourcename) + 2; - filename = malloc (filenamelength); - assert (filename); - sprintf (filename, "%s/%s", out_dir, sourcename); + if (CCTK_MyProc (0) != 0) return; + { CCTK_PRINTSEPARATOR } CCTK_VInfo (CCTK_THORNSTRING, - "Writing tarball with Cactus sources to file \"%s\"", filename); + "Writing tarballs with the Cactus sources into the directory \"%s\"", out_dir); - file = fopen (filename, "w"); - assert (file); - for (chunk = 0; chunk < cactus_source_chunks_length; ++ chunk) + CCTK_CreateDirectory (0755, out_dir); + + /* Output all thorns' tarballs */ + for (count = 0; count < cactus_source_length; ++ count) { - fwrite (cactus_source_chunks[chunk].data, - sizeof * cactus_source_chunks[chunk].data, - * cactus_source_chunks[chunk].length, + snprintf (filename, sizeof filename, + "%s/cactus-source-%s.tar.gz", + out_dir, cactus_source[count]->thorn); + file = fopen (filename, "w"); + assert (file); + fwrite (cactus_source[count]->data, + sizeof * cactus_source[count]->data, + cactus_source[count]->length, file); + fclose (file); } + + /* Add a README */ + snprintf (filename, sizeof filename, "%s/README", out_dir); + file = fopen (filename, "w"); + assert (file); + fprintf (file, +"README for the Cactus source tree\n" +"\n" +"This directory contains a complete Cactus source tree in several tarballs.\n" +"(A tarball is a file with a suffix like \".tar.gz\".)\n" +"The tarballs were created by the thorn AEIThorns/Formaline when the\n" +"corresponding executable was produced, and were stored in the executable.\n" +"The parameter file in this directory was used to extract the tarballs\n" +"from the executable.\n" +"Thorn AEIThorns/Formaline contains more information about this feature.\n" +"\n" +"In order to fully recreate the Cactus source tree, unpack all tarballs\n" +"in this directory, e.g. with commands like\n" +"\ttar xzf cactus-source-Cactus.tar.gz\n" +"for all tarballs. All tarballs should be unpacked into the same directory.\n" +"\n" +"The files \"config-info\" and \"ThornList\" that were used to build the\n" +"executable can then be found in the \"configs\" subdirectory.\n" + ); fclose (file); - free (filename); + return 0; } diff --git a/src/util/makeblob.c b/src/util/makeblob.c index 46f3446..a7f94c0 100644 --- a/src/util/makeblob.c +++ b/src/util/makeblob.c @@ -1,78 +1,58 @@ /* $Header$ */ +#include <assert.h> #include <stdio.h> int main (int argc, char * * argv) { - FILE * metafile; - unsigned long metacount; - char filename [100]; - FILE * file; + char const * arrangement; + char const * thorn; unsigned long count; - for (metacount = 0; ; ++ metacount) - { - sprintf (filename, "cactus-source-%08lu.c", metacount); - file = fopen (filename, "w"); - fprintf (file, "/* This is an auto-generated file -- do not edit */\n"); - fprintf (file, "#include <stddef.h>\n"); - fprintf (file, "\n"); - fprintf (file, "char const cactus_source_%08lu [] = {", metacount); - for (count = 0; count < 1000000; ++ count) - { - int const ch = getc (stdin); - if (feof (stdin)) break; - if (ferror (stdin)) return 1; - if (count != 0) { - fprintf (file, ","); - } - if (count % 16 == 0) - { - fprintf (file, "\n"); - } - fprintf (file, "%3d", ch); - } - fprintf (file, "\n"); - fprintf (file, "};\n"); - fprintf (file, "size_t const cactus_source_length_%08lu = %lu;\n", metacount, count); - fclose (file); - - if (feof (stdin)) break; - } - ++ metacount; - + assert (argc == 3); + arrangement = argv[1]; + thorn = argv[2]; + assert (arrangement); + assert (thorn); - - metafile = fopen ("cactus-source.c", "w"); - fprintf (metafile, "/* This is an auto-generated file -- do not edit */\n"); - fprintf (metafile, "#include <stddef.h>\n"); - fprintf (metafile, "\n"); - fprintf (metafile, "struct chunkinfo\n"); - fprintf (metafile, "{\n"); - fprintf (metafile, " char const * data;\n"); - fprintf (metafile, " size_t * length;\n"); - fprintf (metafile, "};\n"); - fprintf (metafile, "\n"); - for (count = 0; count < metacount; ++ count) - { - fprintf (metafile, "extern char const cactus_source_%08lu [];\n", count); - fprintf (metafile, "extern size_t cactus_source_length_%08lu;\n", count); - } - fprintf (metafile, "\n"); - fprintf (metafile, "struct chunkinfo cactus_source_chunks [] = {"); - for (count = 0; count < metacount; ++ count) + printf ("/* This is an auto-generated file -- do not edit */\n"); + printf ("\n"); + printf ("#include <stddef.h>\n"); + printf ("\n"); + printf ("struct sourceinfo\n"); + printf ("{\n"); + printf (" char const * data;\n"); + printf (" size_t length;\n"); + printf (" char const * arrangement;\n"); + printf (" char const * thorn;\n"); + printf ("};\n"); + printf ("\n"); + printf ("static char const data [] = {"); + for (count = 0; ; ++ count) { + int const ch = getc (stdin); + if (feof (stdin)) break; + if (ferror (stdin)) return 1; if (count != 0) { - fprintf (metafile, ","); + printf (","); + } + if (count % 16 == 0) + { + printf ("\n"); } - fprintf (metafile, "\n"); - fprintf (metafile, "{ cactus_source_%08lu, & cactus_source_length_%08lu }", count, count); + printf ("%3d", ch); } - fprintf (metafile, "\n"); - fprintf (metafile, "};\n"); - fprintf (metafile, "size_t cactus_source_chunks_length = %lu;\n", metacount); - fclose (metafile); + printf ("\n"); + printf ("};\n"); + printf ("\n"); + printf ("struct sourceinfo const cactus_source_%s =\n", thorn); + printf ("{\n"); + printf (" data,\n"); + printf (" %lu,\n", count); + printf (" \"%s\",\n", arrangement); + printf (" \"%s\"\n", thorn); + printf ("};\n"); return 0; } diff --git a/src/util/makemetablob.c b/src/util/makemetablob.c new file mode 100644 index 0000000..bc871a6 --- /dev/null +++ b/src/util/makemetablob.c @@ -0,0 +1,41 @@ +/* $Header$ */ + +#include <stdio.h> + +int +main (int argc, char * * argv) +{ + int count; + + printf ("/* This is an auto-generated file -- do not edit */\n"); + printf ("\n"); + printf ("#include <stddef.h>\n"); + printf ("\n"); + printf ("struct sourceinfo\n"); + printf ("{\n"); + printf (" char const * data;\n"); + printf (" size_t length;\n"); + printf (" char const * arrangement;\n"); + printf (" char const * thorn;\n"); + printf ("};\n"); + printf ("\n"); + for (count = 1; count < argc; ++ count) + { + printf ("extern struct sourceinfo cactus_source_%s;\n", argv[count]); + } + printf ("\n"); + printf ("struct sourceinfo const * const cactus_source [] = {"); + for (count = 1; count < argc; ++ count) + { + if (count != 1) { + printf (","); + } + printf ("\n"); + printf (" & cactus_source_%s", argv[count]); + } + printf ("\n"); + printf ("};\n"); + printf ("size_t const cactus_source_length = %d;\n", argc - 1); + + return 0; +} |