public string GetExtensionOfSourceFiles() { if (this._files.Length > 0) { return(ScriptCompilers.GetExtensionOfSourceFile(this._files[0])); } return("NA"); }
public static ScriptAssembly[] GetAllScriptAssemblies(IEnumerable <string> allSourceFiles, string projectDirectory, ScriptAssemblySettings settings, CompilationAssemblies assemblies, TargetAssemblyType onlyIncludeType = TargetAssemblyType.Undefined) { if (allSourceFiles == null || allSourceFiles.Count() == 0) { return(new ScriptAssembly[0]); } var targetAssemblyFiles = new Dictionary <TargetAssembly, HashSet <string> >(); foreach (var scriptFile in allSourceFiles) { var targetAssembly = GetTargetAssembly(scriptFile, projectDirectory, assemblies.CustomTargetAssemblies); if (!IsCompatibleWithPlatform(targetAssembly, settings)) { continue; } // Optionally only include specific TargetAssemblyType assemblies. if (onlyIncludeType != TargetAssemblyType.Undefined && targetAssembly.Type != onlyIncludeType) { continue; } var scriptExtension = ScriptCompilers.GetExtensionOfSourceFile(scriptFile); var scriptLanguage = ScriptCompilers.GetLanguageFromExtension(scriptExtension); if (targetAssembly.Language == null && targetAssembly.Type == TargetAssemblyType.Custom) { targetAssembly.Language = scriptLanguage; } HashSet <string> assemblySourceFiles; if (!targetAssemblyFiles.TryGetValue(targetAssembly, out assemblySourceFiles)) { assemblySourceFiles = new HashSet <string>(); targetAssemblyFiles[targetAssembly] = assemblySourceFiles; } assemblySourceFiles.Add(AssetPath.Combine(projectDirectory, scriptFile)); } return(ToScriptAssemblies(targetAssemblyFiles, settings, assemblies, null)); }
public static ScriptAssembly[] GenerateChangedScriptAssemblies(GenerateChangedScriptAssembliesArgs args) { var dirtyTargetAssemblies = new Dictionary <TargetAssembly, HashSet <string> >(); var allTargetAssemblies = args.Assemblies.CustomTargetAssemblies == null ? predefinedTargetAssemblies : predefinedTargetAssemblies.Concat(args.Assemblies.CustomTargetAssemblies).ToArray(); // Mark all assemblies that the script updater must be run on as dirty. if (args.RunUpdaterAssemblies != null) { foreach (var assemblyFilename in args.RunUpdaterAssemblies) { var targetAssembly = allTargetAssemblies.First(a => a.FilenameWithSuffix(args.Settings.FilenameSuffix) == assemblyFilename); dirtyTargetAssemblies[targetAssembly] = new HashSet <string>(); } } // Collect all dirty TargetAssemblies foreach (var dirtySourceFile in args.DirtySourceFiles) { var targetAssembly = GetTargetAssembly(dirtySourceFile, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies); if (!IsCompatibleWithPlatform(targetAssembly, args.Settings)) { continue; } HashSet <string> assemblySourceFiles; var scriptExtension = ScriptCompilers.GetExtensionOfSourceFile(dirtySourceFile); var scriptLanguage = ScriptCompilers.GetLanguageFromExtension(scriptExtension); if (!dirtyTargetAssemblies.TryGetValue(targetAssembly, out assemblySourceFiles)) { assemblySourceFiles = new HashSet <string>(); dirtyTargetAssemblies[targetAssembly] = assemblySourceFiles; if (targetAssembly.Type == TargetAssemblyType.Custom) { targetAssembly.Language = scriptLanguage; } } assemblySourceFiles.Add(AssetPath.Combine(args.ProjectDirectory, dirtySourceFile)); // If there are mixed languages in a custom script folder, mark the assembly to not be compiled. if (scriptLanguage != targetAssembly.Language) { args.NotCompiledTargetAssemblies.Add(targetAssembly); } } bool isAnyCustomScriptAssemblyDirty = dirtyTargetAssemblies.Any(entry => entry.Key.Type == TargetAssemblyType.Custom); // If we have any dirty custom target assemblies, then the predefined target assemblies are marked as dirty, // as the predefined assemblies always reference the custom script assemblies. if (isAnyCustomScriptAssemblyDirty) { foreach (var assembly in predefinedTargetAssemblies) { if (!IsCompatibleWithPlatform(assembly, args.Settings)) { continue; } if (!dirtyTargetAssemblies.ContainsKey(assembly)) { dirtyTargetAssemblies[assembly] = new HashSet <string>(); } } } // Collect any TargetAssemblies that reference the dirty TargetAssemblies, as they will also be dirty. int dirtyAssemblyCount; do { dirtyAssemblyCount = 0; foreach (var assembly in allTargetAssemblies) { if (!IsCompatibleWithPlatform(assembly, args.Settings)) { continue; } // If already dirty, skip. if (dirtyTargetAssemblies.ContainsKey(assembly)) { continue; } foreach (var reference in assembly.References) { if (dirtyTargetAssemblies.ContainsKey(reference)) { dirtyTargetAssemblies[assembly] = new HashSet <string>(); dirtyAssemblyCount++; break; } } } }while (dirtyAssemblyCount > 0); // Add any non-dirty source files that belong to dirty TargetAssemblies foreach (var sourceFile in args.AllSourceFiles) { var targetAssembly = GetTargetAssembly(sourceFile, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies); if (!IsCompatibleWithPlatform(targetAssembly, args.Settings)) { continue; } HashSet <string> assemblySourceFiles; var scriptExtension = ScriptCompilers.GetExtensionOfSourceFile(sourceFile); var scriptLanguage = ScriptCompilers.GetLanguageFromExtension(scriptExtension); if (targetAssembly.Language == null && targetAssembly.Type == TargetAssemblyType.Custom) { targetAssembly.Language = scriptLanguage; } // If there are mixed languages in a custom script folder, mark the assembly to not be compiled. if (scriptLanguage != targetAssembly.Language) { args.NotCompiledTargetAssemblies.Add(targetAssembly); } if (dirtyTargetAssemblies.TryGetValue(targetAssembly, out assemblySourceFiles)) { assemblySourceFiles.Add(AssetPath.Combine(args.ProjectDirectory, sourceFile)); } } // Remove any target assemblies which have no source files associated with them. dirtyTargetAssemblies = dirtyTargetAssemblies.Where(e => e.Value.Count > 0).ToDictionary(e => e.Key, e => e.Value); // Remove any target assemblies which have been marked as do not compile. foreach (var removeAssembly in args.NotCompiledTargetAssemblies) { dirtyTargetAssemblies.Remove(removeAssembly); } // Convert TargetAssemblies to ScriptAssembiles var scriptAssemblies = ToScriptAssemblies(dirtyTargetAssemblies, args.Settings, args.Assemblies, args.RunUpdaterAssemblies); return(scriptAssemblies); }
public static ScriptAssembly[] GenerateChangedScriptAssemblies(EditorBuildRules.GenerateChangedScriptAssembliesArgs args) { bool flag = (args.BuildFlags & BuildFlags.BuildingForEditor) == BuildFlags.BuildingForEditor; Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> > dictionary = new Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> >(); EditorBuildRules.TargetAssembly[] array = (args.Assemblies.CustomTargetAssemblies != null) ? EditorBuildRules.predefinedTargetAssemblies.Concat(args.Assemblies.CustomTargetAssemblies).ToArray <EditorBuildRules.TargetAssembly>() : EditorBuildRules.predefinedTargetAssemblies; if (args.RunUpdaterAssemblies != null) { using (HashSet <string> .Enumerator enumerator = args.RunUpdaterAssemblies.GetEnumerator()) { while (enumerator.MoveNext()) { string assemblyFilename = enumerator.Current; EditorBuildRules.TargetAssembly key = array.First((EditorBuildRules.TargetAssembly a) => a.FilenameWithSuffix(args.Settings.FilenameSuffix) == assemblyFilename); dictionary[key] = new HashSet <string>(); } } } foreach (string current in args.DirtySourceFiles) { EditorBuildRules.TargetAssembly targetAssembly = EditorBuildRules.GetTargetAssembly(current, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies); if (flag || !targetAssembly.EditorOnly) { string extensionOfSourceFile = ScriptCompilers.GetExtensionOfSourceFile(current); SupportedLanguage languageFromExtension = ScriptCompilers.GetLanguageFromExtension(extensionOfSourceFile); HashSet <string> hashSet; if (!dictionary.TryGetValue(targetAssembly, out hashSet)) { hashSet = new HashSet <string>(); dictionary[targetAssembly] = hashSet; if (targetAssembly.Type == EditorBuildRules.TargetAssemblyType.Custom) { targetAssembly.Language = languageFromExtension; } } hashSet.Add(Path.Combine(args.ProjectDirectory, current)); if (languageFromExtension != targetAssembly.Language) { args.NotCompiledTargetAssemblies.Add(targetAssembly); } } } bool flag2 = dictionary.Any((KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > entry) => entry.Key.Type == EditorBuildRules.TargetAssemblyType.Custom); if (flag2) { EditorBuildRules.TargetAssembly[] array2 = EditorBuildRules.predefinedTargetAssemblies; for (int i = 0; i < array2.Length; i++) { EditorBuildRules.TargetAssembly targetAssembly2 = array2[i]; if (flag || !targetAssembly2.EditorOnly) { if (!dictionary.ContainsKey(targetAssembly2)) { dictionary[targetAssembly2] = new HashSet <string>(); } } } } int num; do { num = 0; EditorBuildRules.TargetAssembly[] array3 = array; for (int j = 0; j < array3.Length; j++) { EditorBuildRules.TargetAssembly targetAssembly3 = array3[j]; if (flag || !targetAssembly3.EditorOnly) { if (!dictionary.ContainsKey(targetAssembly3)) { foreach (EditorBuildRules.TargetAssembly current2 in targetAssembly3.References) { if (dictionary.ContainsKey(current2)) { dictionary[targetAssembly3] = new HashSet <string>(); num++; break; } } } } } }while (num > 0); foreach (string current3 in args.AllSourceFiles) { EditorBuildRules.TargetAssembly targetAssembly4 = EditorBuildRules.GetTargetAssembly(current3, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies); if (flag || !targetAssembly4.EditorOnly) { string extensionOfSourceFile2 = ScriptCompilers.GetExtensionOfSourceFile(current3); SupportedLanguage languageFromExtension2 = ScriptCompilers.GetLanguageFromExtension(extensionOfSourceFile2); if (targetAssembly4.Language == null && targetAssembly4.Type == EditorBuildRules.TargetAssemblyType.Custom) { targetAssembly4.Language = languageFromExtension2; } if (languageFromExtension2 != targetAssembly4.Language) { args.NotCompiledTargetAssemblies.Add(targetAssembly4); } HashSet <string> hashSet2; if (dictionary.TryGetValue(targetAssembly4, out hashSet2)) { hashSet2.Add(Path.Combine(args.ProjectDirectory, current3)); } } } dictionary = (from e in dictionary where e.Value.Count > 0 select e).ToDictionary((KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > e) => e.Key, (KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > e) => e.Value); foreach (EditorBuildRules.TargetAssembly current4 in args.NotCompiledTargetAssemblies) { dictionary.Remove(current4); } return(EditorBuildRules.ToScriptAssemblies(dictionary, args.Settings, args.BuildFlags, args.Assemblies, args.RunUpdaterAssemblies)); }