コード例 #1
0
 public void Add(ILPostProcessorData postProcessor)
 {
     lock (lockObject)
     {
         postProcessors.Add(postProcessor);
     }
 }
コード例 #2
0
 public void Remove(ILPostProcessorData postProcessor)
 {
     lock (lockObject)
     {
         postProcessors.Remove(postProcessor);
     }
 }
コード例 #3
0
        List <DiagnosticMessage> RunILPostProcessors(ScriptAssembly assembly, string outputTempPath)
        {
            Profiler.BeginSample("CompilationPipeline.RunILPostProcessors");
            var assemblyPath = Path.Combine(outputTempPath, assembly.Filename);

            var resultMessages = new List <DiagnosticMessage>();

            if (!File.Exists(assemblyPath))
            {
                resultMessages.Add(new DiagnosticMessage
                {
                    File           = assemblyPath,
                    MessageData    = $"Could not find {assemblyPath} for post processing",
                    DiagnosticType = DiagnosticType.Error,
                });
            }

            bool isILProcessed = false;
            var  ilPostProcessCompiledAssembly = new ILPostProcessCompiledAssembly(assembly, outputTempPath);

            InMemoryAssembly postProcessedInMemoryAssembly = null;

            foreach (var ilPostProcessor in ILPostProcessors)
            {
                Profiler.BeginSample($"{ilPostProcessor.GetType().FullName}.Process({assembly.Filename})");

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                Console.WriteLine($"  - Starting ILPostProcessor '{ilPostProcessor.GetType().FullName}' on {assembly.Filename}");

                var ilPostProcessorInstance = ilPostProcessor.GetInstance();

                var ilPostProcessorData = new ILPostProcessorData {
                    postProcessor = ilPostProcessorInstance, scriptAssembly = assembly
                };
                RunningPostProcessors.Add(ilPostProcessorData);

                ILPostProcessResult ilPostProcessResult;
                try
                {
                    ilPostProcessResult = ilPostProcessorInstance.Process(ilPostProcessCompiledAssembly);
                }
                finally
                {
                    RunningPostProcessors.Remove(ilPostProcessorData);
                }

                stopwatch.Stop();

                Profiler.EndSample();

                var elapsed = stopwatch.Elapsed;

                Console.WriteLine($"  - Finished ILPostProcessor '{ilPostProcessor.GetType().FullName}' on {assembly.Filename} in {elapsed.TotalSeconds:0.######} seconds");
                postProcessedInMemoryAssembly = ilPostProcessResult?.InMemoryAssembly;

                if (ilPostProcessResult?.InMemoryAssembly != null)
                {
                    isILProcessed = true;
                    ilPostProcessCompiledAssembly.InMemoryAssembly = postProcessedInMemoryAssembly;
                }

                if (ilPostProcessResult?.Diagnostics != null)
                {
                    resultMessages.AddRange(ilPostProcessResult.Diagnostics);
                }
            }

            if (isILProcessed)
            {
                ilPostProcessCompiledAssembly.WriteAssembly();
            }

            Profiler.EndSample();

            return(resultMessages);
        }