void DeserializeDubPrjDependencies(JSONObject j, DubBuildSettings settings) { foreach (var kv in j.Properties) { var depName = kv.Key; var depVersion = string.Empty; var depPath = string.Empty; if (kv.Value is JSONValueLeaf) depVersion = (kv.Value as JSONValueLeaf).Value; else if (kv.Value is JSONObject) { foreach (var kvv in (kv.Value as JSONObject).Properties) { switch (kvv.Key) { case "version": depVersion = ExpectJsonStringValue (kvv.Value, "version"); break; case "path": depPath = ExpectJsonStringValue (kvv.Value, "path"); break; } } } else throw new InvalidDataException ("Error while deserializing dub project dependency"); settings.dependencies[depName] = new DubProjectDependency { Name = depName, Version = depVersion, Path = depPath }; } }
public override void CopyFrom(ItemConfiguration conf) { var cfg = conf as DubProjectConfiguration; if (cfg != null) { BuildSettings = cfg.BuildSettings; } base.CopyFrom (conf); }
void DeserializeDubPrjDependencies(JSONObject j, DubBuildSettings settings) { foreach (var kv in j.Properties) { var depName = kv.Key; var depVersion = string.Empty; var depPath = string.Empty; if (kv.Value is JSONValueLeaf) { depVersion = (kv.Value as JSONValueLeaf).Value; } else if (kv.Value is JSONObject) { foreach (var kvv in (kv.Value as JSONObject).Properties) { switch (kvv.Key) { case "version": depVersion = ExpectJsonStringValue(kvv.Value, "version"); break; case "path": depPath = ExpectJsonStringValue(kvv.Value, "path"); break; } } } else { throw new InvalidDataException("Error while deserializing dub project dependency"); } settings.dependencies[depName] = new DubProjectDependency { Name = depName, Version = depVersion, Path = depPath }; } }
private static void HandleDubSettingsConditionExtraction(List <string> versions, DubBuildSettings buildSets) { List <DubBuildSetting> sets; if (buildSets == null || !buildSets.TryGetValue(DubBuildSettings.VersionsProperty, out sets)) { return; } foreach (var set in sets) { if (set.Values != null) { foreach (var ver in set.Values) { if (!string.IsNullOrWhiteSpace(ver) && !versions.Contains(ver)) { versions.Add(ver); } } } } }
private static void HandleDubSettingsConditionExtraction(List<string> versions, DubBuildSettings buildSets) { List<DubBuildSetting> sets; if(buildSets == null || !buildSets.TryGetValue(DubBuildSettings.VersionsProperty, out sets)) return; foreach (var set in sets) if (set.Values != null) foreach (var ver in set.Values) if (!string.IsNullOrWhiteSpace(ver) && !versions.Contains(ver)) versions.Add(ver); }
bool TryDeserializeBuildSetting(DubBuildSettings cfg, string propName, JSONThing j) { var settingIdentifier = propName.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (settingIdentifier.Length < 1) { return(false); } propName = settingIdentifier[0] = settingIdentifier[0].ToLowerInvariant(); DubBuildSetting sett; switch (propName) { case "dependencies": DeserializeDubPrjDependencies(ExpectJsonObject(j, propName), cfg); return(true); case "targettype": case "targetname": case "targetpath": case "workingdirectory": case "mainsourcefile": sett = new DubBuildSetting { Name = propName, Values = new[] { ExpectJsonStringValue(j, propName) } }; break; case "subconfigurations": foreach (var kv in ExpectJsonObject(j, propName).Properties) { cfg.subConfigurations[kv.Key] = ExpectJsonStringValue(kv.Value, kv.Key); } return(true); case "sourcefiles": case "sourcepaths": case "excludedsourcefiles": case "versions": case "debugversions": case "importpaths": case "stringimportpaths": var values = new List <string> (); foreach (var i in ExpectJsonArray(j, propName).Items) { values.Add(ExpectJsonStringValue(i, propName)); } sett = new DubBuildSetting { Name = propName, Values = values.ToArray() }; for (int i = 1; i < settingIdentifier.Length; i++) { var pn = settingIdentifier[i].ToLowerInvariant(); if (sett.OperatingSystem == null && DubBuildSettings.OsVersions.Contains(pn)) { sett.OperatingSystem = pn; } else if (sett.Architecture == null && DubBuildSettings.Architectures.Contains(pn)) { sett.Architecture = pn; } else { sett.Compiler = pn; } } break; default: return(false); } List <DubBuildSetting> setts; if (!cfg.TryGetValue(settingIdentifier[0], out setts)) { cfg.Add(settingIdentifier[0], setts = new List <DubBuildSetting>()); } setts.Add(sett); return(true); }
void InterpretBuildSetting(SDLDeclaration decl, DubBuildSettings settings) { var propName = decl.Name.ToLowerInvariant(); DubBuildSetting sett = null; switch (propName) { case "dependency": var depName = ExtractFirstAttribute(decl); var depVersion = ExtractFirstAttribute(decl, "version"); var depPath = ExtractFirstAttribute(decl, "path"); if (!string.IsNullOrWhiteSpace(depName)) settings.dependencies[depName] = new DubProjectDependency { Name = depName, Path = depPath, Version = depVersion }; break; case "targettype": case "targetname": case "targetpath": case "workingdirectory": case "mainsourcefile": if (decl.Attributes.Length >= 1) { sett = new DubBuildSetting { Name = propName, Values = new[] { ExtractFirstAttribute(decl) } }; } break; case "subconfiguration": if (decl.Attributes.Length >= 2) { var subConfigName = decl.Attributes[0].Item2; if (!string.IsNullOrWhiteSpace(subConfigName)) settings.subConfigurations[subConfigName] = decl.Attributes[1].Item2; } break; case "sourcefiles": case "sourcepaths": case "excludedsourcefiles": case "versions": case "debugversions": case "importpaths": case "stringimportpaths": sett = new DubBuildSetting(); sett.Values = ExtractUnnamedAttributes(decl).ToArray(); var platformConstraints = ExtractFirstAttribute(decl, "platform").Split('-'); if (platformConstraints.Length > 0) { foreach (var constraint in platformConstraints) { var pn = constraint.ToLowerInvariant(); if (sett.OperatingSystem == null && DubBuildSettings.OsVersions.Contains(pn)) sett.OperatingSystem = pn; else if (sett.Architecture == null && DubBuildSettings.Architectures.Contains(pn)) sett.Architecture = pn; else sett.Compiler = pn; } } break; } if (sett != null) { List<DubBuildSetting> setts; if (!settings.TryGetValue(propName, out setts)) settings.Add(propName, setts = new List<DubBuildSetting>()); setts.Add(sett); } }
bool TryDeserializeBuildSetting(DubBuildSettings cfg, JsonReader j) { if (!(j.Value is string)) return false; var settingIdentifier = (j.Value as string).Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (settingIdentifier.Length < 1) return false; var propName = settingIdentifier[0] = settingIdentifier[0].ToLowerInvariant(); DubBuildSetting sett = null; switch (propName) { case "dependencies": j.Read(); DeserializeDubPrjDependencies(j, cfg); break; case "targettype": case "targetname": case "targetpath": case "workingdirectory": case "mainsourcefile": j.Read(); if (j.TokenType == JsonToken.String) { sett = new DubBuildSetting { Name = propName, Values = new[] { j.Value as string } }; } break; case "subconfigurations": j.Read(); var configurations = (new JsonSerializer()).Deserialize<Dictionary<string, string>>(j); foreach (var kv in configurations) cfg.subConfigurations[kv.Key] = kv.Value; break; case "sourcefiles": case "sourcepaths": case "excludedsourcefiles": case "versions": case "debugversions": case "importpaths": case "stringimportpaths": j.Read(); if (j.TokenType == JsonToken.StartArray) { sett = new DubBuildSetting { Name = propName, Values = (new JsonSerializer()).Deserialize<string[]>(j) }; for (int i = 1; i < settingIdentifier.Length; i++) { var pn = settingIdentifier[i].ToLowerInvariant(); if (sett.OperatingSystem == null && DubBuildSettings.OsVersions.Contains(pn)) sett.OperatingSystem = pn; else if (sett.Architecture == null && DubBuildSettings.Architectures.Contains(pn)) sett.Architecture = pn; else sett.Compiler = pn; } } break; default: j.Skip(); return false; } if (sett != null) { List<DubBuildSetting> setts; if (!cfg.TryGetValue(settingIdentifier[0], out setts)) cfg.Add(settingIdentifier[0], setts = new List<DubBuildSetting>()); setts.Add(sett); } return true; }
void DeserializeDubPrjDependencies(JsonReader j, DubBuildSettings settings) { while (j.Read() && j.TokenType != JsonToken.EndObject) { if (j.TokenType == JsonToken.PropertyName) { var depName = j.Value as string; string depVersion = null; string depPath = null; if (!j.Read()) throw new JsonReaderException("Found EOF when parsing project dependency"); if (j.TokenType == JsonToken.StartObject) { while (j.Read() && j.TokenType != JsonToken.EndObject) { if (j.TokenType == JsonToken.PropertyName) { switch (j.Value as string) { case "version": depVersion = j.ReadAsString(); break; case "path": depPath = j.ReadAsString(); break; } } } } else if (j.TokenType == JsonToken.String) depVersion = j.Value as string; settings.dependencies[depName] = new DubProjectDependency { Name = depName, Version = depVersion, Path = depPath }; } } }
bool TryDeserializeBuildSetting(DubBuildSettings cfg, string propName, JSONThing j) { var settingIdentifier = propName.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (settingIdentifier.Length < 1) return false; propName = settingIdentifier[0] = settingIdentifier[0].ToLowerInvariant(); DubBuildSetting sett; switch (propName) { case "dependencies": DeserializeDubPrjDependencies(ExpectJsonObject(j, propName), cfg); return true; case "targettype": case "targetname": case "targetpath": case "workingdirectory": case "mainsourcefile": sett = new DubBuildSetting { Name = propName, Values = new[] { ExpectJsonStringValue(j, propName) } }; break; case "subconfigurations": foreach (var kv in ExpectJsonObject(j, propName).Properties) cfg.subConfigurations[kv.Key] = ExpectJsonStringValue(kv.Value, kv.Key); return true; case "sourcefiles": case "sourcepaths": case "excludedsourcefiles": case "versions": case "debugversions": case "importpaths": case "stringimportpaths": var values = new List<string> (); foreach (var i in ExpectJsonArray(j, propName).Items) values.Add (ExpectJsonStringValue(i, propName)); sett = new DubBuildSetting { Name = propName, Values = values.ToArray() }; for (int i = 1; i < settingIdentifier.Length; i++) { var pn = settingIdentifier[i].ToLowerInvariant(); if (sett.OperatingSystem == null && DubBuildSettings.OsVersions.Contains(pn)) sett.OperatingSystem = pn; else if (sett.Architecture == null && DubBuildSettings.Architectures.Contains(pn)) sett.Architecture = pn; else sett.Compiler = pn; } break; default: return false; } List<DubBuildSetting> setts; if (!cfg.TryGetValue(settingIdentifier[0], out setts)) cfg.Add(settingIdentifier[0], setts = new List<DubBuildSetting>()); setts.Add(sett); return true; }
void InterpretBuildSetting(SDLDeclaration decl, DubBuildSettings settings) { var propName = decl.Name.ToLowerInvariant(); DubBuildSetting sett = null; switch (propName) { case "dependency": var depName = ExtractFirstAttribute(decl); var depVersion = ExtractFirstAttribute(decl, "version"); var depPath = ExtractFirstAttribute(decl, "path"); if (!string.IsNullOrWhiteSpace(depName)) { settings.dependencies[depName] = new DubProjectDependency { Name = depName, Path = depPath, Version = depVersion } } ; break; case "targettype": case "targetname": case "targetpath": case "workingdirectory": case "mainsourcefile": if (decl.Attributes.Length >= 1) { sett = new DubBuildSetting { Name = propName, Values = new[] { ExtractFirstAttribute(decl) } }; } break; case "subconfiguration": if (decl.Attributes.Length >= 2) { var subConfigName = decl.Attributes[0].Item2; if (!string.IsNullOrWhiteSpace(subConfigName)) { settings.subConfigurations[subConfigName] = decl.Attributes[1].Item2; } } break; case "sourcefiles": case "sourcepaths": case "excludedsourcefiles": case "versions": case "debugversions": case "importpaths": case "stringimportpaths": sett = new DubBuildSetting(); sett.Values = ExtractUnnamedAttributes(decl).ToArray(); var platformConstraints = ExtractFirstAttribute(decl, "platform").Split('-'); if (platformConstraints.Length > 0) { foreach (var constraint in platformConstraints) { var pn = constraint.ToLowerInvariant(); if (sett.OperatingSystem == null && DubBuildSettings.OsVersions.Contains(pn)) { sett.OperatingSystem = pn; } else if (sett.Architecture == null && DubBuildSettings.Architectures.Contains(pn)) { sett.Architecture = pn; } else { sett.Compiler = pn; } } } break; } if (sett != null) { List <DubBuildSetting> setts; if (!settings.TryGetValue(propName, out setts)) { settings.Add(propName, setts = new List <DubBuildSetting>()); } setts.Add(sett); } }