Skip to content

Commit

Permalink
Fix up tests
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <chrisko@google.com>
  • Loading branch information
hugelgupf committed Feb 24, 2024
1 parent 1102213 commit 22fa861
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 125 deletions.
14 changes: 4 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@ templates:
(cd test/diamonddep/mod3 && go build ./...)
(cd test/normaldeps/mod1 && go build ./...)
(cd test/normaldeps/mod2 && go build ./...)
(cd test/requestconflict/mod5 && go build ./...)
(cd test/requestconflict/mod6 && go build ./...)
(cd test/nested && go build ./...)
(cd test/nested/nestedmod && go build ./...)
- run:
name: tests
command: ./gobuilds.sh
- run:
name: build gokrazy & p9 together
command: ./test-multi-simple.sh

build-gomod-multi-template: &build-gomod-multi-template
steps:
- checkout
- run:
name: build u-root & gokrazy & p9 together
name: build u-root & gokrazy & p9 together (workspaces)
command: ./test-external.sh
- run:
name: build u-root & cpu & p9 together (GOPATH)
command: ./test-external-gopath.sh

build-gopath-template: &build-gopath-template
steps:
Expand Down Expand Up @@ -227,8 +225,6 @@ jobs:
(cd test/goembed && go mod tidy && go mod verify)
(cd test/normaldeps/mod1 && go mod tidy && go mod verify)
(cd test/normaldeps/mod2 && go mod tidy && go mod verify)
(cd test/requestconflict/mod5 && go mod tidy && go mod verify)
(cd test/requestconflict/mod6 && go mod tidy && go mod verify)
(cd test/nested && go mod tidy && go mod verify)
(cd test/nested/nestedmod && go mod tidy && go mod verify)
git status
Expand All @@ -250,8 +246,6 @@ jobs:
(cd test/goembed && go vet ./...)
(cd test/normaldeps/mod1 && go vet ./...)
(cd test/normaldeps/mod2 && go vet ./...)
(cd test/requestconflict/mod5 && go vet ./...)
(cd test/requestconflict/mod6 && go vet ./...)
(cd test/nested && go vet ./...)
(cd test/nested/nestedmod && go vet ./...)
- run:
Expand Down
1 change: 0 additions & 1 deletion src/cmd/makebb/makebb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package main

import (
"errors"
"flag"
"io/ioutil"
"log"
Expand Down
5 changes: 3 additions & 2 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ go 1.20

require (
github.com/u-root/uio v0.0.0-20210528151154-e40b768296a7
golang.org/x/tools v0.16.1
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/tools v0.18.0
)

require golang.org/x/mod v0.14.0 // indirect
require golang.org/x/mod v0.15.0 // indirect
12 changes: 7 additions & 5 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
github.com/u-root/uio v0.0.0-20210528151154-e40b768296a7 h1:XMAtQHwKjWHIRwg+8Nj/rzUomQY1q6cM3ncA0wP8GU4=
github.com/u-root/uio v0.0.0-20210528151154-e40b768296a7/go.mod h1:LpEX5FO/cB+WF4TYGY1V5qktpaZLkKkSegbr0V4eYXA=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
22 changes: 2 additions & 20 deletions src/pkg/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"path/filepath"
"strings"

"golang.org/x/exp/maps"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"

Expand All @@ -39,14 +40,6 @@ import (
"github.com/u-root/uio/ulog"
)

func listStrings(m map[string]struct{}) []string {
var l []string
for k := range m {
l = append(l, k)
}
return l
}

func checkDuplicate(cmds []*bbinternal.Package) error {
seen := make(map[string]string)
for _, cmd := range cmds {
Expand Down Expand Up @@ -187,7 +180,7 @@ func BuildBusybox(l ulog.Logger, opts *Opts) (nerr error) {
}
}
if len(modules) > 0 && numNoModule > 0 {
return fmt.Errorf("gobusybox does not support mixed module/non-module compilation -- commands contain main modules %v", strings.Join(listStrings(modules), ", "))
return fmt.Errorf("gobusybox does not support mixed module/non-module compilation -- commands contain main modules %v", strings.Join(maps.Keys(modules), ", "))
}

// List of packages to import in the real main file.
Expand Down Expand Up @@ -288,17 +281,6 @@ func writeBBMain(bbDir, tmpDir string, bbImports []string) error {
return nil
}

func isReplacedModuleLocal(m *packages.Module) bool {
// From "replace directive": https://golang.org/ref/mod#go
//
// If the path on the right side of the arrow is an absolute or
// relative path (beginning with ./ or ../), it is interpreted as the
// local file path to the replacement module root directory, which
// must contain a go.mod file. The replacement version must be
// omitted in this case.
return strings.HasPrefix(m.Path, "./") || strings.HasPrefix(m.Path, "../") || strings.HasPrefix(m.Path, "/")
}

func copyAllDeps(l ulog.Logger, env *golang.Environ, bbDir, tmpDir, pkgDir string, mainPkgs []*bbinternal.Package) error {
var deps []*packages.Package
for _, p := range mainPkgs {
Expand Down
35 changes: 35 additions & 0 deletions test-external-gopath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -ex

if [ -z "$GOROOT" ]; then
GO="go"
else
GO="$GOROOT/bin/go"
fi

cd src/cmd/makebb

$GO generate
$GO build

cd ../../..

# Try vendor-based $GOPATH u-root + cpu + p9.
GOPATH_TMPDIR=$(mktemp -d)
function ctrl_c() {
rm -rf $GOPATH_TMPDIR
}
trap ctrl_c INT

mkdir -p $GOPATH_TMPDIR/src/github.com/u-root
mkdir -p $GOPATH_TMPDIR/src/github.com/hugelgupf

(cd $GOPATH_TMPDIR/src/github.com/u-root && git clone https://github.com/u-root/u-root && cd u-root && git checkout 6ca118b0a77c23ae859cddeee15762d9cd74c63f)
(cd $GOPATH_TMPDIR/src/github.com/u-root && git clone https://github.com/u-root/cpu && cd cpu && git checkout 5529b02a0e41bfc6b3a387c4fa7e7e9cc374a95d && go mod vendor)
(cd $GOPATH_TMPDIR/src/github.com/hugelgupf && git clone https://github.com/hugelgupf/p9 && cd p9 && git checkout 660eb2337e3c1878298fe550ad03248f329eeb72 && go mod vendor)

GOARCH=amd64 GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/* $GOPATH_TMPDIR/src/github.com/u-root/cpu/cmds/* $GOPATH_TMPDIR/src/github.com/hugelgupf/p9/cmd/*
GOARCH=arm64 GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/* $GOPATH_TMPDIR/src/github.com/u-root/cpu/cmds/* $GOPATH_TMPDIR/src/github.com/hugelgupf/p9/cmd/*
GOARCH=riscv64 GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/* $GOPATH_TMPDIR/src/github.com/u-root/cpu/cmds/* $GOPATH_TMPDIR/src/github.com/hugelgupf/p9/cmd/*

rm -rf $GOPATH_TMPDIR bb3
50 changes: 24 additions & 26 deletions test-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ $GO build

cd ../../..

MAKEBB=$(pwd)/src/cmd/makebb/makebb
TMPDIR=$(mktemp -d)
EMPTY_TMPDIR=$(mktemp -d)

pushd $TMPDIR

function ctrl_c() {
popd
rm -rf $TMPDIR
# https://github.com/golang/go/issues/27455
GOPATH=$EMPTY_TMPDIR $GO clean -cache -modcache
Expand All @@ -27,44 +31,38 @@ trap ctrl_c INT

# u-root checked out NOT in $GOPATH.
# Checkout before 1.20+ was required.
(cd $TMPDIR && git clone https://github.com/u-root/u-root && cd u-root && git checkout 6ca118b0a77c23ae859cddeee15762d9cd74c63f)
(git clone https://github.com/u-root/u-root && cd u-root && git checkout 6ca118b0a77c23ae859cddeee15762d9cd74c63f)
# Pin to commit before Go 1.20 was required. (We test 1.18+.)
(cd $TMPDIR && git clone https://github.com/gokrazy/gokrazy && cd gokrazy && git checkout 254af2bf3c82ff9f56e89794b2c146ef9cc85dc6)
(git clone https://github.com/gokrazy/gokrazy && cd gokrazy && git checkout 254af2bf3c82ff9f56e89794b2c146ef9cc85dc6)
# Pin to commit before Go 1.20 was required. (We test 1.18+.)
(cd $TMPDIR && git clone https://github.com/hugelgupf/p9 && cd p9 && git checkout 660eb2337e3c1878298fe550ad03248f329eeb72)
(git clone https://github.com/hugelgupf/p9 && cd p9 && git checkout 660eb2337e3c1878298fe550ad03248f329eeb72)

# Make u-root have modules.
(cd $TMPDIR/u-root && rm -rf vendor)
# Test workspaces.
go work init ./u-root && go work use ./gokrazy && go work use ./p9

GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=auto ./src/cmd/makebb/makebb -o bb1 $TMPDIR/u-root/cmds/*/*
GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on ./src/cmd/makebb/makebb -o bb2 $TMPDIR/u-root/cmds/*/*
# Test reproducible builds.
echo $TMPDIR
echo $(pwd)
GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly -o bb1 ./u-root/cmds/*/*
GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly -o bb2 ./u-root/cmds/*/*

cmp bb1 bb2 || (echo "building u-root is not reproducible" && exit 1)
rm bb1 bb2

GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on ./src/cmd/makebb/makebb $TMPDIR/u-root/cmds/*/* $TMPDIR/gokrazy/cmd/* $TMPDIR/p9/cmd/*
GOARCH=arm64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on ./src/cmd/makebb/makebb $TMPDIR/u-root/cmds/*/* $TMPDIR/gokrazy/cmd/* $TMPDIR/p9/cmd/*
GOARCH=amd64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
GOARCH=arm64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
GOARCH=riscv64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*

if grep -q -v "go1.13" <<< "$($GO version)"; then
GOARCH=riscv64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on ./src/cmd/makebb/makebb $TMPDIR/u-root/cmds/*/* $TMPDIR/gokrazy/cmd/* $TMPDIR/p9/cmd/*
# Try an offline build in go workspaces.
# go work vendor is a Go 1.22 feature.
if grep -q -v "go1.21" <<< "$($GO version)" && grep -q -v "go1.20" <<< "$($GO version)";
then
go work vendor
GOARCH=amd64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=vendor ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
fi

popd
rm -rf $TMPDIR
# https://github.com/golang/go/issues/27455
GOPATH=$EMPTY_TMPDIR $GO clean -cache -modcache
rm -rf $EMPTY_TMPDIR

# Try vendor-based $GOPATH u-root.
GOPATH_TMPDIR=$(mktemp -d)
function ctrl_c() {
rm -rf $GOPATH_TMPDIR
}
trap ctrl_c INT

mkdir -p $GOPATH_TMPDIR/src/github.com/u-root
(cd $GOPATH_TMPDIR/src/github.com/u-root && git clone https://github.com/u-root/u-root && cd u-root && git checkout 6ca118b0a77c23ae859cddeee15762d9cd74c63f)
GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/*
GOARCH=arm64 GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/*
GOARCH=riscv64 GOROOT=$GOROOT GOPATH=$GOPATH_TMPDIR GO111MODULE=off ./src/cmd/makebb/makebb -o bb3 $GOPATH_TMPDIR/src/github.com/u-root/u-root/cmds/*/*

rm -rf $GOPATH_TMPDIR bb3
41 changes: 0 additions & 41 deletions test-multi-simple.sh

This file was deleted.

5 changes: 0 additions & 5 deletions test.sh

This file was deleted.

Loading

0 comments on commit 22fa861

Please sign in to comment.