From 40bc0947eb99ee601f2d10db0762ff3ad9eea154 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 25 Dec 2019 21:27:32 +0100 Subject: [PATCH] =?UTF-8?q?non-hermetic=20build:=20don=E2=80=99t=20error?= =?UTF-8?q?=20out=20when=20packages=20are=20unavailable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit related to #55 --- cmd/distri/build.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/distri/build.go b/cmd/distri/build.go index e34206f1..63c7ca5b 100644 --- a/cmd/distri/build.go +++ b/cmd/distri/build.go @@ -730,19 +730,26 @@ func (b *buildctx) glob1(imgDir, pkg string) (string, error) { return candidates[len(candidates)-1], nil } if len(candidates) == 0 { + if !b.Hermetic { + // no package found, fall back to host tools in non-hermetic mode + return "", nil + } return "", xerrors.Errorf("package %q not found (pattern %s)", pkg, pattern) } return candidates[0], nil } func (b *buildctx) glob(imgDir string, pkgs []string) ([]string, error) { - globbed := make([]string, len(pkgs)) - for idx, pkg := range pkgs { - var err error - globbed[idx], err = b.glob1(imgDir, pkg) + globbed := make([]string, 0, len(pkgs)) + for _, pkg := range pkgs { + tmp, err := b.glob1(imgDir, pkg) if err != nil { return nil, err } + if tmp == "" { + continue + } + globbed = append(globbed, tmp) } return globbed, nil } @@ -1299,7 +1306,13 @@ func (b *buildctx) build() (*pb.Meta, error) { if err != nil { return nil, err } - if err := install(append([]string{"-root=/ro"}, deps...)); err != nil { + if len(deps) > 0 { + if err := install(append([]string{"-root=/ro"}, deps...)); err != nil { + return nil, err + } + } + + if err := os.MkdirAll("/ro/bin", 0755); err != nil { return nil, err }