X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=make_patchnum.pl;h=1644d419d64b6265febf7cbfafe04e0d79598743;hb=133fac12ff7e3894deb31a204a9a12453b87bbf0;hp=ad2e0f2f40ded90fe473abf66a2e0b16bec30ac5;hpb=505afc734ed453559bc43362154a2694b59ece9e;p=p5sagit%2Fp5-mst-13.2.git diff --git a/make_patchnum.pl b/make_patchnum.pl index ad2e0f2..1644d41 100644 --- a/make_patchnum.pl +++ b/make_patchnum.pl @@ -13,7 +13,7 @@ make_patchnum.pl - make patchnum perl make_patchnum.pl -=head1 DESCRITPTION +=head1 DESCRIPTION This program creates the files holding the information about locally applied patches to the source code. The created @@ -23,7 +23,7 @@ files are C and C. Contains status information from git in a form meant to be processed by the tied hash logic of Config.pm. It is actually optional, -although -V will look strange without it. +although -V:git.\* will be uninformative without it. C contains similar information in a C header file format, designed to be used by patchlevel.h. This file is obtained @@ -40,14 +40,31 @@ Same terms as Perl itself. =cut +# from a -Dmksymlink target dir, I need to cd to the git-src tree to +# use git (like script does). Presuming that's not unique, one fix is +# to follow Configure's symlink-path to run git. Maybe GIT_DIR or +# path-args can solve it, if so we should advise here, I tried only +# very briefly ('cd -' works too). + +my ($subcd, $srcdir); +our $opt_v = scalar grep $_ eq '-v', @ARGV; + BEGIN { my $root="."; + # test 1st to see if we're a -Dmksymlinks target dir + $subcd = ''; + $srcdir = $root; + if (-l "./Configure") { + $srcdir = readlink("./Configure"); + $srcdir =~ s/Configure//; + $subcd = "cd $srcdir &&"; # activate backtick fragment + } while (!-e "$root/perl.c" and length($root)<100) { if ($root eq '.') { - $root=".."; + $root=".."; } else { - $root.="/.."; - } + $root.="/.."; + } } die "Can't find toplevel" if !-e "$root/perl.c"; sub path_to { "$root/$_[0]" } # use $_[0] if this'd be placed in toplevel. @@ -57,7 +74,7 @@ sub read_file { my $file = path_to(@_); return "" unless -e $file; open my $fh, '<', $file - or die "Failed to open for read '$file':$!"; + or die "Failed to open for read '$file':$!"; return do { local $/; <$fh> }; } @@ -65,20 +82,26 @@ sub write_file { my ($file, $content) = @_; $file= path_to($file); open my $fh, '>', $file - or die "Failed to open for write '$file':$!"; + or die "Failed to open for write '$file':$!"; print $fh $content; close $fh; } sub backtick { + # only for git. If we're in a -Dmksymlinks build-dir, we need to + # cd to src so git will work . Probably a better way. my $command = shift; if (wantarray) { - my @result= `$command`; + my @result= `$subcd $command`; + warn "$subcd $command: \$?=$?\n" if $?; + print "#> $subcd $command ->\n @result\n" if !$? and $opt_v; chomp @result; return @result; } else { - my $result= `$command`; + my $result= `$subcd $command`; $result="" if ! defined $result; + warn "$subcd $command: \$?=$?\n" if $?; + print "#> $subcd $command ->\n $result\n" if !$? and $opt_v; chomp $result; return $result; } @@ -102,14 +125,15 @@ sub write_files { my $unpushed_commits = '/*no-op*/'; 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')) { +elsif (-d "$srcdir/.git") { # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }' - ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick('git branch'); + ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick("git branch"); my ($remote,$merge); if (length $branch) { $merge= backtick("git config branch.$branch.merge"); @@ -139,18 +163,18 @@ git_remote_branch='$remote/$merge' git_unpushed='$unpushed_commit_list'"; } } - if ($changed) { + if ($changed) { # not touched since init'd. never true. $changed = 'true'; $commit_title = "Derived from:"; $status='"uncommitted-changes"' } else { - $status='/*clean-working-directory*/' + $status='/*clean-working-directory-maybe*/' } $commit_title ||= "Commit id:"; } # we extract the filename out of the warning header, so dont mess with that -exit(write_files(<<"EOF_HEADER", <<"EOF_CONFIG")); +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 @@ -173,4 +197,4 @@ git_commit_id_title='$commit_title' $extra_info ENDOFGIT EOF_CONFIG -# ex: set ts=4 sts=4 et ft=perl: +# ex: set ts=8 sts=4 sw=4 et ft=perl: