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.

BuildDistribution.cc 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // BuildDistribution.cc
  3. //
  4. // Program to build a zipfile containing a distribution of
  5. // PKG-SNF-SDK-WIN.
  6. //
  7. // (C) Copyright 2010 ARM Research Labs, LLC See
  8. // www.armresearch.com for the copyright terms.
  9. //
  10. // Usage:
  11. //
  12. // BuildDistribution -d DistPath -t TempPath [-h -v -i]
  13. //
  14. // where DistPath is the path of the distribution
  15. // (e.g. SNFMultiSDK_Windows_3.1, and TempPath is the name of the
  16. // directory to use for temporary storage. TempPath must be a
  17. // directory, and must exist.
  18. //
  19. // The "-h" input causes the program to output help text and exit.
  20. //
  21. // Specifying "-v" causes the program to be verbose.
  22. //
  23. // Specifying "-i" causes the program to wait for user confirmation
  24. // before proceeding. Specifying "-i" causes the program to be
  25. // verbose.
  26. //
  27. // The program does the following:
  28. //
  29. // 1) For each directory DIR that appears in DistPath and also
  30. // in DistPath\..:
  31. //
  32. // a) Delete the contents of DistPath/DIR, except for .svn.
  33. //
  34. // b) Copy the contents of DistPath\..\DIR to DistPath\DIR, except
  35. // for .svn.
  36. //
  37. // 2) Create a temporary directory TempPath/DistName, where DistName
  38. // is the directory name of DistPath (e.g. if DistName is
  39. // c:\dir1\dir2\SNFMultiSDK_Windows_3.1, then DistName is
  40. // SNFMultiSDK_Windows_3.1).
  41. //
  42. // 3) For each directory DIR that appears in DistPath except for
  43. // .svn:
  44. //
  45. // a) Copy all files from DistPath to TempPath/DistName, except
  46. // for .svn.
  47. //
  48. // $Id$
  49. //
  50. /////////////////////////////////////////////////////////////////////////////////////////////
  51. #include <windows.h>
  52. #include <tchar.h>
  53. #include <iostream>
  54. #include <string>
  55. #include "Utility.h"
  56. int
  57. main(int argc, char **argv) {
  58. std::string TempPath = "C:\\TEMP"; // Default temporary directory.
  59. std::string InputDistPath; // Names of directories and paths.
  60. bool Verbose = false;
  61. bool Interactive = false;
  62. for (int i = 1; i < argc; i++) { // Get command-line input.
  63. std::string CmdArg;
  64. CmdArg = argv[i];
  65. if ("-d" == CmdArg) {
  66. if (++i == argc) {
  67. OutputUsage(TempPath);
  68. return(-1);
  69. }
  70. InputDistPath = argv[i];
  71. } else if ("-t" == CmdArg) {
  72. if (++i == argc) {
  73. OutputUsage(TempPath);
  74. return(-1);
  75. }
  76. TempPath = argv[i];
  77. } else if ("-v" == CmdArg) {
  78. Verbose = true;
  79. } else if ("-i" == CmdArg) {
  80. Interactive = true;
  81. Verbose = true;
  82. } else if ("-h" == CmdArg) {
  83. OutputHelp();
  84. OutputUsage(TempPath);
  85. return(0);
  86. }
  87. }
  88. if ( ("" == InputDistPath) || ("" == TempPath) ) { // Check input.
  89. OutputUsage(TempPath);
  90. return(-1);
  91. }
  92. std::string DistPath; // Names of the directories.
  93. std::string DistParentPath;
  94. std::string DistName;
  95. std::string TempDir;
  96. try {
  97. GetDirectoryNames(InputDistPath,
  98. DistPath,
  99. DistParentPath,
  100. DistName);
  101. TempDir = TempPath + "\\";
  102. TempDir += DistName;
  103. if (Verbose) {
  104. std::cout
  105. << "\nThe distribution will be built from the files in the source "
  106. "directory "
  107. << DistPath << ".\n\n"
  108. << "The files in the directories that exist in both "
  109. << DistParentPath << " and the source directory will be copied into the "
  110. << "distribution.\n\n"
  111. << "The temporary directory is " << TempDir << ".\n\n";
  112. if (Interactive) {
  113. std::cout << "Enter <cr> to continue: ";
  114. (void) std::cin.get();
  115. }
  116. }
  117. StringContainer ExcludeName; // Create the list of file names
  118. ExcludeName.push_back(".svn"); // to not copy.
  119. ExcludeName.push_back(".");
  120. ExcludeName.push_back("..");
  121. ExcludeName.push_back(DistName);
  122. UpdateCommonDirectories(DistPath, DistParentPath, ExcludeName); // Update files in directories
  123. // common to both DistPath and
  124. // DistParentPath.
  125. PrepareTempDir(TempDir); // Delete any existing temporary
  126. // directory.
  127. CopyDirectory(DistPath, TempDir, ExcludeName); // Copy files to temporary directory.
  128. if (Verbose) {
  129. std::cout << "Distribution created in " << TempDir << ".\n";
  130. }
  131. } catch (std::exception &e) {
  132. OutputErrorMessage(e.what());
  133. return(-1);
  134. }
  135. return(0);
  136. }