Source code of Windows XP (NT5)
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.

212 lines
5.7 KiB

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