コード例 #1
0
 public static void CreateOperation(this IBuildState buildState, BuildOperation operation)
 {
     buildState.CreateOperation(
         operation.Title,
         operation.Executable.ToString(),
         operation.Arguments,
         operation.WorkingDirectory.ToString(),
         operation.DeclaredInput.Select(value => value.ToString()).ToArray(),
         operation.DeclaredOutput.Select(value => value.ToString()).ToArray());
 }
コード例 #2
0
ファイル: TestBuildTask.cs プロジェクト: mwasplund/SoupTest
        public void Execute()
        {
            var activeState = this.buildState.ActiveState;
            var sharedState = this.buildState.SharedState;

            var recipeTable      = activeState["Recipe"].AsTable();
            var activeBuildTable = activeState["Build"].AsTable();
            var parametersTable  = activeState["Parameters"].AsTable();

            if (!recipeTable.ContainsKey("Tests"))
            {
                throw new InvalidOperationException("No Tests Specified");
            }

            var arguments = new BuildArguments();

            arguments.TargetArchitecture = parametersTable["Architecture"].AsString();

            // Load up the common build properties from the original Build table in the active state
            LoadBuildProperties(activeBuildTable, arguments);

            // Load the test properties
            var testTable = recipeTable["Tests"].AsTable();

            LoadTestBuildProperties(buildState, testTable, arguments);

            // Load up the input build parameters from the shared build state as if
            // this is a dependency build
            var sharedBuildTable = sharedState["Build"].AsTable();

            LoadDependencyBuildInput(sharedBuildTable, arguments);

            // Load up the test dependencies build input to add extra test runtime libraries
            LoadTestDependencyBuildInput(buildState, activeState, arguments);

            // Update to place the output in a sub folder
            arguments.ObjectDirectory = arguments.ObjectDirectory + new Path("Test/");
            arguments.BinaryDirectory = arguments.BinaryDirectory + new Path("Test/");

            // Initialize the compiler to use
            var compilerName = parametersTable["Compiler"].AsString();

            if (!this.compilerFactory.TryGetValue(compilerName, out var compileFactory))
            {
                this.buildState.LogTrace(TraceLevel.Error, "Unknown compiler: " + compilerName);
                throw new InvalidOperationException();
            }

            var compiler = compileFactory(activeState);

            var buildEngine = new BuildEngine(compiler);
            var buildResult = buildEngine.Execute(buildState, arguments);

            // Create the operation to run tests during build
            var title             = "Run Tests";
            var program           = new Path("C:/Program Files/dotnet/dotnet.exe");
            var runtimeConfigFile = arguments.BinaryDirectory + new Path($"{arguments.TargetName}.runtimeconfig.json");
            var workingDirectory  = arguments.TargetRootDirectory;
            var runArguments      = buildResult.TargetFile.ToString();

            // Ensure that the executable and all runtime dependencies are in place before running tests
            var inputFiles = new List <Path>(buildResult.RuntimeDependencies);

            inputFiles.Add(program);
            inputFiles.Add(runtimeConfigFile);

            // The test should have no output
            var outputFiles = new List <Path>();

            var runTestsOperation =
                new BuildOperation(
                    title,
                    workingDirectory,
                    program,
                    runArguments,
                    inputFiles,
                    outputFiles);

            // Run the test harness
            buildResult.BuildOperations.Add(runTestsOperation);

            // Register the build operations
            foreach (var operation in buildResult.BuildOperations)
            {
                buildState.CreateOperation(operation);
            }
        }