Example #1
0
        bool ShouldProcessElement(XPathNavigator nav)
        {
            var feature = GetAttribute(nav, "feature");

            if (string.IsNullOrEmpty(feature))
            {
                return(true);
            }

            var value = GetAttribute(nav, "featurevalue");

            if (string.IsNullOrEmpty(value))
            {
                _context.LogError($"Feature {feature} does not specify a 'featurevalue' attribute", 1001);
                return(false);
            }

            if (!bool.TryParse(value, out bool bValue))
            {
                _context.LogError($"Unsupported non-boolean feature definition {feature}", 1002);
                return(false);
            }

            if (_context.FeatureSettings == null || !_context.FeatureSettings.TryGetValue(feature, out bool featureSetting))
            {
                return(false);
            }

            return(bValue == featureSetting);
        }
Example #2
0
		public static bool ShouldProcessElement (XPathNavigator nav, LinkContext context, string documentLocation)
		{
			var feature = GetAttribute (nav, "feature");
			if (string.IsNullOrEmpty (feature))
				return true;

			var value = GetAttribute (nav, "featurevalue");
			if (string.IsNullOrEmpty (value)) {
				context.LogError (null, DiagnosticId.XmlFeatureDoesNotSpecifyFeatureValue, documentLocation, feature);
				return false;
			}

			if (!bool.TryParse (value, out bool bValue)) {
				context.LogError (null, DiagnosticId.XmlUnsupportedNonBooleanValueForFeature, documentLocation, feature);
				return false;
			}

			var isDefault = GetAttribute (nav, "featuredefault");
			bool bIsDefault = false;
			if (!string.IsNullOrEmpty (isDefault) && (!bool.TryParse (isDefault, out bIsDefault) || !bIsDefault)) {
				context.LogError (null, DiagnosticId.XmlDocumentLocationHasInvalidFeatureDefault, documentLocation);
				return false;
			}

			if (!context.FeatureSettings.TryGetValue (feature, out bool featureSetting))
				return bIsDefault;

			return bValue == featureSetting;
		}
Example #3
0
        public static AttributeInfo ProcessAttributes(AssemblyDefinition assembly, LinkContext context)
        {
            if (context.Annotations.GetAction(assembly) == AssemblyAction.Skip)
            {
                return(null);
            }

            var rsc = GetEmbeddedXml(assembly, res => res.Name.Equals("ILLink.LinkAttributes.xml", StringComparison.OrdinalIgnoreCase));

            if (rsc == null)
            {
                return(null);
            }

            LinkAttributesParser parser = null;

            try {
                context.LogMessage($"Processing embedded {rsc.Name} from {assembly.Name}");
                parser = GetExternalLinkAttributesParser(context, rsc, assembly);
            } catch (XmlException ex) {
                context.LogError($"Error processing {rsc.Name} from {assembly.Name}: {ex}", 1003);
            }

            if (parser == null)
            {
                return(null);
            }

            var attributeInfo = new AttributeInfo();

            parser.Parse(attributeInfo);
            return(attributeInfo);
        }
Example #4
0
        public static void ProcessDescriptors(AssemblyDefinition assembly, LinkContext context)
        {
            if (context.Annotations.GetAction(assembly) == AssemblyAction.Skip)
            {
                return;
            }

            var rsc = GetEmbeddedXml(assembly, res => ShouldProcessRootDescriptorResource(assembly, context, res.Name));

            if (rsc == null)
            {
                return;
            }

            DescriptorMarker marker = null;

            try {
                context.LogMessage($"Processing embedded linker descriptor {rsc.Name} from {assembly.Name}");
                marker = GetExternalResolveStep(context, rsc, assembly);
            } catch (XmlException ex) {
                /* This could happen if some broken XML file is embedded. */
                context.LogError($"Error processing {rsc.Name}: {ex}", 1003);
            }

            if (marker != null)
            {
                marker.Mark();
            }
        }
Example #5
0
        public static SubstitutionInfo?ProcessSubstitutions(AssemblyDefinition assembly, LinkContext context)
        {
            if (context.Annotations.GetAction(assembly) == AssemblyAction.Skip)
            {
                return(null);
            }

            var rsc = GetEmbeddedXml(assembly, res => res.Name.Equals("ILLink.Substitutions.xml", StringComparison.OrdinalIgnoreCase));

            if (rsc == null)
            {
                return(null);
            }

            BodySubstitutionParser?parser = null;

            try {
                context.LogMessage($"Processing embedded substitution descriptor '{rsc.Name}' from '{assembly.Name}'.");
                parser = GetExternalSubstitutionParser(context, rsc, assembly);
            } catch (XmlException ex) {
                context.LogError(null, DiagnosticId.XmlException, rsc.Name, ex.ToString());
            }

            if (parser == null)
            {
                return(null);
            }

            var substitutionInfo = new SubstitutionInfo();

            parser.Parse(substitutionInfo);
            return(substitutionInfo);
        }
Example #6
0
        public static bool ShouldProcessElement(XPathNavigator nav, LinkContext context, string documentLocation)
        {
            var feature = GetAttribute(nav, "feature");

            if (string.IsNullOrEmpty(feature))
            {
                return(true);
            }

            var value = GetAttribute(nav, "featurevalue");

            if (string.IsNullOrEmpty(value))
            {
                context.LogError($"Failed to process '{documentLocation}'. Feature '{feature}' does not specify a 'featurevalue' attribute", 1001);
                return(false);
            }

            if (!bool.TryParse(value, out bool bValue))
            {
                context.LogError($"Failed to process '{documentLocation}'. Unsupported non-boolean feature definition '{feature}'", 1002);
                return(false);
            }

            var  isDefault  = GetAttribute(nav, "featuredefault");
            bool bIsDefault = false;

            if (!string.IsNullOrEmpty(isDefault) && (!bool.TryParse(isDefault, out bIsDefault) || !bIsDefault))
            {
                context.LogError($"Failed to process '{documentLocation}'. Unsupported value for featuredefault attribute", 1014);
                return(false);
            }

            if (!context.FeatureSettings.TryGetValue(feature, out bool featureSetting))
            {
                return(bIsDefault);
            }

            return(bValue == featureSetting);
        }
Example #7
0
        public bool Run(ILogger customLogger = null)
        {
            int setupStatus = SetupContext(customLogger);

            if (setupStatus > 0)
            {
                return(true);
            }
            if (setupStatus < 0)
            {
                return(false);
            }

            Pipeline p = context.Pipeline;

            PreProcessPipeline(p);

            try {
                p.Process(context);
            } catch (Exception ex) {
                if (ex is LinkerFatalErrorException lex)
                {
                    context.LogMessage(lex.MessageContainer);
                    Console.Error.WriteLine(ex.ToString());
                }
                else
                {
                    context.LogError($"IL Linker has encountered an unexpected error. Please report the issue at https://github.com/mono/linker/issues \n{ex}", 1012);
                }

                return(false);
            } finally {
                context.Tracer.Finish();
            }

            return(true);
        }