func makeTestSnap(c *C, snapYamlContent string) (snapFilePath string) { tmpdir := c.MkDir() os.MkdirAll(filepath.Join(tmpdir, "meta"), 0755) snapYamlFn := filepath.Join(tmpdir, "meta", "snap.yaml") ioutil.WriteFile(snapYamlFn, []byte(snapYamlContent), 0644) err := osutil.ChDir(tmpdir, func() error { var err error snapFilePath, err = snappy.BuildSquashfsSnap(tmpdir, "") c.Assert(err, IsNil) return err }) c.Assert(err, IsNil) return filepath.Join(tmpdir, snapFilePath) }
// Build builds the snap. func (s *Snap) Build(buildDir string) error { fullSnapPath, err := filepath.Abs(s.path) if err != nil { return err } return osutil.ChDir(buildDir, func() error { return runCommand( "mksquashfs", ".", fullSnapPath, "-noappend", "-comp", "xz", "-no-xattrs", ) }) }
func makeTestSnapPackageFullWithFiles(c *C, snapYamlContent string, makeLicense bool, files [][]string) (snapPath string) { tmpdir := c.MkDir() // content os.MkdirAll(filepath.Join(tmpdir, "bin"), 0755) content := `#!/bin/sh echo "hello"` exampleBinary := filepath.Join(tmpdir, "bin", "foo") ioutil.WriteFile(exampleBinary, []byte(content), 0755) // meta os.MkdirAll(filepath.Join(tmpdir, "meta"), 0755) if snapYamlContent == "" { snapYamlContent = ` name: foo version: 1.0 ` } snapYamlFn := filepath.Join(tmpdir, "meta", "snap.yaml") ioutil.WriteFile(snapYamlFn, []byte(snapYamlContent), 0644) if makeLicense { license := filepath.Join(tmpdir, "meta", "license.txt") content = "WTFPL" ioutil.WriteFile(license, []byte(content), 0644) } for _, filenameAndContent := range files { filename := filenameAndContent[0] content := filenameAndContent[1] basedir := filepath.Dir(filepath.Join(tmpdir, filename)) err := os.MkdirAll(basedir, 0755) c.Assert(err, IsNil) err = ioutil.WriteFile(filepath.Join(tmpdir, filename), []byte(content), 0644) c.Assert(err, IsNil) } // build it err := osutil.ChDir(tmpdir, func() error { var err error snapPath, err = snapBuilderFunc(tmpdir, "") c.Assert(err, IsNil) return err }) c.Assert(err, IsNil) return filepath.Join(tmpdir, snapPath) }