public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, string guid, CustomScriptAssemblyData customScriptAssemblyData)
        {
            if (customScriptAssemblyData == null)
                return null;

            var pathPrefix = path.Substring(0, path.Length - AssetPath.GetFileName(path).Length);

            var customScriptAssembly = new CustomScriptAssembly();

            customScriptAssembly.Name = customScriptAssemblyData.name;
            customScriptAssembly.GUID = guid;
            customScriptAssembly.References = customScriptAssemblyData.references;
            customScriptAssembly.FilePath = path;
            customScriptAssembly.PathPrefix = pathPrefix;
            customScriptAssembly.AutoReferenced = customScriptAssemblyData.autoReferenced;
            customScriptAssembly.OverrideReferences = customScriptAssemblyData.overrideReferences;
            customScriptAssembly.NoEngineReferences = customScriptAssemblyData.noEngineReferences;
            customScriptAssembly.PrecompiledReferences = customScriptAssemblyData.precompiledReferences ?? new string[0];
            customScriptAssembly.DefineConstraints = customScriptAssemblyData.defineConstraints ?? new string[0];
            customScriptAssembly.VersionDefines = (customScriptAssemblyData.versionDefines ?? new VersionDefine[0]);

            if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0)
                customScriptAssembly.IncludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.includePlatforms);

            if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0)
                customScriptAssembly.ExcludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.excludePlatforms);

            var compilerOptions = new ScriptCompilerOptions();

            compilerOptions.AllowUnsafeCode = customScriptAssemblyData.allowUnsafeCode;

            customScriptAssembly.CompilerOptions = compilerOptions;

            return customScriptAssembly;
        }
Esempio n. 2
0
 public static EditorBuildRules.TargetAssembly[] CreateTargetAssemblies(IEnumerable <CustomScriptAssembly> customScriptAssemblies)
 {
     EditorBuildRules.TargetAssembly[] result;
     if (customScriptAssemblies == null)
     {
         result = null;
     }
     else
     {
         using (IEnumerator <CustomScriptAssembly> enumerator = customScriptAssemblies.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 CustomScriptAssembly customAssembly = enumerator.Current;
                 if (EditorBuildRules.predefinedTargetAssemblies.Any((EditorBuildRules.TargetAssembly p) => AssetPath.GetAssemblyNameWithoutExtension(p.Filename) == customAssembly.Name))
                 {
                     throw new Exception(string.Format("Assembly cannot be have reserved name '{0}'. Defined in '{1}'", customAssembly.Name, customAssembly.FilePath));
                 }
             }
         }
         List <EditorBuildRules.TargetAssembly> list = new List <EditorBuildRules.TargetAssembly>();
         Dictionary <string, EditorBuildRules.TargetAssembly> dictionary = new Dictionary <string, EditorBuildRules.TargetAssembly>();
         using (IEnumerator <CustomScriptAssembly> enumerator2 = customScriptAssemblies.GetEnumerator())
         {
             while (enumerator2.MoveNext())
             {
                 EditorBuildRules.< CreateTargetAssemblies > c__AnonStorey2 <CreateTargetAssemblies> c__AnonStorey2 = new EditorBuildRules.< CreateTargetAssemblies > c__AnonStorey2();
Esempio n. 3
0
        private static CustomScriptAssembly LoadCustomScriptAssemblyFromJson(string path)
        {
            string json = File.ReadAllText(path);
            CustomScriptAssemblyData customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);

            return(CustomScriptAssembly.FromCustomScriptAssemblyData(path, customScriptAssemblyData));
        }
Esempio n. 4
0
        public bool CompileScripts(EditorScriptCompilationOptions definesOptions, BuildTargetGroup platformGroup, BuildTarget platform)
        {
            ScriptAssemblySettings scriptAssemblySettings = this.CreateScriptAssemblySettings(platformGroup, platform, definesOptions);
            BuildFlags             buildFlags             = BuildFlags.None;

            if ((definesOptions & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor)
            {
                buildFlags |= BuildFlags.BuildingForEditor;
            }
            if ((definesOptions & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild)
            {
                buildFlags |= BuildFlags.BuildingDevelopmentBuild;
            }
            EditorBuildRules.TargetAssembly[] array = null;
            bool result = this.CompileScripts(scriptAssemblySettings, EditorCompilation.EditorTempPath, buildFlags, ref array);

            if (array != null)
            {
                EditorBuildRules.TargetAssembly[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    EditorBuildRules.TargetAssembly targetAssembly       = array2[i];
                    CustomScriptAssembly            customScriptAssembly = this.customScriptAssemblies.Single((CustomScriptAssembly a) => a.Name == Path.GetFileNameWithoutExtension(targetAssembly.Filename));
                    string text = customScriptAssembly.FilePath;
                    if (text.StartsWith(this.projectDirectory))
                    {
                        text = text.Substring(this.projectDirectory.Length);
                    }
                    Debug.LogWarning(string.Format("Script assembly '{0}' has not been compiled. Folder containing assembly definition file '{1}' contains script files for different script languages. Folder must only contain script files for one script language.", targetAssembly.Filename, text));
                }
            }
            return(result);
        }
 internal static ReadOnlySpan <char> GetRelativePathFromAsmdefOrAsmref(CustomScriptAssembly currentMatchingAssemblyDefinition, ReadOnlySpan <char> sourceSpan, string matchedBy)
 {
     if (currentMatchingAssemblyDefinition == null)
     {
         return(sourceSpan);
     }
     return(sourceSpan[matchedBy.Length..]);
        public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, CustomScriptAssemblyData customScriptAssemblyData)
        {
            CustomScriptAssembly result;

            if (customScriptAssemblyData == null)
            {
                result = null;
            }
            else
            {
                string directoryName = Path.GetDirectoryName(path);
                CustomScriptAssembly customScriptAssembly = new CustomScriptAssembly();
                customScriptAssembly.Name       = customScriptAssemblyData.name;
                customScriptAssembly.References = customScriptAssemblyData.references;
                customScriptAssembly.FilePath   = path;
                customScriptAssembly.PathPrefix = directoryName;
                if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0)
                {
                    customScriptAssembly.IncludePlatforms = (from name in customScriptAssemblyData.includePlatforms
                                                             select CustomScriptAssembly.GetPlatformFromName(name)).ToArray <CustomScriptAssemblyPlatform>();
                }
                if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0)
                {
                    customScriptAssembly.ExcludePlatforms = (from name in customScriptAssemblyData.excludePlatforms
                                                             select CustomScriptAssembly.GetPlatformFromName(name)).ToArray <CustomScriptAssemblyPlatform>();
                }
                result = customScriptAssembly;
            }
            return(result);
        }
Esempio n. 7
0
        private CustomScriptAssembly CheckAndUpdateEditorSpecialFolder(
            CustomScriptAssembly currentMatchingAssemblyDefinition, ReadOnlySpan <char> sourceSpan)
        {
            int offset = currentMatchingAssemblyDefinition == null
                ? 0
                : currentMatchingAssemblyDefinition.PathPrefix.Length;

            if (HasEditorSpecialFolder(sourceSpan[offset..]))
 public static CustomScriptAssembly LoadCustomScriptAssemblyFromJson(string path, string json, string guid)
 {
     try
     {
         var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);
         return(CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData));
     }
     catch (Exception e)
     {
         throw new AssemblyDefinitionException(e.Message, path);
     }
 }
Esempio n. 9
0
        public AssemblyGraphBuilder(string projectPath)
        {
            _projectPath = projectPath;
            _globalAssemblyDefinition = new CustomScriptAssembly
            {
                Name         = "Assembly-CSharp",
                PathPrefix   = projectPath,
                FilePath     = Path.Combine(projectPath, "main.asmdef"),
                GUID         = CreateNewUnityGuid(),
                IsPredefined = true,
            };

            _editorAssebmlyDefinition = new CustomScriptAssembly
            {
                Name         = "Assembly-CSharp-Editor",
                PathPrefix   = Path.Combine(projectPath, "Editor"),
                FilePath     = Path.Combine(projectPath, "Editor/main-editor.asmdef"),
                GUID         = CreateNewUnityGuid(),
                IsPredefined = true,
            };

            _globalFirstpassAssemblyDefinition = new CustomScriptAssembly
            {
                Name         = "Assembly-CSharp-firstpass",
                PathPrefix   = Path.Combine(projectPath, "Plugins"),
                FilePath     = Path.Combine(projectPath, "Plugins/firstpass.asmdef"),
                GUID         = CreateNewUnityGuid(),
                IsPredefined = true,
            };

            _editorFirstpassAssemblyDefinition = new CustomScriptAssembly
            {
                Name         = "Assembly-CSharp-Editor-firstpass",
                PathPrefix   = Path.Combine(projectPath, "Plugins/Editor"),
                FilePath     = Path.Combine(projectPath, "Plugins/Editor/firstpass-editor.asmdef"),
                GUID         = CreateNewUnityGuid(),
                IsPredefined = true,
            };

            _globalFirstpassAssemblyReferences = new[]
            {
                CustomScriptAssemblyReference.FromPathAndReference(
                    Path.Combine(projectPath, "standard assets/standard assets.asmref"),
                    _globalFirstpassAssemblyDefinition.Name),
                CustomScriptAssemblyReference.FromPathAndReference(
                    Path.Combine(projectPath, "pro standard assets/pro standard assets.asmref"),
                    _globalFirstpassAssemblyDefinition.Name),
                CustomScriptAssemblyReference.FromPathAndReference(
                    Path.Combine(projectPath, "iphone standard assets/iphone standard assets.asmref"),
                    _globalFirstpassAssemblyDefinition.Name),
            };
        }
        public static CustomScriptAssembly Create(string name, string directory)
        {
            CustomScriptAssembly customScriptAssembly = new CustomScriptAssembly();
            string text = AssetPath.ReplaceSeparators(directory);

            if (text.Last <char>() != AssetPath.Separator)
            {
                text += AssetPath.Separator;
            }
            customScriptAssembly.Name       = name;
            customScriptAssembly.FilePath   = text;
            customScriptAssembly.PathPrefix = text;
            customScriptAssembly.References = new string[0];
            return(customScriptAssembly);
        }
Esempio n. 11
0
        public void Initialize(IReadOnlyCollection <CustomScriptAssembly> assemblies,
                               IReadOnlyCollection <CustomScriptAssemblyReference> customScriptAssemblyReferences)
        {
            var assemblyByNameLookup = assemblies.ToDictionary(x => x.Name, x => x);
            var assemblyByGuidLookup = assemblies.ToDictionary(x => x.GUID, x => x);

            bool rootOverridden = assemblies.Any(x => AssetPath.ComparePaths(x.PathPrefix, _projectPath));

            if (!rootOverridden)
            {
                _npp.Insert(_globalAssemblyDefinition.PathPrefix, _globalAssemblyDefinition);
                _npp.Insert(_editorAssebmlyDefinition.PathPrefix, _editorAssebmlyDefinition);
                _npp.Insert(_globalFirstpassAssemblyDefinition.PathPrefix, _globalFirstpassAssemblyDefinition);
                _npp.Insert(_editorFirstpassAssemblyDefinition.PathPrefix, _editorFirstpassAssemblyDefinition);
            }

            foreach (var assemblyDef in assemblies)
            {
                _npp.Insert(assemblyDef.PathPrefix, assemblyDef);
            }

            if (!rootOverridden)
            {
                foreach (var globalFirstpassAssemblyReference in _globalFirstpassAssemblyReferences)
                {
                    _npp.Insert(globalFirstpassAssemblyReference.PathPrefix, _globalFirstpassAssemblyDefinition);
                }
            }

            foreach (var assemblyReference in customScriptAssemblyReferences)
            {
                CustomScriptAssembly foundAssemblyDef = null;
                var foundAssemblyDefinition           = GUIDReference.IsGUIDReference(assemblyReference.Reference)
                    ? assemblyByGuidLookup.TryGetValue(GUIDReference.GUIDReferenceToGUID(assemblyReference.Reference),
                                                       out foundAssemblyDef)
                    : assemblyByNameLookup.TryGetValue(assemblyReference.Reference, out foundAssemblyDef);

                if (foundAssemblyDefinition)
                {
                    _npp.Insert(assemblyReference.PathPrefix, foundAssemblyDef);
                }
                else
                {
                    Console.WriteLine(
                        $"Assembly reference {assemblyReference.FilePath} has no target assembly definition");
                }
            }
        }
        public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, string guid, CustomScriptAssemblyData customScriptAssemblyData)
        {
            if (customScriptAssemblyData == null)
            {
                return(null);
            }

            var pathPrefix = path.Substring(0, path.Length - AssetPath.GetFileName(path).Length);

            var customScriptAssembly = new CustomScriptAssembly();

            customScriptAssembly.Name                  = customScriptAssemblyData.name;
            customScriptAssembly.GUID                  = guid;
            customScriptAssembly.References            = customScriptAssemblyData.references;
            customScriptAssembly.FilePath              = path;
            customScriptAssembly.PathPrefix            = pathPrefix;
            customScriptAssembly.AutoReferenced        = customScriptAssemblyData.autoReferenced;
            customScriptAssembly.OverrideReferences    = customScriptAssemblyData.overrideReferences;
            customScriptAssembly.PrecompiledReferences = customScriptAssemblyData.precompiledReferences ?? new string[0];
            customScriptAssembly.DefineConstraints     = customScriptAssemblyData.defineConstraints ?? new string[0];
            customScriptAssembly.VersionDefines        = (customScriptAssemblyData.versionDefines ?? new VersionDefine[0]);

            customScriptAssemblyData.optionalUnityReferences = customScriptAssemblyData.optionalUnityReferences ?? new string[0];
            foreach (var optionalUnityReferenceString in customScriptAssemblyData.optionalUnityReferences)
            {
                var optionalUnityReference = (OptionalUnityReferences)Enum.Parse(typeof(OptionalUnityReferences), optionalUnityReferenceString);
                customScriptAssembly.OptionalUnityReferences |= optionalUnityReference;
            }

            if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0)
            {
                customScriptAssembly.IncludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.includePlatforms);
            }

            if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0)
            {
                customScriptAssembly.ExcludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.excludePlatforms);
            }

            var compilerOptions = new ScriptCompilerOptions();

            compilerOptions.AllowUnsafeCode = customScriptAssemblyData.allowUnsafeCode;

            customScriptAssembly.CompilerOptions = compilerOptions;

            return(customScriptAssembly);
        }
Esempio n. 13
0
 private static void CheckCyclicAssemblyReferences(CustomScriptAssembly[] customScriptAssemblies)
 {
     if (customScriptAssemblies != null && customScriptAssemblies.Length >= 2)
     {
         Dictionary <string, CustomScriptAssembly> dictionary = new Dictionary <string, CustomScriptAssembly>();
         for (int i = 0; i < customScriptAssemblies.Length; i++)
         {
             CustomScriptAssembly customScriptAssembly = customScriptAssemblies[i];
             dictionary[customScriptAssembly.Name] = customScriptAssembly;
         }
         HashSet <CustomScriptAssembly> visited = new HashSet <CustomScriptAssembly>();
         for (int j = 0; j < customScriptAssemblies.Length; j++)
         {
             CustomScriptAssembly visitAssembly = customScriptAssemblies[j];
             EditorCompilation.CheckCyclicAssemblyReferencesDFS(visitAssembly, visited, dictionary);
         }
     }
 }
        public static CustomScriptAssembly Create(string name, string directory)
        {
            var customScriptAssembly = new CustomScriptAssembly();

            var modifiedDirectory = AssetPath.ReplaceSeparators(directory);

            if (modifiedDirectory.Last() != AssetPath.Separator)
                modifiedDirectory += AssetPath.Separator;

            customScriptAssembly.Name = name;
            customScriptAssembly.FilePath = modifiedDirectory;
            customScriptAssembly.PathPrefix = modifiedDirectory;
            customScriptAssembly.References = new string[0];
            customScriptAssembly.PrecompiledReferences = new string[0];
            customScriptAssembly.CompilerOptions = new ScriptCompilerOptions();
            customScriptAssembly.AutoReferenced = true;

            return customScriptAssembly;
        }
Esempio n. 15
0
        public void SetAllCustomScriptAssemblyJsons(string[] paths)
        {
            List <CustomScriptAssembly> list = new List <CustomScriptAssembly>();

            for (int i = 0; i < paths.Length; i++)
            {
                string text = paths[i];
                try
                {
                    string path = (!Path.IsPathRooted(text)) ? Path.Combine(this.projectDirectory, text) : text;
                    CustomScriptAssembly loadedCustomScriptAssembly = EditorCompilation.LoadCustomScriptAssemblyFromJson(path);
                    if (list.Any((CustomScriptAssembly a) => string.Equals(a.Name, loadedCustomScriptAssembly.Name, StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new Exception(string.Format("Assembly with name '{0}' is already defined ({1})", loadedCustomScriptAssembly.Name.Length, loadedCustomScriptAssembly.FilePath));
                    }
                    if (loadedCustomScriptAssembly.References == null)
                    {
                        loadedCustomScriptAssembly.References = new string[0];
                    }
                    if (loadedCustomScriptAssembly.References.Length != loadedCustomScriptAssembly.References.Distinct <string>().Count <string>())
                    {
                        throw new Exception(string.Format("Duplicate assembly references in {0}", loadedCustomScriptAssembly.FilePath));
                    }
                    list.Add(loadedCustomScriptAssembly);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + " - '" + text + "'");
                }
            }
            this.customScriptAssemblies = list.ToArray();
            try
            {
                EditorCompilation.CheckCyclicAssemblyReferences(this.customScriptAssemblies);
            }
            catch (Exception ex2)
            {
                this.customScriptAssemblies = null;
                this.customTargetAssemblies = null;
                throw ex2;
            }
            this.customTargetAssemblies = EditorBuildRules.CreateTargetAssemblies(this.customScriptAssemblies);
        }
Esempio n. 16
0
 private static void CheckCyclicAssemblyReferencesDFS(CustomScriptAssembly visitAssembly, HashSet <CustomScriptAssembly> visited, IDictionary <string, CustomScriptAssembly> nameToCustomScriptAssembly)
 {
     if (visited.Contains(visitAssembly))
     {
         throw new Exception(string.Format("Cyclic assembly references detected. Assemblies: {0}", string.Join(", ", (from a in visited
                                                                                                                      select string.Format("'{0}'", a.Name)).ToArray <string>())));
     }
     visited.Add(visitAssembly);
     string[] references = visitAssembly.References;
     for (int i = 0; i < references.Length; i++)
     {
         string text = references[i];
         CustomScriptAssembly visitAssembly2;
         if (!nameToCustomScriptAssembly.TryGetValue(text, out visitAssembly2))
         {
             throw new Exception(string.Format("Reference to non-existent assembly. Assembly {0} has a reference to {1}", visitAssembly.Name, text));
         }
         EditorCompilation.CheckCyclicAssemblyReferencesDFS(visitAssembly2, visited, nameToCustomScriptAssembly);
     }
     visited.Remove(visitAssembly);
 }
        static void CheckPredefinedAssemblyNames(
            HashSet <string> predefinedAssemblyNames,
            Dictionary <string, CustomScriptAssembly> assemblyLowercaseNamesLookup,
            string lowerCaseName,
            Dictionary <string, List <string> > prefixToFilePathLookup,
            ref CustomScriptAssembly loadedCustomScriptAssembly)
        {
            if (predefinedAssemblyNames.Contains(loadedCustomScriptAssembly.Name))
            {
                throw new AssemblyDefinitionException(
                          $"Assembly cannot be have reserved name '{loadedCustomScriptAssembly.Name}'",
                          loadedCustomScriptAssembly.FilePath);
            }

            if (assemblyLowercaseNamesLookup.TryGetValue(lowerCaseName, out var duplicate))
            {
                var filePaths = new[]
                {
                    loadedCustomScriptAssembly.FilePath,
                    duplicate.FilePath
                };
                var errorMsg = $"Assembly with name '{loadedCustomScriptAssembly.Name}' already exists";
                loadedCustomScriptAssembly = null; // Set to null to prevent it being added.
                throw new AssemblyDefinitionException(errorMsg, filePaths);
            }

            // Check both asmdef and asmref files.
            if (prefixToFilePathLookup.TryGetValue(loadedCustomScriptAssembly.PathPrefix,
                                                   out var duplicateFilePaths))
            {
                var filePaths = new List <string> {
                    loadedCustomScriptAssembly.FilePath
                };
                filePaths.AddRange(duplicateFilePaths);

                throw new AssemblyDefinitionException(
                          $"Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files",
                          filePaths.ToArray());
            }
        }
        public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, CustomScriptAssemblyData customScriptAssemblyData)
        {
            CustomScriptAssembly result;

            if (customScriptAssemblyData == null)
            {
                result = null;
            }
            else
            {
                string pathPrefix = path.Substring(0, path.Length - AssetPath.GetFileName(path).Length);
                CustomScriptAssembly customScriptAssembly = new CustomScriptAssembly();
                customScriptAssembly.Name       = customScriptAssemblyData.name;
                customScriptAssembly.References = customScriptAssemblyData.references;
                customScriptAssembly.FilePath   = path;
                customScriptAssembly.PathPrefix = pathPrefix;
                customScriptAssemblyData.optionalUnityReferences = (customScriptAssemblyData.optionalUnityReferences ?? new string[0]);
                string[] optionalUnityReferences = customScriptAssemblyData.optionalUnityReferences;
                for (int i = 0; i < optionalUnityReferences.Length; i++)
                {
                    string value = optionalUnityReferences[i];
                    OptionalUnityReferences optionalUnityReferences2 = (OptionalUnityReferences)Enum.Parse(typeof(OptionalUnityReferences), value);
                    customScriptAssembly.OptionalUnityReferences |= optionalUnityReferences2;
                }
                if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0)
                {
                    customScriptAssembly.IncludePlatforms = (from name in customScriptAssemblyData.includePlatforms
                                                             select CustomScriptAssembly.GetPlatformFromName(name)).ToArray <CustomScriptAssemblyPlatform>();
                }
                if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0)
                {
                    customScriptAssembly.ExcludePlatforms = (from name in customScriptAssemblyData.excludePlatforms
                                                             select CustomScriptAssembly.GetPlatformFromName(name)).ToArray <CustomScriptAssemblyPlatform>();
                }
                result = customScriptAssembly;
            }
            return(result);
        }
 public bool Equals(CustomScriptAssembly other)
 {
     return(assemblyFlags == other.assemblyFlags &&
            string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) &&
            string.Equals(PathPrefix, other.PathPrefix, StringComparison.Ordinal) &&
            string.Equals(Name, other.Name, StringComparison.Ordinal) &&
            string.Equals(RootNamespace, other.RootNamespace, StringComparison.Ordinal) &&
            GUID == other.GUID &&
            Equals(References, other.References) &&
            Equals(AdditionalPrefixes, other.AdditionalPrefixes) &&
            Equals(IncludePlatforms, other.IncludePlatforms) &&
            Equals(ExcludePlatforms, other.ExcludePlatforms) &&
            Equals(AssetPathMetaData, other.AssetPathMetaData) &&
            Equals(CompilerOptions, other.CompilerOptions) &&
            OverrideReferences == other.OverrideReferences &&
            Equals(PrecompiledReferences, other.PrecompiledReferences) &&
            AutoReferenced == other.AutoReferenced &&
            Equals(DefineConstraints, other.DefineConstraints) &&
            Equals(VersionDefines, other.VersionDefines) &&
            Equals(ResponseFileDefines, other.ResponseFileDefines) &&
            NoEngineReferences == other.NoEngineReferences &&
            IsPredefined == other.IsPredefined);
 }
        public void SetAllCustomScriptAssemblyJsonContents(string[] paths, string[] contents, string[] guids)
        {
            var assemblies = new List <CustomScriptAssembly>();
            var assemblyLowercaseNamesLookup = new Dictionary <string, CustomScriptAssembly>();
            var exceptions        = new List <Exception>();
            var guidsToAssemblies = new Dictionary <string, CustomScriptAssembly>();
            HashSet <string> predefinedAssemblyNames = null;

            // To check if a path prefix is already being used we use a Dictionary where the key is the prefix and the value is the file path.
            var prefixToFilePathLookup = CustomScriptAssemblyReferences.ToDictionary(x => x.PathPrefix,
                                                                                     x => new List <string> {
                x.FilePath
            }, StringComparer.OrdinalIgnoreCase);

            m_CompilationSetupErrorsTracker.ClearCompilationSetupErrors(CompilationSetupErrors.LoadError);

            // Load first to setup guidsToAssemblies dictionary and convert guids to assembly names
            // before checking for assembly reference errors, so errors emit assembly names instead of guids.
            for (var i = 0; i < paths.Length; ++i)
            {
                var path = paths[i];
                var guid = guids[i];

                string lowerCaseName = null;
                CustomScriptAssembly loadedCustomScriptAssembly = null;

                try
                {
                    var fullPath = AssetPath.IsPathRooted(path)
                        ? AssetPath.GetFullPath(path)
                        : AssetPath.Combine(m_ProjectDirectory, path);

                    loadedCustomScriptAssembly =
                        contents != null
                        ? LoadCustomScriptAssemblyFromJson(fullPath, contents[i], guid)
                        : LoadCustomScriptAssemblyFromJsonPath(fullPath, guid);

                    loadedCustomScriptAssembly.References = loadedCustomScriptAssembly.References ?? new string[0];

                    lowerCaseName = Utility.FastToLower(loadedCustomScriptAssembly.Name);
                    guidsToAssemblies[Utility.FastToLower(guid)] = loadedCustomScriptAssembly;

                    if (!m_SkipCustomScriptAssemblyGraphValidation)
                    {
                        if (predefinedAssemblyNames == null)
                        {
                            predefinedAssemblyNames = new HashSet <string>(EditorBuildRules.PredefinedTargetAssemblyNames);
                            var netfw = MonoLibraryHelpers
                                        .GetSystemLibraryReferences(ApiCompatibilityLevel.NET_Unity_4_8).Select(Path.GetFileNameWithoutExtension);
                            var netstandard21 = MonoLibraryHelpers
                                                .GetSystemLibraryReferences(ApiCompatibilityLevel.NET_Standard).Select(Path.GetFileNameWithoutExtension);
                            predefinedAssemblyNames.UnionWith(netfw);
                            predefinedAssemblyNames.UnionWith(netstandard21);
                        }

                        CheckPredefinedAssemblyNames(
                            predefinedAssemblyNames,
                            assemblyLowercaseNamesLookup,
                            lowerCaseName,
                            prefixToFilePathLookup,
                            ref loadedCustomScriptAssembly);
                    }
                }
                catch (Exception e)
                {
                    m_CompilationSetupErrorsTracker.SetCompilationSetupErrors(CompilationSetupErrors.LoadError);
                    exceptions.Add(e);
                }

                if (loadedCustomScriptAssembly == null || m_SkipCustomScriptAssemblyGraphValidation && assemblyLowercaseNamesLookup.ContainsKey(lowerCaseName))
                {
                    continue;
                }

                loadedCustomScriptAssembly.References       = loadedCustomScriptAssembly.References ?? new string[0];
                assemblyLowercaseNamesLookup[lowerCaseName] = loadedCustomScriptAssembly;
                assemblies.Add(loadedCustomScriptAssembly);

                if (!prefixToFilePathLookup.TryGetValue(loadedCustomScriptAssembly.PathPrefix, out var duplicateFilePaths))
                {
                    duplicateFilePaths = new List <string>();
                    prefixToFilePathLookup[loadedCustomScriptAssembly.PathPrefix] = duplicateFilePaths;
                }

                duplicateFilePaths.Add(loadedCustomScriptAssembly.FilePath);
            }

            ConvertGUIDReferencesToAssemblyNames(assemblies, guidsToAssemblies);

            if (!m_SkipCustomScriptAssemblyGraphValidation)
            {
                CheckForReferenceErrors(assemblies, exceptions);
            }

            CustomScriptAssemblies = assemblies.ToArray();
            Exceptions             = exceptions.ToArray();
        }
 public void ClearCustomScriptAssemblies()
 {
     CustomScriptAssemblies = new CustomScriptAssembly[0];
     CustomScriptAssemblyReferences.Clear();
 }