예제 #1
0
        private static void OnCompilationFinished(string path, CompilerMessage[] messages)
        {
            Assembly foundAssembly = GetAllAssemblies()
                                     .FirstOrDefault(assembly => string.Equals(assembly.outputPath, path, StringComparison.Ordinal));

            if (foundAssembly == null)
            {
                return;
            }

            IReadOnlyCollection <string> searchPaths = WeaverPathsHelper.GetSearchPaths().ToList();
            Runner runner = new Runner(new Logger());

            runner.Configure(searchPaths, searchPaths);

            WeaveAssembly(foundAssembly, runner);
        }
        private static void WeaveAllAssemblies()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            EditorApplication.LockReloadAssemblies();
            bool didChangeAnyAssembly = false;

            try
            {
                IReadOnlyCollection <string> searchPaths = WeaverPathsHelper.GetSearchPaths().ToList();
                Runner runner = new Runner(new Logger());
                runner.Configure(searchPaths, searchPaths);

                foreach (Assembly assembly in GetAllAssemblies())
                {
                    if (!WeaveAssembly(assembly, runner))
                    {
                        continue;
                    }

                    string sourceFilePath = assembly.sourceFiles.FirstOrDefault();
                    if (sourceFilePath == null)
                    {
                        continue;
                    }

                    AssetDatabase.ImportAsset(sourceFilePath, ImportAssetOptions.ForceUpdate);
                    didChangeAnyAssembly = true;
                }
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
                if (didChangeAnyAssembly)
                {
                    AssetDatabase.Refresh();
                }

                Debug.Log($"{nameof(WeaveAllAssemblies)} done: {sw.ElapsedMilliseconds} ms");
            }
        }
예제 #3
0
        // ReSharper disable once AnnotateNotNullParameter
        public void OnPostprocessBuild(BuildReport buildReport)
        {
            const string managedLibraryRoleName = "ManagedLibrary";
            IReadOnlyCollection <string> managedLibraryFilePaths = buildReport.files
                                                                   .Where(file => string.Equals(file.role, managedLibraryRoleName, StringComparison.OrdinalIgnoreCase))
                                                                   .Select(file => file.path)
                                                                   .ToList();

            if (managedLibraryFilePaths.Count == 0)
            {
                Debug.LogWarning(
                    $"The build didn't create any files of role '{managedLibraryRoleName}'. No weaving will be done.");
                return;
            }

            IEnumerable <string> dependentManagedLibraryFilePaths = buildReport.files.Where(
                file => string.Equals(file.role, "DependentManagedLibrary", StringComparison.OrdinalIgnoreCase))
                                                                    .Select(file => file.path);
            IEnumerable <string> managedEngineApiFilePaths = buildReport.files
                                                             .Where(file => string.Equals(file.role, "ManagedEngineAPI", StringComparison.OrdinalIgnoreCase))
                                                             .Select(file => file.path);
            IReadOnlyCollection <string> potentialReferences = managedLibraryFilePaths
                                                               .Concat(dependentManagedLibraryFilePaths)
                                                               .Concat(managedEngineApiFilePaths)
                                                               .ToList();
            List <string> scriptingDefineSymbols = PlayerSettings
                                                   .GetScriptingDefineSymbolsForGroup(buildReport.summary.platformGroup)
                                                   .Split(
                new[]
            {
                ';'
            },
                StringSplitOptions.RemoveEmptyEntries)
                                                   .ToList();
            bool isDebugBuild = buildReport.summary.options.HasFlag(BuildOptions.Development);

            IReadOnlyCollection <string> searchPaths = WeaverPathsHelper.GetSearchPaths().ToList();
            Runner runner = new Runner(new Logger());

            runner.Configure(searchPaths, searchPaths);

            try
            {
                foreach (string managedLibraryFilePath in managedLibraryFilePaths)
                {
                    runner.RunAsync(
                        managedLibraryFilePath,
                        potentialReferences.Except(
                            new[]
                    {
                        managedLibraryFilePath
                    }),
                        scriptingDefineSymbols,
                        isDebugBuild)
                    .GetAwaiter()
                    .GetResult();
                }
            }
            catch (Exception exception)
            {
                Debug.LogException(exception);
            }
        }