logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git
commit: 741d25282274e59c785b9cbee23cefff3d2721a2
parent 83d57181d1565d9c12b7d2467be9008d2b6edeab
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 15 Feb 2018 21:24:24 -0800

Port build scripts to POSIX shell

Since we are now using Lua to generate ninja files, use of rc in build scripts
seems unnecessary and adds an additional bootstrap dependency. None of them are
too fancy, so just port to POSIX sh instead.

Diffstat:

M.travis.yml3+--
Mgen.lua2+-
Mninja.lua14++++++++++----
Dpkg/ffmpeg/scripts/sources.rc9---------
Apkg/ffmpeg/scripts/sources.sh8++++++++
Dpkg/git/fetch.rc17-----------------
Apkg/git/fetch.sh18++++++++++++++++++
Apkg/openbsd/fetch.sh30++++++++++++++++++++++++++++++
Mpkg/openbsd/gen.lua11+----------
Mpkg/tz/gen.lua2+-
Mpkg/tz/tzdata.lua2+-
Mrules.ninja14+++++++-------
Dscripts/commit.rc19-------------------
Ascripts/commit.sh16++++++++++++++++
Dscripts/configheader.rc18------------------
Dscripts/fetch-curl.rc45---------------------------------------------
Ascripts/fetch-curl.sh40++++++++++++++++++++++++++++++++++++++++
Dscripts/fetch-git.rc15---------------
Ascripts/fetch-git.sh13+++++++++++++
Dscripts/hash.rc24------------------------
Ascripts/hash.sh18++++++++++++++++++
Dscripts/probe.rc7-------
Ascripts/probe.sh7+++++++
Dscripts/tree.rc30------------------------------
Ascripts/tree.sh19+++++++++++++++++++
25 files changed, 191 insertions(+), 210 deletions(-)

diff --git a/.travis.yml b/.travis.yml @@ -6,14 +6,13 @@ git: addons: apt: packages: - - 9base - libwayland-dev - lua5.2 - nasm - pax install: - git clone --depth=1 https://github.com/michaelforney/oasis-toolchain /tmp/toolchain -- PATH=$PATH:/usr/lib/plan9/bin:/tmp/toolchain/bin +- PATH=$PATH:/tmp/toolchain/bin script: - git submodule update --init pkg/samurai/src - make -C pkg/samurai/src diff --git a/gen.lua b/gen.lua @@ -29,7 +29,7 @@ subgen 'src' file('.perms', '644', '$outdir/root.perms') build('gitinit', '$builddir/root.stamp') -build('gittree', '$builddir/root.tree', {'$outdir/root.index', '|', 'scripts/tree.rc', '||', '$builddir/root.stamp'}) +build('gittree', '$builddir/root.tree', {'$outdir/root.index', '|', 'scripts/tree.sh', '||', '$builddir/root.stamp'}) build('gitarchive', '$builddir/root.tar', {'|', '$builddir/root.tree'}) build('gitcommit', '$builddir/root.commit', {'|', '$builddir/root.tree'}) build('phony', 'commit', '$builddir/root.commit') diff --git a/ninja.lua b/ninja.lua @@ -360,8 +360,14 @@ function waylandproto(proto, client, server, code) cc(code, {'pkg/wayland/headers'}) end -function fetch(method, args) - build('fetch'..method, '$dir/fetch', {'|', '$dir/rev'}, {args=args}) +function fetch(method) + local script + if method == 'local' then + script = '$dir/fetch.sh' + else + script = 'scripts/fetch-'..method..'.sh' + end + build('fetch'..method, '$dir/fetch', {'|', '$dir/rev', script}) if next(pkg.inputs.fetch) then build('phony', table.keys(pkg.inputs.fetch), '$dir/fetch') end @@ -404,7 +410,7 @@ function file(path, mode, src) local out = '$builddir/root.hash/'..path mode = tonumber(mode, 8) local perm = string.format('10%04o %s', mode, path) - build('githash', out, {src, '|', 'scripts/hash.rc', '||', '$builddir/root.stamp'}, { + build('githash', out, {src, '|', 'scripts/hash.sh', '||', '$builddir/root.stamp'}, { args=perm, }) table.insert(pkg.inputs.index, out) @@ -426,7 +432,7 @@ function sym(path, target) return end local out = '$builddir/root.hash/'..path - build('githash', out, {'|', 'scripts/hash.rc', '||', '$builddir/root.stamp'}, { + build('githash', out, {'|', 'scripts/hash.sh', '||', '$builddir/root.stamp'}, { args=string.format('120000 %s %s', path, target), }) table.insert(pkg.inputs.index, out) diff --git a/pkg/ffmpeg/scripts/sources.rc b/pkg/ffmpeg/scripts/sources.rc @@ -1,9 +0,0 @@ -#!/bin/rc - -flag e + -flag x + - -../src/configure >/dev/null -awk '{print $2}' config.asm >vars.txt -make -f sources.mk >../sources.txt -git clean -df . diff --git a/pkg/ffmpeg/scripts/sources.sh b/pkg/ffmpeg/scripts/sources.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -ex + +../src/configure >/dev/null +awk '{print $2}' config.asm >vars.txt +make -f sources.mk >../sources.txt +git clean -df . diff --git a/pkg/git/fetch.rc b/pkg/git/fetch.rc @@ -1,17 +0,0 @@ -flag e + - -@ . ./scripts/fetch-git.rc $* - -cd $1 -shift - -if([ -e src/man ]) - rm -rf src/man - -if(! sha256sum -c sha256 >[2]/dev/null) { - curl -L -O -K url - sha256sum -c sha256 -} - -archive=`{awk '{print $2}' sha256} -xzcat $archive | pax -r -s ',^\.,src/man,' diff --git a/pkg/git/fetch.sh b/pkg/git/fetch.sh @@ -0,0 +1,18 @@ +set -e + +(. ./scripts/fetch-git.sh "$@") + +cd "$1" +shift + +if [ -e src/man ] ; then + rm -rf src/man +fi + +if ! sha256sum -c sha256 2>/dev/null ; then + curl -L -O -K url + sha256sum -c sha256 +fi + +read -r checksum archive <sha256 +xzcat "$archive" | pax -r -s ',^\.,src/man,' diff --git a/pkg/openbsd/fetch.sh b/pkg/openbsd/fetch.sh @@ -0,0 +1,30 @@ +set -e + +dir=$1 +shift + +cd "$dir" + +if [ -e src ] ; then + rm -rf src +fi + +if ! sha256sum -c sha256 2>/dev/null ; then + curl -L -K url -O + sha256sum -c sha256 +fi + +zcat src.tar.gz | pax -r -s '/^/src\//' \ + 'bin/pax/*' \ + 'include/*' \ + 'lib/libc/*' \ + 'lib/libcrypto/arc4random/*' \ + 'usr.bin/diff/*' \ + 'usr.bin/doas/*' \ + 'usr.bin/fmt/*' \ + 'usr.bin/nc/*' \ + 'usr.bin/patch/*' \ + 'usr.bin/yacc/*' +zcat sys.tar.gz | pax -r -s '/^/src\//' 'sys/sys/*' + +git apply -v --whitespace=nowarn --directory "$dir/src" patch/* diff --git a/pkg/openbsd/gen.lua b/pkg/openbsd/gen.lua @@ -87,13 +87,4 @@ exe('yacc', [[usr.bin/yacc/( file('bin/yacc', '755', '$outdir/yacc') man{'usr.bin/yacc/yacc.1'} -fetch('curl', paths[[ - -s '/^/src\//' '( - bin/pax - include - lib/(libc/(crypt gen net stdlib string) libcrypto/arc4random) - usr.bin/(diff doas fmt nc patch yacc) - )/*' - ';' - -s '/^/src\//' 'sys/sys/*' -]]) +fetch 'local' diff --git a/pkg/tz/gen.lua b/pkg/tz/gen.lua @@ -19,7 +19,7 @@ local tzdata = { rule('tzdata', 'lua $dir/tzdata.lua $repo $outdir/zoneinfo $in >$out.tmp && mv $out.tmp $out') build('tzdata', '$outdir/tzdata.index', { expand{'$srcdir/', tzdata}, - '|', '$dir/tzdata.lua', 'scripts/hash.rc', + '|', '$dir/tzdata.lua', 'scripts/hash.sh', '||', '$builddir/root.stamp', }) table.insert(pkg.inputs.index, '$outdir/tzdata.index') diff --git a/pkg/tz/tzdata.lua b/pkg/tz/tzdata.lua @@ -4,7 +4,7 @@ local function execute(cmd) end end -local hash = 'rc ./scripts/hash.rc %s %s share/zoneinfo/%s %s' +local hash = 'sh ./scripts/hash.sh %s %s share/zoneinfo/%s %s' local repo = arg[1] local outdir = arg[2] for i = 3, #arg do diff --git a/rules.ninja b/rules.ninja @@ -40,7 +40,7 @@ rule muse command = muse $museflags -o $out $in rule probe - command = rc ./scripts/probe.rc $var $cc $cflags $ldflags -o /dev/null -x c $in >$out.tmp && mv $out.tmp $out + command = sh ./scripts/probe.sh $var $cc $cflags $ldflags -o /dev/null -x c $in >$out.tmp && mv $out.tmp $out # misc tools rule touch @@ -80,14 +80,14 @@ rule waylandproto command = wayland-scanner $type <$in >$out.tmp && mv $out.tmp $out rule githash - command = rc ./scripts/hash.rc $repo $args $in >$out.tmp && mv $out.tmp $out + command = sh ./scripts/hash.sh $repo $args $in >$out.tmp && mv $out.tmp $out rule gittree - command = rc ./scripts/tree.rc $repo $repo_tag $in $out + command = sh ./scripts/tree.sh $repo $repo_tag $in $out restat = 1 rule gitcommit - command = rc ./scripts/commit.rc $repo $repo_branch $repo_tag $out + command = sh ./scripts/commit.sh $repo $repo_branch $repo_tag $out rule gitarchive command = git -C $repo archive -o $$PWD/$out $repo_tag @@ -96,19 +96,19 @@ rule gitinit command = git init $repo_flags $repo && touch $out rule fetchcurl - command = rc ./scripts/fetch-curl.rc $dir $args && touch $out + command = sh ./scripts/fetch-curl.sh $dir && touch $out restat = 1 generator = 1 pool = console rule fetchgit - command = rc ./scripts/fetch-git.rc $dir $args && touch $out + command = sh ./scripts/fetch-git.sh $dir && touch $out restat = 1 generator = 1 pool = console rule fetchlocal - command = rc ./$dir/fetch.rc $dir $args && touch $out + command = sh ./$dir/fetch.sh $dir && touch $out restat = 1 generator = 1 pool = console diff --git a/scripts/commit.rc b/scripts/commit.rc @@ -1,19 +0,0 @@ -#!/bin/rc - -flag e + - -repo=$1 -branch=$2 -tag=$3 -out=$4 - -fn checkstatus {} - -if(git -C $repo show-ref -q --verify refs/heads/$branch) - parent=(-p $branch) -if not parent=() - -message='oasis built by '`{id -un} -commit=`{echo $message | git -C $repo commit-tree $tag $parent} ; checkstatus -git -C $repo update-ref refs/heads/$branch $commit -echo $commit > $out.tmp && mv $out.tmp $out diff --git a/scripts/commit.sh b/scripts/commit.sh @@ -0,0 +1,16 @@ +set -e + +repo=$1 +branch=$2 +tag=$3 +out=$4 + +if git -C "$repo" show-ref -q --verify "refs/heads/$branch" ; then + set -- -p "$branch" +else + set -- +fi + +commit=$(git -C "$repo" commit-tree -m "oasis built by $(id -un)" "$@" "$tag") +git -C "$repo" update-ref "refs/heads/$branch" "$commit" +echo "$commit" >"$out.tmp" && mv "$out.tmp" "$out" diff --git a/scripts/configheader.rc b/scripts/configheader.rc @@ -1,18 +0,0 @@ -#!/bin/rc - -flag e + - -fn checkstatus {} - -posix_defines=`{mktemp} -checkstatus - -fn sigexit { - status=() rm $posix_defines -} - -awk '{if($1 == "#define") print $2 ; if($2 == "#undef") print $3}' include/config-posix.h >$posix_defines -defines=`{awk '{if($1 == "#undef") print $2}' $1 | grep -F -x -v -f $posix_defines} -checkstatus - -printf '#undef %s\n' $defines diff --git a/scripts/fetch-curl.rc b/scripts/fetch-curl.rc @@ -1,45 +0,0 @@ -flag e + - -if(~ $#* 0) { - echo 'usage: fetch-curl.rc dir [paxflags...]' >[1=2] - exit 2 -} - -cd $1 -shift - -if([ -e src ]) rm -rf src - -if(! sha256sum -c sha256 >[2]/dev/null) { - curl -L -K url -O - sha256sum -c sha256 -} - -for(archive in `{awk '{print $2}' sha256}) { - switch($archive) { - case *.tar.gz *.tgz - tool=zcat - case *.tar.bz2 - tool=bzcat - case *.tar.xz - tool=xzcat - case * - tool=() - } - flags=() - while(! ~ $1 '' ';') { - flags=($flags $1) - shift - } - if(~ $#flags 0) - flags=(-s '/^\.\|[^\/]*/src/' '*/*') - shift - if(! ~ $#tool 0) $tool $archive | pax -r $flags -} - -if([ -d patch ]) { - if(prefix=`{git rev-parse --show-prefix >[2]/dev/null}) dir=$prefix^src - if not dir=src - git apply -v '--whitespace=nowarn' --directory $dir patch/* -} -status=() diff --git a/scripts/fetch-curl.sh b/scripts/fetch-curl.sh @@ -0,0 +1,40 @@ +set -e + +if [ "$#" != 1 ] ; then + echo 'usage: fetch-curl.sh dir' >&2 + exit 2 +fi + +dir=$1 +shift + +cd "$dir" + +if [ -e src ] ; then + rm -rf src +fi + +if ! sha256sum -c sha256 2>/dev/null ; then + curl -L -K url -O + sha256sum -c sha256 +fi + +while read -r checksum archive ; do + case $archive in + *.tar.gz|*.tgz) + tool=zcat ;; + *.tar.bz2) + tool=bzcat ;; + *.tar.xz) + tool=xzcat ;; + *) + tool= + esac + if [ -n "$tool" ] ; then + "$tool" "$archive" | pax -r -s '/^\.\|[^\/]*/src/' '*/*' + fi +done <sha256 + +if [ -d patch ] ; then + git apply -v --whitespace=nowarn --directory "$dir/src" patch/* +fi diff --git a/scripts/fetch-git.rc b/scripts/fetch-git.rc @@ -1,15 +0,0 @@ -flag e + - -if(! ~ $#* 1) { - echo 'usage: fetch-git.rc dir' >[1=2] - exit 2 -} - -cd $1 - -git submodule update --init --checkout src -if([ -d patch ]) { - patches=patch/* - git -C src am '--whitespace=nowarn' ../$patches -} -status=() diff --git a/scripts/fetch-git.sh b/scripts/fetch-git.sh @@ -0,0 +1,13 @@ +set -e + +if [ "$#" != 1 ] ; then + echo 'usage: fetch-git.sh dir' >&2 + exit 2 +fi + +cd "$1" + +git submodule update --init --checkout src +if [ -d patch ] ; then + git -C src am --whitespace=nowarn "$PWD"/patch/* +fi diff --git a/scripts/hash.rc b/scripts/hash.rc @@ -1,24 +0,0 @@ -#!/bin/rc - -flag e + - -repo=$1 -mode=$2 -name=$3 -shift 3 - -fn checkstatus {} - -hash=`{ - switch($mode) { - case 12???? - printf %s $1 | git -C $repo hash-object -w --stdin - case 10???? - git -C $repo hash-object -w --stdin <$1 - case * - status=1 - } -} -checkstatus - -printf '%s %s\t%s\n' $mode $hash $name diff --git a/scripts/hash.sh b/scripts/hash.sh @@ -0,0 +1,18 @@ +set -e + +repo=$1 +mode=$2 +name=$3 +shift 3 + +case "$mode" in +12????) + hash=$(printf %s "$1" | git -C "$repo" hash-object -w --stdin) ;; +10????) + hash=$(git -C "$repo" hash-object -w --stdin <"$1") ;; +*) + echo "invalid mode: $mode" + exit 1 +esac + +printf '%s %s\t%s\n' "$mode" "$hash" "$name" diff --git a/scripts/probe.rc b/scripts/probe.rc @@ -1,7 +0,0 @@ -flag e + - -var=$1 -shift -if($* >[2]/dev/null) - echo '#define '$var' 1' -status=() diff --git a/scripts/probe.sh b/scripts/probe.sh @@ -0,0 +1,7 @@ +set -e + +var=$1 +shift +if "$@" 2>/dev/null ; then + echo "#define $var 1" +fi diff --git a/scripts/tree.rc b/scripts/tree.rc @@ -1,30 +0,0 @@ -#!/bin/rc - -flag e + - -repo=$1 -tag=$2 -index=$3 -out=$4 -ifs=' -' - -fn checkstatus {} - -GIT_INDEX_FILE=`{pwd}^/$out.index { - checkstatus - git -C $repo read-tree --empty - git -C $repo update-index --index-info <$index - tree=`{git -C $repo write-tree} ; checkstatus - rm $out.index -} -git -C $repo update-ref refs/tags/$tag $tree - -if([ -e $out ]) { - oldtree=`{cat $out} ; checkstatus - if(~ $tree $oldtree) - exit 0 -} - -echo $tree >$out.tmp -mv $out.tmp $out diff --git a/scripts/tree.sh b/scripts/tree.sh @@ -0,0 +1,19 @@ +set -e + +repo=$1 +tag=$2 +index=$3 +out=$4 + +export GIT_INDEX_FILE="$PWD/$out.index" +git -C "$repo" read-tree --empty +git -C "$repo" update-index --index-info <"$index" +tree=$(git -C "$repo" write-tree) +git -C "$repo" update-ref "refs/tags/$tag" "$tree" + +printf '%s\n' "$tree" >"$out.tmp" +if cmp -s "$out" "$out.tmp" ; then + rm "$out.tmp" +else + mv "$out.tmp" "$out" +fi