~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to misc/dashboard/app/build/build.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
                Order("-Time").
50
50
                Limit(1).
51
51
                GetAll(c, &commits)
 
52
        if _, ok := err.(*datastore.ErrFieldMismatch); ok {
 
53
                // Some fields have been removed, so it's okay to ignore this error.
 
54
                err = nil
 
55
        }
52
56
        if err != nil {
53
57
                return nil, err
54
58
        }
65
69
        if err == datastore.ErrNoSuchEntity {
66
70
                return nil, fmt.Errorf("package %q not found", path)
67
71
        }
 
72
        if _, ok := err.(*datastore.ErrFieldMismatch); ok {
 
73
                // Some fields have been removed, so it's okay to ignore this error.
 
74
                err = nil
 
75
        }
68
76
        return p, err
69
77
}
70
78
 
111
119
        return nil
112
120
}
113
121
 
 
122
// each result line is approx 105 bytes. This constant is a tradeoff between
 
123
// build history and the AppEngine datastore limit of 1mb.
 
124
const maxResults = 1000
 
125
 
114
126
// AddResult adds the denormalized Reuslt data to the Commit's Result field.
115
127
// It must be called from inside a datastore transaction.
116
128
func (com *Commit) AddResult(c appengine.Context, r *Result) error {
117
129
        if err := datastore.Get(c, com.Key(c), com); err != nil {
118
130
                return fmt.Errorf("getting Commit: %v", err)
119
131
        }
120
 
        com.ResultData = append(com.ResultData, r.Data())
 
132
        com.ResultData = trim(append(com.ResultData, r.Data()), maxResults)
121
133
        if _, err := datastore.Put(c, com.Key(c), com); err != nil {
122
134
                return fmt.Errorf("putting Commit: %v", err)
123
135
        }
124
136
        return nil
125
137
}
126
138
 
 
139
func trim(s []string, n int) []string {
 
140
        l := min(len(s), n)
 
141
        return s[len(s)-l:]
 
142
}
 
143
 
 
144
func min(a, b int) int {
 
145
        if a < b {
 
146
                return a
 
147
        }
 
148
        return b
 
149
}
 
150
 
127
151
// Result returns the build Result for this Commit for the given builder/goHash.
128
152
func (c *Commit) Result(builder, goHash string) *Result {
129
153
        for _, r := range c.ResultData {
160
184
        }
161
185
}
162
186
 
163
 
// OK returns the Commit's build state for a specific builder and goHash.
164
 
func (c *Commit) OK(builder, goHash string) (ok, present bool) {
165
 
        r := c.Result(builder, goHash)
166
 
        if r == nil {
167
 
                return false, false
168
 
        }
169
 
        return r.OK, true
170
 
}
171
 
 
172
187
// A Result describes a build result for a Commit on an OS/architecture.
173
188
//
174
189
// Each Result entity is a descendant of its associated Commit entity.
175
190
type Result struct {
176
 
        Builder     string // "arch-os[-note]"
 
191
        Builder     string // "os-arch[-note]"
177
192
        Hash        string
178
193
        PackagePath string // (empty for Go commits)
179
194
 
184
199
        Log     string `datastore:"-"`        // for JSON unmarshaling only
185
200
        LogHash string `datastore:",noindex"` // Key to the Log record.
186
201
 
187
 
        RunTime int64 // time to build+test in nanoseconds 
 
202
        RunTime int64 // time to build+test in nanoseconds
188
203
}
189
204
 
190
205
func (r *Result) Key(c appengine.Context) *datastore.Key {
297
312
        q := datastore.NewQuery("Package").Filter("Kind=", kind)
298
313
        for t := q.Run(c); ; {
299
314
                pkg := new(Package)
300
 
                if _, err := t.Next(pkg); err == datastore.Done {
 
315
                _, err := t.Next(pkg)
 
316
                if _, ok := err.(*datastore.ErrFieldMismatch); ok {
 
317
                        // Some fields have been removed, so it's okay to ignore this error.
 
318
                        err = nil
 
319
                }
 
320
                if err == datastore.Done {
301
321
                        break
302
322
                } else if err != nil {
303
323
                        return nil, err