public static bool ShouldAdd(string assemblyName)
        {
            var name = AssetPath.GetAssemblyNameWithoutExtension(assemblyName);

            if (name.StartsWith(k_UnityAssemblyPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CompilerClientSuffix, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
        public static bool IsCodeGenTest(string assemblyName)
        {
            var name = AssetPath.GetAssemblyNameWithoutExtension(assemblyName);

            if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CompilerTestsSuffix, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CodeGenTestsSuffix, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public static TargetAssembly[] CreateTargetAssemblies(IEnumerable <CustomScriptAssembly> customScriptAssemblies)
        {
            if (customScriptAssemblies == null)
            {
                return(null);
            }


            foreach (var customAssembly in customScriptAssemblies)
            {
                if (predefinedTargetAssemblies.Any(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));
                }
            }

            var targetAssemblies     = new List <TargetAssembly>();
            var nameToTargetAssembly = new Dictionary <string, TargetAssembly>();


            // Create TargetAssemblies
            foreach (var customAssembly in customScriptAssemblies)
            {
                var lowerPathPrefix = customAssembly.PathPrefix.ToLower(CultureInfo.InvariantCulture);

                var targetAssembly = new TargetAssembly(customAssembly.Name + ".dll",
                                                        null,
                                                        customAssembly.AssemblyFlags,
                                                        TargetAssemblyType.Custom,
                                                        customAssembly.PathPrefix,
                                                        path => FastStartsWith(path, customAssembly.PathPrefix, lowerPathPrefix) ? customAssembly.PathPrefix.Length : -1,
                                                        (BuildTarget target, EditorScriptCompilationOptions options) => customAssembly.IsCompatibleWith(target, options),
                                                        customAssembly.CompilerOptions)
                {
                    OptionalUnityReferences = customAssembly.OptionalUnityReferences,
                };

                targetAssemblies.Add(targetAssembly);
                nameToTargetAssembly[customAssembly.Name] = targetAssembly;
            }

            var targetAssembliesEnumerator = targetAssemblies.GetEnumerator();

            // Setup references for TargetAssemblies
            foreach (var customAssembly in customScriptAssemblies)
            {
                targetAssembliesEnumerator.MoveNext();
                var targetAssembly = targetAssembliesEnumerator.Current;

                if (customAssembly.References == null)
                {
                    continue;
                }

                foreach (var reference in customAssembly.References)
                {
                    TargetAssembly referenceAssembly = null;

                    if (!nameToTargetAssembly.TryGetValue(reference, out referenceAssembly))
                    {
                        UnityEngine.Debug.LogWarning(string.Format("Could not find reference '{0}' for assembly '{1}'", reference, customAssembly.Name));
                        continue;
                    }

                    targetAssembly.References.Add(referenceAssembly);
                }
            }

            return(targetAssemblies.ToArray());
        }
Exemple #5
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();