Manifest.vala 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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, Paths.ensure_trailing_slash(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, Paths.ensure_trailing_slash(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, Paths.ensure_trailing_slash(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, Paths.ensure_trailing_slash(build_path), Paths.ensure_trailing_slash(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, Paths.ensure_trailing_slash(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, Paths.ensure_trailing_slash(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. var install_paths = paths.clone();
  346. install_paths.destination = install_path;
  347. base_path = install_paths.get_suggested_path_for_resource(resource.key);
  348. break;
  349. default:
  350. assert_not_reached();
  351. }
  352. var src = File.new_build_filename(base_path, resource.value.path ?? "");
  353. var dest = File.new_for_path(path);
  354. // Don't throw if an alternative format resource wasn't built
  355. var source_exists = src.query_exists();
  356. if(!source_exists) {
  357. throw new ManifestError.INVALID_FILE_PATH(@"Expected to find file listed in manifest at \"$(src.get_path())\", but no such file was found.");
  358. }
  359. // Don't copy an alternative format resource if it has the same path as the non-alternative resource
  360. if(source_exists && !dry_run) {
  361. if(dest.query_exists()) {
  362. dest.delete();
  363. }
  364. src.copy(dest, FileCopyFlags.ALL_METADATA, null, (c, t) => callback(resource.key, resources_installed, resource_count, (float)c / (float)t));
  365. }
  366. }
  367. else if(resource.value.file_type == Usm.ManifestFileType.DIRECTORY) {
  368. var dest = File.new_for_path(path);
  369. if(!dry_run) {
  370. dest.make_directory();
  371. }
  372. }
  373. else if(resource.value.file_type == Usm.ManifestFileType.SYMBOLIC_LINK) {
  374. var dest = File.new_for_path(path);
  375. if(!dry_run){
  376. dest.make_symbolic_link(resource.value.path ?? "");
  377. }
  378. }
  379. else {
  380. throw new TransactionError.INSTALL_ERROR(@"Could not understand resource key \"$(resource.key)\"");
  381. }
  382. callback(resource.key, resources_installed, resource_count, 1.0f);
  383. resources_installed++;
  384. }
  385. }
  386. public void remove_resources(Paths paths, ResourceProgressCallback callback) throws Error {
  387. var non_directories = provides.where(r => r.value.file_type != Usm.ManifestFileType.DIRECTORY).cache();
  388. var directories = provides.where(r => r.value.file_type == Usm.ManifestFileType.DIRECTORY).cache();
  389. var total_operations = non_directories.count() + directories.count();
  390. var current_operation = 0;
  391. // Delete files and symlinks first
  392. foreach (var resource in non_directories) {
  393. callback(resource.key, current_operation, total_operations, 0.0f);
  394. var path = paths.get_suggested_path_for_resource(resource.key);
  395. var file = File.new_for_path(path);
  396. if(file.query_exists()) {
  397. file.delete();
  398. }
  399. callback(resource.key, current_operation, total_operations, 1.0f);
  400. current_operation++;
  401. }
  402. // Delete directories last
  403. foreach (var resource in directories) {
  404. callback(resource.key, current_operation, total_operations, 0.0f);
  405. var path = paths.get_suggested_path_for_resource(resource.key);
  406. try {
  407. var file = File.new_for_path(path);
  408. if(file.query_exists()) {
  409. file.delete();
  410. }
  411. }
  412. catch(IOError.NOT_EMPTY e) {
  413. warning(@"Did not remove resource \"$path\": directory is not empty\n");
  414. }
  415. callback(resource.key, current_operation, total_operations, 1.0f);
  416. current_operation++;
  417. }
  418. }
  419. private void copy_directory(File source, File destination) throws Error {
  420. // Ensure destination directory exists
  421. if (!destination.query_exists()) {
  422. destination.make_directory_with_parents();
  423. }
  424. var enumerator = source.enumerate_children(FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, FileQueryInfoFlags.NONE);
  425. FileInfo file_info;
  426. while ((file_info = enumerator.next_file()) != null) {
  427. var source_child = source.get_child(file_info.get_name());
  428. var destination_child = destination.get_child(file_info.get_name());
  429. if (file_info.get_file_type() == FileType.DIRECTORY) {
  430. // Recursively copy subdirectories
  431. copy_directory(source_child, destination_child);
  432. } else {
  433. // Copy files
  434. source_child.copy(destination_child, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
  435. }
  436. }
  437. }
  438. }
  439. public enum InstallType {
  440. FRESH,
  441. UPGRADE,
  442. DOWNGRADE;
  443. public string to_string() {
  444. switch (this) {
  445. case InstallType.FRESH:
  446. return "fresh";
  447. case InstallType.UPGRADE:
  448. return "upgrade";
  449. case InstallType.DOWNGRADE:
  450. return "downgrade";
  451. default:
  452. assert_not_reached();
  453. }
  454. }
  455. public static InstallType from_string(string str) throws ManifestError {
  456. switch (str) {
  457. case "fresh":
  458. return InstallType.FRESH;
  459. case "upgrade":
  460. return InstallType.UPGRADE;
  461. case "downgrade":
  462. return InstallType.DOWNGRADE;
  463. default:
  464. throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown install type \"$str\".");
  465. }
  466. }
  467. }
  468. public enum RemoveType {
  469. FINAL,
  470. UPGRADE,
  471. DOWNGRADE;
  472. public string to_string() {
  473. switch (this) {
  474. case RemoveType.FINAL:
  475. return "final";
  476. case RemoveType.UPGRADE:
  477. return "upgrade";
  478. case RemoveType.DOWNGRADE:
  479. return "downgrade";
  480. default:
  481. assert_not_reached();
  482. }
  483. }
  484. public static RemoveType from_string(string str) throws ManifestError {
  485. switch (str) {
  486. case "final":
  487. return RemoveType.FINAL;
  488. case "upgrade":
  489. return RemoveType.UPGRADE;
  490. case "downgrade":
  491. return RemoveType.DOWNGRADE;
  492. default:
  493. throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown remove type \"$str\".");
  494. }
  495. }
  496. }
  497. public delegate void ProgressDelegate(float progress);
  498. public enum ManifestFlag {
  499. BUILD_IN_SOURCE_TREE,
  500. SET_MANIFEST_PROPERTY_ENVS,
  501. NINJA_STYLE_PROGRESS,
  502. SIMPLE_BUILD_ENVIRONMENT;
  503. public string to_string() {
  504. switch (this) {
  505. case ManifestFlag.BUILD_IN_SOURCE_TREE:
  506. return "buildInSourceTree";
  507. case ManifestFlag.SET_MANIFEST_PROPERTY_ENVS:
  508. return "setManifestPropertyEnvs";
  509. case ManifestFlag.NINJA_STYLE_PROGRESS:
  510. return "ninjaStyleProgress";
  511. case ManifestFlag.SIMPLE_BUILD_ENVIRONMENT:
  512. return "simpleBuildEnvironment";
  513. default:
  514. assert_not_reached();
  515. }
  516. }
  517. public static ManifestFlag from_string(string str) throws ManifestError {
  518. switch (str) {
  519. case "buildInSourceTree":
  520. return ManifestFlag.BUILD_IN_SOURCE_TREE;
  521. case "setManifestPropertyEnvs":
  522. return ManifestFlag.SET_MANIFEST_PROPERTY_ENVS;
  523. case "ninjaStyleProgress":
  524. return ManifestFlag.NINJA_STYLE_PROGRESS;
  525. case "simpleBuildEnvironment":
  526. return ManifestFlag.SIMPLE_BUILD_ENVIRONMENT;
  527. default:
  528. throw new ManifestError.INVALID_FLAG(@"Unknown flag \"$str\".");
  529. }
  530. }
  531. }
  532. }