]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | #!/usr/bin/perl |
2 | # | |
3 | # This tool is used to stamp kernel version information into files at kernel | |
4 | # build time. Each argument provided on the command line is the path to a file | |
5 | # that needs to be updated with the current verison information. The file | |
6 | # xnu/config/MasterVersion is read to determine the version number to use. | |
7 | # Each file is read, and all occurrences of the following strings are replaced | |
8 | # in-place like so: | |
9 | # ###KERNEL_VERSION_LONG### 1.2.3b4 | |
10 | # ###KERNEL_VERSION_SHORT### 1.2.3 | |
11 | # ###KERNEL_VERSION_MAJOR### 1 | |
12 | # ###KERNEL_VERSION_MINOR### 2 | |
13 | # ###KERNEL_VERSION_VARIANT### 3b4 | |
14 | # ###KERNEL_VERSION_REVISION### 3 | |
15 | # ###KERNEL_VERSION_STAGE### VERSION_STAGE_BETA (see libkern/version.h) | |
16 | # ###KERNEL_VERSION_PRERELEASE_LEVEL### 4 | |
17 | # ###KERNEL_BUILDER### root | |
18 | # ###KERNEL_BUILD_OBJROOT### xnu/xnu-690.obj~2/RELEASE_PPC | |
19 | # ###KERNEL_BUILD_DATE### Sun Oct 24 05:33:28 PDT 2004 | |
20 | ||
316670eb A |
21 | use File::Basename; |
22 | ||
23 | use strict; | |
24 | ||
91447636 A |
25 | sub ReadFile { |
26 | my ($fileName) = @_; | |
27 | my $data; | |
28 | local $/ = undef; # Read complete files | |
29 | ||
30 | if (open(IN, "<$fileName")) { | |
31 | $data=<IN>; | |
32 | close IN; | |
33 | return $data; | |
34 | } | |
35 | die "newvers: Can't read file \"$fileName\"\n"; | |
36 | } | |
37 | ||
38 | sub WriteFile { | |
39 | my ($fileName, $data) = @_; | |
40 | ||
41 | open (OUT, ">$fileName") or die "newvers: Can't write file \"$fileName\"\n"; | |
42 | print OUT $data; | |
43 | close(OUT); | |
44 | } | |
45 | ||
316670eb A |
46 | die("SRCROOT not defined") unless defined($ENV{'SRCROOT'}); |
47 | die("OBJROOT not defined") unless defined($ENV{'OBJROOT'}); | |
48 | ||
91447636 | 49 | my $versfile = "MasterVersion"; |
39236c6e | 50 | $versfile = "$ENV{'SRCROOT'}/config/$versfile" if ($ENV{'SRCROOT'}); |
316670eb A |
51 | my $BUILD_SRCROOT=$ENV{'SRCROOT'}; |
52 | $BUILD_SRCROOT =~ s,/+$,,; | |
53 | my $BUILD_OBJROOT=$ENV{'OBJROOT'}; | |
54 | $BUILD_OBJROOT =~ s,/+$,,; | |
39236c6e | 55 | my $BUILD_OBJPATH=$ENV{'TARGET'} || $ENV{'OBJROOT'}; |
316670eb | 56 | $BUILD_OBJPATH =~ s,/+$,,; |
91447636 A |
57 | my $BUILD_DATE = `date`; |
58 | $BUILD_DATE =~ s/[\n\t]//g; | |
59 | my $BUILDER=`whoami`; | |
60 | $BUILDER =~ s/[\n\t]//g; | |
fe8ab488 | 61 | my $RC_STRING = $ENV{'RC_ProjectNameAndSourceVersion'} . "~" . $ENV{'RC_ProjectBuildVersion'} if defined($ENV{'RC_XBS'}); |
316670eb | 62 | |
fe8ab488 | 63 | # Handle four scenarios: |
316670eb A |
64 | # SRCROOT=/tmp/xnu |
65 | # OBJROOT=/tmp/xnu/BUILD/obj | |
66 | # OBJPATH=/tmp/xnu/BUILD/obj/RELEASE_X86_64 | |
67 | # | |
fe8ab488 A |
68 | # SRCROOT=/SourceCache/xnu/xnu-2706 |
69 | # OBJROOT=/BinaryCache/xnu/xnu-2706~3/Objects | |
70 | # OBJPATH=/BinaryCache/xnu/xnu-2706~3/Objects/DEVELOPMENT_X86_64 | |
71 | # RC_XBS=YES (XBS-16.3+) | |
72 | # RC_ProjectNameAndSourceVersion=xnu-2706 | |
73 | # RC_ProjectBuildVersion=3 | |
74 | # | |
75 | # SRCROOT=/SourceCache/xnu/xnu-2706 | |
76 | # OBJROOT=/private/var/tmp/xnu/xnu-2706~2 | |
77 | # OBJPATH=/private/var/tmp/xnu/xnu-2706~2/DEVELOPMENT_ARM_S5L8940X | |
78 | # RC_XBS=YES (<XBS-16.3) | |
79 | # RC_ProjectNameAndSourceVersion=xnu-2706 | |
80 | # RC_ProjectBuildVersion=2 | |
81 | # | |
82 | # SRCROOT=/tmp/xnu-2800.0.1_xnu-svn.roots/Sources/xnu-2800.0.1 | |
83 | # OBJROOT=/private/tmp/xnu-2800.0.1_xnu-svn.roots/BuildRecords/xnu-2800.0.1_install/Objects | |
84 | # OBJPATH=/private/tmp/xnu-2800.0.1_xnu-svn.roots/BuildRecords/xnu-2800.0.1_install/Objects/DEVELOPMENT_X86_64 | |
85 | # RC_XBS=YES (buildit) | |
86 | # RC_BUILDIT=YES | |
87 | # RC_ProjectNameAndSourceVersion=xnu-2800.0.1 | |
88 | # RC_ProjectBuildVersion=1 | |
89 | # | |
316670eb A |
90 | # |
91 | # If SRCROOT is a strict prefix of OBJPATH, we | |
92 | # want to preserve the "interesting" part | |
93 | # starting with "xnu". If it's not a prefix, | |
94 | # the basename of OBJROOT itself is "interesting". | |
fe8ab488 A |
95 | # Newer versions of XBS just set this to "Objects", so we |
96 | # need to synthesize the directory name to be more interesting. | |
97 | # | |
316670eb | 98 | |
39037602 A |
99 | sub describe { |
100 | my ($basename) = @_; | |
101 | ||
102 | # get a git tag if we can | |
103 | my $tag = `git describe --dirty 2>/dev/null`; | |
104 | chomp $tag; | |
105 | if ($? != 0 or $tag !~ /^xnu-([^\s\n]+)$/) { | |
106 | return $basename; | |
107 | } | |
108 | ||
109 | # If basename is just 'xnu' then replace it with the tag. Otherwise add | |
110 | # the tag in brackets. | |
111 | if ($basename eq 'xnu') { | |
112 | return $tag | |
113 | } else { | |
114 | return "${basename}[$tag]" | |
115 | } | |
116 | } | |
117 | ||
316670eb | 118 | if ($BUILD_OBJPATH =~ m,^$BUILD_SRCROOT/(.*)$,) { |
39037602 | 119 | $BUILD_OBJROOT = describe(basename($BUILD_SRCROOT)) . "/" . $1; |
316670eb | 120 | } elsif ($BUILD_OBJPATH =~ m,^$BUILD_OBJROOT/(.*)$,) { |
39037602 | 121 | if (defined($RC_STRING)) { |
fe8ab488 | 122 | $BUILD_OBJROOT = $RC_STRING . "/" . $1; |
39037602 A |
123 | } else { |
124 | $BUILD_OBJROOT = describe(basename($BUILD_OBJROOT)) . "/" . $1; | |
125 | } | |
316670eb | 126 | } else { |
39037602 | 127 | # Use original OBJROOT |
316670eb | 128 | } |
91447636 A |
129 | |
130 | my $rawvers = &ReadFile($versfile); | |
131 | #$rawvers =~ s/\s//g; | |
132 | ($rawvers) = split "\n", $rawvers; | |
133 | my ($VERSION_MAJOR, $VERSION_MINOR, $VERSION_VARIANT) = split /\./, $rawvers; | |
134 | die "newvers: Invalid MasterVersion \"$rawvers\"!!! " if (!$VERSION_MAJOR); | |
135 | $VERSION_MINOR = "0" unless ($VERSION_MINOR); | |
136 | $VERSION_VARIANT = "0" unless ($VERSION_VARIANT); | |
137 | $VERSION_VARIANT =~ tr/A-Z/a-z/; | |
138 | $VERSION_VARIANT =~ m/(\d+)((?:d|a|b|r|fc)?)(\d*)/; | |
139 | my $VERSION_REVISION = $1; | |
140 | my $stage = $2; | |
141 | my $VERSION_PRERELEASE_LEVEL = $3; | |
142 | $VERSION_REVISION ="0" unless ($VERSION_REVISION); | |
143 | $stage = "r" if (!$stage || ($stage eq "fc")); | |
144 | $VERSION_PRERELEASE_LEVEL = "0" unless ($VERSION_PRERELEASE_LEVEL); | |
145 | ||
146 | my $VERSION_STAGE; | |
147 | $VERSION_STAGE = 'VERSION_STAGE_DEV' if ($stage eq 'd'); | |
148 | $VERSION_STAGE = 'VERSION_STAGE_ALPHA' if ($stage eq 'a'); | |
149 | $VERSION_STAGE = 'VERSION_STAGE_BETA' if ($stage eq 'b'); | |
150 | $VERSION_STAGE = 'VERSION_STAGE_RELEASE' if ($stage eq 'r'); | |
151 | ||
152 | my $VERSION_SHORT = "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_REVISION"; | |
153 | my $VERSION_LONG = $VERSION_SHORT; | |
154 | $VERSION_LONG .= "$stage$VERSION_PRERELEASE_LEVEL" if (($stage ne "r") || ($VERSION_PRERELEASE_LEVEL != 0)); | |
155 | ||
156 | my $file; | |
157 | foreach $file (@ARGV) { | |
158 | print "newvers.pl: Stamping version \"$VERSION_LONG\" into \"$file\" ..."; | |
159 | my $data = &ReadFile($file); | |
160 | my $count=0; | |
161 | $count += $data =~ s/###KERNEL_VERSION_LONG###/$VERSION_LONG/g; | |
162 | $count += $data =~ s/###KERNEL_VERSION_SHORT###/$VERSION_SHORT/g; | |
163 | $count += $data =~ s/###KERNEL_VERSION_MAJOR###/$VERSION_MAJOR/g; | |
164 | $count += $data =~ s/###KERNEL_VERSION_MINOR###/$VERSION_MINOR/g; | |
165 | $count += $data =~ s/###KERNEL_VERSION_VARIANT###/$VERSION_VARIANT/g; | |
166 | $count += $data =~ s/###KERNEL_VERSION_REVISION###/$VERSION_REVISION/g; | |
167 | $count += $data =~ s/###KERNEL_VERSION_STAGE###/$VERSION_STAGE/g; | |
168 | $count += $data =~ s/###KERNEL_VERSION_PRERELEASE_LEVEL###/$VERSION_PRERELEASE_LEVEL/g; | |
169 | $count += $data =~ s/###KERNEL_BUILDER###/$BUILDER/g; | |
170 | $count += $data =~ s/###KERNEL_BUILD_OBJROOT###/$BUILD_OBJROOT/g; | |
171 | $count += $data =~ s/###KERNEL_BUILD_DATE###/$BUILD_DATE/g; | |
172 | print " $count replacements\n"; | |
173 | &WriteFile($file, $data); | |
174 | } | |
175 | ||
176 | if (0==scalar @ARGV) { | |
177 | print "newvers.pl: read version \"$rawvers\" from \"$versfile\"\n"; | |
178 | print "newvers.pl: ###KERNEL_VERSION_LONG### = $VERSION_LONG\n"; | |
179 | print "newvers.pl: ###KERNEL_VERSION_SHORT### = $VERSION_SHORT\n"; | |
180 | print "newvers.pl: ###KERNEL_VERSION_MAJOR### = $VERSION_MAJOR\n"; | |
181 | print "newvers.pl: ###KERNEL_VERSION_MINOR### = $VERSION_MINOR\n"; | |
182 | print "newvers.pl: ###KERNEL_VERSION_VARIANT### = $VERSION_VARIANT\n"; | |
183 | print "newvers.pl: ###KERNEL_VERSION_REVISION### = $VERSION_REVISION\n"; | |
184 | print "newvers.pl: ###KERNEL_VERSION_STAGE### = $VERSION_STAGE\n"; | |
185 | print "newvers.pl: ###KERNEL_VERSION_PRERELEASE_LEVEL### = $VERSION_PRERELEASE_LEVEL\n"; | |
186 | print "newvers.pl: ###KERNEL_BUILDER### = $BUILDER\n"; | |
187 | print "newvers.pl: ###KERNEL_BUILD_OBJROOT### = $BUILD_OBJROOT\n"; | |
188 | print "newvers.pl: ###KERNEL_BUILD_DATE### = $BUILD_DATE\n"; | |
189 | } |