|
1 | 1 | 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 | + |
2 | 43 |
|
3 | 44 | @defer.inlineCallbacks |
4 | 45 | def collapseRequests(master, builder, req1, req2): |
@@ -31,13 +72,16 @@ def collapseRequests(master, builder, req1, req2): |
31 | 72 | str(req2['buildsetid']) |
32 | 73 | ) |
33 | 74 |
|
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) |
41 | 85 |
|
42 | 86 | # Check buildsets properties and do not collapse |
43 | 87 | # if properties do not match. This includes the check |
@@ -92,7 +136,19 @@ def collapseRequests(master, builder, req1, req2): |
92 | 136 | return False |
93 | 137 |
|
94 | 138 | # 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): |
98 | 140 | 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