From 741d25282274e59c785b9cbee23cefff3d2721a2 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 15 Feb 2018 21:24:24 -0800 Subject: 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. --- scripts/commit.rc | 19 ------------------- scripts/commit.sh | 16 ++++++++++++++++ scripts/configheader.rc | 18 ------------------ scripts/fetch-curl.rc | 45 --------------------------------------------- scripts/fetch-curl.sh | 40 ++++++++++++++++++++++++++++++++++++++++ scripts/fetch-git.rc | 15 --------------- scripts/fetch-git.sh | 13 +++++++++++++ scripts/hash.rc | 24 ------------------------ scripts/hash.sh | 18 ++++++++++++++++++ scripts/probe.rc | 7 ------- scripts/probe.sh | 7 +++++++ scripts/tree.rc | 30 ------------------------------ scripts/tree.sh | 19 +++++++++++++++++++ 13 files changed, 113 insertions(+), 158 deletions(-) delete mode 100644 scripts/commit.rc create mode 100644 scripts/commit.sh delete mode 100644 scripts/configheader.rc delete mode 100644 scripts/fetch-curl.rc create mode 100644 scripts/fetch-curl.sh delete mode 100644 scripts/fetch-git.rc create mode 100644 scripts/fetch-git.sh delete mode 100644 scripts/hash.rc create mode 100644 scripts/hash.sh delete mode 100644 scripts/probe.rc create mode 100644 scripts/probe.sh delete mode 100644 scripts/tree.rc create mode 100644 scripts/tree.sh (limited to 'scripts') diff --git a/scripts/commit.rc b/scripts/commit.rc deleted file mode 100644 index 870d7ab3..00000000 --- a/scripts/commit.rc +++ /dev/null @@ -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 new file mode 100644 index 00000000..b4959f48 --- /dev/null +++ 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 deleted file mode 100644 index c1655f91..00000000 --- a/scripts/configheader.rc +++ /dev/null @@ -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 deleted file mode 100644 index a525bcdf..00000000 --- a/scripts/fetch-curl.rc +++ /dev/null @@ -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 new file mode 100644 index 00000000..86f7598e --- /dev/null +++ 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 [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 new file mode 100644 index 00000000..eea32d1c --- /dev/null +++ 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 deleted file mode 100644 index 90151183..00000000 --- a/scripts/hash.rc +++ /dev/null @@ -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 new file mode 100644 index 00000000..15861d27 --- /dev/null +++ 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 deleted file mode 100644 index aba1099d..00000000 --- a/scripts/probe.rc +++ /dev/null @@ -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 new file mode 100644 index 00000000..70867cdb --- /dev/null +++ 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 deleted file mode 100644 index c14e87e0..00000000 --- a/scripts/tree.rc +++ /dev/null @@ -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 new file mode 100644 index 00000000..15ae6991 --- /dev/null +++ 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 -- cgit v1.2.3