summaryrefslogtreecommitdiff
path: root/make_patchnum.pl
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2009-01-04 22:41:05 +0100
committerYves Orton <demerphq@gmail.com>2009-01-04 23:32:40 +0100
commiteb5c076f82ef750418ce94e05feaaccc9df9696e (patch)
tree7de816fa3b9c2f751ce3f25169817dab53f54cfe /make_patchnum.pl
parent12d7e04de30e7bc6b13a6f47e4ed1a1365267e6c (diff)
downloadperl-eb5c076f82ef750418ce94e05feaaccc9df9696e.tar.gz
eliminate make_patchnum.sh, and make the build process use make_patchnum.pl instead
Diffstat (limited to 'make_patchnum.pl')
-rw-r--r--make_patchnum.pl110
1 files changed, 59 insertions, 51 deletions
diff --git a/make_patchnum.pl b/make_patchnum.pl
index e93015f827..95b8db6137 100644
--- a/make_patchnum.pl
+++ b/make_patchnum.pl
@@ -60,30 +60,49 @@ sub write_file {
sub backtick {
my $command = shift;
- my $result = `$command`;
- chomp $result;
- return $result;
+ if (wantarray) {
+ my @result= `$command`;
+ chomp @result;
+ return @result;
+ } else {
+ my $result= `$command`;
+ $result="" if ! defined $result;
+ chomp $result;
+ return $result;
+ }
}
-my $existing_patchnum = read_file('.patchnum');
-my $existing_config = read_file('lib/Config_git.pl');
-my $existing_unpushed = read_file('unpushed.h');
+sub write_files {
+ my %content= map { /WARNING: '([^']+)'/ || die "Bad mojo!"; $1 => $_ } @_;
+ my @files= sort keys %content;
+ my $files= join " and ", map { "'$_'" } @files;
+ foreach my $file (@files) {
+ if (read_file($file) ne $content{$file}) {
+ print "Updating $files\n";
+ write_file($_,$content{$_}) for @files;
+ return 1;
+ }
+ }
+ print "Reusing $files\n";
+ return 0;
+}
my $unpushed_commits = '/*no-op*/';
-my ($read, $branch, $snapshot_created, $commit_id, $describe);
-my ($changed, $extra_info, $commit_title, $new_patchnum);
-if (my $patch_file= read_file('.patch')) {
- ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patchfile;
+my ($read, $branch, $snapshot_created, $commit_id, $describe)= ("") x 5;
+my ($changed, $extra_info, $commit_title, $new_patchnum, $status)= ("") x 5;
+if (my $patch_file= read_file(".patch")) {
+ ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patch_file;
$extra_info = "git_snapshot_date='$snapshot_created'";
$commit_title = "Snapshot of:";
}
elsif (-d path_to('.git')) {
# git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
- $branch = join "", map { (split /\s/, $_)[1] }
- grep {/\*/} split /\n/, backtick('git branch');
- my $remote;
+ ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick('git branch');
+ my ($remote,$merge);
if (length $branch) {
- $remote = backtick("git config branch.$branch.remote");
+ $merge= backtick("git config branch.$branch.merge");
+ $merge =~ s!^refs/heads/!!;
+ $remote= backtick("git config branch.$branch.remote");
}
$commit_id = backtick("git rev-parse HEAD");
$describe = backtick("git describe");
@@ -94,44 +113,45 @@ elsif (-d path_to('.git')) {
# git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'
my $unpushed_commit_list =
join ",", map { (split /\s/, $_)[1] }
- grep {/\+/} split /\n/, backtick("git cherry $remote/$branch");
+ grep {/\+/} backtick("git cherry $remote/$merge");
# git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'
$unpushed_commits =
- join "", map { ',"'.(split /\s/, $_)[1].'"'."\t\\\n" }
- grep {/\+/} split /\n/, backtick("git cherry $remote/$branch");
+ join "", map { ',"'.(split /\s/, $_)[1]."\"\t\\\n" }
+ grep {/\+/} backtick("git cherry $remote/$merge");
if (length $unpushed_commits) {
$commit_title = "Local Commit:";
- my $ancestor = backtick("git rev-parse $remote/$branch");
+ my $ancestor = backtick("git rev-parse $remote/$merge");
$extra_info = "$extra_info
git_ancestor='$ancestor'
+git_remote_branch='$remote/$merge'
git_unpushed='$unpushed_commit_list'";
}
}
- if (length $changed) {
+ if ($changed) {
$changed = 'true';
$commit_title = "Derived from:";
- $new_patchnum = "$new_patchnum
-status: uncommitted-changes";
- }
- if (not length $commit_title) {
- $commit_title = "Commit id:";
+ $status='"uncommitted-changes"'
+ } else {
+ $status='/*clean-working-directory*/'
}
+ $commit_title ||= "Commit id:";
}
-my $new_unpushed =<<"EOFTEXT";
-/*********************************************************************
-* WARNING: unpushed.h is automatically generated by make_patchnum.pl *
-* DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead *
-*********************************************************************/
-#define PERL_GIT_UNPUSHED_COMMITS $unpushed_commits
-/*leave-this-comment*/
-EOFTEXT
-
-my $new_config =<<"EOFDATA";
-#################################################################
-# WARNING: lib/Config_git.pl is generated by make_patchnum.pl #
-# DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead #
-#################################################################
+# we extract the filename out of the warning header, so dont mess with that
+exit(write_files(<<"EOF_HEADER", <<"EOF_CONFIG"));
+/**************************************************************************
+* WARNING: 'git_version.h' is automatically generated by make_patchnum.pl
+* DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
+***************************************************************************/
+#define PERL_GIT_UNCOMMITTED_CHANGES $status
+#define PERL_PATCHNUM "$describe"
+#define PERL_GIT_UNPUSHED_COMMITS\t\t\\
+$unpushed_commits/*leave-this-comment*/
+EOF_HEADER
+######################################################################
+# WARNING: 'lib/Config_git.pl' is generated by make_patchnum.pl
+# DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
+######################################################################
\$Config::Git_Data=<<'ENDOFGIT';
git_commit_id='$commit_id'
git_describe='$describe'
@@ -140,17 +160,5 @@ git_uncommitted_changes='$changed'
git_commit_id_title='$commit_title'
$extra_info
ENDOFGIT
-EOFDATA
-
-# only update the files if necessary, other build product depends on these files
-if (( $existing_patchnum ne $new_patchnum ) || ( $existing_config ne $new_config ) || ( $existing_unpushed ne $new_unpushed )) {
- print "Updating .patchnum and lib/Config_git.pl\n";
- write_file('.patchnum', $new_patchnum);
- write_file('lib/Config_git.pl', $new_config);
- write_file('unpushed.h', $new_unpushed);
-}
-else {
- print "Reusing .patchnum and lib/Config_git.pl\n"
-}
-
+EOF_CONFIG
# ex: set ts=4 sts=4 et ft=perl: