From 51e359b2f85ab367e7cab74066fe7f4e5ff1d4ac Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 4 Jul 2016 21:47:17 -0700 Subject: tzdata: Fix gen.rc to not require contents of source files This also fixes a symlink target calculation bug. --- README.md | 5 ----- core/tz/gen.rc | 20 +++----------------- core/tz/tzdata.awk | 26 ++++++++++++++++++++++++++ rules.ninja | 2 +- scripts/hash.rc | 10 ++++------ 5 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 core/tz/tzdata.awk diff --git a/README.md b/README.md index 2d34ce66..37f9aa12 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,6 @@ Next, configure `config.rc` to your liking. $EDITOR config.rc -Currently, tz's `gen.rc` requires the sources to exist to operate correctly. So, -check them out. - - git submodule update --init core/tz/src - Generate the ninja build files. rc ./setup.rc diff --git a/core/tz/gen.rc b/core/tz/gen.rc index 6fb8af83..838de404 100644 --- a/core/tz/gen.rc +++ b/core/tz/gen.rc @@ -19,22 +19,8 @@ tzdata=(\ systemv\ factory\ ) -for(data in $tzdata) { - zones=`{awk '/^Zone/ {print $2}' src/$data} - if(! ~ $#zones 0) { - outs='$outdir'/zoneinfo/$zones - build $"outs zic '$srcdir'/$data - for(zone in $zones) file share/zoneinfo/$zone '$outdir'/zoneinfo/$zone 644 - } - links=`{awk '/^Link/ {print $2 " " $3}' src/$data} - for(line in $links) { - # TODO: Figure out how to do this better. Maybe just readlink - # the symlinks constructed by zic? - ifs=' ' {link=`{printf %s $line}} - ifs='/' {parts=`{printf %s $link(1)}} - target=`{awk 'BEGIN {for(i=1; i<'$#parts'; i++) printf "../"}'}^$link(1) - sym share/zoneinfo/$link(2) $target - } -} +build '$outdir'/tzdata.tree awk '$srcdir'/$tzdata '|' scripts/hash.rc '$dir/tzdata.awk' ; with\ + expr '-f $dir/tzdata.awk out=$outdir/zoneinfo repo=$builddir/$repo.git' +tree_inputs=($tree_inputs '$outdir'/tzdata.tree) fetch git diff --git a/core/tz/tzdata.awk b/core/tz/tzdata.awk new file mode 100644 index 00000000..8bd70188 --- /dev/null +++ b/core/tz/tzdata.awk @@ -0,0 +1,26 @@ +# usage: awk -f tzdata.awk repo=out/root.git out=out/core/tz/zoneinfo [file...] + +function run(cmd) { + status = system(cmd) + if (status != 0) + exit status +} + +BEGIN { + cmdfmt = "rc ./scripts/hash.rc %s %s share/zoneinfo/%s %s" +} + +FNR == 1 { + run(sprintf("zic -d %s %s", out, FILENAME)) +} + +$1 == "Link" { + s = $3 + gsub(/[^/]+/, "..", s) + s = substr(s, 1, length(s) - 2) $2 + run(sprintf(cmdfmt, repo, 120000, $3, s)) +} + +$1 == "Zone" { + run(sprintf(cmdfmt, repo, 100644, $2, out "/" $2)) +} diff --git a/rules.ninja b/rules.ninja index 9be29eb4..0baf0e60 100644 --- a/rules.ninja +++ b/rules.ninja @@ -49,7 +49,7 @@ rule awk command = awk $expr $in >$out.tmp && mv $out.tmp $out rule githash - command = rc ./scripts/hash.rc $builddir/$repo.git $out $args $in + command = rc ./scripts/hash.rc $builddir/$repo.git $args $in >$out.tmp && mv $out.tmp $out rule gittree command = rc ./scripts/tree.rc $builddir/$repo.git $repo_tag $in diff --git a/scripts/hash.rc b/scripts/hash.rc index 5f894a6b..90151183 100644 --- a/scripts/hash.rc +++ b/scripts/hash.rc @@ -3,10 +3,9 @@ flag e + repo=$1 -out=$2 -mode=$3 -name=$4 -shift 4 +mode=$2 +name=$3 +shift 3 fn checkstatus {} @@ -22,5 +21,4 @@ hash=`{ } checkstatus -printf '%s %s\t%s\n' $mode $hash $name >$out.tmp -mv $out.tmp $out +printf '%s %s\t%s\n' $mode $hash $name -- cgit v1.2.3