Пример #1
0
        public FolderCompiler(CompilerProvider compiler, string subPath, string outputAssemblyName, IWpPluginLogger logger)
        {
            this.Compiler = compiler ?? throw new ArgumentNullException(nameof(compiler));
            this.SubPath  = subPath ?? string.Empty;
            this.Logger   = logger;

            _assemblyNamePrefix = outputAssemblyName ?? throw new ArgumentNullException(nameof(outputAssemblyName));
        }
Пример #2
0
        public HotPlug(string wpRootPath, IWpPluginLogger logger)
        {
            this.RootPath = wpRootPath;

            var compiler = new CompilerProvider(RootPath);

            _pluginsCompiler = new FolderCompiler(compiler, "wp-content/plugins", "wp-plugins", logger);
            _themesCompiler  = new FolderCompiler(compiler, "wp-content/themes", "wp-themes", logger);
        }
Пример #3
0
        public bool Compile(
            CompilerProvider compiler, string assname, bool debug,
            IReadOnlyCollection <string> files,
            out ImmutableArray <Diagnostic> diagnostics,
            out byte[] rawassembly, out byte[] rawsymbols)
        {
            rawassembly = null;
            rawsymbols  = null;

            var success = true;
            var trees   = files.Select(f => GetOrAddFile(f)).ToList();

            foreach (var x in trees)
            {
                success &= IsSuccess(x.Diagnostics);
            }

            if (!success)
            {
                diagnostics = trees.SelectMany(x => x.Diagnostics).ToImmutableArray();
                return(false);
            }

            var compilation = compiler.CreateCompilation(assname, trees, debug);

            var analysis = compilation.GetDiagnostics();

            if (IsSuccess(analysis))
            {
                var peStream    = new MemoryStream();
                var pdbStream   = debug ? new MemoryStream() : null;
                var emitOptions = new EmitOptions();

                if (debug)
                {
                    emitOptions = emitOptions.WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
                }

                var result = compilation.Emit(peStream,
                                              pdbStream: pdbStream,
                                              options: emitOptions);

                diagnostics = result.Diagnostics;

                if (result.Success)
                {
                    rawassembly = peStream.ToArray();
                    rawsymbols  = pdbStream?.ToArray();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                diagnostics = analysis;
                return(false);
            }
        }