Skip to content

Commit 6ea6558

Browse files
committed
Collapse regardless of clean property
1 parent ac5e8af commit 6ea6558

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

zorg/buildbot/process/buildrequest.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
11
from twisted.internet import defer
2+
import json
3+
import sqlalchemy as sa
4+
5+
6+
@defer.inlineCallbacks
7+
def setBuildsetProperty(db, bsid, name, value, source="Collapse"):
8+
"""Set a buildset property
9+
10+
buildbot.db.buildset.BuildsetConnectorComponent only has
11+
getBuildsetProperties, but no setter. This setter is modelled after
12+
setBuildProperty.
13+
"""
14+
def thd(conn):
15+
bs_props_tbl = db.model.buildset_properties
16+
db.buildsets.checkLength(bs_props_tbl.c.property_name, name)
17+
18+
whereclause=sa.and_(bs_props_tbl.c.buildsetid == bsid, bs_props_tbl.c.property_name == name)
19+
q = sa.select([bs_props_tbl.c.property_name, bs_props_tbl.c.property_value], whereclause=whereclause)
20+
prop = conn.execute(q).fetchone()
21+
value_js = json.dumps([value,source])
22+
if prop is None:
23+
conn.execute(bs_props_tbl.insert(), {
24+
"buildsetid": bsid,
25+
"property_name": name,
26+
"property_value": value_js
27+
})
28+
elif prop.property_value != value_js:
29+
conn.execute(bs_props_tbl.update(whereclause=whereclause), {"property_value": value_js})
30+
31+
yield db.pool.do(thd)
32+
33+
# Also update the lookup cache, if this buidset properties' has been cached.
34+
if bsid in db.buildsets. getBuildsetProperties.cache.keys():
35+
# Lookup of old values will be from the cache
36+
properties = yield db.buildsets.getBuildsetProperties(bsid)
37+
38+
# Update the property value and store back to cache
39+
properties[name] = (value,source)
40+
db.buildsets.getBuildsetProperties.cache.put(bsid, properties)
41+
42+
243

344
@defer.inlineCallbacks
445
def collapseRequests(master, builder, req1, req2):
@@ -31,13 +72,16 @@ def collapseRequests(master, builder, req1, req2):
3172
str(req2['buildsetid'])
3273
)
3374

34-
# If the build is going to be a clean build anyway, we can collapse a clean
35-
# build and a non-clean build.
36-
if getattr(builder.config.factory, "clean", False):
37-
if 'clean_obj' in selfBuildsetPoperties:
38-
del selfBuildsetPoperties["clean_obj"]
39-
if 'clean_obj' in otherBuildsetPoperties:
40-
del otherBuildsetPoperties["clean_obj"]
75+
76+
# Requests can be collapsed regardless of clean property, but remember
77+
# whether a collapsed buildrequest should be clean.
78+
anyClean = selfBuildsetPoperties.get("clean") or otherBuildsetPoperties.get("clean")
79+
selfBuildsetPoperties.pop('clean', None)
80+
otherBuildsetPoperties.pop('clean', None)
81+
82+
anyCleanObj = selfBuildsetPoperties.get("clean_obj") or otherBuildsetPoperties.get("clean_obj")
83+
selfBuildsetPoperties.pop('clean_obj', None)
84+
otherBuildsetPoperties.pop('clean_obj', None)
4185

4286
# Check buildsets properties and do not collapse
4387
# if properties do not match. This includes the check
@@ -92,7 +136,19 @@ def collapseRequests(master, builder, req1, req2):
92136
return False
93137

94138
# Build requests with different reasons should be built separately.
95-
if req1.get('reason', None) == req2.get('reason', None):
96-
return True
97-
else:
139+
if req1.get('reason', None) != req2.get('reason', None):
98140
return False
141+
142+
# We decided to collapse the requests. One request will be marked 'SKIPPED',
143+
# the other used to subsume both. If at least one of them requires a clean
144+
# build, mark the subsuming request as such. Since we don't know which one
145+
# it is, mark both.
146+
if anyClean:
147+
yield setBuildsetProperty(master.db, req1['buildsetid'], 'clean', True)
148+
yield setBuildsetProperty(master.db, req2['buildsetid'], 'clean', True)
149+
150+
if anyCleanObj:
151+
yield setBuildsetProperty(master.db, req1['buildsetid'], 'clean_obj', True)
152+
yield setBuildsetProperty(master.db, req2['buildsetid'], 'clean_obj', True)
153+
154+
return True

0 commit comments

Comments
 (0)