Author: peterw
Date: 2006-07-21 17:08:04 -0400 (Fri, 21 Jul 2006)
New Revision: 62880
Added:
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BundleManager.cs
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/IBundleUser.cs
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/NameLookupContext.cs
Removed:
trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs
trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs
trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
Modified:
trunk/mbuild/Monkeywrench.dll.sources
trunk/mbuild/Monkeywrench/ChangeLog
trunk/mbuild/Monkeywrench/Monkeywrench/ProjectInfo.cs
trunk/mbuild/Mono.Build.dll.sources
trunk/mbuild/Mono.Build/ChangeLog
trunk/mbuild/Mono.Build/Mono.Build/Fingerprint.cs
Log:
2006-07-21 Peter Williams <[EMAIL PROTECTED]>
* Mono.Build/Fingerprint.cs (ImportXml): I *knew* that somewhere in
the .Net system libraries there had to be a base64 decode function.
Use it.
Monkeywrench:
2006-07-21 Peter Williams <[EMAIL PROTECTED]>
* Monkeywrench.Compiler/NameLookupContext.cs: Move here from
Mono.Build.Bundling.
No need to have this lower in the stack.
* Monkeywrench.Compiler/BundleManager.cs: Same.
* Monkeywrench.Compiler/IBundleUser.cs: Same.
* Monkeywrench/ProjectInfo.cs: Add a using for the above changes.
Modified: trunk/mbuild/Monkeywrench/ChangeLog
===================================================================
--- trunk/mbuild/Monkeywrench/ChangeLog 2006-07-21 20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Monkeywrench/ChangeLog 2006-07-21 21:08:04 UTC (rev 62880)
@@ -1,3 +1,14 @@
+2006-07-21 Peter Williams <[EMAIL PROTECTED]>
+
+ * Monkeywrench.Compiler/NameLookupContext.cs: Move here from
Mono.Build.Bundling.
+ No need to have this lower in the stack.
+
+ * Monkeywrench.Compiler/BundleManager.cs: Same.
+
+ * Monkeywrench.Compiler/IBundleUser.cs: Same.
+
+ * Monkeywrench/ProjectInfo.cs: Add a using for the above changes.
+
2006-07-20 Peter Williams <[EMAIL PROTECTED]>
* Monkeywrench.Compiler/BuildfileParser-rest.cs (ConstructedInfo): Munge
Modified: trunk/mbuild/Monkeywrench/Monkeywrench/ProjectInfo.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench/ProjectInfo.cs 2006-07-21
20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Monkeywrench/Monkeywrench/ProjectInfo.cs 2006-07-21
21:08:04 UTC (rev 62880)
@@ -6,8 +6,9 @@
using System.Runtime.Serialization;
using Mono.Build;
-using Mono.Build.Bundling;
+using Monkeywrench.Compiler;
+
namespace Monkeywrench {
[Serializable]
Copied: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BundleManager.cs (from
rev 62788, trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs)
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs
2006-07-20 02:40:33 UTC (rev 62788)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BundleManager.cs
2006-07-21 21:08:04 UTC (rev 62880)
@@ -0,0 +1,329 @@
+//
+// BundleManager.cs -- a class for loading and tracking bundles
+//
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.IO;
+using System.Text;
+
+using Mono.Build;
+using Mono.Build.Bundling;
+
+namespace Monkeywrench.Compiler {
+
+ public delegate bool PublicProviderAdded (string basis,
IBuildProvider prov);
+
+ public class BundleManager {
+
+ public const string MBuildPrefix = "MBuildDynamic.";
+
+ public BundleManager () {
+ }
+
+ // Bundle table
+
+ Hashtable bundles = new Hashtable ();
+
+ public IEnumerable BundleAssemblies {
+ get {
+ return bundles.Values;
+ }
+ }
+
+ Assembly this [AssemblyName aname] {
+ get {
+ if (bundles.Contains (aname.Name))
+ return (Assembly) bundles[aname.Name];
+ return null;
+ }
+
+ set {
+ bundles[aname.Name] = value;
+ }
+ }
+
+ // Loading bundles
+
+ public event PublicProviderAdded OnPublicProviderAdded;
+
+ public static AssemblyName MakeName (string shortname, string
version) {
+ byte[] pktok = Assembly.GetExecutingAssembly ().GetName
().GetPublicKeyToken ();
+
+ AssemblyName n = new AssemblyName ();
+ n.Name = MBuildPrefix + shortname;
+ n.SetPublicKeyToken (pktok);
+
+ if (version != null)
+ n.Version = new Version (version);
+
+ return n;
+ }
+
+ public static AssemblyName MakeName (string shortname) {
+ return MakeName (shortname, null);
+ }
+
+ public bool LoadBundle (AssemblyName aname, IWarningLogger
logger) {
+ return LoadBundle (aname, logger, true);
+ }
+
+ public bool LoadBundle (string path, IWarningLogger logger) {
+ return LoadBundle (path, logger, true);
+ }
+
+ public bool LoadBundle (Assembly assy, IWarningLogger logger) {
+ return LoadBundle (assy, null, logger, true);
+ }
+
+ 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 (),
+ e.ToString ());
+ return true;
+ }
+
+ return LoadBundle (assy, aname.Version, logger,
expecting_bundle);
+ }
+
+ bool LoadBundle (string path, IWarningLogger logger, bool
expecting_bundle) {
+ Assembly assy;
+
+ try {
+ assy = System.AppDomain.CurrentDomain.Load
(path);
+ Console.WriteLine ("loadfrom: {0} -> {1}",
path, assy);
+ } catch (Exception e) {
+ logger.Error (2020, "Could not load the
referenced assembly " + path,
+ e.ToString ());
+ return true;
+ }
+
+ return LoadBundle (assy, null, logger,
expecting_bundle);
+ }
+
+ 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 NewBundleLoaded (assy, logger);
+ }
+
+ bool NewBundleLoaded (Assembly assy, IWarningLogger logger) {
+ //Console.WriteLine ("Loaded assembly {0}", assy);
+
+ Type[] types = assy.GetExportedTypes ();
+ Type ibp = typeof (IBuildProvider);
+ SortedList providers = new SortedList ();
+
+ foreach (Type t in types) {
+ foreach (Type iface in t.GetInterfaces ()) {
+ // see note above
+ if (iface.Equals (ibp) ||
iface.IsSubclassOf (ibp)) {
+ object[] attrs =
t.GetCustomAttributes (typeof (ProviderPrefixAttribute), false);
+
+ if (attrs.Length < 1) {
+ logger.Error (4000,
System.String.Format ("Exported build provider {0} " +
+
"in assembly {1} is missing a " +
+
"ProviderPrefixAttribute",
+
t.FullName, assy.FullName), null);
+ return true;
+ }
+
+ foreach
(ProviderPrefixAttribute attr in attrs) {
+ // Might as well let
one class be loaded in multiple prefixes ...
+ string prefix =
attr.Prefix;
+
+ // normalize to end in
slashes
+ if
(prefix[prefix.Length - 1] != '/')
+ prefix = prefix
+ "/";
+
+ if (providers.Contains
(prefix)) {
+ logger.Error
(2032, "Redefinition of provider " + prefix, assy.FullName);
+ return true;
+ }
+
+ // FIXME: just add the
type here, and instantiate as needed?
+
+ providers.Add (prefix,
Activator.CreateInstance (t));
+ }
+
+ break;
+ }
+ }
+ }
+
+ // the providers are sorted so that we add parents
before children, a requirement
+ // that isn't really necessary at this level of
abstraction but is needed for
+ // Monkeywrench.
+ //
+ // Well, now we can add them below if they're not
IDynamicBuildProviders,
+ // which most (all?) public providers will not be, but
might as well still do this.
+
+
+ if (OnPublicProviderAdded != null) {
+ foreach (string prefix in providers.Keys) {
+ if (OnPublicProviderAdded (prefix,
(IBuildProvider) providers[prefix]))
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ // Namespace management
+
+ public bool UseNamespace (string ns, IBundleUser user,
IWarningLogger logger) {
+ int numfound = 0;
+
+ if (ns == null)
+ throw new ArgumentNullException ("ns");
+
+ ns = MBuildPrefix + ns;
+
+ foreach (Assembly assy in bundles.Values)
+ numfound += NotifyTypes (assy, ns, user);
+
+ if (numfound == 0) {
+ logger.Error (2021, "No referenced assembly
provides the requested namespace", ns);
+ return true;
+ }
+
+ return false;
+ }
+
+ int NotifyTypes (Assembly assy, string pns, IBundleUser user) {
+ int numfound = 0;
+ Type[] types = assy.GetExportedTypes ();
+
+ Type imatcher = typeof (IMatcher);
+
+ foreach (Type t in types) {
+ if (t.Namespace != pns)
+ continue;
+
+ numfound++;
+
+ //Console.WriteLine ("Checking out type {0}:
{1}", t.FullName, t.Attributes);
+
+ foreach (Type iface in t.GetInterfaces ()) {
+ if (iface.Equals (imatcher) ||
iface.IsSubclassOf (imatcher)) {
+ int hits = 0;
+ object[] attrs =
t.GetCustomAttributes (typeof (TargetRuleMatcherAttribute), false);
+
+ if (attrs.Length > 0) {
+ hits++;
+
+ if (user != null)
+
user.NotifyTargetRuleMatcher (t);
+ }
+
+ attrs = t.GetCustomAttributes
(typeof (DepRuleMatcherAttribute), false);
+
+ if (attrs.Length > 0) {
+ hits++;
+
+ if (user != null)
+
user.NotifyDepRuleMatcher (t);
+ }
+
+ attrs = t.GetCustomAttributes
(typeof (DirectTransformMatcherAttribute), false);
+
+ if (attrs.Length > 0) {
+ hits++;
+
+ if (user != null)
+
user.NotifyDirectTransformRuleMatcher (t);
+ }
+
+ if (hits == 0)
+ throw new Exception
(System.String.Format ("Type {0} is an IMatcher but does not " +
+
"have a xxxRuleMatcher attribute.",
+
t));
+
+ // really break here? as we add
things here
+ // we must decide
+ break;
+ }
+ }
+ }
+
+ return numfound;
+ }
+
+ public bool LookupType (string name, IWarningLogger logger, out
Type t) {
+ // We need the out parameter because returning null
could either mean
+ // "no match" (ok) or "error with the type" (except
perhaps our one
+ // error condition can't even happen.)
+
+ if (name == null)
+ throw new ArgumentNullException ();
+
+ //if (!StrUtils.StartsWith (name, MBuildPrefix))
+ name = MBuildPrefix + name;
+
+ t = null;
+ Assembly where = null;
+
+ // efficiency? hah!
+ //
+ // Actually, will the runtime throw an error if we load
+ // two assemblies that define the same type? Seems
+ // reasonable.
+
+ foreach (Assembly assy in bundles.Values) {
+ 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, where.FullName, assy.FullName), null);
+ return true;
+ }
+
+ t = match;
+ where = assy;
+ }
+
+ return false;
+ }
+ }
+}
Copied: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/IBundleUser.cs (from
rev 62788, trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs)
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs 2006-07-20
02:40:33 UTC (rev 62788)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/IBundleUser.cs
2006-07-21 21:08:04 UTC (rev 62880)
@@ -0,0 +1,15 @@
+//
+// IBundleUser.cs -- interface for notifying something that loads bundles
+// about the types that it exports
+//
+
+using System;
+
+namespace Monkeywrench.Compiler {
+
+ public interface IBundleUser {
+ void NotifyTargetRuleMatcher (Type t);
+ void NotifyDepRuleMatcher (Type t);
+ void NotifyDirectTransformRuleMatcher (Type t);
+ }
+}
Copied: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/NameLookupContext.cs
(from rev 62788,
trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs)
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
2006-07-20 02:40:33 UTC (rev 62788)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/NameLookupContext.cs
2006-07-21 21:08:04 UTC (rev 62880)
@@ -0,0 +1,226 @@
+//
+// NameLookupContext.cs -- an environment in which we look up names of targets
+// and names in bundles.
+//
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Text;
+
+using Mono.Build;
+using Mono.Build.Bundling;
+
+namespace Monkeywrench.Compiler {
+
+ public class NameLookupContext : IBundleUser, ICloneable {
+ ArrayList namespaces;
+ ArrayList target_rule_matchers;
+ ArrayList dep_rule_matchers;
+ ArrayList dt_rule_matchers;
+
+ public NameLookupContext () {
+ this.namespaces = new ArrayList ();
+ this.target_rule_matchers = new ArrayList ();
+ this.dep_rule_matchers = new ArrayList ();
+ this.dt_rule_matchers = new ArrayList ();
+ }
+
+ // Manager
+
+ BundleManager bm;
+
+ public BundleManager Manager { get { return bm; } }
+
+ public bool SetManager (BundleManager bm, IWarningLogger
logger) {
+ if (bm == null)
+ throw new ArgumentNullException ();
+ if (this.bm != null)
+ throw new Exception ("Already have manager
set");
+
+ this.bm = bm;
+
+ for (int i = 0; i < namespaces.Count; i++)
+ if (bm.UseNamespace ((string) namespaces[i],
this, logger))
+ return true;
+
+ return false;
+ }
+
+ // Lookup
+
+ public bool UseNamespace (string ns, IWarningLogger logger) {
+ if (ns == null)
+ throw new ArgumentNullException ();
+
+ namespaces.Add (ns);
+
+ if (bm == null)
+ return false;
+
+ return bm.UseNamespace (ns, this, logger);
+ }
+
+ public Type LookupType (string name, IWarningLogger logger) {
+ if (name == null)
+ throw new ArgumentNullException ();
+ if (bm == null)
+ throw new Exception ("Need to set manager
before performing type lookup.");
+
+ Type t = null;
+ string matchname = null;
+
+ if (name.IndexOf ('.') != -1) {
+ // fully qualified name
+ if (bm.LookupType (name, logger, out t))
+ return null;
+
+ if (t == null) {
+ logger.Error (2023, "Type lookup failed
-- did you forget a using [] directive?", name);
+ return null;
+ }
+
+ return t;
+ }
+
+ for (int i = 0; i < namespaces.Count; i++) {
+ string pname = namespaces[i] + "." + name;
+ Type match = null;;
+
+ if (bm.LookupType (pname, logger, out match))
+ return null;
+
+ if (match == null)
+ continue;
+
+ if (t != null) {
+ string s = String.Format ("Ambiguous
type reference: {0} could be {1} or {2}",
+ name, pname,
matchname);
+ logger.Error (2022, s, null);
+ return null;
+ }
+
+ matchname = pname;
+ t = match;
+ }
+
+ if (t == null) {
+ logger.Error (2023, "Type lookup failed -- did
you forget a using [] directive?", name);
+ return null;
+ }
+
+ return t;
+ }
+
+ // Utility for users of type lookup
+
+ object CreateName (string name, IWarningLogger logger, Type
expected) {
+ Type t = LookupType (name, logger);
+
+ if (t == null)
+ return null;
+
+ if (expected != null && !t.IsSubclassOf (expected)) {
+ string s = String.Format ("Name {0} (type {1})
is not a subclass of {1} as expected",
+ name, t.FullName,
expected.FullName);
+ logger.Error (2025, s, null);
+ return null;
+ }
+
+ return Activator.CreateInstance (t);
+ }
+
+ public Result CreateResult (string name, IWarningLogger logger)
{
+ return (Result) CreateName (name, logger, typeof
(Result));
+ }
+
+ public Rule CreateRule (string name, IWarningLogger logger) {
+ return (Rule) CreateName (name, logger, typeof (Rule));
+ }
+
+ // IBundleUser
+
+ public void NotifyTargetRuleMatcher (Type t) {
+ target_rule_matchers.Add (Activator.CreateInstance (t));
+ }
+
+ public void NotifyDepRuleMatcher (Type t) {
+ dep_rule_matchers.Add (Activator.CreateInstance (t));
+ }
+
+ public void NotifyDirectTransformRuleMatcher (Type t) {
+ dt_rule_matchers.Add (Activator.CreateInstance (t));
+ }
+
+ // matching
+
+ Type try_match (string name, ArrayList matchers, IWarningLogger
logger) {
+ Type t = null;
+ IMatcher which = null;
+ int quality = 0;
+
+ foreach (IMatcher m in matchers) {
+ int q;
+ Type match = m.TryMatch (name, out q);
+
+ if (match == null)
+ continue;
+
+ if (q < quality)
+ continue;
+
+ if (t != null && q == quality) {
+ // FIXME: provide a way to specify
which one should take priority!
+ string s = String.Format ("Two matches
succeed with equal quality: " +
+ "{0} and {1};
going with the first",
+ which, m);
+ logger.Warning (2026, s, name);
+ break;
+ }
+
+ which = m;
+ t = match;
+ quality = q;
+ }
+
+ return t;
+ }
+
+ // These only need a logger for the double-match warning,
+ // so if the return value is null we know that there is
+ // definitely no match.
+
+ public Type TryTargetRuleMatch (string name, IWarningLogger
logger) {
+ return try_match (name, target_rule_matchers, logger);
+ }
+
+ public Type TryDepRuleMatch (string name, IWarningLogger
logger) {
+ return try_match (name, dep_rule_matchers, logger);
+ }
+
+ public Type TryDirectTransformRuleMatch (string name,
IWarningLogger logger) {
+ return try_match (name, dt_rule_matchers, logger);
+ }
+
+ // blah
+
+ public object Clone () {
+ if (this.bm != null)
+ throw new InvalidOperationException ();
+
+ NameLookupContext clone = new NameLookupContext ();
+ clone.namespaces = (ArrayList) this.namespaces.Clone ();
+ return clone;
+ }
+
+ public override string ToString () {
+ StringBuilder sb = new StringBuilder
("NameLookupContext: ");
+
+ sb.Append ("using namespaces:");
+ for (int i = 0; i < namespaces.Count; i++)
+ sb.AppendFormat (" {0}", namespaces[i]);
+
+ return sb.ToString ();
+ }
+ }
+}
Modified: trunk/mbuild/Monkeywrench.dll.sources
===================================================================
--- trunk/mbuild/Monkeywrench.dll.sources 2006-07-21 20:58:04 UTC (rev
62879)
+++ trunk/mbuild/Monkeywrench.dll.sources 2006-07-21 21:08:04 UTC (rev
62880)
@@ -25,12 +25,15 @@
Monkeywrench/Monkeywrench.Compiler/BuildfileParser-rest.cs
Monkeywrench/Monkeywrench.Compiler/BuildfileProviderLoader.cs
Monkeywrench/Monkeywrench.Compiler/BuildfileTokenizer.cs
+Monkeywrench/Monkeywrench.Compiler/BundleManager.cs
Monkeywrench/Monkeywrench.Compiler/DependentItemInfo.cs
Monkeywrench/Monkeywrench.Compiler/GraphBuilder.cs
Monkeywrench/Monkeywrench.Compiler/GraphCompiler.cs
Monkeywrench/Monkeywrench.Compiler/InsideProviderLoader.cs
+Monkeywrench/Monkeywrench.Compiler/IBundleUser.cs
Monkeywrench/Monkeywrench.Compiler/IGraphState.cs
Monkeywrench/Monkeywrench.Compiler/ITargetRequestSink.cs
+Monkeywrench/Monkeywrench.Compiler/NameLookupContext.cs
Monkeywrench/Monkeywrench.Compiler/ProjectProvider.cs
Monkeywrench/Monkeywrench.Compiler/ProviderBuilder.cs
Monkeywrench/Monkeywrench.Compiler/ProviderCopyLoader.cs
Modified: trunk/mbuild/Mono.Build/ChangeLog
===================================================================
--- trunk/mbuild/Mono.Build/ChangeLog 2006-07-21 20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Mono.Build/ChangeLog 2006-07-21 21:08:04 UTC (rev 62880)
@@ -1,3 +1,9 @@
+2006-07-21 Peter Williams <[EMAIL PROTECTED]>
+
+ * Mono.Build/Fingerprint.cs (ImportXml): I *knew* that somewhere in
+ the .Net system libraries there had to be a base64 decode function.
+ Use it.
+
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
Another touch-all-bundles change. In preparation for better
Modified: trunk/mbuild/Mono.Build/Mono.Build/Fingerprint.cs
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build/Fingerprint.cs 2006-07-21 20:58:04 UTC
(rev 62879)
+++ trunk/mbuild/Mono.Build/Mono.Build/Fingerprint.cs 2006-07-21 21:08:04 UTC
(rev 62880)
@@ -125,24 +125,15 @@
return sb.ToString ();
}
- // XML. XmlWriter has a WriteBase64, but XmlReader doesn't have
- // ReadBase64 (XmlTextReader does, sigh), so we implement our
own
- // hex encoding
+ // XML.
protected override void ExportXml (XmlWriter xw) {
- xw.WriteString (ToString ());
+ xw.WriteBase64 (value, 0, value.Length);
}
protected override bool ImportXml (XmlReader xr, IWarningLogger
log) {
- char[] text = xr.ReadString ().ToCharArray ();
-
try {
- value = new byte[text.Length / 2];
-
- for (int i = 0; i < value.Length; i++) {
- value[i] = HexCharToVal (text[i * 2 + 1]);
- value[i] |= (byte) (HexCharToVal (text[i * 2]) <<
4);
- }
+ value = Convert.FromBase64String (xr.ReadString ());
} catch (Exception e) {
log.Error (9999, "Fingerprint XML recovery hit invalid
format", e.Message);
return true;
@@ -151,30 +142,6 @@
return false;
}
- byte HexCharToVal (char c)
- {
- // don't bother to be smart
- switch (c) {
- case '0': return 0x0;
- case '1': return 0x1;
- case '2': return 0x2;
- case '3': return 0x3;
- case '4': return 0x4;
- case '5': return 0x5;
- case '6': return 0x6;
- case '7': return 0x7;
- case '8': return 0x8;
- case '9': return 0x9;
- case 'a': return 0xA;
- case 'b': return 0xB;
- case 'c': return 0xC;
- case 'd': return 0xD;
- case 'e': return 0xE;
- case 'f': return 0xF;
- default: throw new Exception ("Invalid hex encoding
character: " + c);
- }
- }
-
// Result
public override Fingerprint GetFingerprint (IBuildContext ctxt,
Fingerprint cached) {
Deleted: trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs
2006-07-21 20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Mono.Build/Mono.Build.Bundling/BundleManager.cs
2006-07-21 21:08:04 UTC (rev 62880)
@@ -1,328 +0,0 @@
-//
-// BundleManager.cs -- a class for loading and tracking bundles
-//
-
-using System;
-using System.Collections;
-using System.Reflection;
-using System.IO;
-using System.Text;
-
-using Mono.Build;
-
-namespace Mono.Build.Bundling {
-
- public delegate bool PublicProviderAdded (string basis,
IBuildProvider prov);
-
- public class BundleManager {
-
- public const string MBuildPrefix = "MBuildDynamic.";
-
- public BundleManager () {
- }
-
- // Bundle table
-
- Hashtable bundles = new Hashtable ();
-
- public IEnumerable BundleAssemblies {
- get {
- return bundles.Values;
- }
- }
-
- Assembly this [AssemblyName aname] {
- get {
- if (bundles.Contains (aname.Name))
- return (Assembly) bundles[aname.Name];
- return null;
- }
-
- set {
- bundles[aname.Name] = value;
- }
- }
-
- // Loading bundles
-
- public event PublicProviderAdded OnPublicProviderAdded;
-
- public static AssemblyName MakeName (string shortname, string
version) {
- byte[] pktok = Assembly.GetExecutingAssembly ().GetName
().GetPublicKeyToken ();
-
- AssemblyName n = new AssemblyName ();
- n.Name = MBuildPrefix + shortname;
- n.SetPublicKeyToken (pktok);
-
- if (version != null)
- n.Version = new Version (version);
-
- return n;
- }
-
- public static AssemblyName MakeName (string shortname) {
- return MakeName (shortname, null);
- }
-
- public bool LoadBundle (AssemblyName aname, IWarningLogger
logger) {
- return LoadBundle (aname, logger, true);
- }
-
- public bool LoadBundle (string path, IWarningLogger logger) {
- return LoadBundle (path, logger, true);
- }
-
- public bool LoadBundle (Assembly assy, IWarningLogger logger) {
- return LoadBundle (assy, null, logger, true);
- }
-
- 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 (),
- e.ToString ());
- return true;
- }
-
- return LoadBundle (assy, aname.Version, logger,
expecting_bundle);
- }
-
- bool LoadBundle (string path, IWarningLogger logger, bool
expecting_bundle) {
- Assembly assy;
-
- try {
- assy = System.AppDomain.CurrentDomain.Load
(path);
- Console.WriteLine ("loadfrom: {0} -> {1}",
path, assy);
- } catch (Exception e) {
- logger.Error (2020, "Could not load the
referenced assembly " + path,
- e.ToString ());
- return true;
- }
-
- return LoadBundle (assy, null, logger,
expecting_bundle);
- }
-
- 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 NewBundleLoaded (assy, logger);
- }
-
- bool NewBundleLoaded (Assembly assy, IWarningLogger logger) {
- //Console.WriteLine ("Loaded assembly {0}", assy);
-
- Type[] types = assy.GetExportedTypes ();
- Type ibp = typeof (IBuildProvider);
- SortedList providers = new SortedList ();
-
- foreach (Type t in types) {
- foreach (Type iface in t.GetInterfaces ()) {
- // see note above
- if (iface.Equals (ibp) ||
iface.IsSubclassOf (ibp)) {
- object[] attrs =
t.GetCustomAttributes (typeof (ProviderPrefixAttribute), false);
-
- if (attrs.Length < 1) {
- logger.Error (4000,
System.String.Format ("Exported build provider {0} " +
-
"in assembly {1} is missing a " +
-
"ProviderPrefixAttribute",
-
t.FullName, assy.FullName), null);
- return true;
- }
-
- foreach
(ProviderPrefixAttribute attr in attrs) {
- // Might as well let
one class be loaded in multiple prefixes ...
- string prefix =
attr.Prefix;
-
- // normalize to end in
slashes
- if
(prefix[prefix.Length - 1] != '/')
- prefix = prefix
+ "/";
-
- if (providers.Contains
(prefix)) {
- logger.Error
(2032, "Redefinition of provider " + prefix, assy.FullName);
- return true;
- }
-
- // FIXME: just add the
type here, and instantiate as needed?
-
- providers.Add (prefix,
Activator.CreateInstance (t));
- }
-
- break;
- }
- }
- }
-
- // the providers are sorted so that we add parents
before children, a requirement
- // that isn't really necessary at this level of
abstraction but is needed for
- // Monkeywrench.
- //
- // Well, now we can add them below if they're not
IDynamicBuildProviders,
- // which most (all?) public providers will not be, but
might as well still do this.
-
-
- if (OnPublicProviderAdded != null) {
- foreach (string prefix in providers.Keys) {
- if (OnPublicProviderAdded (prefix,
(IBuildProvider) providers[prefix]))
- return true;
- }
- }
-
- return false;
- }
-
- // Namespace management
-
- public bool UseNamespace (string ns, IBundleUser user,
IWarningLogger logger) {
- int numfound = 0;
-
- if (ns == null)
- throw new ArgumentNullException ("ns");
-
- ns = MBuildPrefix + ns;
-
- foreach (Assembly assy in bundles.Values)
- numfound += NotifyTypes (assy, ns, user);
-
- if (numfound == 0) {
- logger.Error (2021, "No referenced assembly
provides the requested namespace", ns);
- return true;
- }
-
- return false;
- }
-
- int NotifyTypes (Assembly assy, string pns, IBundleUser user) {
- int numfound = 0;
- Type[] types = assy.GetExportedTypes ();
-
- Type imatcher = typeof (IMatcher);
-
- foreach (Type t in types) {
- if (t.Namespace != pns)
- continue;
-
- numfound++;
-
- //Console.WriteLine ("Checking out type {0}:
{1}", t.FullName, t.Attributes);
-
- foreach (Type iface in t.GetInterfaces ()) {
- if (iface.Equals (imatcher) ||
iface.IsSubclassOf (imatcher)) {
- int hits = 0;
- object[] attrs =
t.GetCustomAttributes (typeof (TargetRuleMatcherAttribute), false);
-
- if (attrs.Length > 0) {
- hits++;
-
- if (user != null)
-
user.NotifyTargetRuleMatcher (t);
- }
-
- attrs = t.GetCustomAttributes
(typeof (DepRuleMatcherAttribute), false);
-
- if (attrs.Length > 0) {
- hits++;
-
- if (user != null)
-
user.NotifyDepRuleMatcher (t);
- }
-
- attrs = t.GetCustomAttributes
(typeof (DirectTransformMatcherAttribute), false);
-
- if (attrs.Length > 0) {
- hits++;
-
- if (user != null)
-
user.NotifyDirectTransformRuleMatcher (t);
- }
-
- if (hits == 0)
- throw new Exception
(System.String.Format ("Type {0} is an IMatcher but does not " +
-
"have a xxxRuleMatcher attribute.",
-
t));
-
- // really break here? as we add
things here
- // we must decide
- break;
- }
- }
- }
-
- return numfound;
- }
-
- public bool LookupType (string name, IWarningLogger logger, out
Type t) {
- // We need the out parameter because returning null
could either mean
- // "no match" (ok) or "error with the type" (except
perhaps our one
- // error condition can't even happen.)
-
- if (name == null)
- throw new ArgumentNullException ();
-
- //if (!StrUtils.StartsWith (name, MBuildPrefix))
- name = MBuildPrefix + name;
-
- t = null;
- Assembly where = null;
-
- // efficiency? hah!
- //
- // Actually, will the runtime throw an error if we load
- // two assemblies that define the same type? Seems
- // reasonable.
-
- foreach (Assembly assy in bundles.Values) {
- 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, where.FullName, assy.FullName), null);
- return true;
- }
-
- t = match;
- where = assy;
- }
-
- return false;
- }
- }
-}
Deleted: trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs 2006-07-21
20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Mono.Build/Mono.Build.Bundling/IBundleUser.cs 2006-07-21
21:08:04 UTC (rev 62880)
@@ -1,15 +0,0 @@
-//
-// IBundleUser.cs -- interface for notifying something that loads bundles
-// about the types that it exports
-//
-
-using System;
-
-namespace Mono.Build.Bundling {
-
- public interface IBundleUser {
- void NotifyTargetRuleMatcher (Type t);
- void NotifyDepRuleMatcher (Type t);
- void NotifyDirectTransformRuleMatcher (Type t);
- }
-}
Deleted: trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
===================================================================
--- trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
2006-07-21 20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
2006-07-21 21:08:04 UTC (rev 62880)
@@ -1,225 +0,0 @@
-//
-// NameLookupContext.cs -- an environment in which we look up names of targets
-// and names in bundles.
-//
-
-using System;
-using System.Collections;
-using System.Reflection;
-using System.Text;
-
-using Mono.Build;
-
-namespace Mono.Build.Bundling {
-
- public class NameLookupContext : IBundleUser, ICloneable {
- ArrayList namespaces;
- ArrayList target_rule_matchers;
- ArrayList dep_rule_matchers;
- ArrayList dt_rule_matchers;
-
- public NameLookupContext () {
- this.namespaces = new ArrayList ();
- this.target_rule_matchers = new ArrayList ();
- this.dep_rule_matchers = new ArrayList ();
- this.dt_rule_matchers = new ArrayList ();
- }
-
- // Manager
-
- BundleManager bm;
-
- public BundleManager Manager { get { return bm; } }
-
- public bool SetManager (BundleManager bm, IWarningLogger
logger) {
- if (bm == null)
- throw new ArgumentNullException ();
- if (this.bm != null)
- throw new Exception ("Already have manager
set");
-
- this.bm = bm;
-
- for (int i = 0; i < namespaces.Count; i++)
- if (bm.UseNamespace ((string) namespaces[i],
this, logger))
- return true;
-
- return false;
- }
-
- // Lookup
-
- public bool UseNamespace (string ns, IWarningLogger logger) {
- if (ns == null)
- throw new ArgumentNullException ();
-
- namespaces.Add (ns);
-
- if (bm == null)
- return false;
-
- return bm.UseNamespace (ns, this, logger);
- }
-
- public Type LookupType (string name, IWarningLogger logger) {
- if (name == null)
- throw new ArgumentNullException ();
- if (bm == null)
- throw new Exception ("Need to set manager
before performing type lookup.");
-
- Type t = null;
- string matchname = null;
-
- if (name.IndexOf ('.') != -1) {
- // fully qualified name
- if (bm.LookupType (name, logger, out t))
- return null;
-
- if (t == null) {
- logger.Error (2023, "Type lookup failed
-- did you forget a using [] directive?", name);
- return null;
- }
-
- return t;
- }
-
- for (int i = 0; i < namespaces.Count; i++) {
- string pname = namespaces[i] + "." + name;
- Type match = null;;
-
- if (bm.LookupType (pname, logger, out match))
- return null;
-
- if (match == null)
- continue;
-
- if (t != null) {
- string s = String.Format ("Ambiguous
type reference: {0} could be {1} or {2}",
- name, pname,
matchname);
- logger.Error (2022, s, null);
- return null;
- }
-
- matchname = pname;
- t = match;
- }
-
- if (t == null) {
- logger.Error (2023, "Type lookup failed -- did
you forget a using [] directive?", name);
- return null;
- }
-
- return t;
- }
-
- // Utility for users of type lookup
-
- object CreateName (string name, IWarningLogger logger, Type
expected) {
- Type t = LookupType (name, logger);
-
- if (t == null)
- return null;
-
- if (expected != null && !t.IsSubclassOf (expected)) {
- string s = String.Format ("Name {0} (type {1})
is not a subclass of {1} as expected",
- name, t.FullName,
expected.FullName);
- logger.Error (2025, s, null);
- return null;
- }
-
- return Activator.CreateInstance (t);
- }
-
- public Result CreateResult (string name, IWarningLogger logger)
{
- return (Result) CreateName (name, logger, typeof
(Result));
- }
-
- public Rule CreateRule (string name, IWarningLogger logger) {
- return (Rule) CreateName (name, logger, typeof (Rule));
- }
-
- // IBundleUser
-
- public void NotifyTargetRuleMatcher (Type t) {
- target_rule_matchers.Add (Activator.CreateInstance (t));
- }
-
- public void NotifyDepRuleMatcher (Type t) {
- dep_rule_matchers.Add (Activator.CreateInstance (t));
- }
-
- public void NotifyDirectTransformRuleMatcher (Type t) {
- dt_rule_matchers.Add (Activator.CreateInstance (t));
- }
-
- // matching
-
- Type try_match (string name, ArrayList matchers, IWarningLogger
logger) {
- Type t = null;
- IMatcher which = null;
- int quality = 0;
-
- foreach (IMatcher m in matchers) {
- int q;
- Type match = m.TryMatch (name, out q);
-
- if (match == null)
- continue;
-
- if (q < quality)
- continue;
-
- if (t != null && q == quality) {
- // FIXME: provide a way to specify
which one should take priority!
- string s = String.Format ("Two matches
succeed with equal quality: " +
- "{0} and {1};
going with the first",
- which, m);
- logger.Warning (2026, s, name);
- break;
- }
-
- which = m;
- t = match;
- quality = q;
- }
-
- return t;
- }
-
- // These only need a logger for the double-match warning,
- // so if the return value is null we know that there is
- // definitely no match.
-
- public Type TryTargetRuleMatch (string name, IWarningLogger
logger) {
- return try_match (name, target_rule_matchers, logger);
- }
-
- public Type TryDepRuleMatch (string name, IWarningLogger
logger) {
- return try_match (name, dep_rule_matchers, logger);
- }
-
- public Type TryDirectTransformRuleMatch (string name,
IWarningLogger logger) {
- return try_match (name, dt_rule_matchers, logger);
- }
-
- // blah
-
- public object Clone () {
- if (this.bm != null)
- throw new InvalidOperationException ();
-
- NameLookupContext clone = new NameLookupContext ();
- clone.namespaces = (ArrayList) this.namespaces.Clone ();
- return clone;
- }
-
- public override string ToString () {
- StringBuilder sb = new StringBuilder
("NameLookupContext: ");
-
- sb.Append ("using namespaces:");
- for (int i = 0; i < namespaces.Count; i++)
- sb.AppendFormat (" {0}", namespaces[i]);
-
- return sb.ToString ();
- }
- }
-}
Modified: trunk/mbuild/Mono.Build.dll.sources
===================================================================
--- trunk/mbuild/Mono.Build.dll.sources 2006-07-21 20:58:04 UTC (rev 62879)
+++ trunk/mbuild/Mono.Build.dll.sources 2006-07-21 21:08:04 UTC (rev 62880)
@@ -39,14 +39,11 @@
Mono.Build/Mono.Build/SimpleTarget.cs
Mono.Build/Mono.Build/StrUtils.cs
Mono.Build/Mono.Build/TagTargetBase.cs
-Mono.Build/Mono.Build.Bundling/BundleManager.cs
Mono.Build/Mono.Build.Bundling/DepRuleMatcherAttribute.cs
Mono.Build/Mono.Build.Bundling/DirectTransformMatcherAttribute.cs
-Mono.Build/Mono.Build.Bundling/IBundleUser.cs
Mono.Build/Mono.Build.Bundling/IMatcher.cs
Mono.Build/Mono.Build.Bundling/MonoBuildBundleAttribute.cs
Mono.Build/Mono.Build.Bundling/MonoBuildDictItemAttribute.cs
-Mono.Build/Mono.Build.Bundling/NameLookupContext.cs
Mono.Build/Mono.Build.Bundling/ProviderPrefixAttribute.cs
Mono.Build/Mono.Build.Bundling/TargetRuleMatcherAttribute.cs
Mono.Build/Mono.Build.RuleLib/ArchKindResult.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches