Greatly speed up gensources.sh and improve dependency handling
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 7 Apr 2010 07:07:15 +0000 (07:07 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 7 Apr 2010 07:07:15 +0000 (07:07 -0000)
* build/Makefile (DISTFILES): Add gensources.sh.
* build/gensources.sh: New, improved version of tools/gensources.sh.
* build/library.make ($(sourcefile)): Use the new gensources.sh.
($(makefrag)): Update to handle the optional makefrag generated by
gensources.sh.
* tools/Makefile (DISTFILES): Remove gensources.sh.
* tools/gensources.sh: Remove.

svn path=/trunk/mcs/; revision=154909

mcs/build/ChangeLog
mcs/build/Makefile
mcs/build/gensources.sh [new file with mode: 0644]
mcs/build/library.make
mcs/tools/ChangeLog
mcs/tools/Makefile
mcs/tools/gensources.sh [deleted file]

index d560cb6405ccc24ba420b65db8302a1b74607d90..cb960cc29ffd18530a634f23498c4d41eead7e87 100644 (file)
@@ -1,3 +1,11 @@
+2010-04-07  Raja R Harinath  <harinath@hurrynot.org>
+
+       * Makefile (DISTFILES): Add gensources.sh.
+       * gensources.sh: New, improved version of tools/gensources.sh.
+       * library.make ($(sourcefile)): Use the new gensources.sh.
+       ($(makefrag)): Update to handle the optional makefrag generated by
+       gensources.sh.
+
 2010-04-01  Zoltan Varga  <vargaz@gmail.com>
 
        * config-default.make (LIBRARY_FLAGS): Applied patch from Laurent Etiemble
index af6ce7356b47435ee5625891362c1c7692cba399..69721f73b689fbdff8d9c4bb0ef2d67cf4e4f1cc 100644 (file)
@@ -40,6 +40,7 @@ DISTFILES = \
        corcompare.make                 \
        corcompare-api.xsl              \
        executable.make                 \
+       gensources.sh                   \
        library.make                    \
        nunit-summary.xsl               \
        rules.make                      \
diff --git a/mcs/build/gensources.sh b/mcs/build/gensources.sh
new file mode 100644 (file)
index 0000000..cc76aa5
--- /dev/null
@@ -0,0 +1,48 @@
+#! /bin/sh
+
+outfile=$1
+incfile=$2
+excfile=$3
+
+process_includes_1() {
+    sed -e '/^[ \t]*$/d' -e '/^[ \t]*#/d' $1 > $2
+    if cmp -s $1 $2; then
+       false
+    else
+       sed -n 's,^[ \t]*#include ,,p' $1 |
+       while read inc; do
+           cat $inc >> $2
+           echo $outfile: $inc >> $outfile.makefrag
+           echo $inc: >> $outfile.makefrag
+       done
+    fi
+}
+
+process_includes() {
+    i=$1; o=$2; t=${2}.tmp
+    while process_includes_1 $i $o; do
+       mv $o $t
+       i=$t
+    done
+    rm -f $t
+}
+
+rm -f $outfile.makefrag
+
+process_includes $incfile $outfile.inc
+
+sort -u $outfile.inc > $outfile.inc_s
+
+if test -z "$excfile"; then
+    mv $outfile.inc_s $outfile
+else
+    process_includes $excfile $outfile.exc
+
+    sort -u $outfile.exc > $outfile.exc_s
+
+    sort -m $outfile.inc_s $outfile.exc_s | uniq -u > $outfile
+
+    rm -f $outfile.inc_s $outfile.exc_s
+fi
+
+
index 342be387b1eb9b589b2ecc3aa2824054f9a6016e..d8811d9c199fc0e4064475a054128c397a5a0ad4 100644 (file)
@@ -16,9 +16,12 @@ ifeq ($(wildcard $(PROFILE_sources)), $(PROFILE_sources))
 PROFILE_excludes = $(wildcard $(PROFILE)_$(LIBRARY).exclude.sources)
 COMMON_sourcefile := $(sourcefile)
 sourcefile = $(depsdir)/$(PROFILE)_$(LIBRARY).sources
-$(sourcefile): $(PROFILE_sources) $(PROFILE_excludes) $(COMMON_sourcefile)
+
+# Note, gensources.sh can create a $(sourcefile).makefrag if it sees any '#include's
+# We don't include it in the dependencies since it isn't always created
+$(sourcefile): $(PROFILE_sources) $(PROFILE_excludes) $(COMMON_sourcefile) $(topdir)/build/gensources.sh
        @echo Creating the per profile list $@ ...
-       $(topdir)/tools/gensources.sh $(PROFILE_sources) $(PROFILE_excludes) > $@
+       $(SHELL) $(topdir)/build/gensources.sh $@ $(PROFILE_sources) $(PROFILE_excludes)
 library_CLEAN_FILES += $(sourcefile)
 endif
 
@@ -251,6 +254,10 @@ endif
 $(makefrag): $(sourcefile)
        @echo Creating $@ ...
        @sed 's,^,$(build_lib): ,' $< >$@
+       @if test ! -f $(sourcefile).makefrag; then :; else \
+          cat $(sourcefile).makefrag >> $@ ; \
+          echo '$@: $(sourcefile).makefrag' >> $@; \
+          echo '$(sourcefile).makefrag:' >> $@; fi
 
 ifneq ($(response),$(sourcefile))
 $(response): $(sourcefile) $(PLATFORM_excludes)
index 115c18f02f942cb240d791507e1aa61be6a421dc..5916d229aeb1274ed5a42e7155ea3d156ab68c1f 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-07  Raja R Harinath  <harinath@hurrynot.org>
+
+       * Makefile (DISTFILES): Remove gensources.sh.
+       * gensources.sh: Remove.
+
 2010-04-03  Ankit Jain  <jankit@novell.com>
 
        * Makefile: Move xbuild from net_4_0_dirs to per_profile_dirs.
index 42d150b7850941ecf4d262f231080c345258ff23..970ac6d2e1a49fe4380c998da72b604345421969 100644 (file)
@@ -72,7 +72,6 @@ DISTFILES = \
        scan-tests.pl                   \
        tinderbox/smtp.c                \
        tinderbox/tinderbox.sh          \
-       gensources.sh                   \
        removecomments.sh
 
 test-local csproj-local run-test-local run-test-ondotnet-local all-local install-local uninstall-local doc-update-local:
diff --git a/mcs/tools/gensources.sh b/mcs/tools/gensources.sh
deleted file mode 100755 (executable)
index 7e71029..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env bash
-
-includefile=$1
-excludefile=$2
-
-## input variables:
-##     $filelist:
-##             A colon (':') separated list of files already read.
-##             Must be initialized to ":".
-##     $excludelist:
-##             A newline separated of element (support Shell Patterns) to exclude.
-##     $separator:
-##             The separator used in list for the output
-##     
-## output variables:
-##     $list:
-##             A list of elements separated by the separator given in $separator.
-##             The new elements will be appended to the list.
-readlist () {
-       local onelist
-       local onelistcontent
-       onelist=$1
-
-       if [ ":$onelist:" = "::" ] ; then return ; fi
-       if [ ! -f $onelist ] ; then return ; fi
-       if [ ":${filelist##*:$onelist:*}:" = "::" ]  ; then return ; fi
-       filelist=":$onelist$filelist"
-
-       onelistcontent=`cat $onelist | sed "s=[ \t]*$==g" | while read line ; do echo -n $line ; echo -n ":" ; done`
-
-       OFS="$IFS"
-       IFS=":"
-       for line in $onelistcontent ; do
-               line2=${line##\#}
-               if [ ":$line:" = ":$line2:" ] ; then
-                       for linex in $excludelist ; do
-                               if [ ":${line##$linex}:" = "::" ] ; then line="" ; fi
-                       done
-                       if [ ":$line:" != "::" ] ; then
-                               if [ ":$list:" = "::" ] ; then
-                                       list="$line"
-                               else
-                                       list="$list$separator$line"
-                               fi
-                       fi
-               else
-                       line3=${line2##include }
-                       if [ ":$line3:" != ":$line2:" -a ":$line3:" != "::" ] ; then
-                               readlist "$line3"
-                       fi
-               fi
-       done
-       IFS="$OFS"
-}
-
-list=""
-filelist=":"
-excludelist=""
-separator=":"
-readlist "$excludefile"
-
-excludelist="$list"
-list=""
-filelist=":"
-separator="
-"
-readlist "$includefile"
-echo "$list" | sort | uniq