~sergiusens/snappy/tools-parted

« back to all changes in this revision

Viewing changes to snappy/build.go

  • Committer: Sergio Schvezov
  • Date: 2015-07-30 18:46:22 UTC
  • mfrom: (576.1.1 tools-grub)
  • Revision ID: sergio.schvezov@canonical.com-20150730184622-mga36e3aevz09qw5
Merged tools-grub into tools-parted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//
52
52
// Please resist the temptation of optimizing the regexp by grouping
53
53
// things by hand. People will find it unreadable enough as it is.
54
 
var shouldExclude = regexp.MustCompile(strings.Join([]string{
 
54
var shouldExcludeDefault = regexp.MustCompile(strings.Join([]string{
55
55
        `\.snap$`, // added
56
56
        `\.click$`,
57
57
        `^\..*\.sw.$`,
82
82
        `^_MTN$`,
83
83
        `^_darcs$`,
84
84
        `^{arch}$`,
 
85
        `^\.snapignore$`,
85
86
}, "|")).MatchString
86
87
 
 
88
// fake static function variables
 
89
type keep struct {
 
90
        basedir string
 
91
        exclude func(string) bool
 
92
}
 
93
 
 
94
func (k *keep) shouldExclude(basedir string, file string) bool {
 
95
        if basedir == k.basedir {
 
96
                if k.exclude == nil {
 
97
                        return false
 
98
                }
 
99
 
 
100
                return k.exclude(file)
 
101
        }
 
102
 
 
103
        k.basedir = basedir
 
104
        k.exclude = nil
 
105
 
 
106
        snapignore, err := os.Open(filepath.Join(basedir, ".snapignore"))
 
107
        if err != nil {
 
108
                return false
 
109
        }
 
110
 
 
111
        scanner := bufio.NewScanner(snapignore)
 
112
        var lines []string
 
113
        for scanner.Scan() {
 
114
                line := scanner.Text()
 
115
                if _, err := regexp.Compile(line); err != nil {
 
116
                        // not a regexp
 
117
                        line = regexp.QuoteMeta(line)
 
118
                }
 
119
                lines = append(lines, line)
 
120
        }
 
121
 
 
122
        fullRegex := strings.Join(lines, "|")
 
123
        exclude, err := regexp.Compile(fullRegex)
 
124
        if err == nil {
 
125
                k.exclude = exclude.MatchString
 
126
 
 
127
                return k.exclude(file)
 
128
        }
 
129
 
 
130
        // can't happen; can't even find a way to trigger it in testing.
 
131
        panic(fmt.Sprintf("|-composition of valid regexps is invalid?!? Please report this bug: %#v", fullRegex))
 
132
}
 
133
 
 
134
var shouldExcludeDynamic = new(keep).shouldExclude
 
135
 
 
136
func shouldExclude(basedir string, file string) bool {
 
137
        return shouldExcludeDefault(file) || shouldExcludeDynamic(basedir, file)
 
138
}
 
139
 
87
140
// small helper that return the architecture or "multi" if its multiple arches
88
141
func debArchitecture(m *packageYaml) string {
89
142
        switch len(m.Architectures) {
139
192
}
140
193
 
141
194
func handleServices(buildDir string, m *packageYaml) error {
142
 
        for _, v := range m.Services {
 
195
        for _, v := range m.ServiceYamls {
143
196
                hookName := filepath.Base(v.Name)
144
197
 
145
198
                // handle the apparmor stuff
375
428
                        return errin
376
429
                }
377
430
 
378
 
                if shouldExclude(filepath.Base(path)) {
 
431
                if shouldExclude(sourceDir, filepath.Base(path)) {
379
432
                        if info.IsDir() {
380
433
                                return filepath.SkipDir
381
434
                        }