-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To indicate that a substitution or descriptor should be applied in the absence of a feature setting. Note that this is restricted to still require the featurevalue attribute, to prevent the definition of default substitutions that are never applied for any feature settings. Also address PR feedback: - Move the feature checks into a separate class - #ifdef an implementation instead of callsites
- Loading branch information
Showing
11 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Xml.XPath; | ||
|
||
namespace Mono.Linker | ||
{ | ||
public static class FeatureSettings | ||
{ | ||
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 == null || !context.FeatureSettings.TryGetValue (feature, out bool featureSetting)) | ||
return bIsDefault; | ||
|
||
return bValue == featureSetting; | ||
} | ||
|
||
public static string GetAttribute (XPathNavigator nav, string attribute) | ||
{ | ||
return nav.GetAttribute (attribute, String.Empty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 13 additions & 2 deletions
15
test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureSubstitutions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
<linker feature="OptionalFeature" featurevalue="false"> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutions"> | ||
<method signature="System.Boolean get_IsOptionalFeatureEnabled()" body="stub" value="false"> | ||
</method> | ||
<method signature="System.Boolean get_IsOptionalFeatureEnabled()" body="stub" value="false" /> | ||
</type> | ||
</assembly> | ||
<!-- Check that a feature condition can be used by default --> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="DefaultFeature" featurevalue="true" featuredefault="true"> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutions"> | ||
<method signature ="System.Boolean get_IsDefaultFeatureEnabled()" body="stub" value="true" /> | ||
</type> | ||
</assembly> | ||
<!-- Else case for the default condition --> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="DefaultFeature" featurevalue="false"> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutions"> | ||
<method signature ="System.Boolean get_IsDefaultFeatureEnabled()" body="stub" value="false" /> | ||
</type> | ||
</assembly> | ||
</linker> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureSubstitutionsInvalid.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<linker> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutionsInvalid"> | ||
<method signature="System.Boolean NoValueFeatureMethod()" body="stub" value="true" feature="NoValueFeature" /> | ||
<method signature="System.Boolean NonBooleanFeatureMethod()" body="stub" value="false" feature="NonBooleanFeature" featurevalue="nonboolean" /> | ||
<method signature="System.Boolean BooleanFeatureMethod()" body="stub" value="false" feature="BooleanFeature" featurevalue="true" /> | ||
</type> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutionsInvalid/Foo"> | ||
<field name="NonExistentField" /> | ||
<method signature="NonExistentMethod" /> | ||
</type> | ||
</assembly> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutionsInvalid"> | ||
<method signature="System.Boolean NoValueFeatureMethod()" body="stub" value="true" feature="NoValueFeature" /> | ||
<method signature="System.Boolean NonBooleanFeatureMethod()" body="stub" value="false" feature="NonBooleanFeature" featurevalue="nonboolean" /> | ||
<method signature="System.Boolean InvalidDefaultFeatureMethod()" body="stub" value="true" feature="InvalidDefaultFeatureMethod" featurevalue="true" featuredefault="false" /> | ||
</type> | ||
<type fullname="Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutionsInvalid/Foo"> | ||
<field name="NonExistentField" /> | ||
<method signature="NonExistentMethod" /> | ||
</type> | ||
</assembly> | ||
</linker> |