From 90693da8fecacfbc2709f2905da8753715ceaa73 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 17 Jan 2018 12:26:19 -0800 Subject: [PATCH] Write update metadata to output directory Instead of requiring the new swupd code to create the "format" and "swupd-server-src-version" metadata files enable BuildUpdate to do so. Because the mixer version is now used instead of a swupd-server version write the mixer-tools version to a "mixer-src-version" file. Move the Version const to builder.go so it can be accessed trivially. Update the Makefile parsing to point to builder.go and update the access method in the top-level mixer/cmd/root.go. Signed-off-by: Matthew Johnson --- Makefile | 2 +- builder/builder.go | 22 ++++++++++++++++++++++ mixer/cmd/root.go | 5 +---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f52b0f5..6f9606e 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ release: echo "Release needs to be used from a git repository"; \ exit 1; \ fi - @VERSION=$$(grep -e 'const Version' mixer/cmd/root.go | cut -d '"' -f 2) ; \ + @VERSION=$$(grep -e 'const Version' builder/builder.go | cut -d '"' -f 2) ; \ if [ -z "$$VERSION" ]; then \ echo "Couldn't extract version number from the source code"; \ exit 1; \ diff --git a/builder/builder.go b/builder/builder.go index ff062e8..5a888c2 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -35,6 +35,9 @@ import ( "github.com/pkg/errors" ) +// Version of Mixer. Also used by the Makefile for releases. +const Version = "3.2.1" + // UseNewSwupdServer controls whether to use the new implementation of // swupd-server (package swupd) when possible. This is an experimental feature. var UseNewSwupdServer = false @@ -643,6 +646,10 @@ func (b *Builder) BuildUpdate(prefixflag string, minVersion int, format string, func (b *Builder) buildUpdateWithNewSwupd(timer *stopWatch, mixVersion uint32, minVersion uint32, format uint32, skipSigning bool) error { var err error + err = writeMetaFiles(filepath.Join(b.Statedir, "www", b.Mixver), b.Format, Version) + if err != nil { + return errors.Wrapf(err, "failed to write update metadata files") + } timer.Start("CREATE MANIFESTS") mom, err := swupd.CreateManifests(mixVersion, minVersion, uint(format), b.Statedir) if err != nil { @@ -1062,3 +1069,18 @@ func createDeltaPacks(from *swupd.Manifest, to *swupd.Manifest, outputDir, chroo } return nil } + +// writeMetaFiles writes mixer and format metadata to files +func writeMetaFiles(path, format, version string) error { + err := os.MkdirAll(path, 0777) + if err != nil { + return err + } + + err = ioutil.WriteFile(filepath.Join(path, "format"), []byte(format), 0644) + if err != nil { + return err + } + + return ioutil.WriteFile(filepath.Join(path, "mixer-src-version"), []byte(version), 0644) +} diff --git a/mixer/cmd/root.go b/mixer/cmd/root.go index 6fb025c..bedbdaa 100644 --- a/mixer/cmd/root.go +++ b/mixer/cmd/root.go @@ -29,9 +29,6 @@ import ( "github.com/spf13/cobra" ) -// Version of Mixer. Also used by the Makefile for releases. -const Version = "3.2.1" - var config string // RootCmd represents the base command when called without any subcommands @@ -54,7 +51,7 @@ var RootCmd = &cobra.Command{ // check for external programs. if cmd.Parent() == nil { // This is RootCmd. if rootCmdFlags.version { - fmt.Printf("Mixer %s\n", Version) + fmt.Printf("Mixer %s\n", builder.Version) os.Exit(0) } if rootCmdFlags.check {