Exemplo n.º 1
0
        private IEnumerable <NPath> CompileBeforeTestCaseAssemblies(NPath outputDirectory, NPath[] references, string[] defines, IList <NPath> removeFromLinkerInputAssemblies)
        {
            foreach (var setupCompileInfo in _metadataProvider.GetSetupCompileAssembliesBefore())
            {
                NPath outputFolder;
                if (setupCompileInfo.OutputSubFolder == null)
                {
                    outputFolder = outputDirectory;
                }
                else
                {
                    outputFolder = outputDirectory.Combine(setupCompileInfo.OutputSubFolder);
                    Directory.CreateDirectory(outputFolder.ToString());
                }

                var options = CreateOptionsForSupportingAssembly(
                    setupCompileInfo,
                    outputFolder,
                    CollectSetupBeforeSourcesFiles(setupCompileInfo),
                    references,
                    defines,
                    CollectSetupBeforeResourcesFiles(setupCompileInfo));
                var output = CompileAssembly(options);

                if (setupCompileInfo.RemoveFromLinkerInput)
                {
                    removeFromLinkerInputAssemblies.Add(output);
                }

                if (setupCompileInfo.AddAsReference)
                {
                    yield return(output);
                }
            }
        }
Exemplo n.º 2
0
        public virtual void Populate(TestCaseCompilationMetadataProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                var destination = _directory.Combine(dep.DestinationFileName);
                dep.Source.FileMustExist().Copy(destination);

                // In a few niche tests we need to copy pre-built assemblies directly into the input directory.
                // When this is done, we also need to copy them into the expectations directory so that if they are used
                // as references we can still compile the expectations version of the assemblies
                if (destination.Parent == InputDirectory)
                {
                    dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory)));
                }
            }

            // Copy non class library dependencies to the sandbox
            foreach (var fileName in metadataProvider.GetReferenceValues())
            {
                if (!fileName.StartsWith("System.", StringComparison.Ordinal) && !fileName.StartsWith("Mono.", StringComparison.Ordinal) && !fileName.StartsWith("Microsoft.", StringComparison.Ordinal))
                {
                    CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(fileName.ToNPath()));
                }
            }

            foreach (var referenceDependency in metadataProvider.GetReferenceDependencies())
            {
                CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(referenceDependency.ToNPath()));
            }

            foreach (var res in metadataProvider.GetResources())
            {
                res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName));
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore())
            {
                var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter())
            {
                var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }
        }