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

Enable RuntimeInformation intrinsic functions on all platforms #1926

Merged
merged 5 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<dependency id="Microsoft.Build.Utilities.Core" version="[$version$]" />
<dependency id="System.Collections.Immutable" version="1.3.1" />
<dependency id="System.Reflection.Metadata" version="1.3.0" />
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
1 change: 1 addition & 0 deletions build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</group>
<group targetFramework=".NETFramework4.6">
<dependency id="Microsoft.Build.Framework" version="[$version$]" />
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
1 change: 1 addition & 0 deletions build/NuGetPackages/Microsoft.Build.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<group targetFramework=".NETFramework4.6">
<dependency id="Microsoft.Build.Framework" version="[$version$]" />
<dependency id="System.Collections.Immutable" version="1.3.1" />
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" />
</group>
</dependencies>
<frameworkAssemblies>
Expand Down
1 change: 0 additions & 1 deletion dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@
<DefineConstants>$(DefineConstants);FEATURE_CULTUREINFO_SETTERS</DefineConstants>

<DefineConstants>$(DefineConstants);FEATURE_PROCESSSTARTINFO_ENVIRONMENT</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_RUNTIMEINFORMATION</DefineConstants>
<DefineConstants>$(DefineConstants);USE_MSBUILD_DLL_EXTN</DefineConstants>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions setup/files.swr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ folder InstallDir:\MSBuild\15.0\Bin
file source=$(X86BinPath)MSBuildTaskHost.exe.config
file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets
file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets
file source=$(X86BinPath)Microsoft.Common.overridetasks
Expand Down Expand Up @@ -149,6 +150,7 @@ folder InstallDir:\MSBuild\15.0\Bin\amd64
file source=$(X86BinPath)Microsoft.Build.Utilities.Core.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngenArchitecture=all
file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets
file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets
file source=$(X86BinPath)Microsoft.Common.overridetasks
Expand Down
42 changes: 27 additions & 15 deletions src/Build.UnitTests/Evaluation/Expander_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2565,19 +2565,32 @@ public void PropertyFunctionGetFolderPath()
}
#endif

#if FEATURE_RUNTIMEINFORMATION
/// <summary>
/// Expand property function that uses types available only on .netstandard1.3 and above (RuntimeInformation)
/// The test exercises: static method invocation, static property invocation, method invocation expression as argument, call chain expression as argument,
/// </summary>
[Fact]
public void PropertyFunctionRuntimeInformation()
{
var pg = new PropertyDictionary<ProjectPropertyInstance>();
/// The test exercises: RuntimeInformation / OSPlatform usage, static method invocation, static property invocation, method invocation expression as argument, call chain expression as argument
/// </summary>
[Theory]
[InlineData(
"$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Create($([System.Runtime.InteropServices.OSPlatform]::$$platform$$.ToString())))))",
"True"
)]
[InlineData(
@"$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::$$platform$$)))",
"True"
)]
[InlineData(
"$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)",
"$$architecture$$"
)]
public void PropertyFunctionRuntimeInformation(string propertyFunction, string expectedExpansion)
{
Func<string, string, string, string> formatString = (aString, platform, architecture) => aString
.Replace("$$platform$$", platform)
.Replace("$$architecture$$", architecture);

var pg = new PropertyDictionary<ProjectPropertyInstance>();
var expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);

var currentPlatformString = "";
var currentPlatformString = string.Empty;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -2592,16 +2605,15 @@ public void PropertyFunctionRuntimeInformation()
currentPlatformString = "OSX";
}

var propertyFunction = "$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(" +
"$([System.Runtime.InteropServices.OSPlatform]::Create(" +
$"$([System.Runtime.InteropServices.OSPlatform]::{currentPlatformString}.ToString()" +
")))))";
var currentArchitectureString = RuntimeInformation.OSArchitecture.ToString();

propertyFunction = formatString(propertyFunction, currentPlatformString, currentArchitectureString);
expectedExpansion = formatString(expectedExpansion, currentPlatformString, currentArchitectureString);

var result = expander.ExpandIntoStringLeaveEscaped(propertyFunction, ExpanderOptions.ExpandProperties, MockElementLocation.Instance);

Assert.Equal("True", result);
Assert.Equal(expectedExpansion, result);
}
#endif

/// <summary>
/// Expand property function that calls a method with an enum parameter
Expand Down
15 changes: 0 additions & 15 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -785,19 +785,4 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" Condition="!$(Configuration.EndsWith('MONO'))"/>
-->
<Import Project="..\dir.targets" />
<Target Name="CopyImmutableAndDataflowLocal" BeforeTargets="ResolveAssemblyReferences" AfterTargets="ResolveNuGetPackages">
<!-- The VSIX installer manifest references System.Collections.Immutable and System.Threading.Tasks.Dataflow
from the Output folder, but they won't be placed there by default because NuGet references come in as CopyLocal false.

Work around this by munging the references after NuGet emits them but before RAR.

TODO: this shouldn't be here. After moving to a better binplacing model (like "publish
msbuild.exe to a folder") it should be removed.
-->
<ItemGroup>
<Reference Condition="'%(Reference.NuGetPackageId)' == 'System.Collections.Immutable' or '%(Reference.NuGetPackageId)' == 'System.Threading.Tasks.Dataflow'">
<Private>true</Private>
</Reference>
</ItemGroup>
</Target>
</Project>
4 changes: 0 additions & 4 deletions src/Build/Resources/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ private static void InitializeAvailableMethods()
var environmentType = new Tuple<string, Type>(null, typeof(System.Environment));
var directoryType = new Tuple<string, Type>(null, typeof(System.IO.Directory));
var fileType = new Tuple<string, Type>(null, typeof(System.IO.File));
#if FEATURE_RUNTIMEINFORMATION
var runtimeInformationType = new Tuple<string, Type>(null, typeof(System.Runtime.InteropServices.RuntimeInformation));
var osPlatformType = new Tuple<string, Type>(null, typeof(System.Runtime.InteropServices.OSPlatform));
#endif

// Make specific static methods available (Assembly qualified type names are *NOT* supported, only null which means mscorlib):
TryAdd("System.Environment::ExpandEnvironmentVariables", environmentType);
Expand Down Expand Up @@ -421,10 +419,8 @@ private static void InitializeAvailableMethods()
TryAdd("System.UriBuilder", new Tuple<string, Type>(null, typeof(System.UriBuilder)));
TryAdd("System.Version", new Tuple<string, Type>(null, typeof(System.Version)));
TryAdd("Microsoft.Build.Utilities.ToolLocationHelper", new Tuple<string, Type>("Microsoft.Build.Utilities.ToolLocationHelper, Microsoft.Build.Utilities.Core, Version=" + MSBuildConstants.CurrentAssemblyVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null));
#if FEATURE_RUNTIMEINFORMATION
TryAdd("System.Runtime.InteropServices.RuntimeInformation", runtimeInformationType);
TryAdd("System.Runtime.InteropServices.OSPlatform", osPlatformType);
#endif
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Build/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"dependencies": {
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to add the assembly to our custom copy logic here: https://github.com/cdmihai/msbuild/blob/fa2c0f8541ed96a303927131abe268952bf37706/src/Build/Microsoft.Build.csproj#L798

You might need to also add it to the build definition so that it ends up in our VSIX.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch ... I'll also update the swr and microbuild if needed

},
"frameworks": {
"net46": {
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/MSBuild/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"dependencies": {
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
},
"frameworks": {
"net46": {
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/Tasks/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"dependencies": {
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
},
"frameworks": {
"net46": {
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/Utilities/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"dependencies": {
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
},
"frameworks": {
"net46": {
"dependencies": {
Expand Down
37 changes: 36 additions & 1 deletion targets/DeployDependencies.proj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<Target Name="DeployRuntime"
DependsOnTargets="RestoreRuntimePackages"
Outputs="%(RuntimeProjectJson.LockFile).IntentionallyDoesNotExistSoThisAlwaysRuns">
<PrereleaseResolveNuGetPackageAssets AllowFallbackOnTargetSelection="false"
<PrereleaseResolveNuGetPackageAssets AllowFallbackOnTargetSelection="true"
IncludeFrameworkReferences="false"
NuGetPackagesDirectory="$(PackagesDir)"
RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
Expand All @@ -135,6 +135,41 @@
SkipUnchangedFiles="true"
Condition=" '$(BuildingInsideVisualStudio)' == 'true' "
/>


<Copy SourceFiles="@(ResolvedRuntimeFiles)"
DestinationFolder="$(OutputPath)"
SkipUnchangedFiles="true"
Condition=
"'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Collections.Immutable' or
'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Threading.Tasks.Dataflow' or
'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Runtime.InteropServices.RuntimeInformation'"
/>
</Target>

<!-- The VSIX installer manifest references
System.Collections.Immutable,
System.Threading.Tasks.Dataflow,
System.Runtime.InteropServices.RuntimeInformation
from the Output folder, but they won't be placed there
by default because NuGet references come in as CopyLocal false.

Work around this by manually copying them here.

TODO: this shouldn't be here. After moving to a better binplacing model (like "publish
msbuild.exe to a folder") it should be removed. This whole project file should be removed. :)
-->
<Target Name="CopyDependenciesFromNugetNeededByVsix"
AfterTargets="DeployRuntime">

<Copy SourceFiles="@(ResolvedRuntimeFiles)"
DestinationFolder="$(OutputPath)"
SkipUnchangedFiles="true"
Condition=
"'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Collections.Immutable' or
'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Threading.Tasks.Dataflow' or
'%(ResolvedRuntimeFiles.NuGetPackageId)' == 'System.Runtime.InteropServices.RuntimeInformation'"
/>
</Target>

<Target Name="SetUnixPermissions"
Expand Down
5 changes: 2 additions & 3 deletions targets/runtimeDependencies/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"xunit": "2.1.0",
"microsoft.xunit.netcore.extensions": "1.0.0-prerelease-00629-09",
"System.IO.FileSystem": "4.0.1",
"System.IO.Compression": "4.1.0"
"System.IO.Compression": "4.1.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
},
"frameworks": {
"net46": {
"dependencies": {
"xunit.runner.visualstudio": "2.1.0",
"System.Collections.Immutable": "1.3.1",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Threading.Tasks.Dataflow": "4.5.24.0",
"Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00508-01"
}
Expand All @@ -32,7 +32,6 @@
"Microsoft.NETCore.Platforms": "1.0.1",
"System.Collections.NonGeneric": "4.0.1",
"System.Console": "4.0.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.IO.FileSystem.Watcher": "4.0.0",
"System.IO.FileSystem.DriveInfo": "4.0.0",
"System.IO.Pipes": "4.0.0",
Expand Down