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.

106 lines
2.6 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM buildname.cmd - JeremyD
  4. @REM Parses and return build name components
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. use strict;
  13. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  14. use lib $ENV{RAZZLETOOLPATH};
  15. use PbuildEnv;
  16. use ParseArgs;
  17. use BuildName;
  18. sub Usage { print<<USAGE; exit(1) }
  19. buildname [-name <build name>] <build_* [build_* ...]>
  20. buildname will call functions from the BuildName.pm module. The option
  21. -name paramater allows the caller to pass a build name to the
  22. specified functions to override the default of reading the name from
  23. _NTPostBld\build_logs\buildname.txt.
  24. At least one BuildName function must be given on the command line. The
  25. complete list of functions available is documented in BuildName.pm
  26. If any part of reading or parsing the build name fails an error will
  27. be printed to STDERR and the call will return an exit code greater
  28. than 0.
  29. Example:
  30. >buildname build_number build_flavor build_branch
  31. 2420 x86fre main
  32. >buildname -name 2422.x86fre.lab02_n.010201-1120 build_date
  33. 2422
  34. Or in a CMD script:
  35. for /f "tokens=1,2" %%a in (
  36. 'buildname.cmd build_number build_date') do (
  37. set BUILD_NUMBER=%%a
  38. set BUILD_DATE=%%b
  39. )
  40. if errorlevel 1 (
  41. call errmsg.cmd "Failed to get buildname"
  42. goto :EOF
  43. )
  44. USAGE
  45. my ($build_name, $errors);
  46. # first pass through the command line looking for a build name argument
  47. parseargs('?' => \&Usage,
  48. 'name:' => \$build_name);
  49. my @returns;
  50. for my $func (@ARGV) {
  51. # only try to eval functions that BuildName exports
  52. if (!grep /^$func$/, @BuildName::EXPORT) {
  53. warn "$func is not exported by the BuildName module\n";
  54. $errors++;
  55. last;
  56. }
  57. # try evaling this function with build_name as the argument
  58. eval qq{
  59. my \$r = $func(\$build_name);
  60. if (defined \$r) {
  61. push \@returns, \$r;
  62. }
  63. else {
  64. warn "call to $func returned undef\n";
  65. \$errors++;
  66. }
  67. };
  68. if ($@) {
  69. warn "attempting to call $func failed: $@\n";
  70. $errors++;
  71. last;
  72. }
  73. }
  74. #
  75. # if any function calls failed, don't output any of the results we may
  76. # have the wrong order
  77. #
  78. print join(" ", @returns), "\n" unless $errors;
  79. #
  80. # we didn't call errmsg so we need to return an exit code if we fail
  81. #
  82. exit($errors);