Skip to content

Commit

Permalink
default manifest filename for FindPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Sep 30, 2024
1 parent b39cfe7 commit 8445042
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

const Schema = "1.0"
const DefaultFilename = "manifest.wall"

type Package struct {
Kind string `json:"kind"`
Expand Down Expand Up @@ -165,13 +166,13 @@ func Validate(manifest *Manifest) (err error) {

// FindPaths finds the paths marked with "generate:manifest" and
// returns a map from the manifest path to all the slices that declare it.
func FindPaths(slices []*setup.Slice, manifestFileName string) map[string][]*setup.Slice {
func FindPaths(slices []*setup.Slice) map[string][]*setup.Slice {
manifestSlices := make(map[string][]*setup.Slice)
for _, slice := range slices {
for path, info := range slice.Contents {
if info.Generate == setup.GenerateManifest {
dir := strings.TrimSuffix(path, "**")
path = filepath.Join(dir, manifestFileName)
path = filepath.Join(dir, DefaultFilename)
manifestSlices[path] = append(manifestSlices[path], slice)
}
}
Expand Down
10 changes: 3 additions & 7 deletions internal/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ func (s *S) TestManifestReadValidate(c *C) {
var findPathsTests = []struct {
summary string
slices []*setup.Slice
filename string
expected map[string][]string
}{{
summary: "Single slice",
Expand All @@ -189,7 +188,6 @@ var findPathsTests = []struct {
},
},
}},
filename: "manifest.wall",
expected: map[string][]string{
"/folder/manifest.wall": []string{"slice1"},
},
Expand All @@ -199,7 +197,6 @@ var findPathsTests = []struct {
Name: "slice1",
Contents: map[string]setup.PathInfo{},
}},
filename: "manifest.wall",
expected: map[string][]string{},
}, {
summary: "Several matches with several groups",
Expand Down Expand Up @@ -239,18 +236,17 @@ var findPathsTests = []struct {
},
},
}},
filename: "mfest.wall",
expected: map[string][]string{
"/folder/mfest.wall": {"slice1", "slice2"},
"/other-folder/mfest.wall": {"slice4", "slice5"},
"/folder/manifest.wall": {"slice1", "slice2"},
"/other-folder/manifest.wall": {"slice4", "slice5"},
},
}}

func (s *S) TestFindPaths(c *C) {
for _, test := range findPathsTests {
c.Logf("Summary: %s", test.summary)

manifestSlices := manifest.FindPaths(test.slices, test.filename)
manifestSlices := manifest.FindPaths(test.slices)

slicesByName := map[string]*setup.Slice{}
for _, slice := range test.slices {
Expand Down
3 changes: 1 addition & 2 deletions internal/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/canonical/chisel/internal/setup"
)

const manifestFilename = "manifest.wall"
const manifestMode fs.FileMode = 0644

type RunOptions struct {
Expand Down Expand Up @@ -335,7 +334,7 @@ func Run(options *RunOptions) error {

func generateManifests(targetDir string, selection *setup.Selection,
report *manifest.Report, pkgInfos []*archive.PackageInfo) error {
manifestSlices := manifest.FindPaths(selection.Slices, manifestFilename)
manifestSlices := manifest.FindPaths(selection.Slices)
if len(manifestSlices) == 0 {
// Nothing to do.
return nil
Expand Down

0 comments on commit 8445042

Please sign in to comment.