public ILCompilerOptionsBuilder(TestCaseMetadataProvider metadataProvider)
        {
            Options           = new ILCompilerOptions();
            _metadataProvider = metadataProvider;

            string runtimeBinDir = (string)AppContext.GetData("Mono.Linker.Tests.RuntimeBinDirectory") !;

            AppendExpandedPaths(Options.ReferenceFilePaths, Path.Combine(runtimeBinDir, "aotsdk", "*.dll"));

            string runtimePackDir = (string)AppContext.GetData("Mono.Linker.Tests.MicrosoftNetCoreAppRuntimePackDirectory") !;

            if (!Directory.Exists(runtimePackDir) && runtimePackDir.Contains("Debug"))
            {
                // Frequently we'll have a Debug runtime and Release libraries, which actually produces a Release runtime pack
                // but from within VS we're see Debug everything. So if the runtime pack directory doesn't exist
                // try the Release path (simple string replace)
                string candidate = runtimePackDir.Replace("Debug", "Release");
                if (Directory.Exists(candidate))
                {
                    runtimePackDir = candidate;
                }
            }
            AppendExpandedPaths(Options.ReferenceFilePaths, Path.Combine(runtimePackDir, "*.dll"));

            Options.InitAssemblies.Add("System.Private.CoreLib");
            Options.InitAssemblies.Add("System.Private.StackTraceMetadata");
            Options.InitAssemblies.Add("System.Private.TypeLoader");
            Options.InitAssemblies.Add("System.Private.Reflection.Execution");

            Options.FeatureSwitches.Add("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", false);
            Options.FeatureSwitches.Add("System.Resources.ResourceManager.AllowCustomResourceTypes", false);
            Options.FeatureSwitches.Add("System.Linq.Expressions.CanCompileToIL", false);
            Options.FeatureSwitches.Add("System.Linq.Expressions.CanEmitObjectArrayDelegate", false);
            Options.FeatureSwitches.Add("System.Linq.Expressions.CanCreateArbitraryDelegates", false);
        }
Esempio n. 2
0
        protected virtual LinkerCustomizations CustomizeLinker(LinkerDriver linker, TestCaseMetadataProvider metadataProvider)
        {
            LinkerCustomizations customizations = new LinkerCustomizations();

            metadataProvider.CustomizeLinker(linker, customizations);

            return(customizations);
        }
 public ILCompilerTestCaseResult(TestCase testCase, NPath inputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, TestLogWriter logWriter)
 {
     TestCase                 = testCase;
     InputAssemblyPath        = inputAssemblyPath;
     ExpectationsAssemblyPath = expectationsAssemblyPath;
     Sandbox           = sandbox;
     MetadataProvider  = metadataProvider;
     CompilationResult = compilationResult;
     LogWriter         = logWriter;
 }
Esempio n. 4
0
 public LinkedTestCaseResult(TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations)
 {
     TestCase                 = testCase;
     InputAssemblyPath        = inputAssemblyPath;
     OutputAssemblyPath       = outputAssemblyPath;
     ExpectationsAssemblyPath = expectationsAssemblyPath;
     Sandbox           = sandbox;
     MetadataProvider  = metadataProvider;
     CompilationResult = compilationResult;
     Logger            = logger;
     Customizations    = customizations;
 }
Esempio n. 5
0
        /// <summary>
        /// Any files that are needed for linking should come from the expectations assembly so that these values
        /// can be controlled using #ifs regardless of the framework the NUnit test project is compiled against
        /// </summary>
        /// <param name="metadataProvider"></param>
        public virtual void PopulateFromExpectations(TestCaseMetadataProvider metadataProvider)
        {
            foreach (var res in metadataProvider.GetResponseFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

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

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

            foreach (var res in metadataProvider.GetLinkAttributesFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }
        }
Esempio n. 6
0
        protected virtual void AddLinkOptions(TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadataProvider metadataProvider)
        {
            var caseDefinedOptions = metadataProvider.GetLinkerOptions(sandbox.InputDirectory);

            builder.AddOutputDirectory(sandbox.OutputDirectory);

            foreach (var rspFile in sandbox.ResponseFiles)
            {
                builder.AddResponseFile(rspFile);
            }

            foreach (var inputReference in sandbox.InputDirectory.Files())
            {
                var ext = inputReference.ExtensionWithDot;
                if (ext == ".dll" || ext == ".exe")
                {
                    builder.AddReference(inputReference);
                }
            }
            var coreAction = caseDefinedOptions.TrimMode ?? "skip";

            foreach (var extraReference in metadataProvider.GetExtraLinkerReferences())
            {
                builder.AddReference(extraReference);
                builder.AddAssemblyAction(coreAction, extraReference.FileNameWithoutExtension);
            }

            builder.ProcessOptions(caseDefinedOptions);

            builder.ProcessTestInputAssembly(compilationResult.InputAssemblyPath);
        }
Esempio n. 7
0
        private LinkedTestCaseResult Link(TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadataProvider metadataProvider)
        {
            var linker = _factory.CreateLinker();
            var linkerCustomizations = CustomizeLinker(linker, metadataProvider);

            var builder = _factory.CreateLinkerArgumentBuilder(metadataProvider);

            AddLinkOptions(sandbox, compilationResult, builder, metadataProvider);

            LinkerTestLogger logger = new LinkerTestLogger();

            linker.Link(builder.ToArgs(), linkerCustomizations, logger);

            return(new LinkedTestCaseResult(testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine(compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger, linkerCustomizations));
        }
Esempio n. 8
0
 public LinkerArgumentBuilder(TestCaseMetadataProvider metadataProvider)
 {
     _metadataProvider = metadataProvider;
 }
Esempio n. 9
0
        protected virtual void AddLinkOptions(TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, ILCompilerOptionsBuilder builder, TestCaseMetadataProvider metadataProvider)
        {
            var caseDefinedOptions = metadataProvider.GetLinkerOptions(sandbox.InputDirectory);

            builder.AddOutputDirectory(sandbox.OutputDirectory.Combine(compilationResult.InputAssemblyPath.FileNameWithoutExtension + ".obj"));

            foreach (var rspFile in sandbox.ResponseFiles)
            {
                builder.AddResponseFile(rspFile);
            }

            foreach (var inputReference in sandbox.InputDirectory.Files())
            {
                var ext = inputReference.ExtensionWithDot;
                if (ext == ".dll" || ext == ".exe")
                {
                    if (caseDefinedOptions.AssembliesAction.Contains(("link", inputReference.FileNameWithoutExtension)))
                    {
                        builder.AddLinkAssembly(inputReference);
                    }
                    else
                    {
                        builder.AddReference(inputReference);
                    }
                }
            }
Esempio n. 10
0
        private ILCompilerTestCaseResult Link(TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadataProvider metadataProvider)
        {
            var trimmer = _factory.CreateTrimmer();

            var builder = _factory.CreateTrimmerOptionsBuilder(metadataProvider);

            AddLinkOptions(sandbox, compilationResult, builder, metadataProvider);

            var logWriter = new TestLogWriter();

            trimmer.Trim(builder.Options, logWriter);

            return(new ILCompilerTestCaseResult(testCase, compilationResult.InputAssemblyPath, compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logWriter));
        }
Esempio n. 11
0
 public virtual LinkerArgumentBuilder CreateLinkerArgumentBuilder(TestCaseMetadataProvider metadataProvider)
 {
     return(new LinkerArgumentBuilder(metadataProvider));
 }
Esempio n. 12
0
 public virtual ILCompilerOptionsBuilder CreateTrimmerOptionsBuilder(TestCaseMetadataProvider metadataProvider)
 {
     return(new ILCompilerOptionsBuilder(metadataProvider));
 }