santa.ck 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*++
  2. Copyright (c) 2017 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. mingen.ck
  9. Abstract:
  10. This module implements the Minoca build generator application, which can
  11. transform a build specification into a Makefile or Ninja file.
  12. Author:
  13. Evan Green 30-Jan-2017
  14. Environment:
  15. Chalk
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. from app import argv;
  21. from getopt import gnuGetopt;
  22. import os;
  23. from os import getcwd;
  24. from santa.config import loadConfig;
  25. from santa.file import createStandardPaths;
  26. from santa.modules import enumerateCommands, initModuleSupport, runCommand;
  27. //
  28. // --------------------------------------------------------------------- Macros
  29. //
  30. //
  31. // ---------------------------------------------------------------- Definitions
  32. //
  33. var VERSION_MAJOR = 1;
  34. var VERSION_MINOR = 0;
  35. //
  36. // ------------------------------------------------------ Data Type Definitions
  37. //
  38. //
  39. // ----------------------------------------------- Internal Function Prototypes
  40. //
  41. function
  42. printHelp (
  43. );
  44. //
  45. // -------------------------------------------------------------------- Globals
  46. //
  47. var shortOptions = "+f:r:hvV";
  48. var longOptions = [
  49. "file=",
  50. "root=",
  51. "help",
  52. "verbose",
  53. "version"
  54. ];
  55. var usage =
  56. "usage: santa [global_options] command [command_options]\n"
  57. "Santa is a package manager. It can build, install, and maintain \n"
  58. "packages and environments.\n"
  59. "Global options:\n"
  60. " -f, --file=config -- Use the config file at the given path.\n"
  61. " -r, --root=dir -- Set the given directory as the root directory\n"
  62. " before doing anything else. Used for offline installs.\n"
  63. " -h, --help -- Shows this help.\n"
  64. " -v, --verbose -- Print more information.\n"
  65. " -V, --version -- Print the version of this application and exit.\n";
  66. //
  67. // ------------------------------------------------------------------ Functions
  68. //
  69. function
  70. main (
  71. )
  72. /*++
  73. Routine Description:
  74. This routine implements the application entry point for the mingen
  75. application.
  76. Arguments:
  77. None.
  78. Return Value:
  79. 0 on success.
  80. 1 on failure.
  81. --*/
  82. {
  83. var appOptions = gnuGetopt(argv[1...-1], shortOptions, longOptions);
  84. var args = appOptions[1];
  85. var command;
  86. var configpath = null;
  87. var entries = {};
  88. var help = false;
  89. var name;
  90. var override;
  91. var status;
  92. var value;
  93. override = {
  94. "core": {}
  95. };
  96. //
  97. // The return from getopt is [config, remainingArgs]. Get the config now.
  98. //
  99. appOptions = appOptions[0];
  100. for (option in appOptions) {
  101. name = option[0];
  102. value = option[1];
  103. if ((name == "-f") || (name == "--file")) {
  104. configpath = value;
  105. } else if ((name == "-r") || (name == "--root")) {
  106. override.core.root = value;
  107. } else if ((name == "-h") || (name == "--help")) {
  108. help = true;
  109. } else if ((name == "-v") || (name == "--verbose")) {
  110. override.core.verbose = true;
  111. } else if ((name == "-V") || (name == "--version")) {
  112. Core.print("Santa version %d.%d" % [VERSION_MAJOR, VERSION_MINOR]);
  113. return 1;
  114. } else {
  115. Core.raise(ValueError("Invalid option '%s'" % name));
  116. }
  117. }
  118. //
  119. // Load up the global config.
  120. //
  121. loadConfig(configpath, override);
  122. initModuleSupport();
  123. if (!help && (args.length() == 0)) {
  124. help = true;
  125. Core.print("Error: expected a command.");
  126. }
  127. if (help) {
  128. printHelp();
  129. return 1;
  130. }
  131. createStandardPaths();
  132. command = args[0];
  133. status = runCommand(command, args);
  134. return status;
  135. }
  136. //
  137. // --------------------------------------------------------- Internal Functions
  138. //
  139. function
  140. printHelp (
  141. )
  142. /*++
  143. Routine Description:
  144. This routine prints the application usage.
  145. Arguments:
  146. None.
  147. Return Value:
  148. None.
  149. --*/
  150. {
  151. var commands;
  152. Core.print(usage);
  153. commands = enumerateCommands();
  154. Core.print("Valid commands are:");
  155. for (command in commands) {
  156. Core.print("%-20s %s" % [command.name, command.description]);
  157. }
  158. return;
  159. }
  160. if ((os.basename)(argv[0]).contains("santa")) {
  161. (os.exit)(main());
  162. }