Mon, 15 Dec 2025 19:18:04 +0100
implement build script
| build.template | file | annotate | diff | comparison | revisions | |
| src/main.go | file | annotate | diff | comparison | revisions | |
| testconfig.xml | file | annotate | diff | comparison | revisions |
--- a/build.template Mon Dec 15 10:59:58 2025 +0100 +++ b/build.template Mon Dec 15 19:18:04 2025 +0100 @@ -1,7 +1,133 @@ #!/bin/sh -pwd +# some utility functions +isplatform() +{ + for p in $PLATFORM + do + if [ "$p" = "$1" ]; then + return 0 + fi + done + return 1 +} +notisplatform() +{ + for p in $PLATFORM + do + if [ "$p" = "$1" ]; then + return 1 + fi + done + return 0 +} + +# Simple uname based platform detection +# $PLATFORM is used for platform dependent dependency selection +OS=`uname -s` +OS_VERSION=`uname -r` +ARCH=`uname -m` +printf "detect platform... " +if [ "$OS" = "SunOS" ]; then + PLATFORM="solaris sunos unix svr4" +elif [ "$OS" = "Linux" ]; then + PLATFORM="linux unix" +elif [ "$OS" = "FreeBSD" ]; then + PLATFORM="freebsd bsd unix" +elif [ "$OS" = "OpenBSD" ]; then + PLATFORM="openbsd bsd unix" +elif [ "$OS" = "NetBSD" ]; then + PLATFORM="netbsd bsd unix" +elif [ "$OS" = "Darwin" ]; then + PLATFORM="macos osx bsd unix" +elif echo "$OS" | grep -i "MINGW" > /dev/null; then + PLATFORM="windows mingw" +fi +: ${PLATFORM:="unix"} + +PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` +echo "$PLATFORM_NAME" + +mkdir result +result_dir=`pwd`/result + +configure_log=configure.log +compile_log=compile.log +check_log=check.log + +result_file=`pwd`/result.json + + +echo "[" > $result_file -echo {{ .Path }} -echo TODO +# repo source is always expected to be in src/ +cd src +{{ $nbuild := len .Build }} +{{ range $i, $build := .Build}} +# Build isplatform="{{ .IsPlatform }}" not="{{ .NotPlatform }}" +while true +do + log_dir=$result_dir/build{{$i}} + mkdir -p $log_dir + if [ $? -ne 0 ]; then + echo "failed to create log dir $log_dir" + echo "abort" + exit 1 + fi + + {{- if .IsPlatform}} + if notisplatform "{{ $build.IsPlatform }}"; then + break + fi + {{- end}} + {{- range $build.NotList}} + if isplatform "{{.}}"; then + break + fi + {{- end}} + + # configure + configure= + {{- if $build.Configure}} + {{ $build.Configure }} > $log_dir/$configure_log 2>&1 + configure=$? + {{- end}} + # compile + compile= + {{- if $build.Compile}} + {{ $build.Compile }} > $log_dir/$compile_log 2>&1 + compile=$? + {{- end}} + + # check + check= + {{- if $build.Check}} + {{ $build.Check }} > $log_dir/$check_log 2>&1 + check=$? + {{- end}} + + # write result + echo "write result to $result_file" + echo "{ \"build\":\"{{$i}}\", " >> $result_file + if [ -n "$configure" ]; then + echo " \"configure\":\"$configure\"," >> $result_file + fi + if [ -n "compile" ]; then + echo " \"compile\":\"$compile\"," >> $result_file + fi + if [ -n "check" ]; then + echo " \"check\":\"$check\"" >> $result_file + fi + {{- if eq $i (sub $nbuild 1) }} + echo '}' >> $result_file + {{ else }} + echo '},' >> $result_file + {{- end }} + break +done +# End Build +{{ end}} + +echo "]" >> $result_file +
--- a/src/main.go Mon Dec 15 10:59:58 2025 +0100 +++ b/src/main.go Mon Dec 15 19:18:04 2025 +0100 @@ -31,8 +31,9 @@ Path string `xml:"path"` BuildEnvs string `xml:"buildenvs"` Build []struct { - IsPlatform string `xml:"isplatform,attr"` - NotPlatform string `xml:"not,attr"` + IsPlatform string `xml:"isplatform,attr"` + NotPlatform string `xml:"not,attr"` + NotList []string Test []string `xml:"test"` Var []struct { Name string `xml:"name,attr"` @@ -59,12 +60,28 @@ config.BuildEnvMap[env.Name] = env } + for ri := range config.Repository { + for bi := range config.Repository[ri].Build { + build := &config.Repository[ri].Build[bi] + build.NotList = strings.Split(build.NotPlatform, ",") + } + } + templateStr, err := os.ReadFile("build.template") if err != nil { log.Fatal(err) } - tpl, err := template.New("").Parse(string(templateStr)) + funcs := template.FuncMap{ + "add": func(i int, n int) int { + return i + n + }, + "sub": func(i int, n int) int { + return i - n + }, + } + + tpl, err := template.New("").Funcs(funcs).Parse(string(templateStr)) if err != nil { log.Fatal(err) } @@ -205,6 +222,7 @@ // upload using scp cmd := exec.Command("scp", path.Join(tmp_dir, "build.tar.gz"), env.Host+":") + log.Print("scp: ", cmd.Args) if err := cmd.Run(); err != nil { log.Print("cannot copy build env to ", env.Host) continue
--- a/testconfig.xml Mon Dec 15 10:59:58 2025 +0100 +++ b/testconfig.xml Mon Dec 15 19:18:04 2025 +0100 @@ -7,14 +7,14 @@ <repository> <path>../ucx</path> <buildenvs>x1</buildenvs> - <build isplatform="linux"> + <build isplatform="unix"> <test>true</test> <test>which make</test> <var name="CFLAGS">-m64</var> <var name="LDFLAGS">-m64></var> <configure>./configure --debug</configure> <compile>make</compile> - <test>build/test/ucxtest</test> + <check>build/tests/ucxtest</check> </build> </repository> </config>