Fix things up to avoid assertions. default tip
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 01 Oct 2009 09:35:48 -0400
changeset 24 19e7a98a8dc4
parent 23 8894b0ca1189
push id14
push userbsmedberg@mozilla.com
push dateThu, 01 Oct 2009 13:35:55 +0000
Fix things up to avoid assertions.
warning-parser.py
warning-ui/dbschema.sql
warningstep.py
--- a/warning-parser.py
+++ b/warning-parser.py
@@ -5,17 +5,17 @@ Reads a build log on stdin. Parse warnin
 and store them in a sqlite database for later consumption.
 
 Uses gmake "Entering directory" and "Leaving directory" messages to
 keep track of the working directory. Resolves relative file paths against
 these working directories, and also follows symlinks back into the
 source tree.
 """
 
-import sys, os, re, mercurial.hg, mercurial.ui, mercurial.revlog, mercurial.node
+import sys, os, re, mercurial.hg, mercurial.ui, mercurial.revlog, mercurial.node, sqlite3
 
 (srcdir, blamedb, logfile) = sys.argv[1:]
 
 srcdir = os.path.realpath(srcdir) + '/'
 
 blamedb = sqlite3.connect(blamedb)
 blamecur = blamedb.cursor()
 
--- a/warning-ui/dbschema.sql
+++ b/warning-ui/dbschema.sql
@@ -102,17 +102,18 @@ AS
   FROM v_buildwarninglines, buildwarnings, v_warnings
   WHERE buildwarnings.warningid = v_buildwarninglines.warningid
     AND v_warnings.warningid = v_buildwarninglines.warningid
     AND v_buildwarninglines.buildnumber = buildwarnings.buildnumber
     AND v_buildwarninglines.wline = v_warnings.primaryline;
 
 delimiter /;
 
-DROP PROCEDURE IF EXISTS setuptables;
+DROP PROCEDURE IF EXISTS setuptables/;
+
 CREATE PROCEDURE setuptables()
 MODIFIES SQL DATA
 BEGIN
   CREATE TEMPORARY TABLE _BUILDDATA (
     id INTEGER NOT NULL,
     ord INTEGER NOT NULL,
     CONSTRAINT PRIMARY KEY (id, ord),
     wcount INTEGER NOT NULL DEFAULT 1,
@@ -138,59 +139,66 @@ BEGIN
     id INTEGER NOT NULL,
     wline TINYINT NOT NULL,
     CONSTRAINT PRIMARY KEY (id, wline),
     locationid INTEGER NOT NULL
   );
 END
 /;
 
-DROP FUNCTION IF EXISTS getwarningid;
-DROP PROCEDURE IF EXISTS getwarningid;
+DROP PROCEDURE IF EXISTS getwarningid/;
 CREATE PROCEDURE getwarningid(OUT _warningid INTEGER)
 MODIFIES SQL DATA
 BEGIN
   -- Given the _WLINES temporary table, figure out the warningid, perhaps
   -- by inserting a new one.
-  DECLARE haslock INTEGER;
+  DECLARE _haslock INTEGER;
+  DECLARE _linecount INTEGER;
 
   REPEAT
-    SET @haslock = GET_LOCK('warningdb_warningid', 5);
-  UNTIL @haslock
+    SET _haslock = GET_LOCK('warningdb_warningid', 5);
+  UNTIL _haslock
   END REPEAT;
 
+  SELECT COUNT(*) INTO _linecount FROM _WLINES;
+
+  IF _linecount = 0 THEN
+    PREPARE throw_err FROM 'CALL programming_err(''0 rows in _WLINES'')';
+    EXECUTE throw_err;
+  END IF;
+
   SET _warningid = (
     SELECT warningid
     FROM warnings
     WHERE linecount = (
       SELECT COUNT(*)
       FROM warninglines, _WLINES
       WHERE warnings.warningid = warninglines.warningid
         AND warninglines.wline = _WLINES.wline
         AND warninglines.locationid = _WLINES.locationid
         AND warninglines.msgid = _WLINES.msgid
-    )
+    ) AND
+    linecount = _linecount
   );
+
   IF _warningid IS NULL THEN
     INSERT INTO warnings (linecount, primaryline)
-    VALUES (
-      (SELECT COUNT(*) FROM _WLINES),
-      0
-    );
+      VALUES (_linecount, 0);
     SET _warningid = LAST_INSERT_ID();
     INSERT INTO warninglines (warningid, wline, locationid, msgid)
       SELECT _warningid, wline, locationid, msgid FROM _WLINES;
     COMMIT;
   END IF;
 
-  SET @haslock = RELEASE_LOCK('warningdb_warningid');
+  SET _haslock = RELEASE_LOCK('warningdb_warningid');
 END
 /;
 
-DROP PROCEDURE IF EXISTS insertbuild;
+DROP PROCEDURE IF EXISTS insertbuild/;
+
 CREATE PROCEDURE insertbuild(buildnumber INTEGER, rev VARCHAR(40))
 MODIFIES SQL DATA
 BEGIN
   -- Takes a temporary table #BUILDDATA and inserts the data into the database.
   -- Schema of #BUILDDATA should be id, count, ord, file, line, msg,
   --   blametype, blamewho, blamefile, blamerev, blameline, loc, blameloc, msgid
 
   DECLARE done INT DEFAULT 0;
--- a/warningstep.py
+++ b/warningstep.py
@@ -1,11 +1,11 @@
 from buildbot.process.buildstep import SUCCESS, FAILURE
 from buildbot.steps.shell import ShellCommand
-import MySQLdb, os.path, sys
+import MySQLdb, os.path, sys, sqlite3
 
 class WarningParserStep(ShellCommand):
     """
     A subclass of shellcommand used for running warning-parser.py.
 
     This parses the output and saves interesting information to the
     master-side sqlite database. It produces output about "new" warnings, etc.