From fe713a0995fddf53b024beeedaa412c6a083a45d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 25 Mar 2025 12:58:30 +0100 Subject: [PATCH] main: tweak how ibcli determines if bootstraping is needed This simplifies the way that ibcli determines if the manifest needs a bootstrap stage or not. The logic is simple: - when doing `image-builder manifest` we never include one - when doing `image-builder build --arch` we add one if the target arch and host arch differ Instead of passing a callback this is now just a simple bool option. Thanks to Achilleas for suggesting this. Co-Authored-by: Achilleas Koutsou --- cmd/image-builder/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 8beda22..8d62201 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -81,7 +81,14 @@ func ostreeImageOptions(cmd *cobra.Command) (*ostree.ImageOptions, error) { }, nil } -func cmdManifestWrapper(pbar progress.ProgressBar, cmd *cobra.Command, args []string, w io.Writer, needBootstrap func(string) bool) (*imagefilter.Result, error) { +type cmdManifestWrapperOptions struct { + useBootstrapIfNeeded bool +} + +func cmdManifestWrapper(pbar progress.ProgressBar, cmd *cobra.Command, args []string, w io.Writer, wrapperOpts *cmdManifestWrapperOptions) (*imagefilter.Result, error) { + if wrapperOpts == nil { + wrapperOpts = &cmdManifestWrapperOptions{} + } dataDir, err := cmd.Flags().GetString("data-dir") if err != nil { return nil, err @@ -170,9 +177,7 @@ func cmdManifestWrapper(pbar progress.ProgressBar, cmd *cobra.Command, args []st ForceRepos: forceRepos, } - if needBootstrap != nil { - opts.UseBootstrapContainer = needBootstrap(img.Arch.Name()) - } + opts.UseBootstrapContainer = wrapperOpts.useBootstrapIfNeeded && (img.Arch.Name() != arch.Current().String()) if opts.UseBootstrapContainer { fmt.Fprintf(os.Stderr, "WARNING: using experimental cross-architecture building to build %q\n", img.Arch.Name()) } @@ -227,6 +232,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error { if err != nil { return err } + // XXX: check env here, i.e. if user is root and osbuild is installed pbar, err := progressFromCmd(cmd) if err != nil { @@ -242,10 +248,10 @@ func cmdBuild(cmd *cobra.Command, args []string) error { }() var mf bytes.Buffer - // XXX: check env here, i.e. if user is root and osbuild is installed - res, err := cmdManifestWrapper(pbar, cmd, args, &mf, func(archStr string) bool { - return archStr != arch.Current().String() - }) + opts := &cmdManifestWrapperOptions{ + useBootstrapIfNeeded: true, + } + res, err := cmdManifestWrapper(pbar, cmd, args, &mf, opts) if err != nil { return err }