Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
6.0 KiB

  1. #---------------------------------------------------------------------
  2. package BuildName;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version:
  7. # 1.00 08/31/2000 JeremyD: initial design
  8. # 1.01 12/18/2000 JeremyD: expect and return all lowercase
  9. # add filter_build_names function
  10. #---------------------------------------------------------------------
  11. use strict;
  12. use vars qw(@ISA @EXPORT $VERSION);
  13. use Carp;
  14. use Exporter;
  15. use IO::File;
  16. @ISA = qw(Exporter);
  17. @EXPORT = qw(build_name build_name_parts build_number build_arch
  18. build_type build_branch build_date build_flavor
  19. build_number_major);
  20. $VERSION = '1.01';
  21. sub build_name {
  22. if ($_[0]) { return lc($_[0]) }
  23. my $BuildNamePath = "$ENV{_NTPOSTBLD}\\build_logs";
  24. my $BuildNameFile = "$BuildNamePath\\BuildName.txt";
  25. my $build_name;
  26. if (-e $BuildNameFile) {
  27. my $fh = new IO::File $BuildNameFile, "r";
  28. if (defined $fh) {
  29. $build_name = $fh->getline;
  30. chomp($build_name);
  31. undef $fh;
  32. } else {
  33. carp "Couldn't open file $BuildNameFile: $!";
  34. }
  35. } else {
  36. carp "File $BuildNameFile did not exist";
  37. }
  38. return lc($build_name);
  39. }
  40. sub build_name_parts {
  41. my $name = lc(build_name($_[0]));
  42. return ($name =~ /(\d+(?:-\d+)?) # b. number and opt. revision
  43. \.
  44. (x86|amd64|ia64) # hardcoded flavor list...
  45. (fre|chk) # debug type
  46. \.
  47. ([^\.]+) # branch name, no .'s allowed
  48. \.
  49. (\d{6}-\d{4})/x); # date-time stamp
  50. }
  51. sub build_number {
  52. return (build_name_parts($_[0]))[0];
  53. }
  54. sub build_arch {
  55. return (build_name_parts($_[0]))[1];
  56. }
  57. sub build_type {
  58. return (build_name_parts($_[0]))[2];
  59. }
  60. sub build_branch {
  61. return (build_name_parts($_[0]))[3];
  62. }
  63. sub build_date {
  64. return (build_name_parts($_[0]))[4];
  65. }
  66. sub build_flavor {
  67. my ($arch, $type) = (build_arch($_[0]), build_type($_[0]));
  68. if (defined $arch and defined $type) {
  69. return "$arch$type";
  70. }
  71. else {
  72. return;
  73. }
  74. }
  75. sub build_number_major {
  76. my $number = build_number($_[0]);
  77. my ($major) = $number =~ /^(\d+)/;
  78. return $major;
  79. }
  80. 1;
  81. __END__
  82. =head1 NAME
  83. BuildName - Read and parse build names
  84. =head1 SYNOPSIS
  85. use BuildName;
  86. $build_name = build_name;
  87. $build_number = build_number;
  88. $build_number = build_number("2222-33.x86fre.LabT2_n.000829-0000");
  89. =head1 DESCRIPTION
  90. BuildName provides several functions for reading and parsing
  91. buildnames.
  92. All build name functions (including build_name) can take a build name
  93. argument to override the default of using the buildname stored in
  94. $ENV{_NTPostBld}\build_logs\BuildName.txt.
  95. If no build name is specified then errors finding or reading
  96. $ENV{_NTPostBld}\build_logs\BuildName.txt are printed to STDERR.
  97. All build name functions return undef if the buildname cannot be read
  98. or parsed.
  99. All functions expect and return lowercase strings.
  100. =over
  101. =item build_name( [$build_name] )
  102. Returns the buildname stored in BuildName.txt, if an argument is
  103. provided that is returned instead without checking BuildName.txt.
  104. Errors finding or reading the buildname file are printed to STDERR
  105. and undef is returned.
  106. =item build_name_parts( [$build_name] )
  107. Returns the individual components of a build name as an array
  108. ($number, $arch, $debugtype, $branch, $datetime).
  109. =item build_number( [$build_name] )
  110. Returns the build number component of a build name, including the
  111. minor revision. Minor revision is for international builds only. As
  112. a result the build number may contain non-digit characters. When
  113. testing for equality use the string comparison operator 'eq' instead
  114. of '=='.
  115. =item build_number_major( [$build_name] )
  116. Returns the build number component of a build name, without the minor
  117. revision. This function may return non-digit characters. When testing
  118. for equality use the string comparison operator 'eq' instead of '=='.
  119. =item build_flavor( [$build_name] )
  120. Returns the build flavor component of a build name. 'x86fre' for
  121. example. This is the simple concatenation of arch and debug type.
  122. This can usually be better obtained from
  123. "$ENV{_BuildArch}$ENV{_BuildType}".
  124. =item build_arch( [$build_name] )
  125. Returns the build architecture component of a build name. The only
  126. possible values are currently 'x86', 'amd64', and 'ia64'. This can
  127. usually be better obtained from $ENV{_BuildArch}.
  128. =item build_type( [$build_name] )
  129. Returns the build debug type component of a build name. This is
  130. either 'chk' for builds with debugging enabled and 'fre' for free
  131. builds. This can usually be better obtained from $ENV{_BuildType}.
  132. =item build_branch( [$build_name] )
  133. Returns the branch name component of a build name. This is the value
  134. of branch name environment variable in effect when postbuild was
  135. started. This can usually be better obtained from $ENV{_BuildBranch}.
  136. =item build_date( [$build_name] )
  137. Returns the date/time stamp component of a build name. This is
  138. always in the format YYMMDD-HHMM. Note that sorting this string
  139. ASCIIbetically will also achieve chronological sorting (you can use
  140. perl's default sort).
  141. =back
  142. =head1 RETURN VALUES
  143. All functions return lowercase strings. This includes the functions
  144. build_number and build_number_major.
  145. =head1 ERRORS
  146. All functions return undef to indicate and error and a true value
  147. otherwise.
  148. =head1 ENVIRONMENT
  149. The _NTPOSTBLD environment variable is used to find the build name if
  150. none is given.
  151. =head1 NOTES
  152. Several things are hardcoded in the buildname regular expression. Any
  153. significant change to the build name will require this module to be
  154. updated.
  155. =head1 AUTHOR
  156. Jeremy Devenport <JeremyD>
  157. =head1 COPYRIGHT
  158. Copyright (c) Microsoft Corporation. All rights reserved.
  159. =cut