Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static AssemblyDefinitionInfo Parse(FileInfo file, UnityProjectInfo unity
toReturn.BuiltInPackage = isBuiltInPackage;
toReturn.Validate(unityProjectInfo.AvailablePlatforms);
toReturn.PrecompiledAssemblyReferences = new HashSet<string>(toReturn.precompiledReferences?.Select(t => t.Replace(".dll", string.Empty)) ?? Array.Empty<string>());
toReturn.DefineConstraints = new HashSet<string>(toReturn.defineConstraints ?? (toReturn.defineConstraints = new string[0]));
return toReturn;
}

Expand All @@ -90,7 +91,9 @@ public static AssemblyDefinitionInfo Parse(FileInfo file, UnityProjectInfo unity
[SerializeField]
private string[] precompiledReferences = null;
public bool autoReferenced;
public string[] defineConstraints;

[SerializeField]
private string[] defineConstraints = null;

/// <summary>
/// Gets or sets the parsed Guid of the AssemblyDefinition asset.
Expand Down Expand Up @@ -147,8 +150,16 @@ public static AssemblyDefinitionInfo Parse(FileInfo file, UnityProjectInfo unity
/// </summary>
public HashSet<string> PrecompiledAssemblyReferences { get; private set; }

/// <summary>
/// Gets assembly defintions that are nested (in terms of folder hierarchy) in respect to this assembly defintion.
/// </summary>
public HashSet<AssemblyDefinitionInfo> NestedAssemblyDefinitionFiles { get; } = new HashSet<AssemblyDefinitionInfo>();

/// <summary>
/// Gets the define constraints for this assembly defintion.
/// </summary>
public HashSet<string> DefineConstraints { get; private set; }

/// <summary>
/// After it's parsed from JSON, this method should be invoked to validate some of the values and set additional properties.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -138,12 +137,29 @@ private ReadOnlyDictionary<BuildTarget, CompilationPlatformInfo> GetCompilationP
}

// We only are an asmdef at this point, as above we handle all PredfinedAssemblies, then EditorAsmDef and PredefinedEditorAssembly for inEditor and not inEditor cases above
Func<CompilationPlatformInfo, bool> predicate = AssemblyDefinitionInfo.includePlatforms.Length > 0
? predicate = (t) => AssemblyDefinitionInfo.includePlatforms.Contains(t.Name)
: predicate = (t) => !AssemblyDefinitionInfo.excludePlatforms.Contains(t.Name);
bool IsPlatformSupported(CompilationPlatformInfo platform)
{
HashSet<string> additionalSet = inEditor ? platform.AdditionalInEditorDefines : platform.AdditionalPlayerDefines;

// Check for defines to ensure they are included in the platform (differentiate between editor/player)
foreach (string define in AssemblyDefinitionInfo.DefineConstraints)
{
if (!platform.CommonPlatformDefines.Contains(define) && !additionalSet.Contains(define))
{
return false;
}
}

if (AssemblyDefinitionInfo.includePlatforms.Length > 0)
{
return AssemblyDefinitionInfo.includePlatforms.Contains(platform.Name);
}
// else
return !AssemblyDefinitionInfo.excludePlatforms.Contains(platform.Name);
}

return new ReadOnlyDictionary<BuildTarget, CompilationPlatformInfo>(
UnityProjectInfo.AvailablePlatforms.Where(predicate)
UnityProjectInfo.AvailablePlatforms.Where(IsPlatformSupported)
.ToDictionary(t => t.BuildTarget, t => t));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ void ProcessDefaultMappings(ProjectConfigurationMapping mapping, Dictionary<stri
}
}

List<string> availablePlatformNames = unityProjectInfo.AvailablePlatforms.Select(t => t.Name).ToList();
Dictionary<string, List<string>> defaultPlatformsMap = new Dictionary<string, List<string>> { { "InEditor", availablePlatformNames }, { "Player", availablePlatformNames } };

// Iterate over every project
foreach (CSProjectInfo project in orderedProjects)
{
Expand Down Expand Up @@ -442,7 +445,7 @@ void ProcessProjectPlatforms(string configuration, IEnumerable<string> platforms
ProcessProjectPlatforms("Player", enabledPlayerPlatforms);

// Add all other known solution mappings, map to itself or allowed mappings
ProcessDefaultMappings(mapping, new Dictionary<string, List<string>> { { "InEditor", enabledInEditorPlatforms }, { "Player", enabledPlayerPlatforms } });
ProcessDefaultMappings(mapping, defaultPlatformsMap);
}

// Process the Dependencies Project now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public class UnityProjectInfo : IDisposable
{ "Unity.ugui", "UnityEngine.UI" }
};

/// <summary>
/// Another patching technique to add defines to some assembly defintion files. TestRunner for example, is only referenced by projects with UNITY_INCLUDE_TESTS and references nunit that has UNITY_INCLUDE_TESTS;
/// However it doesn't have the define itself. This breaks Player build, and as it appears that Unity specially handles this case as well.
/// </summary>
private static readonly Dictionary<string, List<string>> ImpliedDefinesForAsmDefs = new Dictionary<string, List<string>>()
{
{ "UnityEditor.TestRunner", new List<string>(){ "UNITY_INCLUDE_TESTS" } },
{ "UnityEngine.TestRunner", new List<string>(){ "UNITY_INCLUDE_TESTS" } },
};

/// <summary>
/// Gets the name of this Unity Project.
/// </summary>
Expand Down Expand Up @@ -222,7 +232,7 @@ private Dictionary<string, CSProjectInfo> CreateUnityProjects(MSBuildToolsConfig
}

// Now we have all of the assembly definiton files, let's run a quick validation.
CorrectReferences(asmDefInfoMap);
ValidateAndPatchAssemblyDefinitions(asmDefInfoMap);

int index = 0;
ProcessSortedAsmDef(asmDefDirectoriesSorted.ToArray(), ref index, (uri) => true, (a) => { });
Expand All @@ -243,7 +253,7 @@ private Dictionary<string, CSProjectInfo> CreateUnityProjects(MSBuildToolsConfig
/// <summary>
/// This performs reference correction, for example this corrects "Unity.ugui" to be "UnityEngine.UI" (a known error of TextMeshPro). For correction map see <see cref="ProjectAliases"/>.
/// </summary>
private void CorrectReferences(Dictionary<string, AssemblyDefinitionInfo> asmDefInfoMap)
private void ValidateAndPatchAssemblyDefinitions(Dictionary<string, AssemblyDefinitionInfo> asmDefInfoMap)
{
foreach (KeyValuePair<string, AssemblyDefinitionInfo> asmDefPair in asmDefInfoMap)
{
Expand All @@ -259,6 +269,14 @@ private void CorrectReferences(Dictionary<string, AssemblyDefinitionInfo> asmDef
}
}
}

if (ImpliedDefinesForAsmDefs.TryGetValue(asmDefPair.Key, out List<string> defines))
{
foreach (string define in defines)
{
asmDefPair.Value.DefineConstraints.Add(define);
}
}
Copy link
Contributor

@chrisfromwork chrisfromwork Jan 13, 2020

Choose a reason for hiding this comment

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

nit: It seems like this should be broken out into a CorrectConstantDefines function #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rename the entire function, I just think we should loop over asmdefs once.


In reply to: 366027569 [](ancestors = 366027569)

}
}

Expand Down