From 02f1d40e09cf22879ce76fe95ad6cb52a48c3924 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 31 May 2015 21:09:48 +0000 Subject: [PATCH] basic svn capability svn path=/trunk/; revision=31288 --- build/arguments.sh | 85 ++++++++++++++++++++++++++++ build/build_main.sh | 121 ++++++---------------------------------- build/buildrun.sh | 86 +++++++++++++--------------- build/makerules.sh | 94 ++++++++++++++++++++++++++----- build/misc.sh | 5 ++ build/process_file.sh | 38 +------------ build/processor.sh | 6 +- build/scaffold.sh | 1 - build/source_globber.sh | 52 ++--------------- build/stirrups.sh | 6 +- 10 files changed, 239 insertions(+), 255 deletions(-) create mode 100755 build/arguments.sh diff --git a/build/arguments.sh b/build/arguments.sh new file mode 100755 index 0000000000..5e6af1fe71 --- /dev/null +++ b/build/arguments.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +basedir="$(realpath -m "$0/../..")" +[ -z "$inc_misc" ] && . "$basedir/build/misc.sh" + +while [ "$#" -gt 0 ]; do + case "$1" in + -s|--statusdir|--status-dir) + [ "$#" -gt 0 ] && shift 1 && statusdir="$1" + ;; + --domain) + [ "$#" -gt 0 ] && shift 1 && domain="$1" + ;; + --source) + [ "$#" -gt 0 ] && shift 1 && basedir="$1" + ;; + -d|--dest|--destination) + [ "$#" -gt 0 ] && shift 1 && target="$1" + ;; + -h|--help) + command="help" + ;; + build_into) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && target="$1" + ;; + svn_build_into) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && target="$1" + ;; + build_xmlstream) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && workfile="$1" + [ "$#" -gt 0 ] && shift 1 && olang="$1" + ;; + tree_maker) + command="$1$command" + [ -n "$target" -o -n "$3" ] && shift 1 && tree="$1" + shift 1; [ -n "$1" ] && target="$1" + ;; + process_file) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && workfile="$1" + [ "$#" -gt 0 ] && shift 1 && processor="$1" + [ "$#" -gt 0 ] && shift 1 && olang="$1" + ;; + sourceglobs) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && sourcesfile="$1" + ;; + cast_globfile) + command="$1$command" + [ "$#" -gt 0 ] && shift 1 && sourceglobfile="$1" + [ "$#" -gt 0 ] && shift 1 && lang="$1" + [ "$#" -gt 0 ] && shift 1 && globfile="$1" + ;; + *) + print_error "Unknown option $1" + exit 1 + ;; + esac + [ "$#" -gt 0 ] && shift 1 +done + +olang="${olang:-en}" +tree="${tree:-$basedir}" +readonly tree="${tree:+$(realpath "$tree")}" +readonly basedir="${basedir:+$(realpath "$basedir")}" +readonly statusdir="${statusdir:+$(realpath "$statusdir")}" +readonly target="${target:+$(realpath "$target")}" +readonly domain="${domain:-www.fsfe.org}" +readonly command + +case "$command" in + build_into) [ -z "$target" ] && die "Missing destination directory" ;; + svn_build_into) [ -z "$target" ] && die "Missing destination directory" ;; + process_file) [ -z "$workfile" ] && die "Need at least input file" ;; + build_xmlstream) [ -z "$workfile" ] && die "Missing xhtml file name" ;; + tree_maker) [ -z "$target" ] && die "Missing target location" ;; + sourceglobs) [ -z "$sourcesfile" ] && die "Missing .sources file" ;; + cast_globfile) [ -z "$sourceglobfile" -o -z "$lang" -o -z "$globfile" ] && die "Need source globfile language and globfile" ;; + *help*) print_help; exit 0 ;; + *) die "Urecognised command or no command given" ;; +esac + diff --git a/build/build_main.sh b/build/build_main.sh index 06e805d87f..23b6f36ba3 100755 --- a/build/build_main.sh +++ b/build/build_main.sh @@ -1,129 +1,42 @@ #!/bin/sh basedir="$(realpath -m "$0/../..")" - [ -z "$inc_misc" ] && . "$basedir/build/misc.sh" +. "$basedir/build/arguments.sh" + buildpids=$( ps -eo pid,command \ | egrep 'sh .*[b]uild_main.sh .*' \ | wc -l ) -if [ "$buildpids" -gt 2 ]; then +if [ $command = "build_into" -o $command = "svn_build_into" ] && [ "$buildpids" -gt 2 ]; then print_error "build script is already running" exit 0 fi [ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh" -[ -z "$inc_buildrun" ] && . "$basedir/build/buildrun.sh" +[ -z "$inc_buildrun" ] && . "$basedir/build/buildrun.sh" [ -z "$inc_languages" ] && . "$basedir/build/languages.sh" [ -z "$inc_makerules" ] && . "$basedir/build/makerules.sh" [ -z "$inc_processor" ] && . "$basedir/build/processor.sh" -[ -z "$inc_scaffold" ] && . "$basedir/build/scaffold.sh" -[ -z "$inc_sources" ] && . "$basedir/build/sources.sh" - -domain="www.fsfe.org" - -while [ -n "$*" ]; do - case "$1" in - -s|--statusdir|--status-dir) - [ -n "$*" ] && shift 1 && statusdir="$1" - ;; - --domain) - [ -n "$*" ] && shift 1 && domain="$1" - ;; - --source) - [ -n "$*" ] && shift 1 && basedir="$1" - ;; - -d|--dest|--destination) - [ -n "$*" ] && shift 1 && target="$1" - ;; - -h|--help) - command="help" - ;; - build_into) - command="$1$command" - [ -n "$*" ] && shift 1 && target="$1" - ;; - build_xmlstream) - command="$1$command" - [ -n "$*" ] && shift 1 && workfile="$1" - [ -n "$*" ] && shift 1 && olang="$1" - ;; - tree_maker) - command="$1$command" - [ -n "$target" -o -n "$3" ] && shift 1 && tree="$1" - shift 1; [ -n "$1" ] && target="$1" - ;; - process_file) - command="$1$command" - [ -n "$*" ] && shift 1 && workfile="$1" - [ -n "$*" ] && shift 1 && processor="$1" - [ -n "$*" ] && shift 1 && olang="$1" - ;; - sourceglobs) - command="$1$command" - [ -n "$*" ] && shift 1 && sourcesfile="$1" - ;; - cast_globfile) - command="$1$command" - [ -n "$*" ] && shift 1 && sourceglobfile="$1" - [ -n "$*" ] && shift 1 && lang="$1" - [ -n "$*" ] && shift 1 && globfile="$1" - ;; - *) - print_error "Unknown option $1" - exit 1 - ;; - esac - [ -n "$*" ] && shift 1 -done - -[ -z "$tree" ] && tree="$basedir" -tree="$(realpath "$tree")" -basedir="$(realpath "$basedir")" -target="$(realpath "$target")" +[ -z "$inc_scaffold" ] && . "$basedir/build/scaffold.sh" +[ -z "$inc_sources" ] && . "$basedir/build/sources.sh" if [ -n "$statusdir" ]; then mkdir -p "$statusdir" - statusdir="$(realpath "$statusdir")" - if [ ! -w "$statusdir" -o ! -d "$statusdir" ]; then - print_error "Unable to set up status directory in \"$statusdir\", -either select a status directory that exists and is writable, -or run the build script without output to a status directory" - exit 1 - fi + [ ! -w "$statusdir" -o ! -d "$statusdir" ] && \ + die "Unable to set up status directory in \"$statusdir\",\n" \ + "either select a status directory that exists and is writable,\n" \ + "or run the build script without output to a status directory" fi case "$command" in - build_into) - [ -z "$target" ] && print_error "Missing destination directory" && exit 1 - build_into - ;; - process_file) - [ -z "$workfile" ] && print_error "Need at least input file" && exit 1 - process_file "$workfile" "$processor" "$olang" - ;; - build_xmlstream) - [ -z "$workfile" ] && print_error "Missing xhtml file name" && exit 1 - build_xmlstream "$(get_shortname "$workfile")" "$(get_language "$workfile")" "$olang" - ;; - tree_maker) - [ -z "$target" ] && print_error "Missing target location" && exit 1 - tree_maker "$tree" "$target" - ;; - sourceglobs) - [ -z "$sourcesfile" ] && print_error "Missing .sources file" && exit 1 - sourceglobs "$sourcesfile" - ;; - cast_globfile) - [ -z "$sourceglobfile" -o -z "$lang" -o -z "$globfile" ] && print_error "Need source globfile language and globfile" && exit 1 - cast_globfile "$sourceglobfile" "$lang" "$globfile" - ;; - *help*) - print_help - ;; - *) - print_error "Urecognised command or no command given" - ;; + build_into) build_into ;; + svn_build_into) svn_build_into ;; + process_file) process_file "$workfile" "$processor" "$olang" ;; + build_xmlstream) build_xmlstream "$(get_shortname "$workfile")" "$(get_language "$workfile")" "$olang" ;; + tree_maker) tree_maker "$tree" "$target" ;; + sourceglobs) sourceglobs "$sourcesfile" ;; + cast_globfile) cast_globfile "$sourceglobfile" "$lang" "$globfile" ;; esac diff --git a/build/buildrun.sh b/build/buildrun.sh index 63db7c4630..a914e30c89 100755 --- a/build/buildrun.sh +++ b/build/buildrun.sh @@ -4,52 +4,7 @@ inc_buildrun=true [ -z "$inc_makerules" ] && . "$basedir/build/makerules.sh" [ -z "$inc_stirrups" ] && . "$basedir/build/stirrups.sh" [ -z "$inc_logging" ] && . "$basedir/build/logging.sh" - -svn_update(){ - run_make=true - regen_globs=false - regen_xsldeps=false - regen_xhtml=false - regen_copy=false - - svn update "$basedir" 2>&1 \ - | logstatus SVNchanges \ - | while read update; do - case "$update" in - Updating*) true;; - Updated*) true;; - "At revision"*) run_make=false;; - C???" "*) conflict=true;; - ?C??" "*) conflict=true;; - ???C" "*) conflict=true;; - A???" "*.xml) regen_globs=true;; - [UGR]???" "*.xml) true;; - ????" "*.xml) regen_globs=true;; - A???" "*.sources) echo "$update";; - [UGR]???" "*.sources) regen_globs=true;; - ????" "*.sources) regen_globs=true;; - A???" "*.xsl) echo "$update";; - [UGR]???" "*.xsl) regen_xsldeps=true;; - ????" "*.xsl) regen_xsldeps=true;; - A???" "*.xhtml) echo "$update" - regen_globs=true;; - [UGR]???" "*.xhtml) true;; - ????" "*.xhtml) regen_xhtml=true;; - ????" "*Makefile) true;; - A???" "*) echo "$update";; - [UGR]???" "*) true;; - ????" "*) regen_copy=true;; - *) true;; - esac - done | cut -c6- -} - -svn_build_into(){ - svn_update \ - | logstatus additions - - build_into -} +[ -z "$inc_misc" ] && . "$basedir/build/misc.sh" build_into(){ ncpu="$(grep -c ^processor /proc/cpuinfo)" @@ -61,7 +16,7 @@ build_into(){ dir_maker "$basedir" "$target" - tree_maker "$basedir" "$target" \ + tree_maker "$basedir" "$target" "$@" \ | logstatus Makefile \ | build_manifest \ | logstatus manifest \ @@ -71,3 +26,40 @@ build_into(){ make -j $ncpu -f "$(logname Makefile)" all \ | logstatus buildlog } + +svn_build_into(){ + forcelog SVNchanges; SVNchanges="$(logname SVNchanges)" + forcelog SVNerrors; SVNerrors="$(logname SVNerrors)" + + svn update "$basedir" >"$SVNchanges" 2>"$SVNerrors" + + if [ -s "$SVNerrors" ]; then + print_error "SVN reported the following problem:\n" \ + "$(cat "$SVNerrors")" + exit 1 + elif egrep '^(C...|.C..|...C) .+' "$SVNchanges"; then + print_error "SVN encountered a conflict:\n" \ + "$(cat "$SVNchanges")" + exit 1 + elif egrep '^At revision [0-9]+\.' "$SVNchanges"; then + debug "No changes to SVN:\n" \ + "$(cat "$SVNchanges")" + exit 0 + else + regen_globs=false + regen_xhtml=false + regen_xsldeps=false + regen_copy=false + + egrep -q '^[^UGR]... .*\.xml' "$SVNchanges" && regen_globs=true + egrep -q '^[^A]... .*\.sources' "$SVNchanges" && regen_globs=true + egrep -q '^A... .*\.xhtml' "$SVNchanges" && regen_globs=true + egrep -q '^[^AUGR]... .*\.xhtml' "$SVNchanges" && regen_xhtml=true + egrep -q '^A... .*\.xsl' "$SVNchanges" && regen_xhtml=true + egrep -q '^[^A]... .*\.xsl' "$SVNchanges" && regen_xsldeps=true + sed -r '/.*\.(xml|xsl|xhtml|sources)$/d;/Makefile$/d' "$SVNchanges" \ + | egrep -q '^[AUGR]... .*' && regen_copy=true + + build_into $(sed -rn '/.*(Makefile|\.xml)$/d;s;^A... (.+)$;\1;p' "$SVNchanges") + fi +} diff --git a/build/makerules.sh b/build/makerules.sh index 47d8653a1c..b052307606 100755 --- a/build/makerules.sh +++ b/build/makerules.sh @@ -53,13 +53,25 @@ $(mes "$globfile"): $(mes "$sourceglobfile") MakeEND done } + glob_makers(){ + # generate make rules for globbing all .sources files + # within input tree sourcefind -name '*.sources' \ | while read filepath; do glob_maker "$filepath" done } +glob_additions(){ + printf "$input/%s\n" "$@" \ + | egrep '.+\.sources$' \ + | xargs realpath \ + | while read addition; do + glob_maker "${addition#$input/}" + done +} + xhtml_maker(){ # generate make rules for building html files out of xhtml # account for included xml files and xsl rules @@ -106,19 +118,19 @@ xhtml_maker(){ cat <"$outfile" + \${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "$processor")" "$olang" >"$outfile" $(mes "$outlink"): ln -sf "${outbase}" "${outlink}" MakeEND $bool_rss && cat<"$rssfile" + \${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "${shortname}.rss.xsl")" "$olang" >"$rssfile" MakeEND $bool_ics && cat<"$icsfile" + \${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "${shortname}.ics.xsl")" "$olang" >"$icsfile" MakeEND $bool_indexname && cat <>"$Make_globs" \ || glob_makers >"$Make_globs" & - [ "$regen_xslt" = false -a -s "$Make_xslt" ] \ + [ "$regen_xslt" = false -a -s "$Make_xslt" ] && \ + xslt_additions "$@" >>"$Make_xslt" \ || xslt_makers >"$Make_xslt" & - [ "$regen_copy" = false -a -s "$Make_copy" ] \ + [ "$regen_copy" = false -a -s "$Make_copy" ] && \ + copy_additions "$@" >>"$Make_copy" \ || copy_makers >"$Make_copy" & - [ "$regen_xhtml" = false -a -s "$Make_sourcecopy" ] \ + [ "$regen_xhtml" = false -a -s "$Make_sourcecopy" ] && \ + copy_sourceadditions "$@" >>"$Make_sourcecopy" \ || copy_sources >"$Make_sourcecopy" & - - [ "$regen_xhtml" = false -a -s "$Make_xhtml" ] && \ - cat "$Make_xhtml" \ - || xhtml_makers |tee "$Make_xhtml" + if [ "$regen_xhtml" = false -a -s "$Make_xhtml" ]; then + cat "$Make_xhtml" + xhtml_additions "$@" |tee -a "$Make_xhtml" + else + xhtml_makers |tee "$Make_xhtml" + fi wait trap - 0 2 3 6 9 15 + cat "$Make_globs" "$Make_xslt" "$Make_copy" "$Make_sourcecopy" } diff --git a/build/misc.sh b/build/misc.sh index c426a47b29..3297fa768e 100755 --- a/build/misc.sh +++ b/build/misc.sh @@ -25,3 +25,8 @@ print_error(){ echo "Error: $@" |logstatus lasterror >/dev/stderr echo "Run '$0 --help' to see usage instructions" >/dev/stderr } + +die(){ + print_error "$@" + exit 1 +} diff --git a/build/process_file.sh b/build/process_file.sh index ca9c8f545f..fb286e2a83 100755 --- a/build/process_file.sh +++ b/build/process_file.sh @@ -1,41 +1,9 @@ #!/bin/sh basedir="$(dirname $0)/.." - -[ -z "$inc_misc" ] && . "$basedir/build/misc.sh" [ -z "$inc_processor" ] && . "$basedir/build/processor.sh" -domain="www.fsfe.org" -while [ -n "$*" ]; do - case "$1" in - -s|--statusdir|--status-dir) - [ -n "$*" ] && shift 1 && statusdir="$1" - ;; - --domain) - [ -n "$*" ] && shift 1 && domain="$1" - ;; - --source) - [ -n "$*" ] && shift 1 && basedir="$1" - ;; - -h|--help) - print_help - exit 0 - ;; - *) - if [ -z "$workfile" ]; then - workfile="$1" - elif [ -z "$processor" ]; then - processor="$1" - elif [ -z "$olang" ]; then - olang="$1" - else - print_error "Unknown option $1" - exit 1 - fi - ;; - esac - [ -n "$*" ] && shift 1 -done +. "$basedir/build/arguments.sh" -[ -z "$workfile" ] && print_error "Need at least input file" && exit 1 -process_file "$workfile" "$processor" "$olang" +[ "$command" = process_file ] && process_file "$workfile" "$processor" "$olang" \ +|| die "Urecognised command or no command given" diff --git a/build/processor.sh b/build/processor.sh index 18b2e1a87b..b179d9ccf8 100755 --- a/build/processor.sh +++ b/build/processor.sh @@ -1,16 +1,14 @@ #!/bin/sh inc_processor=true -[ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh" -[ -z "$inc_scaffold" ] && . "$basedir/build/scaffold.sh" +[ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh" +[ -z "$inc_scaffold" ] && . "$basedir/build/scaffold.sh" process_file(){ infile="$1" processor="$2" olang="$3" - [ -z "$domain" ] && domain="www.fsfe.org" - shortname=$(get_shortname "$infile") lang=$(get_language "$infile") [ -z "$processor" ] && processor="$(get_processor "$shortname")" diff --git a/build/scaffold.sh b/build/scaffold.sh index b29e73d137..fe44455f91 100755 --- a/build/scaffold.sh +++ b/build/scaffold.sh @@ -23,7 +23,6 @@ build_xmlstream(){ time="$(date +%H:%M:%S)" outdated=no - [ -z "$olang" ] && olang="en" if [ -f "${shortname}.${lang}.xhtml" ]; then act_lang="$lang" [ "${shortname}.${olang}.xhtml" -nt "${shortname}.${lang}.xhtml" ] && outdated=yes diff --git a/build/source_globber.sh b/build/source_globber.sh index 29a43185cb..40d4483fd6 100755 --- a/build/source_globber.sh +++ b/build/source_globber.sh @@ -1,56 +1,12 @@ #!/bin/sh basedir="$(dirname $0)/.." - -[ -z "$inc_misc" ] && . "$basedir/build/misc.sh" [ -z "$inc_sources" ] && . "$basedir/build/sources.sh" -while [ -n "$*" ]; do - case "$1" in - -s|--statusdir|--status-dir) - [ -n "$*" ] && shift 1 && statusdir="$1" - ;; - --domain) - [ -n "$*" ] && shift 1 && domain="$1" - ;; - --source) - [ -n "$*" ] && shift 1 && basedir="$1" - ;; - -d|--dest|--destination) - [ -n "$*" ] && shift 1 && target="$1" - ;; - -h|--help) - print_help - exit 0 - ;; - sourceglobs) - command="$1$command" - [ -n "$*" ] && shift 1 && sourcesfile="$1" - ;; - cast_globfile) - command="$1$command" - [ -n "$*" ] && shift 1 && sourceglobfile="$1" - [ -n "$*" ] && shift 1 && lang="$1" - [ -n "$*" ] && shift 1 && globfile="$1" - ;; - *) - print_error "Unknown option $1" - exit 1 - ;; - esac - [ -n "$*" ] && shift 1 -done +. "$basedir/build/arguments.sh" case "$command" in - sourceglobs) - [ -z "$sourcesfile" ] && print_error "Missing .sources file" && exit 1 - sourceglobs "$sourcesfile" - ;; - cast_globfile) - [ -z "$sourceglobfile" -o -z "$lang" -o -z "$globfile" ] && print_error "Need source globfile language and globfile" && exit 1 - cast_globfile "$sourceglobfile" "$lang" "$globfile" - ;; - *) - print_error "Urecognised command or no command given" - ;; + sourceglobs) sourceglobs "$sourcesfile" ;; + cast_globfile) cast_globfile "$sourceglobfile" "$lang" "$globfile" ;; + *) die "Urecognised command or no command given" ;; esac diff --git a/build/stirrups.sh b/build/stirrups.sh index 3bfa92c86b..012c2dbba2 100755 --- a/build/stirrups.sh +++ b/build/stirrups.sh @@ -32,7 +32,7 @@ build_manifest(){ remove_orphans(){ # read list of files which should be in a directory tree # and remove everything else - tree="${1%/}" + dtree="${1%/}" # Idea behind the algorithm: # `find` will list every existing file once. @@ -42,10 +42,10 @@ remove_orphans(){ # We use 'uniq -u' to drop those from the list. # Remaining single files exist only in the tree and are to be removed - (find "$tree" -type f -o -type l; sed "s;^.*$;$tree/&;") \ + (find "$dtree" -type f -o -type l; sed "s;^.*$;$dtree/&;") \ | sort \ | uniq -u \ | while read file; do - match "$file" "^$tree" && rm -v "$file" + match "$file" "^$dtree" && rm -v "$file" done }