public bool IsCompatibleWith(BuildTarget buildTarget, EditorScriptCompilationOptions options, string[] defines) { bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor; var isBuildingWithTestAssemblies = (options & EditorScriptCompilationOptions.BuildingIncludingTestAssemblies) == EditorScriptCompilationOptions.BuildingIncludingTestAssemblies; var isTestAssembly = DefineConstraints != null && DefineConstraints.Any(x => x == "UNITY_INCLUDE_TESTS"); if (!buildingForEditor && isTestAssembly && !isBuildingWithTestAssemblies) { return(false); } if (defines != null && defines.Length == 0) { throw new ArgumentException("defines cannot be empty", "defines"); } if (!DefineConstraintsHelper.IsDefineConstraintsCompatible(defines, DefineConstraints)) { return(false); } if (isTestAssembly && AssetPathMetaData != null && !AssetPathMetaData.IsTestable) { return(false); } // Compatible with editor and all platforms. if (IncludePlatforms == null && ExcludePlatforms == null) { return(true); } if (buildingForEditor) { return(IsCompatibleWithEditor()); } if (ExcludePlatforms != null) { return(ExcludePlatforms.All(p => p.BuildTarget != buildTarget)); } return(IncludePlatforms.Any(p => p.BuildTarget == buildTarget)); }
private void FilterPlatformsBasedOnDefineConstraints(IDictionary <BuildTarget, CompilationPlatformInfo> platformDictionary, bool inEditor) { if (DefineConstraints.Count == 0) { // No exclusions return; } bool defaultExcludeValue = DefineConstraints.Any(t => !t.StartsWith("!")); HashSet <BuildTarget> toExclude = new HashSet <BuildTarget>(); foreach (KeyValuePair <BuildTarget, CompilationPlatformInfo> platformPair in platformDictionary) { // We presume exclude, then check bool exclude = defaultExcludeValue; foreach (string define in DefineConstraints) { // Does this define exclude if (define.StartsWith("!")) { if (ContainsDefineHelper(define.Substring(1), inEditor, platformPair.Value)) { exclude = true; break; } } else if (ContainsDefineHelper(define, inEditor, platformPair.Value)) { // This platform is supported, but still search for !defineconstraitns that may force exclusion exclude = false; } } if (exclude) { toExclude.Add(platformPair.Key); } } foreach (BuildTarget buildTarget in toExclude) { platformDictionary.Remove(buildTarget); } }
public bool NeedsEntryPointAdded() { return(!DefineConstraints.Contains("UNITY_DOTS_ENTRYPOINT") && References.All(r => r.NeedsEntryPointAdded())); }
public bool IsCompatibleWith(BuildTarget buildTarget, EditorScriptCompilationOptions options, string[] defines) { bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor; var isBuildingWithTestAssemblies = (options & EditorScriptCompilationOptions.BuildingIncludingTestAssemblies) == EditorScriptCompilationOptions.BuildingIncludingTestAssemblies; var isTestAssembly = DefineConstraints != null && DefineConstraints.Any(x => x == "UNITY_INCLUDE_TESTS"); var isTestFrameworkAssembly = DefineConstraints != null && DefineConstraints.Any(x => x == "UNITY_TESTS_FRAMEWORK"); if (!buildingForEditor && (isTestAssembly || isTestFrameworkAssembly) && !isBuildingWithTestAssemblies) { return(false); } if (defines != null && defines.Length == 0) { throw new ArgumentException("Defines cannot be empty", nameof(defines)); } // Log invalid define constraints if (DefineConstraints != null) { for (var i = 0; i < DefineConstraints.Length; ++i) { if (!DefineConstraintsHelper.IsDefineConstraintValid(DefineConstraints[i])) { throw new AssemblyDefinitionException($"Invalid Define Constraint: \"{DefineConstraints[i]}\" at line {(i+1).ToString()}", FilePath); } } } var allDefines = ResponseFileDefines != null ? (defines != null ? defines.Concat(ResponseFileDefines) : ResponseFileDefines) : defines; if (!DefineConstraintsHelper.IsDefineConstraintsCompatible_Enumerable(allDefines, DefineConstraints)) { return(false); } if (isTestAssembly && AssetPathMetaData != null && !AssetPathMetaData.IsTestable) { return(false); } // Compatible with editor and all platforms. if (IncludePlatforms == null && ExcludePlatforms == null) { return(true); } if (buildingForEditor) { return(IsCompatibleWithEditor()); } if (ExcludePlatforms != null) { return(ExcludePlatforms.All(p => p.BuildTarget != buildTarget)); } return(IncludePlatforms.Any(p => p.BuildTarget == buildTarget)); }