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.

139 lines
4.2 KiB

  1. # FileName: publish.pl
  2. #
  3. # Function: Given a file, publish it to the requested locations.
  4. #
  5. # Usage: publish.pl <logfile> <publishspec>
  6. # where: <logfile> is the name of the log file to be generated
  7. # <publishspec> is of the form:
  8. # {<filename>=<location>;<location>}{...}
  9. #
  10. # <filename> is a single filename to publish.
  11. # <location> is where to publish the file. Multiple locations
  12. # are delimited with semicolon
  13. #
  14. # or publish <logfile> -f <specfile>
  15. # where: <logfile> is the name of the logfile to be generated
  16. # <specfile> contains one or more <publishspec> entries
  17. #
  18. # Example:
  19. # publish.pl publish.log {kernel32.lib=\public\sdk\lib\amd64\kernel32.lib;\mypub\_kernel32.lib}
  20. #
  21. $currenttime = time;
  22. open (CWD, 'cd 2>&1|');
  23. $PublishDir = <CWD>;
  24. close (CWD);
  25. chop $PublishDir;
  26. # strip the logfile name out of the arguments array.
  27. $logfilename = $ARGV[0];
  28. shift;
  29. # print "PUBLISH: logging to $logfilename\n";
  30. if ($ARGV[0] =~ /^[\/-][fF]$/) {
  31. shift;
  32. $indirname = shift;
  33. if (@ARGV || !$indirname) {
  34. die "Build_Status PUBLISH() : error p1000: Invalid syntax - Expected: publish -f FILE\n";
  35. }
  36. # print "PUBLISH: getting input from $indirname\n";
  37. open INDIR, $indirname or die "Build_Status PUBLISH(): error p1005: Could not open: $indirname\n";
  38. @ARGV=<INDIR>;
  39. close INDIR;
  40. } elsif ($ARGV[0] =~ /^[\/-][iI]$/) {
  41. shift;
  42. # print "PUBLISH: getting input from STDIN\n";
  43. @ARGV=<STDIN>;
  44. }
  45. for (@ARGV) {
  46. s/\s//g; # Remove spaces, tabs, newlines, etc
  47. $NextSpec = $_;
  48. # print "PUBLISH: NextSpec = $_";
  49. while ($NextSpec) {
  50. $SaveSpec = $NextSpec;
  51. $Spec1 = "";
  52. $PublishSpec = "";
  53. # Filter out the current publish spec
  54. ($PreCurly,$Spec1) = split (/{/, $NextSpec,2);
  55. # See if there's another one
  56. ($PublishSpec,$NextSpec) = split (/}/, $Spec1,2);
  57. # Break out the filename
  58. ($FileName,$LocationSpec) = split (/=/, $PublishSpec,2);
  59. # Create the location list
  60. @Location = split ((/\;/), $LocationSpec);
  61. die "PUBLISH(80) : error p1003: Bad input: $SaveSpec\n" unless($PublishSpec && $FileName && $#Location >= 0);
  62. # See if the source exists.
  63. if (!stat($FileName)) {
  64. print "Build_Status PUBLISH() : error p1001: $PublishDir - $FileName does not exist\n";
  65. } else {
  66. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  67. $TimeDate = sprintf "%04d/%02d/%02d-%02d:%02d:%02d", 1900+$year, 1+$mon, $mday, $hour, $min, $sec;
  68. # Run pcopy for every location listed.
  69. for (@Location) {
  70. # print "PUBLISH: pcopy.exe $FileName $_";
  71. system "pcopy.exe $FileName $_";
  72. $ReturnCode = $? / 256;
  73. if ($ReturnCode == 0) {
  74. $CopiedFile=$_;
  75. $PUBLISH_LOG = $ENV{'_NTBINDIR'};
  76. $PUBLISH_LOG="$PUBLISH_LOG\\public\\$logfilename";
  77. # RC == 0 means success.
  78. $ReturnCode = -1;
  79. $LoopCount = 0;
  80. while ($ReturnCode) {
  81. system ("echo $CopiedFile $PublishDir $FileName $currenttime >> $PUBLISH_LOG");
  82. $ReturnCode = $?;
  83. $LoopCount = $LoopCount + 1;
  84. # Retry a max of 100 times to log the change.
  85. if ($LoopCount == 100) {
  86. print "Build_Status PUBLISH() : warning p1002: Unable to log \"$CopiedFile $PublishDir $FileName\" to $PUBLISH_LOG";
  87. $ReturnCode = 0;
  88. }
  89. }
  90. #
  91. # BUGBUG: Need to log this for build/sd/more build process
  92. #
  93. print "PUBLISHLOG: $PublishDir, $FileName, $_, Updated, $TimeDate\n";
  94. } else {
  95. if ($ReturnCode == 255) {
  96. # Current location is good enough.
  97. print "PUBLISHLOG: $PublishDir, $FileName, $_, Current, $TimeDate\n";
  98. } else {
  99. # Problem copying (bad source, missing dest, out of mem, etc).
  100. print "Build_Status PUBLISH() : error p1004: ERROR($ReturnCode) copying $FileName to $_\n";
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }