bool AddNamed(int aid, Result r, Fingerprint fp, int index_into_values, IWarningLogger logger) { if (aid < 0 || aid >= args.Length) { string s = String.Format("Trying to add {0} to nonexistant " + "argument ID {1}.", r, aid); logger.Error(2042, s, r.ToString()); return(true); } Result subres = CompositeResult.FindCompatible(r, args[aid].Type); if (subres == null) { string err = String.Format("Argument value should be of type {0}, but " + "its type is {1}", args[aid].Type, r.GetType()); logger.Error(2036, err, r.ToString()); return(true); } if (subres == r) { args[aid].AddResult(r, fp, index_into_values); } else { // FIXME: the FP is really invalid, right? args[aid].AddResult(r, null, index_into_values); } return(false); }
public bool ResolveType(string name, out Type t, IWarningLogger log) { if (name == null) { throw new ArgumentNullException(); } if (bm == null) { throw new Exception("Need to set manager before performing type lookup."); } t = null; if (name.IndexOf('.') != -1) { if (bm.LookupType(name, out t, log)) { return(true); } } else { foreach (string ns in namespaces) { Type match = null; if (bm.LookupType(ns + name, out match, log)) { return(true); } if (match == null) { continue; } if (t != null) { string s = String.Format("Ambiguous type reference: {0} could be {1} or {2}", name, t.FullName, match.FullName); log.Error(2022, s, null); return(true); } t = match; } } if (t == null) { log.Error(2022, "Could not resolve type name " + name, null); return(true); } return(false); }
public static SourceSettings Load(IWarningLogger log) { SourceSettings ss = new SourceSettings(); try { XmlTextReader tr = new XmlTextReader(SourceFileName); while (!tr.EOF) { if (tr.NodeType != XmlNodeType.Element) { tr.Read(); continue; } // Yeah this is awesome. Note that topsrc-from-topbuild // must come before subpath-here otherwise nullref. if (tr.Name == "topsrc-from-topbuild") { ss.topsrc_from_topbuild = tr.ReadElementString(); } else if (tr.Name == "buildfile-name") { ss.buildfile_name = tr.ReadElementString(); } else if (tr.Name == "subpath-here" && ss.topsrc_from_topbuild != null) { ss.SetCurrentSubpath(tr.ReadElementString()); } tr.Read(); } tr.Close(); } catch (Exception e) { log.Error(1009, "Cannot load build breadcrumb file " + SourceFileName, e.Message); return(null); } if (ss.topsrc_from_topbuild == null || ss.buildfile_name == null || ss.subpath == null) { log.Error(1009, "Malformed build breadcrumb file " + SourceFileName, ss.ToString()); return(null); } return(ss); }
public override bool Initialize (WrenchProvider wp, IWarningLogger log, Queue children) { bool is_top = (basis == "/"); string topsrc = ss.PathToSourceRelative (""); string file = ss.PathToSourceRelative (srcrel); BuildfileParser parser = BuildfileParser.CreateForFile (topsrc, srcrel, wp, log); if (parser.Parse () > 0) // Parse errors return true; // FIXME: tell the parser whether a project[] section is OK and have // it signal the error. That way we get line info. if (!is_top && parser.PInfo != null) { log.Error (2006, "Found a project[] directive in a non-toplevel buildfile", file); return true; } else if (is_top && parser.PInfo == null) { log.Error (2006, "Toplevel buildfile did not have a project[] directive", file); return true; } if (is_top) { // kinda ugly. parser.PInfo.BuildfileName = Path.GetFileName (srcrel); if (((GraphBuilder) wp.Owner).SetProjectInfo (parser.PInfo, log)) return true; children.Enqueue (new ProjectProviderLoader (parser.PInfo)); } foreach (string sub in parser.Subdirs) children.Enqueue (new BuildfileProviderLoader (basis + sub, ss)); foreach (BuildfileParser.InsideInfo ii in parser.Insides) { foreach (string s in ii.Bases) children.Enqueue (new InsideProviderLoader (basis + s, ii.Context)); } if (parser.ManualLoads != null) { foreach (string k in parser.ManualLoads.Keys) { string srel = (string) parser.ManualLoads[k]; children.Enqueue (new BuildfileProviderLoader (basis + k, DeclarationLoc, ss, srel)); } } return false; }
protected override TargetTemplate InferTemplate(TypeResolver res, IWarningLogger log) { TargetTemplate tmpl = null; string dtname = DirectTransformDep; if (dtname != null) { if (res.TryMatch(dtname, MatcherKind.DirectTransform, out tmpl, log)) { return(null); } if (tmpl != null) { return(tmpl); } } if (Rule == null) { if (res.TryMatch(Name, MatcherKind.Target, out tmpl, log)) { return(null); } } if (tmpl == null) { log.Error(2028, "Cannot guess the template or rule for this target", FullName); } return(tmpl); }
protected override bool ImportXml(XmlReader xr, IWarningLogger log) { int depth = xr.Depth; while (xr.Depth >= depth) { if (xr.NodeType != XmlNodeType.Element) { xr.Read(); continue; } if (xr.Name != "enum") { log.Warning(3019, "Unknown element in EnumResult during XML import", xr.Name); xr.Skip(); break; } string s = xr.ReadElementString(); try { ValueString = s; } catch (Exception e) { log.Error(3019, "Error converting input string to enumeration value", e.Message); return(true); } } return(false); }
public bool DoneRequesting(TypeResolver res, IWarningLogger log) { if (done_modifying) { throw ExHelp.InvalidOp("Cannot call DoneRequesting twice on a provider"); } foreach (KeyValuePair <string, TargetBuilder> kvp in targets) { TargetValidity tv = kvp.Value.Validity; string fullname = Basis + kvp.Key; if (tv == TargetValidity.Referenced) { // FIXME: this error message sucks log.Error(2000, "A target was referenced from another provider " + "that was not formally allowed to request it, and the " + "target was not defined by its provider", fullname); return(true); } if (tv == TargetValidity.Requested) { TargetTemplate tmpl; if (res.TryMatch(kvp.Key, MatcherKind.Dependency, out tmpl, log)) { return(true); } if (tmpl == null) { log.Error(2027, "Could not guess a rule for a target " + "implicitly defined in a dependency. Do you " + "need to add a using [] line?", fullname); return(true); } kvp.Value.Define(log); tmpl.ApplyTemplate(kvp.Value); } } done_modifying = true; return(false); }
protected bool ResolveTemplate(TypeResolver res, IWarningLogger log) { TargetTemplate tmpl; if (TemplateName != null) { tmpl = res.ResolveName(TemplateName, log); } else if (Rule == null) { // This is sketchy: assume that if we have a rule by now, // we need no templating; if we don't, assume that we // want to do inference tmpl = InferTemplate(res, log); } else { return(false); } if (tmpl == null) { // Error will already be reported return(true); } tmpl.ApplyTemplate(this); if (Rule == null) { log.Error(9999, "Target did not have its rule set by " + "its primary template {0}", tmpl.ToString()); return(true); } if (!Rule.IsSubclassOf(typeof(Mono.Build.Rule))) { string s = String.Format("Invalid rule `{0}\' for target {1}: not a subclass of Rule", Rule, FullName); log.Error(2029, s, Rule.FullName); return(true); } return(false); }
bool LoadInternal(Stream s, IWarningLogger log) { BinaryReader br = new BinaryReader(s); // 4-byte identification header. byte[] b = br.ReadBytes(4); if (b[0] != (byte)'M' || b[1] != (byte)'B' || b[2] != (byte)'G' || b[3] != BinaryFormatIdent) { log.Error(1012, "Invalid header in saved graph file", null); return(true); } // 32-bit int check for endianness if (BinaryHelper.ReadRawInt(br) != 0x01B2C3D4) { log.Error(1012, "Endianness change in saved graph file", null); return(true); } // Actual data ReadProjectInfo(br); BinaryHelper.ExpectDelimiter(br); ReadDependents(br); BinaryHelper.ExpectDelimiter(br); ReadTags(br); BinaryHelper.ExpectDelimiter(br); ReadTargetTables(br); BinaryHelper.ExpectDelimiter(br); ReadProviders(br); BinaryHelper.ExpectDelimiter(br); ReadTagTable(br); BinaryHelper.ExpectDelimiter(br); ReadTypeTable(br); BinaryHelper.ExpectDelimiter(br); ReadResultTable(br); return(false); }
public bool UseIdent (string ident, string declloc, IWarningLogger log) { if (ident[0] == '/') throw new Exception ("Boo"); // UseStructureTemplate (); else if (ident.IndexOf ('/') < 0) return UseNamespace (ident, declloc, log); log.Error (9999, "Don't know how to use[] the identifier", ident); return true; }
bool LoadBundle(Assembly assy, Version expected_version, IWarningLogger logger, bool expecting_bundle) { object[] bundleattrs = assy.GetCustomAttributes(typeof(MonoBuildBundleAttribute), false); if (bundleattrs.Length == 0) { if (expecting_bundle) { logger.Error(4001, "The assembly is not a bundle: no MonoBuildBundleAttribute.", assy.FullName); return(true); } // This is so a bundle assembly can depend on non-MBuild assemblies and // our dependent assembly loading below won't freak out. return(false); } AssemblyName aname = assy.GetName(); if (expected_version != null && aname.Version != expected_version) { string s = String.Format("Bundle version requirement mismatch: want {0} version {1}, " + "loaded version {3}", aname.Name, expected_version, aname.Version); logger.Error(2033, s, null); return(true); } this[aname] = assy; // load info from referenced bundles first (the assemblies are // already loaded, but we load the type information for them.) foreach (AssemblyName aref in assy.GetReferencedAssemblies()) { if (LoadBundle(aref, logger, false)) { return(true); } } return(false); }
protected override bool ImportXml(XmlReader xr, IWarningLogger log) { try { value = Convert.FromBase64String(xr.ReadString()); } catch (Exception e) { log.Error(9999, "Fingerprint XML recovery hit invalid format", e.Message); return(true); } return(false); }
bool LoadInternal (Stream s, IWarningLogger log) { BinaryReader br = new BinaryReader (s); // 4-byte identification header. byte[] b = br.ReadBytes (4); if (b[0] != (byte) 'M' || b[1] != (byte) 'B' || b[2] != (byte) 'G' || b[3] != BinaryFormatIdent) { log.Error (1012, "Invalid header in saved graph file", null); return true; } // 32-bit int check for endianness if (BinaryHelper.ReadRawInt (br) != 0x01B2C3D4) { log.Error (1012, "Endianness change in saved graph file", null); return true; } // Actual data ReadProjectInfo (br); BinaryHelper.ExpectDelimiter (br); ReadDependents (br); BinaryHelper.ExpectDelimiter (br); ReadTags (br); BinaryHelper.ExpectDelimiter (br); ReadTargetTables (br); BinaryHelper.ExpectDelimiter (br); ReadProviders (br); BinaryHelper.ExpectDelimiter (br); ReadTagTable (br); BinaryHelper.ExpectDelimiter (br); ReadTypeTable (br); BinaryHelper.ExpectDelimiter (br); ReadResultTable (br); return false; }
// Returns null and logs an error if the provider at the given // basis has already been defined. public ProviderBuilder DefineProvider (string basis, string decl_loc, IWarningLogger log) { if (providers.ContainsKey (basis)) { log.Error (2043, "Trying to redefine the provider at " + basis, null); return null; } ProviderBuilder pb = CreateProvider (basis); pb.Claim (decl_loc); providers[basis] = pb; return pb; }
public bool AddDefaultOrdered(int target, IWarningLogger logger) { if (default_ordered_id < 0) { logger.Error(2037, "Trying to add a dependency to the default " + "ordered argument, but no default ordered argument is defined", target.ToString()); return(true); } return(Add(default_ordered_id, target, logger)); }
internal bool Define(IWarningLogger log) { if (validity == TargetValidity.Defined) { log.Error(2009, "Trying to redefine the target " + FullName, null); return(true); } validity = TargetValidity.Defined; return(false); }
public bool SetDefault(int aid, int target, IWarningLogger logger) { if (aid < 0 || aid >= args.Length) { string s = String.Format("Trying to set default {0} of nonexistant " + "argument ID {1}.", target, aid); logger.Error(2042, s, target.ToString()); return(true); } args[aid].SetDefault(target); return(false); }
public bool Add(int aid, int target, IWarningLogger logger) { if (aid < 0 || aid > args.Length) { string s = String.Format("Trying to add target #{0} to invalid " + "argument ID #{1}.", target, aid); logger.Error(2042, s, null); return(true); } AddNamed(aid, target); return(false); }
public StructureTemplate GetNamespaceTemplate(string ns, IWarningLogger log) { if (sinfo.ContainsKey(ns)) { return(sinfo[ns]); } string cfg = MBuildPrefix + ns + "." + DefaultStructureClass; Type t = null; if (LookupType(cfg, out t, log)) { log.Error(9999, "Error looking up namespacep parameter class " + cfg, null); return(null); } if (t == null) { log.Error(9999, "No bundle defines the namespace parameter class" + cfg, null); return(null); } StructureTemplate stmpl = (StructureTemplate)Activator.CreateInstance(t); MethodInfo mi = t.GetMethod("ApplyDefaults"); object ret = mi.Invoke(stmpl, new object[] { this, log }); if ((bool)ret) { return(null); } sinfo[ns] = stmpl; sused[ns] = false; return(stmpl); }
public bool UseIdent(string ident, string declloc, IWarningLogger log) { if (ident[0] == '/') { throw new Exception("Boo"); // UseStructureTemplate (); } else if (ident.IndexOf('/') < 0) { return(UseNamespace(ident, declloc, log)); } log.Error(9999, "Don't know how to use[] the identifier", ident); return(true); }
public static BinaryLoadedGraph Load (Stream s, IWarningLogger log) { BinaryLoadedGraph blg = new BinaryLoadedGraph (); try { if (blg.LoadInternal (s, log)) return null; } catch (Exception e) { log.Error (1012, "Unhandled exception during graph load", e.Message); return null; } return blg; }
public TargetTemplate ResolveName (string name, IWarningLogger log) { TargetTemplate tmpl; if (ResolveName (name, out tmpl, log)) return null; if (tmpl == null) { log.Error (2023, "Template lookup failed -- did you forget a using [] directive?", name); return null; } return tmpl; }
// Returns null and logs an error if the provider at the given // basis has already been defined. public ProviderBuilder DefineProvider(string basis, string decl_loc, IWarningLogger log) { if (providers.ContainsKey(basis)) { log.Error(2043, "Trying to redefine the provider at " + basis, null); return(null); } ProviderBuilder pb = CreateProvider(basis); pb.Claim(decl_loc); providers[basis] = pb; return(pb); }
public bool Finalize(IBuildManager manager, IWarningLogger log) { if (DefaultTo != null && Values.Count < 1) { if (DefaultTo is Result) { AddResult((Result)DefaultTo, null, -1); } else { BuiltItem[] bi = manager.EvaluateTargets(new int[1] { (int)DefaultTo }); if (bi == null || bi[0].Result == null) { return(true); } AddResult(bi[0].Result, bi[0].ResultPrint, -1); } } if ((Flags & ArgFlags.Optional) == 0 && Values.Count < 1) { log.Error(3015, String.Format("Argument \"{0}\" is not optional but has no values", this), null); return(true); } if ((Flags & ArgFlags.Multi) == 0 && Values.Count > 1) { log.Error(3016, String.Format("Argument \"{0}\" is not multiple-valued but has multiple values", this), null); return(true); } return(false); }
bool LoadBundle(string path, IWarningLogger logger, bool expecting_bundle) { Assembly assy; try { assy = System.AppDomain.CurrentDomain.Load(path); } catch (Exception e) { logger.Error(2020, "Could not load the referenced assembly " + path, e.Message); return(true); } return(LoadBundle(assy, null, logger, expecting_bundle)); }
public static BinaryLoadedGraph Load(Stream s, IWarningLogger log) { BinaryLoadedGraph blg = new BinaryLoadedGraph(); try { if (blg.LoadInternal(s, log)) { return(null); } } catch (Exception e) { log.Error(1012, "Unhandled exception during graph load", e.Message); return(null); } return(blg); }
internal bool DoFixup(NameLookupContext nlc, IWarningLogger log) { log.PushLocation(FullName); try { if (ResolveTemplate(nlc, log)) { return(true); } ApplyWaitTags(); // Now register our tags with the GraphBuilder GraphBuilder gb = (GraphBuilder)Owner.Owner; foreach (string tag in TagsWithValues) { if (gb.GetTagId(tag) < 0) { return(true); } } // Now make sure that all of our argument names are valid. Rule rinst = (Rule)Activator.CreateInstance(Rule); Dictionary <string, int> argmap = rinst.MakeArgNameMap(); foreach (string arg in ArgsWithDeps) { if (argmap.ContainsKey(arg)) { continue; } string s = String.Format("Argument `{0}' does not exist in rule " + "`{1}'", arg, Rule); log.Error(2024, s, null); return(true); } } finally { log.PopLocation(); } return(false); }
public bool AddDefaultOrdered(Result r, Fingerprint fp, IWarningLogger logger) { if (r == null) { throw new ArgumentNullException(); } if (default_ordered_id < 0) { logger.Error(2037, "Trying to add a dependency to the default " + "ordered argument, but no default ordered argument is defined", r.ToString()); return(true); } return(AddNamed(default_ordered_id, r, fp, -1, logger)); }
public TargetTemplate ResolveName(string name, IWarningLogger log) { TargetTemplate tmpl; if (ResolveName(name, out tmpl, log)) { return(null); } if (tmpl == null) { log.Error(2023, "Template lookup failed -- did you forget a using [] directive?", name); return(null); } return(tmpl); }
public override bool ResolveName(string name, out TargetTemplate tmpl, IWarningLogger log) { tmpl = null; Type t; if (ResolveType(name, out t, log)) { return(true); } if (t.IsSubclassOf(typeof(Rule))) { Type t2 = TemplateForRule(t, log); if (t2 == null) { // So yeah this is kinda dumb namespacing. tmpl = new Mono.Build.RuleLib.RegexMatcher.RuleOnlyTemplate(t); return(false); } t = t2; } if (!t.IsSubclassOf(typeof(TargetTemplate))) { string s = String.Format("Type {0} (resolved from {1}) should be a TargetTemplate but isn't", t.FullName, name); log.Error(2022, s, null); return(true); } object o; if (InstantiateBoundType(t, out o, log)) { return(true); } tmpl = (TargetTemplate)o; return(false); }
public bool LookupType(string name, out Type t, IWarningLogger logger) { // We need the out parameter because returning null could either mean // "no match" (ok) or "error during lookup" (bad, and we should stop). // Currently, the only error condition is that the type is defined // more than one bundle; it is annoying to have to make all the callers // of this function jump through hoops, but it is the kind of circumstance // that can occur. if (name == null) { throw new ArgumentNullException(); } //if (!StrUtils.StartsWith (name, MBuildPrefix)) //name = MBuildPrefix + name; t = null; // efficiency? hah! foreach (Assembly assy in BundleAssemblies) { Type match = assy.GetType(name); if (match == null) { continue; } if (t != null) { logger.Error(2024, String.Format("Two assemblies define the type" + "{0}: {1} and {2}", name, t.Assembly.FullName, assy.FullName), null); return(true); } t = match; } return(false); }
bool LoadBundle(AssemblyName aname, IWarningLogger logger, bool expecting_bundle) { Assembly assy; if (this[aname] != null) { return(false); } try { assy = System.AppDomain.CurrentDomain.Load(aname); } catch (Exception e) { logger.Error(2020, "Could not load the referenced assembly " + aname.ToString(), String.Format("{0}: {1}", e.GetType(), e.Message)); return(true); } return(LoadBundle(assy, aname.Version, logger, expecting_bundle)); }
public Type LookupFQN(string name, IWarningLogger logger) { Type t; // fully qualified name. Assume that the name must be found -- // null return value can/does not distinguish between 'type not // found' and 'error occurred when attempting to find type'. if (bm.LookupType(name, out t, logger)) { return(null); } if (t == null) { logger.Error(2023, "Type lookup failed -- did you forget a using [] directive?", name); return(null); } return(t); }
public bool InstantiateBoundType(Type t, out object result, IWarningLogger log) { object init_obj; result = null; object[] attrs = t.GetCustomAttributes(typeof(StructureBindingAttribute), false); if (attrs == null || attrs.Length == 0) { init_obj = null; } else { StructureBindingAttribute sba = attrs[0] as StructureBindingAttribute; if (!sba.UsesStructure) { init_obj = null; } else { Type stype = sba.StructureType; if (!known_structs.ContainsKey(stype)) { string s = String.Format("Type {0} must be created in the context of a {1} structure, " + "but none is referenced in this scope.", t, stype); log.Error(9999, s, null); return(true); } init_obj = known_structs[stype]; } } result = Activator.CreateInstance(t, init_obj); return(false); }
public bool SaveForSubpath(string subpath, IWarningLogger log) { try { string f = Path.Combine(PathToBuildRelative(subpath), SourceFileName); XmlTextWriter tw = new XmlTextWriter(f, Encoding.UTF8); tw.Formatting = Formatting.Indented; tw.WriteStartElement("breadcrumb"); tw.WriteElementString("topsrc-from-topbuild", topsrc_from_topbuild); tw.WriteElementString("buildfile-name", buildfile_name); tw.WriteElementString("subpath-here", subpath); tw.WriteEndElement(); tw.Close(); } catch (Exception e) { log.Error(1009, "Cannot write build breadcrumb file " + SourceFileName, e.Message); return(true); } return(false); }
public static SourceSettings CreateToplevel(string topsrc, string bfname, IWarningLogger log) { if (File.Exists(SourceFileName)) { log.Error(1009, "Build breadcrumb file " + SourceFileName + " should " + "not exist here, but it does.", null); return(null); } SourceSettings ss = new SourceSettings(); ss.topsrc_from_topbuild = topsrc; ss.buildfile_name = bfname; ss.SetCurrentSubpath("."); if (ss.SaveForSubpath(".", log)) { return(null); } return(ss); }
public bool LookupType (string name, out Type t, IWarningLogger logger) { // We need the out parameter because returning null could either mean // "no match" (ok) or "error during lookup" (bad, and we should stop). // Currently, the only error condition is that the type is defined // more than one bundle; it is annoying to have to make all the callers // of this function jump through hoops, but it is the kind of circumstance // that can occur. if (name == null) throw new ArgumentNullException (); //if (!StrUtils.StartsWith (name, MBuildPrefix)) //name = MBuildPrefix + name; t = null; // efficiency? hah! foreach (Assembly assy in BundleAssemblies) { Type match = assy.GetType (name); if (match == null) continue; if (t != null) { logger.Error (2024, String.Format ("Two assemblies define the type" + "{0}: {1} and {2}", name, t.Assembly.FullName, assy.FullName), null); return true; } t = match; } return false; }
public static SourceSettings CreateToplevel (string topsrc, string bfname, IWarningLogger log) { if (File.Exists (SourceFileName)) { log.Error (1009, "Build breadcrumb file " + SourceFileName + " should " + "not exist here, but it does.", null); return null; } SourceSettings ss = new SourceSettings (); ss.topsrc_from_topbuild = topsrc; ss.buildfile_name = bfname; ss.SetCurrentSubpath ("."); if (ss.SaveForSubpath (".", log)) return null; return ss; }
public bool SaveForSubpath (string subpath, IWarningLogger log) { try { string f = Path.Combine (PathToBuildRelative (subpath), SourceFileName); XmlTextWriter tw = new XmlTextWriter (f, Encoding.UTF8); tw.Formatting = Formatting.Indented; tw.WriteStartElement ("breadcrumb"); tw.WriteElementString ("topsrc-from-topbuild", topsrc_from_topbuild); tw.WriteElementString ("buildfile-name", buildfile_name); tw.WriteElementString ("subpath-here", subpath); tw.WriteEndElement (); tw.Close (); } catch (Exception e) { log.Error (1009, "Cannot write build breadcrumb file " + SourceFileName, e.Message); return true; } return false; }
/////////////////////////////////////////// // Done public bool Finish (IWarningLogger log) { foreach (WrenchProvider wp in Providers) { if (!wp.Claimed) { log.Error (2001, "Something referenced a target in the provider " + wp.Basis + " but it never was registered.", null); return true; } if (wp.DoneModifying) continue; if (wp.Finish (bm, log)) return true; } return false; }
public static SourceSettings Load (IWarningLogger log) { SourceSettings ss = new SourceSettings (); try { XmlTextReader tr = new XmlTextReader (SourceFileName); while (!tr.EOF) { if (tr.NodeType != XmlNodeType.Element) { tr.Read (); continue; } // Yeah this is awesome. Note that topsrc-from-topbuild // must come before subpath-here otherwise nullref. if (tr.Name == "topsrc-from-topbuild") ss.topsrc_from_topbuild = tr.ReadElementString (); else if (tr.Name == "buildfile-name") ss.buildfile_name = tr.ReadElementString (); else if (tr.Name == "subpath-here" && ss.topsrc_from_topbuild != null) ss.SetCurrentSubpath (tr.ReadElementString ()); tr.Read (); } tr.Close (); } catch (Exception e) { log.Error (1009, "Cannot load build breadcrumb file " + SourceFileName, e.Message); return null; } if (ss.topsrc_from_topbuild == null || ss.buildfile_name == null || ss.subpath == null) { log.Error (1009, "Malformed build breadcrumb file " + SourceFileName, ss.ToString ()); return null; } return ss; }
// evaluation public bool FinalizeArgs (IBuildManager manager, IWarningLogger logger) { int i; // evaluate deferred args int[] ids = new int[deferred.Count]; for (i = 0; i < deferred.Count; i++) ids[i] = deferred[i].target; BuiltItem[] bis = manager.EvaluateTargets (ids); if (bis == null) return true; for (i = 0; i < deferred.Count; i++) { int aid = deferred[i].aid; if (aid < 0) { if (Add (bis[i].Result, bis[i].ResultPrint, logger)) return true; } else { if (AddNamed (aid, bis[i].Result, bis[i].ResultPrint, deferred[i].index_into_values, logger)) return true; } } deferred.Clear (); // check counts and types, apply defaults if needed for (i = 0; i < args.Length; i++) { if (args[i].Finalize (manager, logger)) return true; } // Check target if (need_target_name && target_name == null) { logger.Error (3015, "Rule needs target name but it has not been set", null); return true; } // all done args_finalized = true; return false; }
public bool Finalize (IBuildManager manager, IWarningLogger log) { if (DefaultTo != null && Values.Count < 1) { if (DefaultTo is Result) AddResult ((Result) DefaultTo, null, -1); else { BuiltItem[] bi = manager.EvaluateTargets (new int[1] { (int) DefaultTo }); if (bi == null || bi[0].Result == null) return true; AddResult (bi[0].Result, bi[0].ResultPrint, -1); } } if ((Flags & ArgFlags.Optional) == 0 && Values.Count < 1) { log.Error (3015, String.Format ("Argument \"{0}\" is not optional but has no values", this), null); return true; } if ((Flags & ArgFlags.Multi) == 0 && Values.Count > 1) { log.Error (3016, String.Format ("Argument \"{0}\" is not multiple-valued but has multiple values", this), null); return true; } return false; }
public bool InstantiateBoundType (Type t, out object result, IWarningLogger log) { object init_obj; result = null; object[] attrs = t.GetCustomAttributes (typeof (StructureBindingAttribute), false); if (attrs == null || attrs.Length == 0) init_obj = null; else { StructureBindingAttribute sba = attrs[0] as StructureBindingAttribute; if (!sba.UsesStructure) init_obj = null; else { Type stype = sba.StructureType; if (!known_structs.ContainsKey (stype)) { string s = String.Format ("Type {0} must be created in the context of a {1} structure, " + "but none is referenced in this scope.", t, stype); log.Error (9999, s, null); return true; } init_obj = known_structs[stype]; } } result = Activator.CreateInstance (t, init_obj); return false; }
protected override TargetTemplate InferTemplate (TypeResolver res, IWarningLogger log) { TargetTemplate tmpl = null; string dtname = DirectTransformDep; if (dtname != null) { if (res.TryMatch (dtname, MatcherKind.DirectTransform, out tmpl, log)) return null; if (tmpl != null) return tmpl; } if (Rule == null) { if (res.TryMatch (Name, MatcherKind.Target, out tmpl, log)) return null; } if (tmpl == null) log.Error (2028, "Cannot guess the template or rule for this target", FullName); return tmpl; }
public Type LookupFQN (string name, IWarningLogger logger) { Type t; // fully qualified name. Assume that the name must be found -- // null return value can/does not distinguish between 'type not // found' and 'error occurred when attempting to find type'. if (bm.LookupType (name, out t, logger)) return null; if (t == null) { logger.Error (2023, "Type lookup failed -- did you forget a using [] directive?", name); return null; } return t; }
protected override bool ImportXml (XmlReader xr, IWarningLogger log) { try { value = Convert.FromBase64String (xr.ReadString ()); } catch (Exception e) { log.Error (9999, "Fingerprint XML recovery hit invalid format", e.Message); return true; } return false; }
public bool Add (Result r, Fingerprint fp, IWarningLogger logger) { if (r == null) throw new ArgumentNullException (); Type t = r.GetType (); List<int> possible_args = new List<int> (); Type best_match = typeof (Result); for (int i = 0; i < args.Length; i++) { Type atype = args[i].Type; // Cannot add an unnamed arg to an ordered arg if ((args[i].Flags & ArgFlags.Ordered) != 0) continue; // Prune out the egregiously wrong arguments (not even a superclass of the result) if (! TypeIs (t, atype)) continue; // Prune out those that have been bettered if (! TypeIs (atype, best_match)) continue; // If we've narrowed the type further, we don't want any of the // previous vaguer matches. if (atype.IsSubclassOf (best_match)) { possible_args.Clear (); best_match = atype; } possible_args.Add (i); } //Console.WriteLine ("Finished with {0} possible arguments", possible_args.Count); if (possible_args.Count == 1) { args[possible_args[0]].AddResult (r, fp, -1); return false; } if (possible_args.Count > 0) { // Several possible choices. Check for a default foreach (int aid in possible_args) { if ((args[aid].Flags & ArgFlags.Default) != 0) { args[aid].AddResult (r, fp, -1); return false; } } // No dice. Ambiguity not tolerated. Ah, computers. StringBuilder sb = new StringBuilder (); sb.AppendFormat ("Ambiguous dependency of type {0} could " + "be one of these arguments:", t); foreach (int aid in possible_args) sb.AppendFormat (" {0}", args[aid].Name); logger.Error (2035, sb.ToString (), r.ToString ()); return true; } // Maybe this is a composite result, and it has a default? // We recurse here, so we tunnel through the composites // sequentially. It's correct to check at every step, rather // than calling FindCompatible, since we don't know what // type we're looking for. if (r is CompositeResult) { CompositeResult cr = (CompositeResult) r; if (cr.HasDefault) { // See note above about losing FP info in composite results. // this case happens when we are guessing the arg; te //logger.Warning (9999, "LOSING FINGERPRINT INFO in AC (2)", r.ToString ()); if (Add (cr.Default, null, logger) == false) return false; // if that didn't work, continue // and give a warning about the container // Result, not the default. } } // Bummer. string s = String.Format ("Dependency {0} of type {1} isn't compatible " + "with any defined arguments.", r, t); logger.Error (2034, s, null); return true; }
bool AddNamed (int aid, Result r, Fingerprint fp, int index_into_values, IWarningLogger logger) { if (aid < 0 || aid >= args.Length) { string s = String.Format ("Trying to add {0} to nonexistant " + "argument ID {1}.", r, aid); logger.Error (2042, s, r.ToString ()); return true; } Result subres = CompositeResult.FindCompatible (r, args[aid].Type); if (subres == null) { string err = String.Format ("Argument value should be of type {0}, but " + "its type is {1}", args[aid].Type, r.GetType ()); logger.Error (2036, err, r.ToString ()); return true; } if (subres == r) args[aid].AddResult (r, fp, index_into_values); else // FIXME: the FP is really invalid, right? args[aid].AddResult (r, null, index_into_values); return false; }
public StructureTemplate GetNamespaceTemplate (string ns, IWarningLogger log) { if (sinfo.ContainsKey (ns)) return sinfo[ns]; string cfg = MBuildPrefix + ns + "." + DefaultStructureClass; Type t = null; if (LookupType (cfg, out t, log)) { log.Error (9999, "Error looking up namespacep parameter class " + cfg, null); return null; } if (t == null) { log.Error (9999, "No bundle defines the namespace parameter class" + cfg, null); return null; } StructureTemplate stmpl = (StructureTemplate) Activator.CreateInstance (t); MethodInfo mi = t.GetMethod ("ApplyDefaults"); object ret = mi.Invoke (stmpl, new object[] { this, log }); if ((bool) ret) return null; sinfo[ns] = stmpl; sused[ns] = false; return stmpl; }
public bool DoneRequesting (TypeResolver res, IWarningLogger log) { if (done_modifying) throw ExHelp.InvalidOp ("Cannot call DoneRequesting twice on a provider"); foreach (KeyValuePair<string,TargetBuilder> kvp in targets) { TargetValidity tv = kvp.Value.Validity; string fullname = Basis + kvp.Key; if (tv == TargetValidity.Referenced) { // FIXME: this error message sucks log.Error (2000, "A target was referenced from another provider " + "that was not formally allowed to request it, and the " + "target was not defined by its provider", fullname); return true; } if (tv == TargetValidity.Requested) { TargetTemplate tmpl; if (res.TryMatch (kvp.Key, MatcherKind.Dependency, out tmpl, log)) return true; if (tmpl == null) { log.Error (2027, "Could not guess a rule for a target " + "implicitly defined in a dependency. Do you " + "need to add a using [] line?", fullname); return true; } kvp.Value.Define (log); tmpl.ApplyTemplate (kvp.Value); } } done_modifying = true; return false; }
public bool ResolveType (string name, out Type t, IWarningLogger log) { if (name == null) throw new ArgumentNullException (); if (bm == null) throw new Exception ("Need to set manager before performing type lookup."); t = null; if (name.IndexOf ('.') != -1) { if (bm.LookupType (name, out t, log)) return true; } else { foreach (string ns in namespaces) { Type match = null; if (bm.LookupType (ns + name, out match, log)) return true; if (match == null) continue; if (t != null) { string s = String.Format ("Ambiguous type reference: {0} could be {1} or {2}", name, t.FullName, match.FullName); log.Error (2022, s, null); return true; } t = match; } } if (t == null) { log.Error (2022, "Could not resolve type name " + name, null); return true; } return false; }
public bool Add (int aid, int target, IWarningLogger logger) { if (aid < 0 || aid > args.Length) { string s = String.Format ("Trying to add target #{0} to invalid " + "argument ID #{1}.", target, aid); logger.Error (2042, s, null); return true; } AddNamed (aid, target); return false; }
internal bool DoFixup (NameLookupContext nlc, IWarningLogger log) { log.PushLocation (FullName); try { if (ResolveTemplate (nlc, log)) return true; ApplyWaitTags (); // Now register our tags with the GraphBuilder GraphBuilder gb = (GraphBuilder) Owner.Owner; foreach (string tag in TagsWithValues) { if (gb.GetTagId (tag) < 0) return true; } // Now make sure that all of our argument names are valid. Rule rinst = (Rule) Activator.CreateInstance (Rule); Dictionary<string,int> argmap = rinst.MakeArgNameMap (); foreach (string arg in ArgsWithDeps) { if (argmap.ContainsKey (arg)) continue; string s = String.Format ("Argument `{0}' does not exist in rule " + "`{1}'", arg, Rule); log.Error (2024, s, null); return true; } } finally { log.PopLocation (); } return false; }
public bool AddDefaultOrdered (Result r, Fingerprint fp, IWarningLogger logger) { if (r == null) throw new ArgumentNullException (); if (default_ordered_id < 0) { logger.Error (2037, "Trying to add a dependency to the default " + "ordered argument, but no default ordered argument is defined", r.ToString ()); return true; } return AddNamed (default_ordered_id, r, fp, -1, logger); }
public bool AddDefaultOrdered (int target, IWarningLogger logger) { if (default_ordered_id < 0) { logger.Error (2037, "Trying to add a dependency to the default " + "ordered argument, but no default ordered argument is defined", target.ToString ()); return true; } return Add (default_ordered_id, target, logger); }
bool LoadBundle (AssemblyName aname, IWarningLogger logger, bool expecting_bundle) { Assembly assy; if (this[aname] != null) return false; try { assy = System.AppDomain.CurrentDomain.Load (aname); } catch (Exception e) { logger.Error (2020, "Could not load the referenced assembly " + aname.ToString (), String.Format ("{0}: {1}", e.GetType (), e.Message)); return true; } return LoadBundle (assy, aname.Version, logger, expecting_bundle); }
public bool SetDefault (int aid, int target, IWarningLogger logger) { if (aid < 0 || aid >= args.Length) { string s = String.Format ("Trying to set default {0} of nonexistant " + "argument ID {1}.", target, aid); logger.Error (2042, s, target.ToString ()); return true; } args[aid].SetDefault (target); return false; }
// Rule template helpers public bool GetTemplateForRule (string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log) { ttmpl = null; StructureTemplate stmpl = GetNamespaceTemplate (ns, log); if (stmpl == null || !sused[ns]) { log.Error (9999, "Trying to use structure template of namespace " + ns + ", but either it wasn't defined or it hasn't been " + "initialized yet.", null); return true; } // See if we can find a type that has a StructureBinding to tmpl // and a RuleBinding to rtype. string pns = MBuildPrefix + ns; Type ttype = null, stype = stmpl.GetType (); foreach (Assembly assy in BundleAssemblies) { foreach (Type t in assy.GetExportedTypes ()) { if (t.Namespace != pns) continue; if (!t.IsSubclassOf (typeof (TargetTemplate))) continue; object[] attrs = t.GetCustomAttributes (typeof (StructureBindingAttribute), false); if (attrs.Length == 0) continue; StructureBindingAttribute sba = (StructureBindingAttribute) attrs[0]; if (sba.StructureType == null) continue; if (!sba.StructureType.Equals (stype)) continue; attrs = t.GetCustomAttributes (typeof (RuleBindingAttribute), false); if (attrs.Length == 0) continue; if (!((RuleBindingAttribute) attrs[0]).RuleType.Equals (rtype)) continue; if (ttype != null) { log.Warning (9999, "Two hits for rule template: " + ttype.ToString () + " and " + t.ToString (), rtype.ToString ()); } ttype = t; } } if (ttype != null) ttmpl = (TargetTemplate) Activator.CreateInstance (ttype, stmpl); return false; }
public override bool ResolveName (string name, out TargetTemplate tmpl, IWarningLogger log) { tmpl = null; Type t; if (ResolveType (name, out t, log)) return true; if (t.IsSubclassOf (typeof (Rule))) { Type t2 = TemplateForRule (t, log); if (t2 == null) { // So yeah this is kinda dumb namespacing. tmpl = new Mono.Build.RuleLib.RegexMatcher.RuleOnlyTemplate (t); return false; } t = t2; } if (!t.IsSubclassOf (typeof (TargetTemplate))) { string s = String.Format ("Type {0} (resolved from {1}) should be a TargetTemplate but isn't", t.FullName, name); log.Error (2022, s, null); return true; } object o; if (InstantiateBoundType (t, out o, log)) return true; tmpl = (TargetTemplate) o; return false; }