Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 205 lines (178 sloc) 6.792 kB
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
1 #!/usr/bin/perl
f22725b Message about making make_patchnum.pl Perl 5.005 compatible (A test f…
Max Maischein authored
2 # These two should go upon release to make the script Perl 5.005 compatible
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
3 use strict;
4 use warnings;
5
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
6 =head1 NAME
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
7
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
8 make_patchnum.pl - make patchnum
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
9
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
10 =head1 SYNOPSIS
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
11
6033099 Add more documentation to make_patchnum.pl
Max Maischein authored
12 miniperl make_patchnum.pl
13
14 perl make_patchnum.pl
15
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
16 =head1 DESCRIPTION
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
17
6033099 Add more documentation to make_patchnum.pl
Max Maischein authored
18 This program creates the files holding the information
19 about locally applied patches to the source code. The created
d921726 make_patchnum.pl: Change some C<> into F<>
Karl Williamson authored
20 files are F<git_version.h> and F<lib/Config_git.pl>.
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
21
64da300 @obra more pod cleanups based on the new podcheck.t
obra authored
22 =head2 C<lib/Config_git.pl>
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
23
24 Contains status information from git in a form meant to be processed
25 by the tied hash logic of Config.pm. It is actually optional,
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
26 although -V:git.\* will be uninformative without it.
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
27
28 C<git_version.h> contains similar information in a C header file
29 format, designed to be used by patchlevel.h. This file is obtained
30 from stock_git_version.h if miniperl is not available, and then
31 later on replaced by the version created by this script.
32
33 =head1 AUTHOR
6033099 Add more documentation to make_patchnum.pl
Max Maischein authored
34
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
35 Yves Orton, Kenichi Ishigaki, Max Maischein
6033099 Add more documentation to make_patchnum.pl
Max Maischein authored
36
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
37 =head1 COPYRIGHT
6033099 Add more documentation to make_patchnum.pl
Max Maischein authored
38
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
39 Same terms as Perl itself.
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
40
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
41 =cut
42
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
43 # from a -Dmksymlink target dir, I need to cd to the git-src tree to
44 # use git (like script does). Presuming that's not unique, one fix is
45 # to follow Configure's symlink-path to run git. Maybe GIT_DIR or
46 # path-args can solve it, if so we should advise here, I tried only
47 # very briefly ('cd -' works too).
48
49 my ($subcd, $srcdir);
50 our $opt_v = scalar grep $_ eq '-v', @ARGV;
51
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
52 BEGIN {
53 my $root=".";
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
54 # test 1st to see if we're a -Dmksymlinks target dir
55 $subcd = '';
56 $srcdir = $root;
57 if (-l "./Configure") {
58 $srcdir = readlink("./Configure");
59 $srcdir =~ s/Configure//;
60 $subcd = "cd $srcdir &&"; # activate backtick fragment
61 }
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
62 while (!-e "$root/perl.c" and length($root)<100) {
63 if ($root eq '.') {
91c3081 @rgs Correct vim modeline
rgs authored
64 $root="..";
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
65 } else {
91c3081 @rgs Correct vim modeline
rgs authored
66 $root.="/..";
67 }
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
68 }
69 die "Can't find toplevel" if !-e "$root/perl.c";
70 sub path_to { "$root/$_[0]" } # use $_[0] if this'd be placed in toplevel.
71 }
72
73 sub read_file {
74 my $file = path_to(@_);
75 return "" unless -e $file;
76 open my $fh, '<', $file
91c3081 @rgs Correct vim modeline
rgs authored
77 or die "Failed to open for read '$file':$!";
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
78 return do { local $/; <$fh> };
79 }
80
81 sub write_file {
82 my ($file, $content) = @_;
83 $file= path_to($file);
84 open my $fh, '>', $file
91c3081 @rgs Correct vim modeline
rgs authored
85 or die "Failed to open for write '$file':$!";
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
86 print $fh $content;
87 close $fh;
88 }
89
90 sub backtick {
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
91 # only for git. If we're in a -Dmksymlinks build-dir, we need to
92 # cd to src so git will work . Probably a better way.
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
93 my $command = shift;
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
94 if (wantarray) {
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
95 my @result= `$subcd $command`;
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
96 #warn "$subcd $command: \$?=$?\n" if $?;
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
97 print "#> $subcd $command ->\n @result\n" if !$? and $opt_v;
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
98 chomp @result;
99 return @result;
100 } else {
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
101 my $result= `$subcd $command`;
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
102 $result="" if ! defined $result;
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
103 warn "$subcd $command: \$?=$?\n" if $?;
104 print "#> $subcd $command ->\n $result\n" if !$? and $opt_v;
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
105 chomp $result;
106 return $result;
107 }
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
108 }
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
109
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
110 sub write_files {
111 my %content= map { /WARNING: '([^']+)'/ || die "Bad mojo!"; $1 => $_ } @_;
112 my @files= sort keys %content;
113 my $files= join " and ", map { "'$_'" } @files;
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
114 foreach my $file (@files) {
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
115 if (read_file($file) ne $content{$file}) {
116 print "Updating $files\n";
117 write_file($_,$content{$_}) for @files;
118 return 1;
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
119 }
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
120 }
121 print "Reusing $files\n";
122 return 0;
123 }
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
124
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
125 my $unpushed_commits = ' ';
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
126 my ($read, $branch, $snapshot_created, $commit_id, $describe)= ("") x 5;
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
127 my ($changed, $extra_info, $commit_title)= ("") x 3;
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
128
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
129 if (my $patch_file= read_file(".patch")) {
130 ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patch_file;
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
131 $extra_info = "git_snapshot_date='$snapshot_created'";
132 $commit_title = "Snapshot of:";
133 }
3f1788e @jimc make_patchnum.pl now works in -Dmksymlink target dirs
jimc authored
134 elsif (-d "$srcdir/.git") {
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
135 # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
9077509 @iabyn make_patchnum.pl: handle not on a branch properly
iabyn authored
136 ($branch) = map { /\* ([^(]\S*)/ ? $1 : "" } backtick("git branch");
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
137 my ($remote,$merge);
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
138 if (length $branch) {
505afc7 @demerphq add better pod and headers, and clean up some whitespace issues in th…
demerphq authored
139 $merge= backtick("git config branch.$branch.merge");
326df89 git config lossage
Zefram authored
140 $merge = "" unless $? == 0;
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
141 $merge =~ s!^refs/heads/!!;
142 $remote= backtick("git config branch.$branch.remote");
326df89 git config lossage
Zefram authored
143 $remote = "" unless $? == 0;
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
144 }
145 $commit_id = backtick("git rev-parse HEAD");
b6194a9 @demerphq various changes
demerphq authored
146 $describe = backtick("git describe");
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
147 my $commit_created = backtick(qq{git log -1 --pretty="format:%ci"});
148 $extra_info = "git_commit_date='$commit_created'";
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
149 backtick("git diff --no-ext-diff --quiet --exit-code");
150 $changed = $?;
151 unless ($changed) {
152 backtick("git diff-index --cached --quiet HEAD --");
153 $changed = $?;
154 }
155
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
156 if (length $branch && length $remote) {
157 # git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'
158 my $unpushed_commit_list =
159 join ",", map { (split /\s/, $_)[1] }
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
160 grep {/\+/} backtick("git cherry $remote/$merge");
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
161 # git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'
29299e4 @demerphq move subs from bottom to top, and add a vim and shebang line
demerphq authored
162 $unpushed_commits =
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
163 join "", map { ',"'.(split /\s/, $_)[1]."\"\t\\\n" }
164 grep {/\+/} backtick("git cherry $remote/$merge");
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
165 if (length $unpushed_commits) {
166 $commit_title = "Local Commit:";
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
167 my $ancestor = backtick("git rev-parse $remote/$merge");
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
168 $extra_info = "$extra_info
169 git_ancestor='$ancestor'
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
170 git_remote_branch='$remote/$merge'
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
171 git_unpushed='$unpushed_commit_list'";
172 }
173 }
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
174 if ($changed) {
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
175 $commit_title = "Derived from:";
176 }
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
177 $commit_title ||= "Commit id:";
786aaa2 @charsbar Almost a literal conversion of make_patchnum.sh
charsbar authored
178 }
179
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
180 # we extract the filename out of the warning header, so dont mess with that
16ad9bf The exit code of make_patchnum.pl is no longer used, so make it retur…
Nicholas Clark authored
181 write_files(<<"EOF_HEADER", <<"EOF_CONFIG");
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
182 /**************************************************************************
183 * WARNING: 'git_version.h' is automatically generated by make_patchnum.pl
184 * DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
185 ***************************************************************************/
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
186 @{[$describe ? "#define PERL_PATCHNUM \"$describe\"" : ()]}
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
187 #define PERL_GIT_UNPUSHED_COMMITS\t\t\\
188 $unpushed_commits/*leave-this-comment*/
691ce77 @gisle Only define PERL_PATCHNUM when either git or the .patch file is avail…
gisle authored
189 @{[$changed ? "#define PERL_GIT_UNCOMMITTED_CHANGES" : ()]}
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
190 EOF_HEADER
191 ######################################################################
192 # WARNING: 'lib/Config_git.pl' is generated by make_patchnum.pl
193 # DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
194 ######################################################################
8ed12dc @demerphq prepare for refactoring to perl
demerphq authored
195 \$Config::Git_Data=<<'ENDOFGIT';
196 git_commit_id='$commit_id'
197 git_describe='$describe'
198 git_branch='$branch'
199 git_uncommitted_changes='$changed'
200 git_commit_id_title='$commit_title'
201 $extra_info
202 ENDOFGIT
eb5c076 @demerphq eliminate make_patchnum.sh, and make the build process use make_patch…
demerphq authored
203 EOF_CONFIG
91c3081 @rgs Correct vim modeline
rgs authored
204 # ex: set ts=8 sts=4 sw=4 et ft=perl:
Something went wrong with that request. Please try again.