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 = ArrayHelper.Merge(defines, ResponseFileDefines);

            if (!DefineConstraintsHelper.IsDefineConstraintsCompatible(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));
        }
        public bool IsCompatibleWithEditor()
        {
            if (ExcludePlatforms != null)
                return ExcludePlatforms.All(p => p.BuildTarget != BuildTarget.NoTarget);

            if (IncludePlatforms != null)
                return IncludePlatforms.Any(p => p.BuildTarget == BuildTarget.NoTarget);

            return true;
        }
        public bool IsCompatibleWithEditor()
        {
            if (ExcludePlatforms != null)
            {
                return(ExcludePlatforms.All(p => p.BuildTarget != BuildTarget.NoTarget));
            }

            if (IncludePlatforms != null)
            {
                return(IncludePlatforms.Any(p => p.BuildTarget == BuildTarget.NoTarget));
            }

            return(true);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        public bool IsCompatibleWith(BuildTarget buildTarget, EditorScriptCompilationOptions options, string[] defines = null)
        {
            bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor;

            var isTestAssembly = (OptionalUnityReferences & OptionalUnityReferences.TestAssemblies) == OptionalUnityReferences.TestAssemblies;
            var isBuildingWithTestAssemblies = (options & EditorScriptCompilationOptions.BuildingIncludingTestAssemblies) == EditorScriptCompilationOptions.BuildingIncludingTestAssemblies;

            if (!buildingForEditor && isTestAssembly && !isBuildingWithTestAssemblies)
            {
                return(false);
            }

            if (!DefineConstraintsHelper.IsDefineConstraintsCompatible(defines, DefineConstraints))
            {
                return(false);
            }

            var isPackage = PackageAssembly.HasValue;

            if (isTestAssembly && isPackage && !PackageAssembly.Value.IncludeTestAssemblies)
            {
                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));
        }