build.ck 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. build.ck
  9. Abstract:
  10. This module implements the build command, which will build a package based
  11. on an input recipe.
  12. Author:
  13. Evan Green 3-Jul-2017
  14. Environment:
  15. Chalk
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. from getopt import gnuGetopt;
  21. import os;
  22. from santa.config import config;
  23. from santa.lib.build import Build;
  24. //
  25. // --------------------------------------------------------------------- Macros
  26. //
  27. //
  28. // ---------------------------------------------------------------- Definitions
  29. //
  30. //
  31. // ------------------------------------------------------ Data Type Definitions
  32. //
  33. //
  34. // ----------------------------------------------- Internal Function Prototypes
  35. //
  36. //
  37. // -------------------------------------------------------------------- Globals
  38. //
  39. var description = "Build a package from its sources";
  40. var shortOptions = "c:his:o:r:v";
  41. var longOptions = [
  42. "cross=",
  43. "help",
  44. "ignore-missing-deps",
  45. "output="
  46. "solo-step=",
  47. "run=",
  48. "verbose"
  49. ];
  50. var usage =
  51. "usage: santa build [options] <recipe.ck|build_number...>\n"
  52. "This command builds a package from source. The input parameter is either\n"
  53. "a path to a recipe file or a previously incomplete build number.\n"
  54. "Options are:\n"
  55. " -c, --cross=[arch-]os -- Cross compile (eg \"Minoca\" or "
  56. "\"x86_64-Minoca\"\n"
  57. " -i, --ignore-missing-deps -- Ignore missing dependencies\n"
  58. " -o, --output=dir -- Output packages to the specified directory\n"
  59. " -r, --run=step -- Run to the specified step and stop.\n"
  60. " -s, --solo-step=step -- Run only the specified step and stop.\n"
  61. " -v, --verbose -- Print out more information about what's going on.\n"
  62. " -h, --help -- Print this help text.\n";
  63. //
  64. // ------------------------------------------------------------------ Functions
  65. //
  66. function
  67. command (
  68. args
  69. )
  70. /*++
  71. Routine Description:
  72. This routine implements the build command.
  73. Arguments:
  74. args - Supplies the arguments to the function.
  75. Return Value:
  76. Returns an exit code.
  77. --*/
  78. {
  79. var argc;
  80. var build;
  81. var crossArch;
  82. var crossOs;
  83. var inputPath;
  84. var ignoreMissingDeps = false;
  85. var mode = "r";
  86. var name;
  87. var options = gnuGetopt(args[1...-1], shortOptions, longOptions);
  88. var output;
  89. var runTo;
  90. var soloStep;
  91. var startDirectory = (os.getcwd)();
  92. var status;
  93. var value;
  94. var verbose = config.getKey("core.verbose");
  95. args = options[1];
  96. argc = args.length();
  97. options = options[0];
  98. for (option in options) {
  99. name = option[0];
  100. value = option[1];
  101. if ((name == "-c") || (name == "--cross")) {
  102. crossOs = value.split("-", 1);
  103. if (crossOs.length() == 1) {
  104. crossOs = crossOs[0];
  105. } else {
  106. crossArch = crossOs[0];
  107. crossOs = crossOs[1];
  108. }
  109. } else if ((name == "-h") || (name == "--help")) {
  110. Core.print(usage);
  111. return 1;
  112. } else if ((name == "-i") || (name == "--ignore-missing-deps")) {
  113. ignoreMissingDeps = true;
  114. } else if ((name == "-o") || (name == "--output")) {
  115. output = value;
  116. } else if ((name == "-s") || (name == "--solo-step")) {
  117. soloStep = value;
  118. } else if ((name == "-r") || (name == "--run")) {
  119. runTo = value;
  120. } else if ((name == "-v") || (name == "--verbose")) {
  121. verbose = true;
  122. } else {
  123. Core.raise(ValueError("Invalid option '%s'" % name));
  124. }
  125. }
  126. if (args.length() < 1) {
  127. Core.raise(ValueError("Expected an input recipe path."));
  128. }
  129. //
  130. // Build each recipe.
  131. //
  132. for (arg in args) {
  133. try {
  134. arg = Int.fromString(arg);
  135. if (verbose) {
  136. Core.print("Resuming build: %d" % arg);
  137. }
  138. } except ValueError {
  139. if (verbose) {
  140. Core.print("Building recipe: %s" % arg);
  141. }
  142. }
  143. build = Build(arg);
  144. if (crossOs) {
  145. build.vars.os = crossOs;
  146. }
  147. if (crossArch) {
  148. build.vars.arch = crossArch;
  149. }
  150. if (output) {
  151. build.outdir = output;
  152. }
  153. build.ignoreMissingDeps = ignoreMissingDeps;
  154. Core.print("%s build %d" % [(arg is String) ? "starting" : "resuming",
  155. build.number]);
  156. if (verbose) {
  157. build.vars.verbose = verbose;
  158. }
  159. //
  160. // Run a single step directly if requested.
  161. //
  162. if (soloStep) {
  163. build.runStep(soloStep);
  164. //
  165. // Run up to a certain point if requested.
  166. //
  167. } else if (runTo) {
  168. while (build.step != runTo) {
  169. build.runStep(build.step);
  170. }
  171. //
  172. // Run to completion.
  173. //
  174. } else {
  175. build.run();
  176. }
  177. //
  178. // Return back to the original working directory in case the next
  179. // argument is a relative path.
  180. //
  181. (os.chdir)(startDirectory);
  182. }
  183. return 0;
  184. }
  185. //
  186. // --------------------------------------------------------- Internal Functions
  187. //