Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support feature settings on descriptor files #1277

Merged
merged 9 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ error and warning codes.

## Error Codes

#### `IL1001`: Failed to process XML substitution: 'XML document location'. Feature 'feature' does not specify a "featurevalue" attribute
#### `IL1001`: Failed to process 'XML document location'. Feature 'feature' does not specify a "featurevalue" attribute

- The substitution in 'XML document location' with feature value 'feature' does not use the `featurevalue` attribute. These attributes have to be used together.

#### `IL1002`: Failed to process XML substitution: 'XML document location'. Unsupported non-boolean feature definition 'feature'
#### `IL1002`: Failed to process 'XML document location'. Unsupported non-boolean feature definition 'feature'

- The substitution in 'XML document location' with feature value 'feature' sets the attribute `featurevalue` to a non-boolean value. Only boolean values are supported for this attribute.

Expand Down
29 changes: 4 additions & 25 deletions src/linker/Linker.Steps/BodySubstituterStep.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Globalization;
using System.Xml.XPath;
Expand Down Expand Up @@ -41,28 +42,7 @@ protected override void Process ()
ReadSubstitutions (_document);
}

bool ShouldProcessSubstitutions (XPathNavigator nav)
{
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 XML substitution: '{_xmlDocumentLocation}'. Feature {feature} does not specify a 'featurevalue' attribute", 1001);
return false;
}

if (!bool.TryParse (value, out bool bValue)) {
Context.LogError ($"Failed to process XML substitution: '{_xmlDocumentLocation}'. 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;
}
bool ShouldProcessSubstitutions (XPathNavigator nav) => ResolveFromXmlStep.ShouldProcessElement (nav, Context, _xmlDocumentLocation);

void ReadSubstitutions (XPathDocument document)
{
Expand Down Expand Up @@ -126,10 +106,9 @@ void ProcessTypes (AssemblyDefinition assembly, XPathNodeIterator iterator)

void ProcessType (TypeDefinition type, XPathNavigator nav)
{
if (!nav.HasChildren)
return;
Debug.Assert (ShouldProcessSubstitutions (nav));

if (!ShouldProcessSubstitutions (nav))
if (!nav.HasChildren)
return;

XPathNodeIterator methods = nav.SelectChildren ("method", "");
Expand Down
49 changes: 14 additions & 35 deletions src/linker/Linker.Steps/LinkAttributesStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -154,7 +155,7 @@ void ProcessAssemblies (LinkContext context, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
if (!ShouldProcessElement (iterator.Current))
return;
continue;

if (GetFullName (iterator.Current) == "*") {
foreach (AssemblyDefinition assemblyIterator in context.GetAssemblies ()) {
Expand Down Expand Up @@ -249,6 +250,8 @@ void ProcessTypePattern (string fullname, AssemblyDefinition assembly, XPathNavi

void ProcessType (TypeDefinition type, XPathNavigator nav)
{
Debug.Assert (ShouldProcessElement (nav));

IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav);
if (attributes.Count () > 0)
Context.CustomAttributes.AddCustomAttributes (type, attributes);
Expand Down Expand Up @@ -283,9 +286,9 @@ void ProcessSelectedFields (XPathNavigator nav, TypeDefinition type)
return;

while (fields.MoveNext ()) {
if (!ShouldProcessElement (fields.Current)) {
return;
}
if (!ShouldProcessElement (fields.Current))
continue;

string value = GetSignature (fields.Current);
if (!String.IsNullOrEmpty (value))
ProcessFieldSignature (type, value, fields);
Expand All @@ -303,9 +306,8 @@ void ProcessSelectedMethods (XPathNavigator nav, TypeDefinition type)
return;

while (methods.MoveNext ()) {
if (!ShouldProcessElement (methods.Current)) {
return;
}
if (!ShouldProcessElement (methods.Current))
continue;

string value = GetSignature (methods.Current);
if (!String.IsNullOrEmpty (value))
Expand All @@ -323,9 +325,8 @@ void ProcessSelectedProperties (XPathNavigator nav, TypeDefinition type)
if (properties.Count == 0)
return;
while (properties.MoveNext ()) {
if (!ShouldProcessElement (properties.Current)) {
return;
}
if (!ShouldProcessElement (properties.Current))
continue;

string value = GetSignature (properties.Current);
if (!String.IsNullOrEmpty (value))
Expand All @@ -343,9 +344,8 @@ void ProcessSelectedEvents (XPathNavigator nav, TypeDefinition type)
if (events.Count == 0)
return;
while (events.MoveNext ()) {
if (!ShouldProcessElement (events.Current)) {
return;
}
if (!ShouldProcessElement (events.Current))
continue;

string value = GetSignature (events.Current);
if (!String.IsNullOrEmpty (value))
Expand Down Expand Up @@ -600,27 +600,6 @@ static PropertyDefinition GetProperty (TypeDefinition type, string signature)
return null;
}

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;
}
bool ShouldProcessElement (XPathNavigator nav) => ResolveFromXmlStep.ShouldProcessElement (nav, Context, _xmlDocumentLocation);
}
}
Loading