Manifest.vala 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. using Invercargill;
  2. using Invercargill.Mapping;
  3. using Invercargill.DataStructures;
  4. namespace Usm {
  5. public errordomain ManifestError {
  6. MISSING_FIELD,
  7. INVALID_VERSION,
  8. INVALID_LICENCE_CATEGORY,
  9. INVALID_RESOURCE_TYPE,
  10. INVALID_FILE_TYPE,
  11. INVALID_REMOVE_TYPE,
  12. INVALID_INSTALL_TYPE,
  13. INVALID_PACKAGE,
  14. INVALID_PATH_BASE,
  15. INVALID_FILE_PATH,
  16. INVALID_FLAG
  17. }
  18. public class Manifest {
  19. public string name { get; set; }
  20. public string summary { get; set; }
  21. public Version version { get; set; }
  22. public Vector<Licence> licences { get; set; }
  23. public Dictionary<ResourceRef, ManifestFile> provides { get; set; }
  24. public Dependencies dependencies { get; set; }
  25. public Executables executables { get; set; }
  26. public Set<ManifestFlag> flags { get; set; }
  27. public string? markdown_path { get; set; }
  28. public string? url { get; set; }
  29. public Vector<string>? screenshot_paths { get; set; }
  30. public string? icon_path { get; set; }
  31. public string? metainfo_path { get; set; }
  32. public Git? git { get; set; }
  33. public Properties? extra_properties { get; set; }
  34. public static PropertyMapper<Manifest> get_mapper() {
  35. return PropertyMapper.build_for<Manifest>(cfg => {
  36. cfg.map<string>("name", o => o.name, (o, v) => o.name = v);
  37. cfg.map<string>("version", o => o.version.to_string(), (o, v) => o.version = new Version.from_string(v));
  38. cfg.map<string>("summary", o => o.summary, (o, v) => o.summary = v);
  39. cfg.map_property_groups_with<Licence>("licences", o => o.licences, (o, v) => o.licences = v.to_vector(), Licence.get_mapper());
  40. cfg.map<Properties>("provides", o => o.map_from_provides_dict(), (o, v) => o.build_provides_dict(v));
  41. cfg.map_properties_with<Dependencies>("depends", o => o.dependencies, (o, v) => o.dependencies = v, Dependencies.get_mapper());
  42. cfg.map_properties_with<Executables>("execs", o => o.executables, (o, v) => o.executables = v, Executables.get_mapper());
  43. cfg.map_many<string>("flags", o => o.flags.select<string>(f => f.to_string()), (o, v) => o.flags = v.attempt_select<ManifestFlag>(f => ManifestFlag.from_string(f)).to_set());
  44. cfg.map<string>("md", o => o.markdown_path, (o, v) => o.markdown_path = v)
  45. .undefined_when(o => o.markdown_path == null)
  46. .when_undefined(o => o.markdown_path = null);
  47. cfg.map<string>("url", o => o.url, (o, v) => o.url = v)
  48. .undefined_when(o => o.url == null)
  49. .when_undefined(o => o.url = null);
  50. cfg.map_many<string>("screenshots", o => o.screenshot_paths, (o, v) => o.screenshot_paths = v.to_vector())
  51. .undefined_when(o => o.screenshot_paths == null)
  52. .when_undefined(o => o.screenshot_paths = null);
  53. cfg.map<string>("icon", o => o.icon_path, (o, v) => o.icon_path = v)
  54. .undefined_when(o => o.icon_path == null)
  55. .when_undefined(o => o.icon_path = null);
  56. cfg.map<string>("metainfo", o => o.metainfo_path, (o, v) => o.metainfo_path = v)
  57. .undefined_when(o => o.metainfo_path == null)
  58. .when_undefined(o => o.metainfo_path = null);
  59. // cfg.map_with<Git>("git", o => o.git, (o, v) => o.git = v, Git.get_mapper(), false);
  60. cfg.map<Properties>("extras", o => o.extra_properties, (o, v) => o.extra_properties = v)
  61. .undefined_when(o => o.extra_properties == null)
  62. .when_undefined(o => o.extra_properties = null);
  63. cfg.set_constructor(() => new Manifest());
  64. });
  65. }
  66. public Manifest.from_file(string path) throws Error {
  67. var element = new InvercargillJson.JsonElement.from_file(path);
  68. Manifest.get_mapper().map_into(this, element.as<Invercargill.Properties>());
  69. }
  70. public Manifest.from_package(string path) throws Error {
  71. var archive = new Archive.Read();
  72. archive.support_format_tar();
  73. archive.support_filter_xz();
  74. var result = archive.open_filename(path, 10240);
  75. if(result != Archive.Result.OK) {
  76. throw new ManifestError.INVALID_PACKAGE("Could not read archive");
  77. }
  78. unowned Archive.Entry entry;
  79. while(archive.next_header(out entry) == Archive.Result.OK) {
  80. var path_name = entry.pathname();
  81. if(path_name != "./MANIFEST.usm") {
  82. continue;
  83. }
  84. var manifest_blob = new ByteComposition();
  85. uint8[] buffer;
  86. Posix.off_t offset;
  87. while (archive.read_data_block (out buffer, out offset) == Archive.Result.OK) {
  88. manifest_blob.append_byte_array(buffer[offset:]);
  89. }
  90. var element = new InvercargillJson.JsonElement.from_string(manifest_blob.to_raw_string());
  91. Manifest.get_mapper().map_into(this, element.as<Invercargill.Properties>());
  92. return;
  93. }
  94. throw new ManifestError.INVALID_PACKAGE("MANIFEST.usm not found within archive");
  95. }
  96. private void build_provides_dict(Properties obj) throws Error {
  97. provides = new Dictionary<ResourceRef, ManifestFile>();
  98. var mapper = ManifestFile.get_mapper();
  99. foreach (var pair in obj) {
  100. ManifestFile file;
  101. if(pair.value.assignable_to<string>()) {
  102. file = new ManifestFile.from_string(pair.value.as<string>());
  103. }
  104. else {
  105. file = mapper.materialise(pair.value.as<Properties>());
  106. }
  107. // Validate the ManifestFile after creation
  108. file.validate();
  109. provides[new ResourceRef(pair.key)] = file;
  110. }
  111. }
  112. private Properties map_from_provides_dict() {
  113. var dict = new PropertyDictionary();
  114. var mapper = ManifestFile.get_mapper();
  115. foreach (var pair in provides) {
  116. try {
  117. // Handle special case: when pathBase is as-expected, path is empty, and type is reg
  118. // output string "as-expected" instead of full JSON object
  119. if(pair.value.path_base == ManifestFilePathBase.AS_EXPECTED &&
  120. pair.value.path == "" &&
  121. pair.value.file_type == ManifestFileType.REGULAR) {
  122. dict.set_native<string>(pair.key.to_string(), "as-expected");
  123. } else {
  124. dict.set_native<Properties>(pair.key.to_string(), mapper.map_from(pair.value));
  125. }
  126. }
  127. catch(Error e) {
  128. assert_not_reached();
  129. }
  130. }
  131. return dict;
  132. }
  133. public Subprocess run_build(string build_path, Paths paths, SubprocessFlags flags, ProgressDelegate? progress_delegate = null) throws Error {
  134. // Handle SIMPLE_BUILD_ENVIRONMENT flag
  135. string original_working_dir = Environment.get_current_dir();
  136. string working_dir = original_working_dir;
  137. string effective_build_path = build_path;
  138. if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
  139. // Copy the full source tree to the build directory
  140. var source_dir = File.new_for_path(working_dir);
  141. var build_dir = File.new_for_path(build_path);
  142. // Copy all files from source to build directory
  143. copy_directory(source_dir, build_dir);
  144. // Use build directory as working directory
  145. working_dir = build_path;
  146. }
  147. var path = Path.build_filename(working_dir, executables.build);
  148. // Change to the working directory for subprocess execution
  149. Environment.set_current_dir(working_dir);
  150. paths.set_envs();
  151. // Check if NINJA_STYLE_PROGRESS flag is set and progress delegate is provided
  152. if (this.flags.contains(ManifestFlag.NINJA_STYLE_PROGRESS) && progress_delegate != null) {
  153. // Set up subprocess to capture STDOUT for progress parsing
  154. var modified_flags = flags;
  155. // Ensure STDOUT is not silenced when we need to parse progress
  156. if ((modified_flags & SubprocessFlags.STDOUT_SILENCE) != 0) {
  157. modified_flags = modified_flags & ~SubprocessFlags.STDOUT_SILENCE;
  158. }
  159. modified_flags = modified_flags | SubprocessFlags.STDOUT_PIPE;
  160. var proc = new Subprocess.newv(new string[] { path, effective_build_path }, modified_flags);
  161. // Start a new thread to monitor STDOUT for progress information
  162. ThreadFunc<void> progress_thread_func = () => {
  163. try {
  164. var stdout_pipe = proc.get_stdout_pipe();
  165. if (stdout_pipe != null) {
  166. var dis = new DataInputStream(stdout_pipe);
  167. string line;
  168. // Read lines from STDOUT until the process ends
  169. while ((line = dis.read_line(null)) != null) {
  170. // Look for Ninja progress pattern: "[x/x] "
  171. if (line.has_prefix("[")) {
  172. var end_bracket = line.index_of("]");
  173. if (end_bracket > 1) {
  174. var progress_str = line.substring(1, end_bracket - 1);
  175. var parts = progress_str.split("/");
  176. if (parts.length == 2) {
  177. int current_task = 0;
  178. int total_tasks = 0;
  179. // Parse the current and total task numbers
  180. if (int.try_parse(parts[0], out current_task) &&
  181. int.try_parse(parts[1], out total_tasks) &&
  182. total_tasks > 0) {
  183. // Calculate progress as a float between 0.0 and 1.0
  184. float progress = (float)current_task / (float)total_tasks;
  185. // Ensure progress is within valid bounds
  186. progress = float.max(0.0f, float.min(1.0f, progress));
  187. // Call the progress delegate with the calculated progress
  188. progress_delegate(progress);
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. } catch (Error e) {
  196. // Log any errors during progress monitoring but don't fail the build
  197. warning(@"Error monitoring build progress: $(e.message)");
  198. }
  199. };
  200. try {
  201. // Start the progress monitoring thread
  202. new Thread<void>(null, progress_thread_func);
  203. } catch (Error e) {
  204. // If we can't start the thread, log a warning but continue with the build
  205. warning(@"Failed to start progress monitoring thread: $(e.message)");
  206. }
  207. // Restore original working directory after subprocess completes
  208. Environment.set_current_dir(original_working_dir);
  209. return proc;
  210. } else {
  211. var proc = new Subprocess.newv(new string[] { path, effective_build_path }, flags);
  212. // Restore original working directory after subprocess completes
  213. Environment.set_current_dir(original_working_dir);
  214. return proc;
  215. }
  216. }
  217. public Subprocess? run_rebuild(string build_path, SubprocessFlags flags) throws Error {
  218. if(executables.rebuild == null) {
  219. return null;
  220. }
  221. string original_working_dir = Environment.get_current_dir();
  222. string working_dir = original_working_dir;
  223. if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
  224. working_dir = build_path;
  225. }
  226. var path = Path.build_filename(working_dir, executables.rebuild);
  227. // Change to the working directory for subprocess execution
  228. Environment.set_current_dir(working_dir);
  229. var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
  230. // Restore original working directory after subprocess completes
  231. Environment.set_current_dir(original_working_dir);
  232. return proc;
  233. }
  234. public Subprocess? run_acquire(SubprocessFlags flags) throws Error {
  235. if(executables.acquire == null) {
  236. return null;
  237. }
  238. string working_dir = Environment.get_current_dir();
  239. // Note: acquire doesn't have a build_path parameter, so it can't use SIMPLE_BUILD_ENVIRONMENT
  240. var path = Path.build_filename(working_dir, executables.acquire);
  241. var proc = new Subprocess.newv(new string[] { path }, flags);
  242. return proc;
  243. }
  244. public Subprocess? run_install(string build_path, string install_path, Paths paths, InstallType type, SubprocessFlags flags) throws Error {
  245. if(executables.install == null) {
  246. return null;
  247. }
  248. string original_working_dir = Environment.get_current_dir();
  249. string working_dir = original_working_dir;
  250. if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
  251. working_dir = build_path;
  252. }
  253. var path = Path.build_filename(working_dir, executables.install);
  254. // Override destination environment variable
  255. var new_paths = paths.clone();
  256. new_paths.destination = install_path;
  257. // Change to the working directory for subprocess execution
  258. Environment.set_current_dir(working_dir);
  259. new_paths.set_envs();
  260. var proc = new Subprocess.newv(new string[] { path, build_path, install_path, type.to_string() }, flags);
  261. // Restore original working directory after subprocess completes
  262. Environment.set_current_dir(original_working_dir);
  263. return proc;
  264. }
  265. public Subprocess? run_post_install(string build_path, InstallType type, SubprocessFlags flags) throws Error {
  266. if(executables.post_install == null) {
  267. return null;
  268. }
  269. string original_working_dir = Environment.get_current_dir();
  270. string working_dir = original_working_dir;
  271. if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
  272. working_dir = build_path;
  273. }
  274. var path = Path.build_filename(working_dir, executables.post_install);
  275. // Change to the working directory for subprocess execution
  276. Environment.set_current_dir(working_dir);
  277. var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
  278. // Restore original working directory after subprocess completes
  279. Environment.set_current_dir(original_working_dir);
  280. return proc;
  281. }
  282. public Subprocess? run_remove(RemoveType type, SubprocessFlags flags) throws Error {
  283. if(executables.remove == null) {
  284. return null;
  285. }
  286. string working_dir = Environment.get_current_dir();
  287. // Note: remove doesn't have a build_path parameter, so it can't use SIMPLE_BUILD_ENVIRONMENT
  288. var path = Path.build_filename(working_dir, executables.remove);
  289. var proc = new Subprocess.newv(new string[] { path, type.to_string() }, flags);
  290. return proc;
  291. }
  292. public Subprocess? run_test(string build_path, SubprocessFlags flags) throws Error {
  293. if(executables.test == null) {
  294. return null;
  295. }
  296. string original_working_dir = Environment.get_current_dir();
  297. string working_dir = original_working_dir;
  298. if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
  299. working_dir = build_path;
  300. }
  301. var path = Path.build_filename(working_dir, executables.test);
  302. // Change to the working directory for subprocess execution
  303. Environment.set_current_dir(working_dir);
  304. var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
  305. // Restore original working directory after subprocess completes
  306. Environment.set_current_dir(original_working_dir);
  307. return proc;
  308. }
  309. public delegate void ResourceProgressCallback(ResourceRef resource, uint current_resource, uint total_resources, float resource_frac);
  310. public void install_resources(string source_path, string build_path, string? install_path, Paths paths, ResourceProgressCallback callback, bool dry_run = false) throws Error {
  311. // Install each resource speficied by the manifest
  312. var resource_count = provides.count();
  313. var resources_installed = 0;
  314. // Install from shortest path to longest path, to ensure directories are created before children
  315. var install_order = provides.sort((a, b) => paths.get_suggested_path_for_resource(a.key).length - paths.get_suggested_path_for_resource(b.key).length);
  316. foreach (var resource in install_order) {
  317. callback(resource.key, resources_installed, resource_count, 0.0f);
  318. var path = paths.get_suggested_path_for_resource(resource.key);
  319. if(resource.key.resource_type == ResourceType.TAG) {
  320. // Ensure parent directories are created first
  321. var parent_dir = File.new_for_path(Path.get_basename(path));
  322. if(!parent_dir.query_exists() && !dry_run) {
  323. parent_dir.make_directory_with_parents();
  324. }
  325. }
  326. if(resource.value.file_type == Usm.ManifestFileType.REGULAR) {
  327. var base_path = "";
  328. switch (resource.value.path_base) {
  329. case ManifestFilePathBase.BUILD:
  330. base_path = build_path;
  331. break;
  332. case ManifestFilePathBase.SOURCE:
  333. base_path = source_path;
  334. break;
  335. case ManifestFilePathBase.INSTALL:
  336. if(install_path == null) {
  337. throw new ManifestError.INVALID_FILE_PATH("Install path was not provided");
  338. }
  339. base_path = install_path;
  340. break;
  341. case ManifestFilePathBase.AS_EXPECTED:
  342. if(install_path == null) {
  343. throw new ManifestError.INVALID_FILE_PATH("Install path was not provided");
  344. }
  345. base_path = Path.build_filename(install_path, paths.get_suggested_path_for_resource(resource.key));
  346. break;
  347. default:
  348. assert_not_reached();
  349. }
  350. var src = File.new_build_filename(base_path, resource.value.path ?? "");
  351. var dest = File.new_for_path(path);
  352. if(!src.query_exists()) {
  353. throw new ManifestError.INVALID_FILE_PATH(@"Expected to find file listed in manifest at \"$(src.get_path())\", but no such file was found.");
  354. }
  355. if(!dry_run) {
  356. src.copy(dest, FileCopyFlags.OVERWRITE, null, (c, t) => callback(resource.key, resources_installed, resource_count, (float)c / (float)t));
  357. }
  358. }
  359. else if(resource.value.file_type == Usm.ManifestFileType.DIRECTORY) {
  360. var dest = File.new_for_path(path);
  361. if(!dry_run) {
  362. dest.make_directory();
  363. }
  364. }
  365. else if(resource.value.file_type == Usm.ManifestFileType.SYMBOLIC_LINK) {
  366. var dest = File.new_for_path(path);
  367. if(!dry_run){
  368. dest.make_symbolic_link(resource.value.path ?? "");
  369. }
  370. }
  371. else {
  372. throw new TransactionError.INSTALL_ERROR(@"Could not understand resource key \"$(resource.key)\"");
  373. }
  374. callback(resource.key, resources_installed, resource_count, 1.0f);
  375. resources_installed++;
  376. }
  377. }
  378. public void remove_resources(Paths paths, ResourceProgressCallback callback) throws Error {
  379. var non_directories = provides.where(r => r.value.file_type != Usm.ManifestFileType.DIRECTORY).cache();
  380. var directories = provides.where(r => r.value.file_type == Usm.ManifestFileType.DIRECTORY).cache();
  381. var total_operations = non_directories.count() + directories.count();
  382. var current_operation = 0;
  383. // Delete files and symlinks first
  384. foreach (var resource in non_directories) {
  385. callback(resource.key, current_operation, total_operations, 0.0f);
  386. var path = paths.get_suggested_path_for_resource(resource.key);
  387. var file = File.new_for_path(path);
  388. if(file.query_exists()) {
  389. file.delete();
  390. }
  391. callback(resource.key, current_operation, total_operations, 1.0f);
  392. current_operation++;
  393. }
  394. // Delete directories last
  395. foreach (var resource in directories) {
  396. callback(resource.key, current_operation, total_operations, 0.0f);
  397. var path = paths.get_suggested_path_for_resource(resource.key);
  398. try {
  399. var file = File.new_for_path(path);
  400. if(file.query_exists()) {
  401. file.delete();
  402. }
  403. }
  404. catch(IOError.NOT_EMPTY e) {
  405. warning(@"Did not remove resource \"$path\": directory is not empty\n");
  406. }
  407. callback(resource.key, current_operation, total_operations, 1.0f);
  408. current_operation++;
  409. }
  410. }
  411. private void copy_directory(File source, File destination) throws Error {
  412. // Ensure destination directory exists
  413. if (!destination.query_exists()) {
  414. destination.make_directory_with_parents();
  415. }
  416. var enumerator = source.enumerate_children(FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, FileQueryInfoFlags.NONE);
  417. FileInfo file_info;
  418. while ((file_info = enumerator.next_file()) != null) {
  419. var source_child = source.get_child(file_info.get_name());
  420. var destination_child = destination.get_child(file_info.get_name());
  421. if (file_info.get_file_type() == FileType.DIRECTORY) {
  422. // Recursively copy subdirectories
  423. copy_directory(source_child, destination_child);
  424. } else {
  425. // Copy files
  426. source_child.copy(destination_child, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
  427. }
  428. }
  429. }
  430. }
  431. public enum InstallType {
  432. FRESH,
  433. UPGRADE,
  434. DOWNGRADE;
  435. public string to_string() {
  436. switch (this) {
  437. case InstallType.FRESH:
  438. return "fresh";
  439. case InstallType.UPGRADE:
  440. return "upgrade";
  441. case InstallType.DOWNGRADE:
  442. return "downgrade";
  443. default:
  444. assert_not_reached();
  445. }
  446. }
  447. public static InstallType from_string(string str) throws ManifestError {
  448. switch (str) {
  449. case "fresh":
  450. return InstallType.FRESH;
  451. case "upgrade":
  452. return InstallType.UPGRADE;
  453. case "downgrade":
  454. return InstallType.DOWNGRADE;
  455. default:
  456. throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown install type \"$str\".");
  457. }
  458. }
  459. }
  460. public enum RemoveType {
  461. FINAL,
  462. UPGRADE,
  463. DOWNGRADE;
  464. public string to_string() {
  465. switch (this) {
  466. case RemoveType.FINAL:
  467. return "final";
  468. case RemoveType.UPGRADE:
  469. return "upgrade";
  470. case RemoveType.DOWNGRADE:
  471. return "downgrade";
  472. default:
  473. assert_not_reached();
  474. }
  475. }
  476. public static RemoveType from_string(string str) throws ManifestError {
  477. switch (str) {
  478. case "final":
  479. return RemoveType.FINAL;
  480. case "upgrade":
  481. return RemoveType.UPGRADE;
  482. case "downgrade":
  483. return RemoveType.DOWNGRADE;
  484. default:
  485. throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown remove type \"$str\".");
  486. }
  487. }
  488. }
  489. public delegate void ProgressDelegate(float progress);
  490. public enum ManifestFlag {
  491. BUILD_IN_SOURCE_TREE,
  492. SET_MANIFEST_PROPERTY_ENVS,
  493. NINJA_STYLE_PROGRESS,
  494. SIMPLE_BUILD_ENVIRONMENT;
  495. public string to_string() {
  496. switch (this) {
  497. case ManifestFlag.BUILD_IN_SOURCE_TREE:
  498. return "buildInSourceTree";
  499. case ManifestFlag.SET_MANIFEST_PROPERTY_ENVS:
  500. return "setManifestPropertyEnvs";
  501. case ManifestFlag.NINJA_STYLE_PROGRESS:
  502. return "ninjaStyleProgress";
  503. case ManifestFlag.SIMPLE_BUILD_ENVIRONMENT:
  504. return "simpleBuildEnvironment";
  505. default:
  506. assert_not_reached();
  507. }
  508. }
  509. public static ManifestFlag from_string(string str) throws ManifestError {
  510. switch (str) {
  511. case "buildInSourceTree":
  512. return ManifestFlag.BUILD_IN_SOURCE_TREE;
  513. case "setManifestPropertyEnvs":
  514. return ManifestFlag.SET_MANIFEST_PROPERTY_ENVS;
  515. case "ninjaStyleProgress":
  516. return ManifestFlag.NINJA_STYLE_PROGRESS;
  517. case "simpleBuildEnvironment":
  518. return ManifestFlag.SIMPLE_BUILD_ENVIRONMENT;
  519. default:
  520. throw new ManifestError.INVALID_FLAG(@"Unknown flag \"$str\".");
  521. }
  522. }
  523. }
  524. }