Bug 21591 - prepare-ChangeLog should know how to find functions in Perl files
Summary: prepare-ChangeLog should know how to find functions in Perl files
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 525.x (Safari 3.1)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-14 11:37 PDT by David Kilzer (:ddkilzer)
Modified: 2011-07-05 15:21 PDT (History)
3 users (show)

See Also:


Attachments
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template (5.65 KB, patch)
2011-07-05 15:07 PDT, Adam Roben (:aroben)
ddkilzer: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2008-10-14 11:37:37 PDT
Since most of the tools in WebKitTools are written in Perl, we should make prepare-ChangeLog work with Perl scripts.
Comment 1 David Kilzer (:ddkilzer) 2008-10-14 11:38:40 PDT
See Bug 21567 for a similar change for JavaScript files.

We'll need to check the first line of files to see if "#!/usr/bin/perl" or similar appears there since not all Perl scripts end with ".pl".
Comment 2 Adam Roben (:aroben) 2011-05-26 09:56:02 PDT
A very simple first cut would be to match against /^sub (\w\S+)/.
Comment 3 Adam Roben (:aroben) 2011-07-05 15:07:07 PDT
Created attachment 99751 [details]
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template
Comment 4 Adam Roben (:aroben) 2011-07-05 15:10:02 PDT
Comment on attachment 99751 [details]
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template

View in context: https://bugs.webkit.org/attachment.cgi?id=99751&action=review

> Tools/Scripts/prepare-ChangeLog:1213
> +# Read a file and get all the line ranges of the things that look like Perl functions. Only lines
> +# which start with "sub " are recognized as starting a function, and only lines that are exactly "}"
> +# are recognized as ending a function.

This isn't quite accurate. Rewritten as:

# Read a file and get all the line ranges of the things that look like Perl functions. Functions
# start on a line that starts with "sub ", and end on the first line starting with "}" thereafter.
Comment 5 David Kilzer (:ddkilzer) 2011-07-05 15:13:17 PDT
Comment on attachment 99751 [details]
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template

View in context: https://bugs.webkit.org/attachment.cgi?id=99751&action=review

r=me!

> Tools/Scripts/prepare-ChangeLog:1232
> +                warn "nested functions found at top-level at $fileName:$.\n";

FYI, it is possible to nest subroutines in Perl.  You can define a subroutine and assign it to a variable, too.

I guess you can change $currentFunction to @currentFunction later.
Comment 6 Adam Roben (:aroben) 2011-07-05 15:13:51 PDT
Comment on attachment 99751 [details]
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template

View in context: https://bugs.webkit.org/attachment.cgi?id=99751&action=review

> Tools/Scripts/prepare-ChangeLog:1227
> +        if (/^sub ([^(]+)/) {

I tweaked this to:

/^sub\s+([^(\s]+)/

This better handles functions which have no prototype, and is a little more lenient about spaces after "sub".
Comment 7 Adam Roben (:aroben) 2011-07-05 15:15:22 PDT
Comment on attachment 99751 [details]
Make prepare-ChangeLog include modified Perl functions in its ChangeLog template

View in context: https://bugs.webkit.org/attachment.cgi?id=99751&action=review

>> Tools/Scripts/prepare-ChangeLog:1232
>> +                warn "nested functions found at top-level at $fileName:$.\n";
> 
> FYI, it is possible to nest subroutines in Perl.  You can define a subroutine and assign it to a variable, too.
> 
> I guess you can change $currentFunction to @currentFunction later.

Yes, I just decided to punt on nested subroutines in this patch. Note that we'll only complain if the nested function isn't indented, like this:

sub outerFunction
{

sub innerFunction
{
}

}
Comment 8 Adam Roben (:aroben) 2011-07-05 15:21:39 PDT
Committed r90409: <http://trac.webkit.org/changeset/90409>