Skip to content

Commit

Permalink
Use ReadPackageDefinition from go.sandstorm
Browse files Browse the repository at this point in the history
  • Loading branch information
zenhack committed Jul 25, 2020
1 parent b2fb0db commit 108deae
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions metadata.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package main

import (
"bytes"
"os"
"os/exec"

"zenhack.net/go/sandstorm/capnp/spk"
"zenhack.net/go/sandstorm/exp/spk"
"zombiezen.com/go/capnproto2"
)

Expand All @@ -21,30 +17,16 @@ func getPkgMetadata(pkgDefFile, pkgDefVar string) *pkgMetadata {
// path for the capnp command.
tmpDir, err := saveSchemaFiles()
chkfatal("Saving temporary schema files", err)
cmd := exec.Command(
"capnp", "eval", "--binary", "-I", tmpDir, pkgDefFile, pkgDefVar,
)
stderrBuf := &bytes.Buffer{}
cmd.Stderr = stderrBuf
pkgDefBytes, err := cmd.Output()
deleteSchemaFiles(tmpDir)
if err != nil {
os.Stderr.Write(stderrBuf.Bytes())
}
defer deleteSchemaFiles(tmpDir)
pkgDef, err := spk.ReadPackageDefinition(pkgDefFile, pkgDefVar, []string{tmpDir})
chkfatal("Reading the package definition", err)

// There are two pieces of information we want out of the package definition:
//
// 1. The app id, which tells us which key to use to sign the package.
// 2. The manifest, which we embed in the package's archive.

pkgDefMsg, err := capnp.Unmarshal(pkgDefBytes)
chkfatal("Parsing the package definition message", err)

pkgDefVal, err := spk.ReadRootPackageDefinition(pkgDefMsg)
chkfatal("Parsing the package definition message struct", err)

pkgManifest, err := pkgDefVal.Manifest()
pkgManifest, err := pkgDef.Manifest()
chkfatal("Reading the package manifest", err)

appTitle, err := pkgManifest.AppTitle()
Expand All @@ -59,10 +41,10 @@ func getPkgMetadata(pkgDefFile, pkgDefVar string) *pkgMetadata {
versionText, err := appMarketingVersion.DefaultText()
chkfatal("Getting version text", err)

appIdStr, err := pkgDefVal.Id()
appIdStr, err := pkgDef.Id()
chkfatal("Reading the package's app id", err)

bridgeCfg, err := pkgDefVal.BridgeConfig()
bridgeCfg, err := pkgDef.BridgeConfig()
chkfatal("Reading the bridge config", err)

// Generate the contents of the file /sandstorm-manifest
Expand Down

0 comments on commit 108deae

Please sign in to comment.