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 HashSet <TargetAssembly> GetTargetAssembliesWithScriptsHashSet( Dictionary <string, string> allScripts, string projectDirectory, IDictionary <string, TargetAssembly> customTargetAssemblies, ScriptAssemblySettings settings) { var uniqueTargetAssemblies = new HashSet <TargetAssembly>(); foreach (var entry in allScripts) { var script = entry.Key; var assemblyName = entry.Value; var targetAssembly = GetTargetAssembly(script, assemblyName, projectDirectory, customTargetAssemblies); // This can happen for scripts in packages that are not included in an .asmdef assembly // and they will therefore not be compiled. if (targetAssembly == null) { continue; } if (!IsCompatibleWithPlatformAndDefines(targetAssembly, settings)) { continue; } uniqueTargetAssemblies.Add(targetAssembly); } return(uniqueTargetAssemblies); }
internal static TargetAssembly[] GetTargetAssembliesWithScripts( Dictionary <string, string> allScripts, string projectDirectory, IDictionary <string, TargetAssembly> customTargetAssemblies, ScriptAssemblySettings settings) { return(GetTargetAssembliesWithScriptsHashSet(allScripts, projectDirectory, customTargetAssemblies, settings).ToArray()); }
public static ScriptAssembly[] GetAllScriptAssemblies( Dictionary <string, string> allSourceFiles, String projectDirectory, ScriptAssemblySettings settings, CompilationAssemblies assemblies, ISafeModeInfo safeModeInfo, TargetAssemblyType onlyIncludeType = TargetAssemblyType.Undefined, Func <TargetAssembly, bool> targetAssemblyCondition = null, ICompilationSetupWarningTracker warningSink = null) { if (allSourceFiles == null || allSourceFiles.Count == 0) { return(new ScriptAssembly[0]); } var targetAssemblyFiles = new Dictionary <TargetAssembly, DirtyTargetAssembly>(); foreach (var entry in allSourceFiles) { var scriptFile = entry.Key; var assemblyName = entry.Value; var targetAssembly = GetTargetAssembly(scriptFile, assemblyName, projectDirectory, assemblies.CustomTargetAssemblies); if (targetAssembly == null) { continue; } if (!IsCompatibleWithPlatformAndDefines(targetAssembly, settings)) { continue; } if (targetAssemblyCondition != null && !targetAssemblyCondition(targetAssembly)) { continue; } // Optionally only include specific TargetAssemblyType assemblies. if (onlyIncludeType != TargetAssemblyType.Undefined && targetAssembly.Type != onlyIncludeType) { continue; } DirtyTargetAssembly dirtyTargetAssembly; if (!targetAssemblyFiles.TryGetValue(targetAssembly, out dirtyTargetAssembly)) { dirtyTargetAssembly = new DirtyTargetAssembly(); targetAssemblyFiles[targetAssembly] = dirtyTargetAssembly; } dirtyTargetAssembly.SourceFiles.Add(AssetPath.Combine(projectDirectory, scriptFile)); } return(ToScriptAssemblies(targetAssemblyFiles, settings, assemblies, warningSink, safeModeInfo)); }
public static bool IsCompatibleWithPlatformAndDefines(TargetAssembly assembly, BuildTarget buildTarget, EditorScriptCompilationOptions options) { var settings = new ScriptAssemblySettings { BuildTarget = buildTarget, CompilationOptions = options }; return(IsCompatibleWithPlatformAndDefines(assembly, settings)); }
private ScriptAssembly[] GetAllScriptAssemblies(BuildFlags buildFlags, EditorScriptCompilationOptions options, PrecompiledAssembly[] unityAssembliesArg, PrecompiledAssembly[] precompiledAssembliesArg) { EditorBuildRules.CompilationAssemblies assemblies = new EditorBuildRules.CompilationAssemblies { UnityAssemblies = unityAssembliesArg, PrecompiledAssemblies = precompiledAssembliesArg, CustomTargetAssemblies = this.customTargetAssemblies, EditorAssemblyReferences = ModuleUtils.GetAdditionalReferencesForUserScripts() }; ScriptAssemblySettings settings = this.CreateEditorScriptAssemblySettings(options); return(EditorBuildRules.GetAllScriptAssemblies(this.allScripts, this.projectDirectory, buildFlags, settings, assemblies)); }
internal static TargetAssembly[] GetTargetAssembliesWithScripts(IEnumerable <string> allScripts, string projectDirectory, TargetAssembly[] customTargetAssemblies, ScriptAssemblySettings settings) { var uniqueTargetAssemblies = new HashSet <TargetAssembly>(); foreach (var script in allScripts) { var targetAssembly = GetTargetAssembly(script, projectDirectory, customTargetAssemblies); if (!IsCompatibleWithPlatform(targetAssembly, settings)) { continue; } uniqueTargetAssemblies.Add(targetAssembly); } return(uniqueTargetAssemblies.ToArray()); }
internal static void AddScriptAssemblyReferences(ref ScriptAssembly scriptAssembly, TargetAssembly targetAssembly, ScriptAssemblySettings settings, CompilationAssemblies assemblies, IDictionary <TargetAssembly, ScriptAssembly> targetToScriptAssembly, string filenameSuffix) { var scriptAssemblyReferences = new List <ScriptAssembly>(); var references = new List <string>(); bool buildingForEditor = settings.BuildingForEditor; // Add Unity assemblies (UnityEngine.dll, UnityEditor.dll) referencees. var unityReferences = GetUnityReferences(scriptAssembly, assemblies.UnityAssemblies, settings.CompilationOptions); references.AddRange(unityReferences); // Setup target assembly references foreach (var reference in targetAssembly.References) { ScriptAssembly scriptAssemblyReference; // Add ScriptAssembly references to other dirty script assemblies that also need to be rebuilt. if (targetToScriptAssembly.TryGetValue(reference, out scriptAssemblyReference)) { System.Diagnostics.Debug.Assert(scriptAssemblyReference != null); scriptAssemblyReferences.Add(scriptAssemblyReference); } else { // Add string references to other assemblies that do not need to be rebuilt. var assemblyPath = reference.FullPath(settings.OutputDirectory, filenameSuffix); if (File.Exists(assemblyPath)) { references.Add(assemblyPath); } } } // For predefined target assembly add references to custom target assemblies if (assemblies.CustomTargetAssemblies != null && (targetAssembly.Type & TargetAssemblyType.Predefined) == TargetAssemblyType.Predefined) { foreach (var customTargetAssembly in assemblies.PredefinedAssembliesCustomTargetReferences ?? Enumerable.Empty <TargetAssembly>()) { ScriptAssembly scriptAssemblyReference; // Only add ScriptAssembly reference if the custom target assembly is dirty, e.g. is in targetToScriptAssembly dictionary // Otherwise just add already compiled custom target assembly as precompiled reference. if (targetToScriptAssembly.TryGetValue(customTargetAssembly, out scriptAssemblyReference)) { scriptAssemblyReferences.Add(scriptAssemblyReference); } else { var customTargetAssemblyPath = customTargetAssembly.FullPath(settings.OutputDirectory, filenameSuffix); // File might not exist if there are no scripts in the custom target assembly folder. if (File.Exists(customTargetAssemblyPath)) { references.Add(customTargetAssemblyPath); } } } } // Add pre-compiled assemblies as references PrecompiledAssembly[] precompiledAssembliesForReferences = assemblies.PrecompiledAssemblies ?? new PrecompiledAssembly[] {}; if (settings.OptionalUnityReferences != OptionalUnityReferences.None) { precompiledAssembliesForReferences = precompiledAssembliesForReferences.Where(x => x.OptionalUnityReferences == OptionalUnityReferences.None || ((targetAssembly.OptionalUnityReferences & x.OptionalUnityReferences & settings.OptionalUnityReferences) != 0)).ToArray(); } var precompiledReferences = GetPrecompiledReferences(scriptAssembly, targetAssembly.Type, settings.CompilationOptions, targetAssembly.editorCompatibility, precompiledAssembliesForReferences); references.AddRange(precompiledReferences); if (buildingForEditor && assemblies.EditorAssemblyReferences != null) { references.AddRange(assemblies.EditorAssemblyReferences); } references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(scriptAssembly.ApiCompatibilityLevel, scriptAssembly.BuildTarget, scriptAssembly.Language, buildingForEditor, scriptAssembly.Filename)); scriptAssembly.ScriptAssemblyReferences = scriptAssemblyReferences.ToArray(); scriptAssembly.References = references.ToArray(); }
public static bool IsCompatibleWithPlatformAndDefines(TargetAssembly assembly, ScriptAssemblySettings settings) { return(assembly.IsCompatibleFunc == null || assembly.IsCompatibleFunc(settings, assembly.Defines)); }
static bool IsCompatibleWithEditor(ScriptAssemblySettings settings) { return((settings.CompilationOptions & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor); }
internal static void AddScriptAssemblyReferences(ref ScriptAssembly scriptAssembly, TargetAssembly targetAssembly, ScriptAssemblySettings settings, CompilationAssemblies assemblies, IDictionary <TargetAssembly, ScriptAssembly> targetToScriptAssembly, ICompilationSetupWarningTracker warningSink) { var scriptAssemblyReferences = new List <ScriptAssembly>(targetAssembly.References.Count); var references = new List <string>(); bool buildingForEditor = settings.BuildingForEditor; bool noEngineReferences = (targetAssembly.Flags & AssemblyFlags.NoEngineReferences) == AssemblyFlags.NoEngineReferences; bool shouldProcessPredefinedCustomTargets = assemblies.CustomTargetAssemblies != null && (targetAssembly.Type & TargetAssemblyType.Predefined) == TargetAssemblyType.Predefined; var predefinedCustomTargetReferences = Enumerable.Empty <TargetAssembly>(); if (shouldProcessPredefinedCustomTargets && assemblies.PredefinedAssembliesCustomTargetReferences != null) { predefinedCustomTargetReferences = assemblies.PredefinedAssembliesCustomTargetReferences; } var unityReferences = new Dictionary <string, string>(); // Add Unity assemblies (UnityEngine.dll, UnityEditor.dll) references, as long as the target // doesn't specify that it doesn't want them. if (!noEngineReferences) { // Add predefined custom target references in a hash-set for fast lookup var predefinedCustomTargetRefs = new HashSet <string>(predefinedCustomTargetReferences.Select(x => x.Filename)); unityReferences = GetUnityReferences(scriptAssembly, targetAssembly, assemblies.UnityAssemblies, predefinedCustomTargetRefs, settings.CompilationOptions, UnityReferencesOptions.None); references.AddRange(unityReferences.Values); } AddTestRunnerCustomReferences(ref targetAssembly, assemblies.CustomTargetAssemblies); // Setup target assembly references foreach (var reference in targetAssembly.References) { ScriptAssembly scriptAssemblyReference; // If the assembly already showed up in the unity references, don't reference it here. // This can happen when an assembly is configured as a unity assembly override, but // overrides are disabled. The Unity assembly should take precedence in that case. if (unityReferences.ContainsKey(reference.Filename)) { continue; } // Add ScriptAssembly references to other dirty script assemblies that also need to be rebuilt. if (targetToScriptAssembly.TryGetValue(reference, out scriptAssemblyReference)) { System.Diagnostics.Debug.Assert(scriptAssemblyReference != null); scriptAssemblyReferences.Add(scriptAssemblyReference); } } // For predefined target assembly add references to custom target assemblies if (shouldProcessPredefinedCustomTargets) { foreach (var customTargetAssembly in predefinedCustomTargetReferences) { ScriptAssembly scriptAssemblyReference; // Only add ScriptAssembly reference if the custom target assembly is dirty, e.g. is in targetToScriptAssembly dictionary // Otherwise just add already compiled custom target assembly as precompiled reference. if (targetToScriptAssembly.TryGetValue(customTargetAssembly, out scriptAssemblyReference)) { scriptAssemblyReferences.Add(scriptAssemblyReference); } } } // Add pre-compiled assemblies as references var allPrecompiledAssemblies = assemblies.PrecompiledAssemblies ?? new Dictionary <string, PrecompiledAssembly>(0); List <PrecompiledAssembly> precompiledReferences = new List <PrecompiledAssembly>(allPrecompiledAssemblies.Count); var explicitPrecompiledReferences = new List <PrecompiledAssembly>(targetAssembly.ExplicitPrecompiledReferences.Count); if ((targetAssembly.Flags & AssemblyFlags.ExplicitReferences) == AssemblyFlags.ExplicitReferences) { if (!noEngineReferences) { precompiledReferences.AddRange(allPrecompiledAssemblies .Where(x => (x.Value.Flags & AssemblyFlags.UserAssembly) != AssemblyFlags.UserAssembly) .Select(x => x.Value)); } foreach (var explicitPrecompiledReference in targetAssembly.ExplicitPrecompiledReferences) { PrecompiledAssembly assembly; if (allPrecompiledAssemblies.TryGetValue(explicitPrecompiledReference, out assembly)) { explicitPrecompiledReferences.Add(assembly); } } } else { var precompiledAssemblies = allPrecompiledAssemblies.Values.Where(x => (x.Flags & AssemblyFlags.ExplicitlyReferenced) != AssemblyFlags.ExplicitlyReferenced).ToList(); // if noEngineReferences, add just the non-explicitly-referenced user assemblies if (noEngineReferences) { precompiledReferences.AddRange(precompiledAssemblies.Where(x => (x.Flags & AssemblyFlags.UserAssembly) == AssemblyFlags.UserAssembly)); } else { precompiledReferences.AddRange(precompiledAssemblies); } } AddTestRunnerPrecompiledReferences(targetAssembly, allPrecompiledAssemblies, ref precompiledReferences); var precompiledReferenceNames = GetPrecompiledReferences(scriptAssembly, targetAssembly.Type, settings.CompilationOptions, targetAssembly.editorCompatibility, precompiledReferences, explicitPrecompiledReferences, warningSink); references.AddRange(precompiledReferenceNames); if (buildingForEditor && assemblies.EditorAssemblyReferences != null) { references.AddRange(assemblies.EditorAssemblyReferences); } references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(scriptAssembly.CompilerOptions.ApiCompatibilityLevel)); scriptAssembly.ScriptAssemblyReferences = scriptAssemblyReferences.ToArray(); scriptAssembly.References = references.ToArray(); }
internal static ScriptAssembly[] ToScriptAssemblies( IDictionary <TargetAssembly, DirtyTargetAssembly> targetAssemblies, ScriptAssemblySettings settings, CompilationAssemblies assemblies, ICompilationSetupWarningTracker warningSink, ISafeModeInfo safeModeInfo) { var scriptAssemblies = new ScriptAssembly[targetAssemblies.Count]; var targetToScriptAssembly = new Dictionary <TargetAssembly, ScriptAssembly>(); int index = 0; bool buildingForEditor = settings.BuildingForEditor; var safeModeWhiteList = new HashSet <string>(safeModeInfo.GetWhiteListAssemblyNames()); foreach (var entry in targetAssemblies) { var targetAssembly = entry.Key; var dirtyTargetAssembly = entry.Value; var scriptAssembly = new ScriptAssembly(); // Setup TargetAssembly -> ScriptAssembly mapping for converting references scriptAssemblies[index] = scriptAssembly; targetToScriptAssembly[targetAssembly] = scriptAssemblies[index++]; // Setup ScriptAssembly scriptAssembly.Flags = targetAssembly.Flags; scriptAssembly.BuildTarget = settings.BuildTarget; scriptAssembly.OriginPath = targetAssembly.PathPrefix; scriptAssembly.Filename = targetAssembly.Filename; scriptAssembly.SkipCodeGen = safeModeWhiteList.Contains(targetAssembly.Filename); scriptAssembly.RootNamespace = targetAssembly.Type == TargetAssemblyType.Predefined ? settings.ProjectRootNamespace : targetAssembly.RootNamespace; scriptAssembly.OutputDirectory = settings.OutputDirectory; scriptAssembly.Defines = targetAssembly.Defines == null ? s_CSharpVersionDefines : targetAssembly.Defines.Concat(s_CSharpVersionDefines).ToArray(); scriptAssembly.Files = dirtyTargetAssembly.SourceFiles.ToArray(); scriptAssembly.TargetAssemblyType = targetAssembly.Type; scriptAssembly.AsmDefPath = targetAssembly.AsmDefPath; if (scriptAssembly.TargetAssemblyType == TargetAssemblyType.Predefined) { scriptAssembly.CompilerOptions = new ScriptCompilerOptions(settings.PredefinedAssembliesCompilerOptions); } else { scriptAssembly.CompilerOptions = targetAssembly.CompilerOptions; } scriptAssembly.CompilerOptions.RoslynAnalyzerDllPaths = new string[0]; scriptAssembly.CompilerOptions.RoslynAnalyzerRulesetPath = string.Empty; scriptAssembly.CompilerOptions.AdditionalCompilerArguments = settings.AdditionalCompilerArguments; var editorOnlyTargetAssembly = (targetAssembly.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly; if (editorOnlyTargetAssembly) { scriptAssembly.CompilerOptions.ApiCompatibilityLevel = ApiCompatibilityLevel.NET_Unity_4_8; } else { scriptAssembly.CompilerOptions.ApiCompatibilityLevel = settings.PredefinedAssembliesCompilerOptions.ApiCompatibilityLevel; } if ((settings.CompilationOptions & EditorScriptCompilationOptions.BuildingUseDeterministicCompilation) == EditorScriptCompilationOptions.BuildingUseDeterministicCompilation) { scriptAssembly.CompilerOptions.UseDeterministicCompilation = true; } else { scriptAssembly.CompilerOptions.UseDeterministicCompilation = false; } scriptAssembly.CompilerOptions.CodeOptimization = settings.CodeOptimization; } // Don't add the auto-referenced engine assemblies if the assembly either has the flag set, or // is a codegen assembly AutoReferencedPackageAssemblies.AddReferences(assemblies.CustomTargetAssemblies, settings.CompilationOptions, t => { var hasNoEngineReferencesFlag = (t.Flags & AssemblyFlags.NoEngineReferences) == AssemblyFlags.NoEngineReferences; if (hasNoEngineReferencesFlag) { return(false); } return(!UnityCodeGenHelpers.IsCodeGen(t.Filename)); }); // Setup ScriptAssembly references index = 0; foreach (var entry in targetAssemblies) { var scriptAssembly = scriptAssemblies[index++]; AddScriptAssemblyReferences(ref scriptAssembly, entry.Key, settings, assemblies, targetToScriptAssembly, warningSink); if (UnityCodeGenHelpers.IsCodeGen(entry.Key.Filename) || UnityCodeGenHelpers.IsCodeGenTest(entry.Key.Filename) || CompilationPipelineCommonHelper.ShouldAdd(entry.Key.Filename)) { CompilationPipelineCommonHelper.UpdateScriptAssemblyReference(ref scriptAssembly); } if (!buildingForEditor) { PlatformSupportModuleHelpers.AddAdditionalPlatformSupportData(settings.CompilationExtension, ref scriptAssembly); } } if ((settings.CompilationOptions & EditorScriptCompilationOptions.BuildingWithRoslynAnalysis) != 0) { var analyzers = assemblies.RoslynAnalyzerDllPaths; foreach (var a in analyzers) { var targetAssemblyOwningAnalyzer = assemblies.CustomTargetAssemblies.Values .OrderBy(c => c.PathFilter(a)).LastOrDefault(); if (targetAssemblyOwningAnalyzer?.PathFilter(a) <= 0) { targetAssemblyOwningAnalyzer = null; } foreach (var scriptAssembly in scriptAssemblies) { if (ShouldUseAnalyzerForScriptAssembly(scriptAssembly, targetAssemblyOwningAnalyzer)) { scriptAssembly.CompilerOptions.RoslynAnalyzerDllPaths = scriptAssembly.CompilerOptions.RoslynAnalyzerDllPaths.Concat(new[] { a }).ToArray(); scriptAssembly.CompilerOptions.RoslynAnalyzerRulesetPath = scriptAssembly.TargetAssemblyType == TargetAssemblyType.Predefined ? RuleSetFileCache.GetRuleSetFilePathInRootFolder(Path.ChangeExtension(scriptAssembly.Filename, null)) : RuleSetFileCache.GetPathForAssembly(scriptAssembly.OriginPath); } } } } return(scriptAssemblies); }
internal static void AddScriptAssemblyReferences(ref ScriptAssembly scriptAssembly, EditorBuildRules.TargetAssembly targetAssembly, ScriptAssemblySettings settings, BuildFlags buildFlags, EditorBuildRules.CompilationAssemblies assemblies, IDictionary <EditorBuildRules.TargetAssembly, ScriptAssembly> targetToScriptAssembly, string filenameSuffix) { List <ScriptAssembly> list = new List <ScriptAssembly>(); List <string> list2 = new List <string>(); bool flag = (buildFlags & BuildFlags.BuildingForEditor) == BuildFlags.BuildingForEditor; bool flag2 = (targetAssembly.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly; if (assemblies.UnityAssemblies != null) { PrecompiledAssembly[] unityAssemblies = assemblies.UnityAssemblies; for (int i = 0; i < unityAssemblies.Length; i++) { PrecompiledAssembly compiledAssembly = unityAssemblies[i]; if (flag || flag2) { if ((compiledAssembly.Flags & AssemblyFlags.UseForMono) != AssemblyFlags.None) { list2.Add(compiledAssembly.Path); } } else if ((compiledAssembly.Flags & AssemblyFlags.EditorOnly) != AssemblyFlags.EditorOnly) { if (EditorBuildRules.IsCompiledAssemblyCompatibleWithTargetAssembly(compiledAssembly, targetAssembly, settings.BuildTarget, assemblies.CustomTargetAssemblies)) { list2.Add(compiledAssembly.Path); } } } } foreach (EditorBuildRules.TargetAssembly current in targetAssembly.References) { ScriptAssembly item; if (targetToScriptAssembly.TryGetValue(current, out item)) { list.Add(item); } else { string text = Path.Combine(settings.OutputDirectory, current.Filename); if (!string.IsNullOrEmpty(filenameSuffix)) { text = text.Replace(".dll", filenameSuffix + ".dll"); } if (File.Exists(text)) { list2.Add(text); } } } if (assemblies.CustomTargetAssemblies != null && targetAssembly.Type == EditorBuildRules.TargetAssemblyType.Predefined) { EditorBuildRules.TargetAssembly[] customTargetAssemblies = assemblies.CustomTargetAssemblies; for (int j = 0; j < customTargetAssemblies.Length; j++) { EditorBuildRules.TargetAssembly key = customTargetAssemblies[j]; ScriptAssembly item2; if (targetToScriptAssembly.TryGetValue(key, out item2)) { list.Add(item2); } } } if (assemblies.PrecompiledAssemblies != null) { PrecompiledAssembly[] precompiledAssemblies = assemblies.PrecompiledAssemblies; for (int k = 0; k < precompiledAssemblies.Length; k++) { PrecompiledAssembly compiledAssembly2 = precompiledAssemblies[k]; bool flag3 = (compiledAssembly2.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly; if (!flag3 || flag2) { if (EditorBuildRules.IsCompiledAssemblyCompatibleWithTargetAssembly(compiledAssembly2, targetAssembly, settings.BuildTarget, assemblies.CustomTargetAssemblies)) { list2.Add(compiledAssembly2.Path); } } } } if (flag && assemblies.EditorAssemblyReferences != null) { list2.AddRange(assemblies.EditorAssemblyReferences); } scriptAssembly.ScriptAssemblyReferences = list.ToArray(); scriptAssembly.References = list2.ToArray(); }
internal static ScriptAssembly[] ToScriptAssemblies(IDictionary <EditorBuildRules.TargetAssembly, HashSet <string> > targetAssemblies, ScriptAssemblySettings settings, BuildFlags buildFlags, EditorBuildRules.CompilationAssemblies assemblies, HashSet <string> runUpdaterAssemblies) { ScriptAssembly[] array = new ScriptAssembly[targetAssemblies.Count]; Dictionary <EditorBuildRules.TargetAssembly, ScriptAssembly> dictionary = new Dictionary <EditorBuildRules.TargetAssembly, ScriptAssembly>(); int num = 0; bool flag = (buildFlags & BuildFlags.BuildingForEditor) == BuildFlags.BuildingForEditor; foreach (KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > current in targetAssemblies) { EditorBuildRules.TargetAssembly key = current.Key; HashSet <string> value = current.Value; ScriptAssembly scriptAssembly = new ScriptAssembly(); array[num] = scriptAssembly; dictionary[key] = array[num++]; scriptAssembly.BuildTarget = settings.BuildTarget; if (key.EditorOnly || (flag && settings.ApiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6)) { scriptAssembly.ApiCompatibilityLevel = ((EditorApplication.scriptingRuntimeVersion != ScriptingRuntimeVersion.Latest) ? ApiCompatibilityLevel.NET_2_0 : ApiCompatibilityLevel.NET_4_6); } else { scriptAssembly.ApiCompatibilityLevel = settings.ApiCompatibilityLevel; } if (!string.IsNullOrEmpty(settings.FilenameSuffix)) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(key.Filename); string extension = Path.GetExtension(key.Filename); scriptAssembly.Filename = fileNameWithoutExtension + settings.FilenameSuffix + extension; } else { scriptAssembly.Filename = key.Filename; } if (runUpdaterAssemblies != null && runUpdaterAssemblies.Contains(scriptAssembly.Filename)) { scriptAssembly.RunUpdater = true; } scriptAssembly.OutputDirectory = settings.OutputDirectory; scriptAssembly.Defines = settings.Defines; scriptAssembly.Files = value.ToArray <string>(); Array.Sort <string>(scriptAssembly.Files); } num = 0; foreach (KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > current2 in targetAssemblies) { EditorBuildRules.AddScriptAssemblyReferences(ref array[num++], current2.Key, settings, buildFlags, assemblies, dictionary, settings.FilenameSuffix); } return(array); }
public FindReferences(Dictionary <string, EditorBuildRules.TargetAssembly> targetAssemblies, ScriptAssemblySettings assemblySettings) { m_AllTargetAssemblies = targetAssemblies; m_AssemblySettings = assemblySettings; }
internal static ScriptAssembly[] ToScriptAssemblies(IDictionary <TargetAssembly, HashSet <string> > targetAssemblies, ScriptAssemblySettings settings, CompilationAssemblies assemblies, HashSet <string> runUpdaterAssemblies) { var scriptAssemblies = new ScriptAssembly[targetAssemblies.Count]; var targetToScriptAssembly = new Dictionary <TargetAssembly, ScriptAssembly>(); int index = 0; bool buildingForEditor = settings.BuildingForEditor; foreach (var entry in targetAssemblies) { var targetAssembly = entry.Key; var sourceFiles = entry.Value; var scriptAssembly = new ScriptAssembly(); // Setup TargetAssembly -> ScriptAssembly mapping for converting references scriptAssemblies[index] = scriptAssembly; targetToScriptAssembly[targetAssembly] = scriptAssemblies[index++]; // Setup ScriptAssembly scriptAssembly.Flags = targetAssembly.Flags; scriptAssembly.BuildTarget = settings.BuildTarget; scriptAssembly.Language = targetAssembly.Language; var editorOnlyTargetAssembly = (targetAssembly.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly; if (editorOnlyTargetAssembly || (buildingForEditor && settings.ApiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6)) { scriptAssembly.ApiCompatibilityLevel = (EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest) ? ApiCompatibilityLevel.NET_4_6 : ApiCompatibilityLevel.NET_2_0; } else { scriptAssembly.ApiCompatibilityLevel = settings.ApiCompatibilityLevel; } if (!string.IsNullOrEmpty(settings.FilenameSuffix)) { var basename = AssetPath.GetAssemblyNameWithoutExtension(targetAssembly.Filename); scriptAssembly.Filename = string.Concat(basename, settings.FilenameSuffix, ".dll"); } else { scriptAssembly.Filename = targetAssembly.Filename; } if (runUpdaterAssemblies != null && runUpdaterAssemblies.Contains(scriptAssembly.Filename)) { scriptAssembly.RunUpdater = true; } scriptAssembly.OutputDirectory = settings.OutputDirectory; scriptAssembly.Defines = settings.Defines; scriptAssembly.Files = sourceFiles.ToArray(); if (targetAssembly.Type == TargetAssemblyType.Predefined) { scriptAssembly.CompilerOptions = settings.PredefinedAssembliesCompilerOptions; } else { scriptAssembly.CompilerOptions = targetAssembly.CompilerOptions; } // Script files must always be passed in the same order to the compiler. // Otherwise player builds might fail for partial classes. Array.Sort(scriptAssembly.Files); } // Setup ScriptAssembly references index = 0; foreach (var entry in targetAssemblies) { AddScriptAssemblyReferences(ref scriptAssemblies[index++], entry.Key, settings, assemblies, targetToScriptAssembly, settings.FilenameSuffix); } return(scriptAssemblies); }
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)); }
internal bool CompileScripts(ScriptAssemblySettings scriptAssemblySettings, string tempBuildDirectory, BuildFlags buildflags, ref EditorBuildRules.TargetAssembly[] notCompiledTargetAssemblies) { this.DeleteUnusedAssemblies(); this.allScripts.RemoveWhere((string path) => !File.Exists(Path.Combine(this.projectDirectory, path))); this.StopAllCompilation(); if (!Directory.Exists(scriptAssemblySettings.OutputDirectory)) { Directory.CreateDirectory(scriptAssemblySettings.OutputDirectory); } if (!Directory.Exists(tempBuildDirectory)) { Directory.CreateDirectory(tempBuildDirectory); } IEnumerable <string> enumerable = (!this.areAllScriptsDirty) ? this.dirtyScripts.ToArray <string>() : this.allScripts.ToArray <string>(); this.areAllScriptsDirty = false; this.dirtyScripts.Clear(); bool result; if (!enumerable.Any <string>() && this.runScriptUpdaterAssemblies.Count == 0) { result = false; } else { EditorBuildRules.CompilationAssemblies assemblies = new EditorBuildRules.CompilationAssemblies { UnityAssemblies = this.unityAssemblies, PrecompiledAssemblies = this.precompiledAssemblies, CustomTargetAssemblies = this.customTargetAssemblies, EditorAssemblyReferences = ModuleUtils.GetAdditionalReferencesForUserScripts() }; EditorBuildRules.GenerateChangedScriptAssembliesArgs generateChangedScriptAssembliesArgs = new EditorBuildRules.GenerateChangedScriptAssembliesArgs { AllSourceFiles = this.allScripts, DirtySourceFiles = enumerable, ProjectDirectory = this.projectDirectory, BuildFlags = buildflags, Settings = scriptAssemblySettings, Assemblies = assemblies, RunUpdaterAssemblies = this.runScriptUpdaterAssemblies }; ScriptAssembly[] array = EditorBuildRules.GenerateChangedScriptAssemblies(generateChangedScriptAssembliesArgs); notCompiledTargetAssemblies = generateChangedScriptAssembliesArgs.NotCompiledTargetAssemblies.ToArray <EditorBuildRules.TargetAssembly>(); if (!array.Any <ScriptAssembly>()) { result = false; } else { this.compilationTask = new CompilationTask(array, tempBuildDirectory, buildflags, SystemInfo.processorCount); this.compilationTask.OnCompilationStarted += delegate(ScriptAssembly assembly, int phase) { Console.WriteLine("- Starting compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename)); }; IEnumerable <MonoIsland> compilingMonoIslands = from i in this.GetAllMonoIslands() where 0 < i._files.Length select i; this.compilationTask.OnCompilationFinished += delegate(ScriptAssembly assembly, List <CompilerMessage> messages) { Console.WriteLine("- Finished compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename)); if (this.runScriptUpdaterAssemblies.Contains(assembly.Filename)) { this.runScriptUpdaterAssemblies.Remove(assembly.Filename); } if (!messages.Any((CompilerMessage m) => m.type == CompilerMessageType.Error)) { string engineAssemblyPath = InternalEditorUtility.GetEngineAssemblyPath(); string unityUNet = EditorApplication.applicationContentsPath + "/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll"; if (!Weaver.WeaveUnetFromEditor(compilingMonoIslands, Path.Combine(tempBuildDirectory, assembly.Filename), Path.Combine(EditorCompilation.EditorTempPath, assembly.Filename), engineAssemblyPath, unityUNet, (buildflags & BuildFlags.BuildingForEditor) != BuildFlags.None)) { messages.Add(new CompilerMessage { message = "UNet Weaver failed", type = CompilerMessageType.Error, file = assembly.FullPath, line = -1, column = -1 }); this.StopAllCompilation(); } else { EditorCompilation.CopyAssembly(Path.Combine(tempBuildDirectory, assembly.Filename), assembly.FullPath); } } }; this.compilationTask.Poll(); result = true; } } return(result); }
static bool IsCompatibleWithPlatform(TargetAssembly assembly, ScriptAssemblySettings settings) { return(assembly.IsCompatibleFunc == null || assembly.IsCompatibleFunc(settings.BuildTarget, settings.CompilationOptions)); }
public static ScriptAssembly[] GetAllScriptAssemblies(IEnumerable <string> allSourceFiles, string projectDirectory, BuildFlags buildFlags, ScriptAssemblySettings settings, EditorBuildRules.CompilationAssemblies assemblies) { ScriptAssembly[] result; if (allSourceFiles == null || allSourceFiles.Count <string>() == 0) { result = new ScriptAssembly[0]; } else { bool flag = (buildFlags & BuildFlags.BuildingForEditor) == BuildFlags.BuildingForEditor; Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> > dictionary = new Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> >(); foreach (string current in allSourceFiles) { EditorBuildRules.TargetAssembly targetAssembly = EditorBuildRules.GetTargetAssembly(current, projectDirectory, assemblies.CustomTargetAssemblies); if (targetAssembly != null) { if (flag || !targetAssembly.EditorOnly) { HashSet <string> hashSet; if (!dictionary.TryGetValue(targetAssembly, out hashSet)) { hashSet = new HashSet <string>(); dictionary[targetAssembly] = hashSet; } hashSet.Add(Path.Combine(projectDirectory, current)); } } } result = EditorBuildRules.ToScriptAssemblies(dictionary, settings, buildFlags, assemblies, null); } return(result); }