mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
rename snappy.Build() snappy.BuildLegacySnap() and refactor
This commit is contained in:
@@ -53,7 +53,7 @@ func (x *cmdBuild) Execute(args []string) (err error) {
|
||||
args = []string{"."}
|
||||
}
|
||||
|
||||
snapPackage, err := snappy.Build(args[0], x.Output)
|
||||
snapPackage, err := snappy.BuildLegacySnap(args[0], x.Output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -489,9 +489,7 @@ func checkLicenseExists(sourceDir string) error {
|
||||
|
||||
var licenseChecker = checkLicenseExists
|
||||
|
||||
// Build the given sourceDirectory and return the generated snap file
|
||||
func Build(sourceDir, targetDir string) (string, error) {
|
||||
|
||||
func prepare(sourceDir, targetDir, buildDir string) (snapName string, err error) {
|
||||
// ensure we have valid content
|
||||
m, err := parsePackageYamlFile(filepath.Join(sourceDir, "meta", "package.yaml"))
|
||||
if err != nil {
|
||||
@@ -508,13 +506,6 @@ func Build(sourceDir, targetDir string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// create build dir
|
||||
buildDir, err := ioutil.TempDir("", "snappy-build-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer os.RemoveAll(buildDir)
|
||||
|
||||
if err := copyToBuildDir(sourceDir, buildDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -544,7 +535,7 @@ func Build(sourceDir, targetDir string) (string, error) {
|
||||
}
|
||||
|
||||
// build the package
|
||||
snapName := fmt.Sprintf("%s_%s_%v.snap", m.Name, m.Version, debArchitecture(m))
|
||||
snapName = fmt.Sprintf("%s_%s_%v.snap", m.Name, m.Version, debArchitecture(m))
|
||||
|
||||
if targetDir != "" {
|
||||
snapName = filepath.Join(targetDir, snapName)
|
||||
@@ -555,7 +546,23 @@ func Build(sourceDir, targetDir string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// build it
|
||||
return snapName, nil
|
||||
}
|
||||
|
||||
// BuildLegacySnap the given sourceDirectory and return the generated snap file
|
||||
func BuildLegacySnap(sourceDir, targetDir string) (string, error) {
|
||||
// create build dir
|
||||
buildDir, err := ioutil.TempDir("", "snappy-build-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer os.RemoveAll(buildDir)
|
||||
|
||||
snapName, err := prepare(sourceDir, targetDir, buildDir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
d, err := clickdeb.Create(snapName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -102,7 +102,7 @@ integration:
|
||||
apparmor-profile: meta/hello.apparmor
|
||||
`)
|
||||
|
||||
resultSnap, err := Build(sourceDir, "")
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.Remove(resultSnap)
|
||||
|
||||
@@ -152,7 +152,7 @@ binaries:
|
||||
- name: bin/hello-world
|
||||
`)
|
||||
|
||||
resultSnap, err := Build(sourceDir, "")
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.Remove(resultSnap)
|
||||
|
||||
@@ -194,7 +194,7 @@ services:
|
||||
start: bin/hello-world
|
||||
`)
|
||||
|
||||
resultSnap, err := Build(sourceDir, "")
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.Remove(resultSnap)
|
||||
|
||||
@@ -236,7 +236,7 @@ vendor: Foo <foo@example.com>
|
||||
err := ioutil.WriteFile(filepath.Join(hooksDir, "config"), []byte(""), 0755)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
resultSnap, err := Build(sourceDir, "")
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.Remove(resultSnap)
|
||||
|
||||
@@ -265,7 +265,7 @@ vendor: Foo <foo@example.com>
|
||||
func (s *SnapTestSuite) TestBuildNoManifestFails(c *C) {
|
||||
sourceDir := makeExampleSnapSourceDir(c, "")
|
||||
c.Assert(os.Remove(filepath.Join(sourceDir, "meta", "package.yaml")), IsNil)
|
||||
_, err := Build(sourceDir, "")
|
||||
_, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, NotNil) // XXX maybe make the error more explicit
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ integration:
|
||||
apparmor-profile: meta/hello.apparmor
|
||||
explicit-license-agreement: Y
|
||||
`)
|
||||
_, err := Build(sourceDir, "")
|
||||
_, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, NotNil) // XXX maybe make the error more explicit
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ explicit-license-agreement: Y
|
||||
`)
|
||||
lic := filepath.Join(sourceDir, "meta", "license.txt")
|
||||
ioutil.WriteFile(lic, []byte("\n"), 0755)
|
||||
_, err := Build(sourceDir, "")
|
||||
_, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, Equals, ErrLicenseBlank)
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ integration:
|
||||
|
||||
outputDir := filepath.Join(c.MkDir(), "output")
|
||||
snapOutput := filepath.Join(outputDir, "hello_1.0.1_multi.snap")
|
||||
resultSnap, err := Build(sourceDir, outputDir)
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, outputDir)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// check that there is result
|
||||
@@ -438,7 +438,7 @@ services:
|
||||
binaries:
|
||||
- name: foo
|
||||
`)
|
||||
_, err := Build(sourceDir, "")
|
||||
_, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, ErrorMatches, ".*binary and service both called foo.*")
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ version: 1.0.1
|
||||
vendor: Foo <foo@example.com>
|
||||
`)
|
||||
|
||||
resultSnap, err := Build(sourceDir, "")
|
||||
resultSnap, err := BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.Remove(resultSnap)
|
||||
|
||||
@@ -490,6 +490,6 @@ vendor: Foo <foo@example.com>
|
||||
err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = Build(sourceDir, "")
|
||||
_, err = BuildLegacySnap(sourceDir, "")
|
||||
c.Assert(err, ErrorMatches, "can not handle type of file .*")
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ vendor: Foo Bar <foo@example.com>
|
||||
// build it
|
||||
err := helpers.ChDir(tmpdir, func() {
|
||||
var err error
|
||||
snapFile, err = Build(tmpdir, "")
|
||||
snapFile, err = BuildLegacySnap(tmpdir, "")
|
||||
c.Assert(err, IsNil)
|
||||
})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
Reference in New Issue
Block a user