Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I’m still fairly new to Perl. As a build manager I search through the build log and if I find an error, the build is deemed failed.

What I'm trying to figure out, is how to extract from the build log the name of the specific VS project that failed. I'd like to put this information in my build e-mail.

For example, here are two projects in the build log:

------ Rebuild All started: Project: test1, Configuration: Release Win32 ------

Performing Makefile project actions
Copying updated dictionary to test folder
1 file(s) copied.

The system cannot find the file specified.
NMAKE : fatal error U1077: 'copy' : return code '0x1'

Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
Build log was saved at "file://c:\test\build.htm"

Test1 - 2 errors, 0 warnings

------ Rebuild All started: Project: test2, Configuration: Release .NET ------
Updating references...
Performing main compilation...

Build complete -- 0 errors, 0 warnings

Obviously Project: test1 is what failed, but how do I extract that project name? I can find the string "2 errors" but can't figure out the rest. Any help would be greatly appreciated. I'm pulling out my hair with this one.
  • Comment on Extract failed VS project name from build log

Replies are listed 'Best First'.
Re: Extract failed VS project name from build log
by McMahon (Chaplain) on May 18, 2004 at 20:52 UTC
    I happened to have just done this the other day. This regex works for me. (Note bonus regexes! The value you want goes to "@badProjects".)

    my @msgs = <LOG>; foreach $msg(@msgs) { if ($msg =~ ": error") { $errors++; } if ($msg =~ ": warning") { $warnings++; } if (($msg =~ "error") and ($msg =~ "warning") and !($msg =~ "0 err +or")) { $failures++; push @badProjects, $msg; } if ($msg =~ "0 error") { $success++; push @goodProjects, $msg; } }
Re: Extract failed VS project name from build log
by pbeckingham (Parson) on May 18, 2004 at 20:50 UTC

    How about looking for the following:

    Project : error PRJ0019
    although using a regular expresson to do it, such as:
    if ($totalOutput =~ /^Project : error (\w+)/) { my $project = $1; ... }
    (or better), as that seems to also be a good indicator of which project failed. Or is it more complex than that?

Re: Extract failed VS project name from build log
by Ven'Tatsu (Deacon) on May 18, 2004 at 21:01 UTC
    You could keep track of the project named in the last 'Rebuild All started' line and then use that for the next error.
    my $project = ''; while (<BUILDLOG>) { if (/Project: (.+), Configuration/) { $project = $1; } if (/- (\d+) errors?, (\d+) warnings?/) { if ($1 > 0) { print "$1 errors for project $project\n"; } } }
    As long as each project starts with a like like the 'Rebuild All started' line and projects are not interlaced in the file it should extract the correct project.
      Thanks for the help everyone. Sorry, I wasn't logged in when I had submitted the original post. Anyway I ended up using the code provided by Ven'Tatsu. It works great!

      I had to modify it a bit because some of the errors say "errors" and some say "error(s)", but that was pretty easy to do. I also used a bit of the code provided by McMahon to figure out the total number of projects that failed and the total that succeeded. Thanks again.....