123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- using Invercargill;
- namespace Usm {
- public errordomain ManifestError {
- MISSING_FIELD,
- INVALID_VERSION,
- INVALID_LICENCE_CATEGORY,
- INVALID_RESOURCE_TYPE,
- INVALID_FILE_TYPE,
- INVALID_REMOVE_TYPE,
- INVALID_INSTALL_TYPE,
- }
- public class Manifest {
- public string name { get; set; }
- public string summary { get; set; }
- public Version version { get; set; }
- public Vector<Licence> licences { get; set; }
- public Dictionary<ResourceRef, ManifestFile> provides { get; set; }
- public Dependencies dependencies { get; set; }
- public Executables executables { get; set; }
- public string? markdown_path { get; set; }
- public string? url { get; set; }
- public Vector<string>? screenshot_paths { get; set; }
- public string? icon_path { get; set; }
- public string? metainfo_path { get; set; }
- public Git? git { get; set; }
- public Properties? extra_properties { get; set; }
- public static PropertyMapper<Manifest> get_mapper() {
- return PropertyMapper.build_for<Manifest>(cfg => {
- cfg.map<string>("name", o => o.name, (o, v) => o.name = v);
- cfg.map<string>("version", o => o.version.to_string(), (o, v) => o.version = new Version.from_string(v));
- cfg.map<string>("summary", o => o.summary, (o, v) => o.summary = v);
- cfg.map_many_with<Licence>("licences", o => o.licences, (o, v) => o.licences = v.to_vector(), Licence.get_mapper());
- cfg.map<Properties>("provides", o => o.map_from_provides_dict(), (o, v) => o.build_provides_dict(v));
- cfg.map_with<Dependencies>("depends", o => o.dependencies, (o, v) => o.dependencies = v, Dependencies.get_mapper());
- cfg.map_with<Executables>("execs", o => o.executables, (o, v) => o.executables = v, Executables.get_mapper());
- cfg.map<string>("md", o => o.markdown_path, (o, v) => o.markdown_path = v, false);
- cfg.map<string>("url", o => o.url, (o, v) => o.url = v, false);
- cfg.map_many<string>("screenshots", o => o.screenshot_paths, (o, v) => o.screenshot_paths = v.to_vector(), false);
- cfg.map<string>("icon", o => o.icon_path, (o, v) => o.icon_path = v, false);
- cfg.map<string>("metainfo", o => o.metainfo_path, (o, v) => o.metainfo_path = v, false);
- cfg.map_with<Git>("git", o => o.git, (o, v) => o.git = v, Git.get_mapper(), false);
- cfg.map<Properties>("extras", o => o.extra_properties, (o, v) => o.extra_properties = v, false);
- cfg.set_constructor(() => new Manifest());
- });
- }
- private void build_provides_dict(Properties obj) throws Error {
- provides = new Dictionary<ResourceRef, ManifestFile>();
- var mapper = ManifestFile.get_mapper();
- foreach (var pair in obj) {
- if(pair.value.assignable_to<string>()) {
- provides[new ResourceRef(pair.key)] = new ManifestFile.from_string(pair.value.as<string>());
- }
- else {
- provides[new ResourceRef(pair.key)] = mapper.materialise(obj);
- }
- }
- }
- private Properties map_from_provides_dict() {
- var dict = new PropertiesDictionary();
- var mapper = ManifestFile.get_mapper();
- foreach (var pair in provides) {
- try {
- dict.set_native<Properties>(pair.key.to_string(), mapper.map_from(pair.value));
- }
- catch(Error e) {
- assert_not_reached();
- }
- }
- return dict;
- }
-
- public Subprocess run_build(string build_path, Paths paths, SubprocessFlags flags) throws Error {
- var path = Path.build_filename(Environment.get_current_dir(), executables.build);
- paths.set_envs();
- var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
- return proc;
- }
- public Subprocess? run_rebuild(string build_path, SubprocessFlags flags) throws Error {
- if(executables.rebuild == null) {
- return null;
- }
- var path = Path.build_filename(Environment.get_current_dir(), executables.rebuild);
- var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
- return proc;
- }
- public Subprocess? run_acquire(SubprocessFlags flags) throws Error {
- if(executables.acquire == null) {
- return null;
- }
- var path = Path.build_filename(Environment.get_current_dir(), executables.acquire);
- var proc = new Subprocess.newv(new string[] { path }, flags);
- return proc;
- }
- public Subprocess? run_install(string build_path, InstallType type, SubprocessFlags flags) throws Error {
- if(executables.install == null) {
- return null;
- }
- var path = Path.build_filename(Environment.get_current_dir(), executables.install);
- var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
- return proc;
- }
- public Subprocess? run_remove(RemoveType type, SubprocessFlags flags) throws Error {
- if(executables.remove == null) {
- return null;
- }
- var path = Path.build_filename(Environment.get_current_dir(), executables.remove);
- var proc = new Subprocess.newv(new string[] { path, type.to_string() }, flags);
- return proc;
- }
-
- }
- public enum InstallType {
- FRESH,
- UPGRADE,
- DOWNGRADE;
- public string to_string() {
- switch (this) {
- case InstallType.FRESH:
- return "fresh";
- case InstallType.UPGRADE:
- return "upgrade";
- case InstallType.DOWNGRADE:
- return "downgrade";
- default:
- assert_not_reached();
- }
- }
- public static InstallType from_string(string str) throws ManifestError {
- switch (str) {
- case "fresh":
- return InstallType.FRESH;
- case "upgrade":
- return InstallType.UPGRADE;
- case "downgrade":
- return InstallType.DOWNGRADE;
- default:
- throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown install type \"$str\".");
- }
- }
- }
- public enum RemoveType {
- FINAL,
- UPGRADE,
- DOWNGRADE;
- public string to_string() {
- switch (this) {
- case RemoveType.FINAL:
- return "final";
- case RemoveType.UPGRADE:
- return "upgrade";
- case RemoveType.DOWNGRADE:
- return "downgrade";
- default:
- assert_not_reached();
- }
- }
- public static RemoveType from_string(string str) throws ManifestError {
- switch (str) {
- case "final":
- return RemoveType.FINAL;
- case "upgrade":
- return RemoveType.UPGRADE;
- case "downgrade":
- return RemoveType.DOWNGRADE;
- default:
- throw new ManifestError.INVALID_REMOVE_TYPE(@"Unknown remove type \"$str\".");
- }
- }
- }
- }
|