コード例 #1
0
ファイル: EditorWeaver.cs プロジェクト: D-Bantz/Malimbe
 private static bool WeaveAssembly(Assembly assembly, Runner runner)
 {
     try
     {
         string assemblyPath             = WeaverPathsHelper.AddProjectPathRootIfNeeded(assembly.outputPath);
         IEnumerable <string> references =
             assembly.allReferences.Select(WeaverPathsHelper.AddProjectPathRootIfNeeded);
         return(runner.RunAsync(assemblyPath, references, assembly.defines.ToList(), true)
                .GetAwaiter()
                .GetResult());
     }
     catch (Exception exception)
     {
         Debug.LogException(exception);
         return(false);
     }
 }
コード例 #2
0
ファイル: EditorWeaver.cs プロジェクト: D-Bantz/Malimbe
        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);
        }
コード例 #3
0
        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");
            }
        }
コード例 #4
0
ファイル: BuildWeaver.cs プロジェクト: D-Bantz/Malimbe
        // 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);
            }
        }