Skip to content

Commit

Permalink
Additional IL2CPP vs. .NET and NET46 vs NETStandard20 fixes (+ other) (
Browse files Browse the repository at this point in the history
…#27)

* This handles the case where dependency is given in form of 'GUID:{asset guid}' instead of project name, also fixes initially mistaken NETStandard and NET46 diff to be NET and IL2CPP diff. And also adds tests

* Fixed a bug

* Removed empty propertygroup.

Removed empty propertygroup.
  • Loading branch information
Andrei Borodin committed Sep 9, 2019
1 parent 794a787 commit 7a4c4e7
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 16 deletions.
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths);<!--PLATFORM_COMMON_ASSEMBLY_SEARCH_PATHS_TOKEN-->;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5;$(UnityEditorInstallFolder)Data\PlaybackEngines\MetroSupport\Managed\UAP\</AssemblySearchPaths>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework><!--TARGET_FRAMEWORK_TOKEN--></TargetFramework>
<DefaultLanguage>en-US</DefaultLanguage>
<DefineConstants>$(DefineConstants);<!--PLATFORM_COMMON_DEFINE_CONSTANTS-->;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<TargetPlatformVersion><!--UWP_TARGET_PLATFORM_VERSION_TOKEN--></TargetPlatformVersion>
Expand Down Expand Up @@ -32,10 +32,6 @@
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>

<Reference Include="WinRTLegacy" Condition="$(UnityMajorVersion) &lt; 2019">
<HintPath>$(UnityEditorInstallFolder)Data\PlaybackEngines\MetroSupport\Managed\UAP\WinRTLegacy.dll</HintPath>
</Reference>

<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\$(TargetPlatformVersion)\windows.winmd</HintPath>
</Reference>
Expand Down
Expand Up @@ -51,4 +51,4 @@
</Reference>
<!--PLATFORM_COMMON_REFERENCE_TEMPLATE_END-->
</ItemGroup>
</Project>
</Project>
Expand Up @@ -117,6 +117,11 @@ private static IEnumerable<string> FilterOutProjectReferences(string[] reference
/// </summary>
public TargetFramework TargetFramework { get; }

/// <summary>
/// Gets the scripting backend for this platform (Mono, .NET, IL2CPP)
/// </summary>
public ScriptingBackend ScriptingBackend { get; }

/// <summary>
/// These defines are specific for this platform and common or player/editor.
/// </summary>
Expand Down Expand Up @@ -156,6 +161,7 @@ private static IEnumerable<string> FilterOutProjectReferences(string[] reference
BuildTargetGroup = Utilities.GetBuildTargetGroup(BuildTarget);

TargetFramework = BuildTargetGroup.GetTargetFramework();
ScriptingBackend = BuildTargetGroup.GetScriptingBackend();

CommonPlatformDefines = commonPlatformDefines;
AdditionalPlayerDefines = additionalPlayerDefines;
Expand Down
Expand Up @@ -177,7 +177,7 @@ private static void ProcessPlatformTemplateForConfiguration(CompilationPlatformI
{
string configuration = inEditorConfiguration ? "InEditor" : "Player";

string platformTemplate = File.ReadAllText(TemplateFiles.Instance.GetTemplateFilePathForPlatform(platform.Name, configuration, platform.TargetFramework.AsTemplateString()));
string platformTemplate = File.ReadAllText(TemplateFiles.Instance.GetTemplateFilePathForPlatform(platform.Name, configuration, platform.ScriptingBackend));

string platformPropsText;
if (inEditorConfiguration)
Expand Down
Expand Up @@ -16,7 +16,14 @@ public enum TargetFramework
Net20,
Net46
}


public enum ScriptingBackend
{
Mono,
Net,
IL2CPP
}

/// <summary>
/// Helper extensions for the <see cref="TargetFramework"/> enum.
/// </summary>
Expand Down Expand Up @@ -91,6 +98,32 @@ public static TargetFramework GetTargetFramework(this BuildTargetGroup @this)

throw new PlatformNotSupportedException("ApiCompatibilityLevel platform not matched.");
}

/// <summary>
/// Returns the configured <see cref="ScriptingBackend"/> for the <see cref="BuildTargetGroup"/>.
/// </summary>
/// <param name="this">The <see cref="BuildTargetGroup"/> to get <see cref="ScriptingBackend"/> for.</param>
/// <returns>The <see cref="ScriptingBackend"/> configured for given <see cref="BuildTargetGroup"/>.</returns>
public static ScriptingBackend GetScriptingBackend(this BuildTargetGroup @this)
{
if (@this == BuildTargetGroup.Unknown)
{
// This may be different on older unity versions
return ScriptingBackend.Mono;
}

switch (PlayerSettings.GetScriptingBackend(@this))
{
case ScriptingImplementation.Mono2x:
return ScriptingBackend.Mono;
case ScriptingImplementation.IL2CPP:
return ScriptingBackend.IL2CPP;
case ScriptingImplementation.WinRTDotNET:
return ScriptingBackend.Net;
}

throw new PlatformNotSupportedException("ScriptingBackend platform not matched.");
}
}
}
#endif
Expand Up @@ -147,9 +147,9 @@ private TemplateFiles()
/// <param name="platform">The platform of the requested template.</param>
/// <param name="configuration">The configuration of the requested template.</param>
/// <returns>The absolute file path for the platform template to use.</returns>
public string GetTemplateFilePathForPlatform(string platform, string configuration, string apiLevel)
public string GetTemplateFilePathForPlatform(string platform, string configuration, ScriptingBackend scriptingBackend)
{
if (PlatformTemplates.TryGetValue($"{platform}.{configuration}.{apiLevel}.props.template", out string templatePath)
if (PlatformTemplates.TryGetValue($"{platform}.{configuration}.{scriptingBackend.ToString()}.props.template", out string templatePath)
|| PlatformTemplates.TryGetValue($"{platform}.{configuration}.Any.props.template", out templatePath)
|| PlatformTemplates.TryGetValue($"{platform}.Configuration.Any.props.template", out templatePath))
{
Expand Down
Expand Up @@ -145,14 +145,20 @@ public UnityProjectInfo(IEnumerable<CompilationPlatformInfo> availablePlatforms,

private CSProjectInfo GetProjectInfo(Dictionary<string, CSProjectInfo> projectsMap, Dictionary<string, AssemblyDefinitionInfo> asmDefInfoMap, HashSet<string> builtInPackagesWithoutSource, string projectKey, string projectOutputPath)
{
if (projectKey.StartsWith("GUID:"))
{
projectKey = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(projectKey.Substring("GUID:".Length)));
}

if (projectsMap.TryGetValue(projectKey, out CSProjectInfo value))
{
return value;
}

if (!asmDefInfoMap.TryGetValue(projectKey, out AssemblyDefinitionInfo assemblyDefinitionInfo))
{
throw new InvalidOperationException($"Can't find an asmdef for project: {projectKey}");
Debug.LogError($"Can't find an asmdef for project: {projectKey}; Unity actually allows this, so proceeding.");
return null;
}

CSProjectInfo toReturn = new CSProjectInfo(this, assemblyDefinitionInfo, projectOutputPath);
Expand Down Expand Up @@ -183,7 +189,11 @@ private CSProjectInfo GetProjectInfo(Dictionary<string, CSProjectInfo> projectsM
continue;
}

toReturn.AddDependency(GetProjectInfo(projectsMap, asmDefInfoMap, builtInPackagesWithoutSource, reference, projectOutputPath));
CSProjectInfo dependencyToAdd = GetProjectInfo(projectsMap, asmDefInfoMap, builtInPackagesWithoutSource, reference, projectOutputPath);
if (dependencyToAdd != null)
{
toReturn.AddDependency(dependencyToAdd);
}
}

return toReturn;
Expand Down
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Linq;
using UnityEngine;

#if UNITY_WSA
using System;
#endif

namespace Microsoft.Build.Unity.ProjectGeneration.Test
{
[Serializable]
public enum TestResult
{
Success,
Expand Down

0 comments on commit 7a4c4e7

Please sign in to comment.