コード例 #1
0
        /// <summary>
        /// The compiling process is closely related to the rollback process. When the initial compilation fails, the rollback process will be executed.
        /// </summary>
        /// <param name="syntaxTrees">The syntaxtrees to compile</param>
        /// <param name="ms">The memory stream to store the compilation result onto</param>
        public CompilingProcessResult Compile(IEnumerable <SyntaxTree> syntaxTrees, MemoryStream ms)
        {
            var compiler = CSharpCompilation.Create(_input.ProjectInfo.ProjectUnderTestAssemblyName,
                                                    syntaxTrees: syntaxTrees,
                                                    options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                                                    references: _input.AssemblyReferences);
            RollbackProcessResult rollbackProcessResult = null;

            // first try compiling
            var emitResult = compiler.Emit(ms);

            if (!emitResult.Success)
            {
                LogEmitResult(emitResult);
                // remove broken mutations
                rollbackProcessResult = _rollbackProcess.Start(compiler, emitResult.Diagnostics);

                // reset the memoryStream for the second compilation
                ms.SetLength(0);

                // second try compiling
                emitResult = rollbackProcessResult.Compilation.Emit(ms);
            }

            LogEmitResult(emitResult);
            return(new CompilingProcessResult()
            {
                Success = emitResult.Success,
                RollbackResult = rollbackProcessResult
            });
        }
コード例 #2
0
        private (RollbackProcessResult, EmitResult, int) TryCompilation(
            MemoryStream ms,
            CSharpCompilation compilation,
            EmitResult previousEmitResult,
            bool lastAttempt,
            bool devMode,
            int retryCount)
        {
            RollbackProcessResult rollbackProcessResult = null;

            if (previousEmitResult != null)
            {
                // remove broken mutations
                rollbackProcessResult = _rollbackProcess.Start(compilation, previousEmitResult.Diagnostics, lastAttempt, devMode);
                compilation           = rollbackProcessResult.Compilation;
            }

            // reset the memoryStream
            ms.SetLength(0);

            _logger.LogDebug($"Trying compilation for the {ReadableNumber(retryCount)} time.");

            var emitResult = compilation.Emit(
                ms,
                manifestResources: _input.ProjectInfo.ProjectUnderTestAnalyzerResult.Resources,
                win32Resources: compilation.CreateDefaultWin32Resources(
                    versionResource: true, // Important!
                    noManifest: false,
                    manifestContents: null,
                    iconInIcoFormat: null));

            LogEmitResult(emitResult);

            return(rollbackProcessResult, emitResult, ++retryCount);
        }
コード例 #3
0
        public CompilingProcessResult Compile(IEnumerable <ParsedInput> syntaxTrees, bool devMode)
        {
            var analyzerResult = _input.ProjectInfo.ProjectUnderTestAnalyzerResult;

            FSharpList <ParsedInput> trees        = ListModule.OfSeq(syntaxTrees.Reverse());
            FSharpList <string>      dependencies = ListModule.OfSeq(analyzerResult.References);

            //we need a checker if we want to compile
            var checker = FSharpChecker.Create(projectCacheSize: null, keepAssemblyContents: null, keepAllBackgroundResolutions: null, legacyReferenceResolver: null, tryGetMetadataSnapshot: null, suggestNamesForErrors: null, keepAllBackgroundSymbolUses: null, enableBackgroundItemKeyStoreAndSemanticClassification: null);

            var pathlist = new List <string>();
            var pdblist  = new List <string>();

            foreach (var testProject in _input.ProjectInfo.TestProjectAnalyzerResults)
            {
                var injectionPath = _input.ProjectInfo.GetInjectionFilePath(testProject);
                if (!_fileSystem.Directory.Exists(injectionPath.Substring(0, injectionPath.LastIndexOf('\\'))))
                {
                    _fileSystem.Directory.CreateDirectory(injectionPath);
                }

                pathlist.Add(Path.Combine(injectionPath, _input.ProjectInfo.GetInjectionFilePath(testProject)));

                pdblist.Add(Path.Combine(injectionPath,
                                         _input.ProjectInfo.ProjectUnderTestAnalyzerResult.GetSymbolFileName()));

                _logger.LogDebug("Injected the mutated assembly file into {0}", injectionPath);
            }
            if (!pathlist.Any())
            {
                throw new GeneralStrykerException("Could not find project under test.");
            }

            //rollback still needs to be implemented
            RollbackProcessResult rollbackProcessResult = null;

            (var compilationSucces, FSharpErrorInfo[] errorinfo) = TryCompilation(checker, trees, pathlist, dependencies);

            if (compilationSucces)
            {
                //we return if compiled succesfully
                //it is however not used as this is the end of the current F# implementation
                return(new CompilingProcessResult()
                {
                    Success = compilationSucces,
                    RollbackResult = rollbackProcessResult
                });
            }

            // compiling failed
            _logger.LogError("Failed to restore the project to a buildable state. Please report the issue. Stryker can not proceed further");
            throw new CompilationException("Failed to restore build able state.");
        }
コード例 #4
0
        /// <summary>
        /// The compiling process is closely related to the rollback process. When the initial compilation fails, the rollback process will be executed.
        /// </summary>
        /// <param name="syntaxTrees">The syntaxtrees to compile</param>
        /// <param name="ms">The memory stream to store the compilation result onto</param>
        /// <param name="devMode"></param>
        public CompilingProcessResult Compile(IEnumerable <SyntaxTree> syntaxTrees, MemoryStream ms, bool devMode)
        {
            var analyzerResult = _input.ProjectInfo.ProjectUnderTestAnalyzerResult;

            var compiler = CSharpCompilation.Create(analyzerResult.Properties.GetValueOrDefault("TargetName"),
                                                    syntaxTrees: syntaxTrees,
                                                    options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
                                                                                          allowUnsafe: true,
                                                                                          cryptoKeyFile: analyzerResult.SignAssembly ? analyzerResult.AssemblyOriginatorKeyFile : null,
                                                                                          strongNameProvider: analyzerResult.SignAssembly ? new DesktopStrongNameProvider() : null),

                                                    references: _input.AssemblyReferences);
            RollbackProcessResult rollbackProcessResult = null;

            // first try compiling
            var emitResult = compiler.Emit(ms, manifestResources: analyzerResult.Resources);

            if (!emitResult.Success)
            {
                // second try compiling
                (rollbackProcessResult, emitResult) = RetryCompilation(ms, compiler, emitResult, devMode);
            }

            if (!emitResult.Success)
            {
                // third try compiling
                (rollbackProcessResult, emitResult) = RetryCompilation(ms, rollbackProcessResult.Compilation, emitResult, devMode);
            }

            LogEmitResult(emitResult);
            if (!emitResult.Success)
            {
                // compiling failed
                _logger.LogError("Failed to restore the project to a buildable state. Please report the issue. Stryker can not proceed further");
                foreach (var emitResultDiagnostic in emitResult.Diagnostics)
                {
                    _logger.LogWarning($"{emitResultDiagnostic}");
                }
                throw new ApplicationException("Failed to restore build able state.");
            }
            return(new CompilingProcessResult()
            {
                Success = emitResult.Success,
                RollbackResult = rollbackProcessResult
            });
        }
コード例 #5
0
        /// <summary>
        /// The compiling process is closely related to the rollback process. When the initial compilation fails, the rollback process will be executed.
        /// </summary>
        /// <param name="syntaxTrees">The syntaxtrees to compile</param>
        /// <param name="ms">The memory stream to store the compilation result onto</param>
        /// <param name="devMode"></param>
        public CompilingProcessResult Compile(IEnumerable <SyntaxTree> syntaxTrees, MemoryStream ms, bool devMode)
        {
            var analyzerResult = _input.ProjectInfo.ProjectUnderTestAnalyzerResult;

            // Set assembly and file info
            AddVersionInfoSyntaxes(syntaxTrees, analyzerResult);

            var compilation = CSharpCompilation.Create(analyzerResult.Properties.GetValueOrDefault("TargetName"),
                                                       syntaxTrees: syntaxTrees,
                                                       options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
                                                                                             allowUnsafe: true,
                                                                                             cryptoKeyFile: analyzerResult.SignAssembly ? analyzerResult.AssemblyOriginatorKeyFile : null,
                                                                                             strongNameProvider: analyzerResult.SignAssembly ? new DesktopStrongNameProvider() : null),
                                                       references: _input.AssemblyReferences);

            RollbackProcessResult rollbackProcessResult = null;

            // first try compiling
            EmitResult emitResult = null;
            int        retryCount = 1;

            (rollbackProcessResult, emitResult, retryCount) = TryCompilation(ms, compilation, null, devMode, retryCount);

            for (var count = 1; !emitResult.Success && count < 50; count++)
            {
                // compilation did not succeed. let's compile a couple times more for good measure
                (rollbackProcessResult, emitResult, retryCount) = TryCompilation(ms, rollbackProcessResult?.Compilation ?? compilation, emitResult, devMode, retryCount);
            }

            if (!emitResult.Success)
            {
                // compiling failed
                _logger.LogError("Failed to restore the project to a buildable state. Please report the issue. Stryker can not proceed further");
                foreach (var emitResultDiagnostic in emitResult.Diagnostics)
                {
                    _logger.LogWarning($"{emitResultDiagnostic}");
                }
                throw new ApplicationException("Failed to restore build able state.");
            }
            return(new CompilingProcessResult()
            {
                Success = emitResult.Success,
                RollbackResult = rollbackProcessResult
            });
        }
コード例 #6
0
        private (RollbackProcessResult, EmitResult, int) TryCompilation(
            Stream ms,
            Stream symbolStream,
            CSharpCompilation compilation,
            EmitResult previousEmitResult,
            bool lastAttempt,
            bool devMode,
            int retryCount)
        {
            RollbackProcessResult rollbackProcessResult = null;

            if (previousEmitResult != null)
            {
                // remove broken mutations
                rollbackProcessResult = _rollbackProcess.Start(compilation, previousEmitResult.Diagnostics, lastAttempt, devMode);
                compilation           = rollbackProcessResult.Compilation;
            }

            // reset the memoryStream
            ms.SetLength(0);
            symbolStream?.SetLength(0);

            _logger.LogDebug($"Trying compilation for the {ReadableNumber(retryCount)} time.");

            var emitOptions = symbolStream == null ? null : new EmitOptions(false, DebugInformationFormat.PortablePdb,
                                                                            _input.ProjectInfo.ProjectUnderTestAnalyzerResult.GetSymbolFileName());
            var emitResult = compilation.Emit(
                ms,
                symbolStream,
                manifestResources: _input.ProjectInfo.ProjectUnderTestAnalyzerResult.GetResources(_logger),
                win32Resources: compilation.CreateDefaultWin32Resources(
                    true, // Important!
                    false,
                    null,
                    null),
                options: emitOptions);

            LogEmitResult(emitResult);

            return(rollbackProcessResult, emitResult, ++retryCount);
        }
コード例 #7
0
        /// <summary>
        /// The compiling process is closely related to the rollback process. When the initial compilation fails, the rollback process will be executed.
        /// </summary>
        /// <param name="syntaxTrees">The syntaxtrees to compile</param>
        /// <param name="ms">The memory stream to store the compilation result onto</param>
        /// <param name="devMode"></param>
        public CompilingProcessResult Compile(IEnumerable <SyntaxTree> syntaxTrees, MemoryStream ms, bool devMode)
        {
            var compiler = CSharpCompilation.Create(_input.ProjectInfo.ProjectUnderTestAssemblyName,
                                                    syntaxTrees: syntaxTrees,
                                                    options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true),
                                                    references: _input.AssemblyReferences);
            RollbackProcessResult rollbackProcessResult = null;

            // first try compiling
            var emitResult = compiler.Emit(ms);

            if (!emitResult.Success)
            {
                // second try compiling
                (rollbackProcessResult, emitResult) = RetryCompilation(ms, compiler, emitResult, devMode);
            }

            if (!emitResult.Success)
            {
                // third try compiling
                (rollbackProcessResult, emitResult) = RetryCompilation(ms, rollbackProcessResult.Compilation, emitResult, devMode);
            }

            LogEmitResult(emitResult);
            if (!emitResult.Success)
            {
                // compiling failed
                _logger.LogError("Failed to restore the project to a buildable state. Please report the issue. Stryker can not proceed further");
                foreach (var emitResultDiagnostic in emitResult.Diagnostics)
                {
                    _logger.LogWarning($"{emitResultDiagnostic}");
                }
                throw new ApplicationException("Failed to restore build able state.");
            }
            return(new CompilingProcessResult()
            {
                Success = emitResult.Success,
                RollbackResult = rollbackProcessResult
            });
        }
コード例 #8
0
        /// <summary>
        /// The compiling process is closely related to the rollback process. When the initial compilation fails, the rollback process will be executed.
        /// </summary>
        /// <param name="syntaxTrees">The syntaxtrees to compile</param>
        /// <param name="ms">The memory stream to store the compilation result onto</param>
        /// <param name="devMode"></param>
        public CompilingProcessResult Compile(IEnumerable <SyntaxTree> syntaxTrees, MemoryStream ms, bool devMode)
        {
            var compiler = CSharpCompilation.Create(_input.ProjectInfo.ProjectUnderTestAssemblyName,
                                                    syntaxTrees: syntaxTrees,
                                                    options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                                                    references: _input.AssemblyReferences);
            RollbackProcessResult rollbackProcessResult = null;

            // first try compiling
            var emitResult = compiler.Emit(ms);

            if (!emitResult.Success)
            {
                LogEmitResult(emitResult);
                // remove broken mutations
                rollbackProcessResult = _rollbackProcess.Start(compiler, emitResult.Diagnostics, devMode);

                // reset the memoryStream for the second compilation
                ms.SetLength(0);

                // second try compiling
                emitResult = rollbackProcessResult.Compilation.Emit(ms);
            }

            LogEmitResult(emitResult);
            if (!emitResult.Success)
            {
                _logger.LogError("Failed to restore the project to a buildable state. Please report the issue. Stryker can not proceed further");
                throw new ApplicationException("Failed to restore build able state.");
            }
            return(new CompilingProcessResult()
            {
                Success = emitResult.Success,
                RollbackResult = rollbackProcessResult
            });
        }