Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way supernovae files are generated so that out of source works
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 28 Nov 2010 10:45:35 +0000 (10:45 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 28 Nov 2010 10:45:35 +0000 (10:45 +0000)
Use a perl script instead of a shell script
Move filtering of fragile files from cmake to perl
Generate stuff in CMAKE_CURRENT_BINARY_DIR and not source tree
Generate stuff on demand (create a make target) instead of on configuring only

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8710 48e7efb5-ca39-0410-a469-dd3cf9ba447f

buildtools/Cmake/DefinePackages.cmake
buildtools/Cmake/Modules/FindSupernovae.cmake
buildtools/Cmake/Supernovae.cmake
src/mk_supernovae.pl [new file with mode: 0755]
src/mk_supernovae.sh [deleted file]

index e6cbf4b..32335e8 100644 (file)
@@ -87,7 +87,7 @@ set(EXTRA_DIST
        src/smpi/smpi_coll_private.h
        src/smpi/smpi_mpi_dt_private.h
        src/smpi/README
        src/smpi/smpi_coll_private.h
        src/smpi/smpi_mpi_dt_private.h
        src/smpi/README
-       src/mk_supernovae.sh
+       src/mk_supernovae.pl
 )
 
 set(XBT_RL_SRC 
 )
 
 set(XBT_RL_SRC 
index 2409ac6..505bad8 100644 (file)
@@ -8,6 +8,7 @@ if(CAT_EXE AND GREP_EXE AND SED_EXE AND ECHO_EXE AND SH_EXE)
     set(HAVE_SUPERNOVAE_TOOLS 1)
 else(CAT_EXE AND GREP_EXE AND SED_EXE AND ECHO_EXE AND SH_EXE)
     if(enable_supernovae)
     set(HAVE_SUPERNOVAE_TOOLS 1)
 else(CAT_EXE AND GREP_EXE AND SED_EXE AND ECHO_EXE AND SH_EXE)
     if(enable_supernovae)
+    message(FATAL "You are missing some elements to use the supernovae compilation mode")
     message("CAT_EXE ${CAT_EXE}")
     message("GREP_EXE ${GREP_EXE}")
     message("SED_EXE ${SED_EXE}")
     message("CAT_EXE ${CAT_EXE}")
     message("GREP_EXE ${GREP_EXE}")
     message("SED_EXE ${SED_EXE}")
index 62499fe..a798e33 100644 (file)
@@ -1,73 +1,76 @@
 ### Make supernovae files and libs
 
 ### Make supernovae files and libs
 
+#############################################################################
+### Add here every files that should not be supernovaed (generated files) ###
+#############################################################################
 set(simgrid_fragile_sources 
 set(simgrid_fragile_sources 
-src/gras/DataDesc/ddt_parse.yy.c
-src/surf/surfxml_parse.c
-src/xbt/graphxml_parse.c
-src/simdag/sd_daxloader.c
+       src/gras/DataDesc/ddt_parse.yy.c
+       src/surf/surfxml_parse.c
+       src/xbt/graphxml_parse.c
+       src/simdag/sd_daxloader.c
 )
 set(gras_fragile_sources
 )
 set(gras_fragile_sources
-src/gras/DataDesc/ddt_parse.yy.c
-src/xbt/graphxml_parse.c
+       src/gras/DataDesc/ddt_parse.yy.c
+       src/xbt/graphxml_parse.c
 )
 )
-set(temp_src_smpi "")
-set(temp_src_simgrid "")
-set(temp_src_gras "")
 
 
-if(enable_smpi)
-       foreach(file ${SMPI_SRC})
-               set(temp_src_smpi "${temp_src_smpi} ${file}")
-       endforeach(file ${SMPI_SRC})
-endif(enable_smpi)
+#####################################################
+### END OF CONFIGURATION, NO NEED TO READ FURTHER ###
+#####################################################
 
 
-foreach(file ${simgrid_sources})
-       set(en_plus yes)
-       foreach(file_delete ${simgrid_fragile_sources})
-               if(file_delete MATCHES "${file}")
-                       set(en_plus no)
-                       #message("${file}")
-               endif(file_delete MATCHES "${file}")
-       endforeach (file_delete ${simgrid_fragile_sources})
-       if(en_plus)
-               if(file MATCHES "src/xbt/log.c")
-                       set(file "xbt/log.c")
-               endif(file MATCHES "src/xbt/log.c")
-               set(temp_src_simgrid "${temp_src_simgrid} ${file}")
-       endif(en_plus)
-endforeach(file ${simgrid_sources})
+### Rebuild the supernovae source files
 
 
-foreach(file ${gras_sources})
-       set(en_plus yes)
-       foreach(file_delete ${gras_fragile_sources})
-               if(file_delete MATCHES "${file}")
-                       set(en_plus no)
-                       #message("${file}")
-               endif(file_delete MATCHES "${file}")
-       endforeach (file_delete ${gras_fragile_sources})
-       if(en_plus)
-               if(file MATCHES "src/xbt/log.c")
-                       set(file "xbt/log.c")
-               endif(file MATCHES "src/xbt/log.c")
-               set(temp_src_gras "${temp_src_gras} ${file}")
-       endif(en_plus)
-endforeach(file ${gras_sources})
+set_source_files_properties(${PROJECT_DIRECTORY}/src/supernovae_sg.c;${PROJECT_DIRECTORY}/src/supernovae_gras.c;${PROJECT_DIRECTORY}/src/supernovae_smpi.c
+                             PROPERTIES GENERATED true)
 
 
-exec_program("${CMAKE_COMMAND} -E remove -f ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${PROJECT_DIRECTORY}/src/supernovae_smpi.c" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/src/mk_supernovae.sh" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_sg.c   ${temp_src_simgrid}" "${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${temp_src_gras}" "${PROJECT_DIRECTORY}"    OUTPUT_VARIABLE "SUPER_OK")
-if(enable_smpi)
-       exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_smpi.c ${temp_src_smpi}" "${PROJECT_DIRECTORY}"     OUTPUT_VARIABLE "SUPER_OK")
-endif(enable_smpi)
+exec_program("${CMAKE_COMMAND} -E remove -f ${PROJECT_DIRECTORY}/src/supernovae_sg.c
+                                            ${PROJECT_DIRECTORY}/src/supernovae_gras.c 
+                                           ${PROJECT_DIRECTORY}/src/supernovae_smpi.c"
+       OUTPUT_VARIABLE "SUPER_OK")
 
 
-add_library(simgrid    SHARED  ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${simgrid_fragile_sources})
+exec_program("chmod +x ${PROJECT_DIRECTORY}/src/mk_supernovae.pl" OUTPUT_VARIABLE "SUPER_OK")
+
+ADD_CUSTOM_COMMAND(
+       OUTPUT   ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c
+       DEPENDS  ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+       COMMAND  perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c '--fragile=${simgrid_fragile_sources}' '${simgrid_sources}'
+       WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+       COMMENT "Generating supernovae_sg.c"
+)
+
+ADD_CUSTOM_COMMAND(
+       OUTPUT   ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c
+       DEPENDS  ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+       COMMAND  perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c '--fragile=${gras_fragile_sources}'    '${gras_sources}'
+       WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+       COMMENT "Generating supernovae_gras.c"
+)
+
+ADD_CUSTOM_COMMAND(
+       OUTPUT   ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c
+       DEPENDS  ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+       COMMAND  perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c  '${SMPI_SRC}'
+       WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+       COMMENT "Generating supernovae_smpi.c"
+)
+
+### Make sure that the libs are built from the supernovae sources
+       add_library(simgrid     SHARED  ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c ${simgrid_fragile_sources})
+       add_dependencies(simgrid ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
+       
        if(enable_lib_static)
        if(enable_lib_static)
-               add_library(simgrid_static STATIC ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${simgrid_fragile_sources})  
+               add_library(simgrid_static STATIC ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c ${simgrid_fragile_sources})
+               add_dependencies(simgrid_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
        endif(enable_lib_static)
        endif(enable_lib_static)
-add_library(gras       SHARED  ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${gras_fragile_sources})
-if(enable_smpi)
-       add_library(smpi        SHARED  ${PROJECT_DIRECTORY}/src/supernovae_smpi.c)
+       
+       add_library(gras        SHARED  ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c ${gras_fragile_sources})
+       add_dependencies(gras ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c)
+
+       if(enable_smpi)
+               add_library(smpi        SHARED  ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
+               add_dependencies(smpi ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
                        if(enable_lib_static)
                        if(enable_lib_static)
-                       add_library(smpi_static STATIC ${PROJECT_DIRECTORY}/src/supernovae_smpi.c)      
-               endif(enable_lib_static)
-endif(enable_smpi)
+                               add_library(smpi_static STATIC ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)       
+                               add_dependencies(smpi_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
+                       endif(enable_lib_static)
+       endif(enable_smpi)
diff --git a/src/mk_supernovae.pl b/src/mk_supernovae.pl
new file mode 100755 (executable)
index 0000000..5eb5100
--- /dev/null
@@ -0,0 +1,101 @@
+#! /usr/bin/perl
+
+use strict;
+use Getopt::Long qw(GetOptions);
+
+#open TMP,">mk_supernovae.pl.args";
+#map {print TMP "$_ "} @ARGV;
+#close TMP;
+
+sub usage($) {
+    my $ret;
+    print "USAGE: mk_supernovae.pl [--fragile=file]* --out=file file1 file2*\n";
+    print "  --help: show this message\n";
+    print "  --fragile=file: specify that file is fragile and shouldn't be supernovaed\n";
+    print "  --out=file: specify the name of the output file\n";
+    print "elements may be separated by semi-columns (;) instead of spaces, too\n";
+    exit $ret;
+}
+
+my @fragile_files=undef;
+my $outfile=undef;
+my $help;
+
+Getopt::Long::config('permute','no_getopt_compat', 'no_auto_abbrev');
+GetOptions(
+    'help|h'                => \$help,
+
+    'fragile=s' =>\@fragile_files,
+    'out=s'     =>\$outfile) or usage(1);
+
+@fragile_files = split(/;/,join(';',@fragile_files));
+@fragile_files = split(/ /,join(' ',@fragile_files));
+
+usage(0) if (defined($help));
+unless(defined($outfile)) {
+    print "ERROR: No outfile defined.\n";
+    usage(1);
+}
+
+#print "mk_supernovae: generate $outfile\n";  
+
+open OUT, ">$outfile" or die "ERROR: cannot open $outfile: $!\n";
+
+print OUT <<EOF
+#define SUPERNOVAE_MODE 1
+#ifndef _GNU_SOURCE
+#  define _GNU_SOURCE   /* for getline() with older libc */
+#endif
+#include <ctype.h>
+#include "portable.h"
+#include "xbt.h"
+  
+EOF
+  ;
+
+sub readfile($) {
+    my $filename=shift;
+    open IN,"$filename" || die "ERROR: cannot read $filename: $!\n";
+    my $res;
+    while (<IN>) {
+       $res .= $_;
+    }
+    close IN;  
+    return $res;
+}
+
+
+my %fragile;
+map {$fragile{$_}=1} @fragile_files;
+my @args = split(/;/,join(';',@ARGV));
+@args = split(/ /,join(' ',@args));
+my $nbfile=0;
+foreach my $file (@args) {
+    if ($fragile{$file}) {
+       print "mk_supernovae: $file is fragile, skip it\n";
+       next;
+    } 
+#      print "mk_supernovae: process $file\n";
+    $nbfile++;
+
+    my $needundef=1;
+    print OUT "/* file $file */\n";
+    if ($file eq "xbt/log.c") {
+       print OUT "  #define _simgrid_log_category__default &_simgrid_log_category__log\n";
+    } else {
+       my $ctn = readfile($file);
+       if ($ctn =~ m/XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY/s) {
+           my $default=$ctn;
+           $default =~ s/.*XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY[^(]*\(([^,)]*).*$/$1/s;
+           print OUT "  #define _simgrid_log_category__default &_simgrid_log_category__$default\n";
+       } else {
+           print OUT "  /* no default category in file $file */\n";
+           $needundef = 0;
+       }
+    }
+    print OUT "  #include \"$file\"\n";
+    print OUT "  #undef _simgrid_log_category__default\n" if $needundef;
+    print OUT "\n";
+}
+close OUT;
+print "mk_supernovae: $outfile contains $nbfile files inlined\n";
diff --git a/src/mk_supernovae.sh b/src/mk_supernovae.sh
deleted file mode 100755 (executable)
index cec0876..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#! /bin/sh
-
-file=$1
-shift
-
-cat > $file <<EOF
-#define SUPERNOVAE_MODE 1
-#ifndef _GNU_SOURCE
-#  define _GNU_SOURCE   /* for getline() with older libc */
-#endif
-#include <ctype.h>
-#include "portable.h"
-#include "xbt.h"
-EOF
-for n in $@ ; do
-#    echo "File $n"
-    if [ "X$n" = 'Xxbt/log.c' ] ; then 
-      echo "#define _simgrid_log_category__default &_simgrid_log_category__log">> $file;
-    else 
-      if grep -q 'XBT_LOG_[^ ]*DEFAULT_[^ ]*CATEGORY' $n ; then 
-        default=`grep 'XBT_LOG_[^ ]*DEFAULT_[^ ]*CATEGORY' $n|
-                 sed 's/^[^(]*(\([^,)]*\).*$/\1/'|head -n1`; 
-        echo "#define _simgrid_log_category__default &_simgrid_log_category__$default">> $file;
-      else
-        echo "/* no default category in file $n */" >> $file; 
-      fi;
-    fi;
-    echo '  #include "'$n'"' >> $file ; 
-    echo "#undef _simgrid_log_category__default">> $file; 
-    echo >> $file; 
-done
-
-exit 0
\ No newline at end of file