コード例 #1
0
        public void ShouldBuildWithoutErrors_AndLinkCorrectFramework(ProjectType type)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = GenerateTestProject(type, tmpDir);
                var logs     = BuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir);

                var bgenInvocation = logs.Item1.SplitLines().First(x => x.Contains("bin/bgen"));
                var bgenParts      = bgenInvocation.Split(new char[] { ' ' });
                var mscorlib       = bgenParts.First(x => x.Contains("mscorlib.dll"));
                var system         = bgenParts.First(x => x.Contains("System.dll"));

                switch (type)
                {
                case ProjectType.Modern:
                case ProjectType.ModernNoTag:
                    Assert.True(mscorlib.EndsWith("lib/mono/Xamarin.Mac/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Modern location: " + mscorlib);
                    Assert.True(system.EndsWith("lib/mono/Xamarin.Mac/System.dll", StringComparison.Ordinal), "system not found in expected Modern location: " + system);
                    break;

                case ProjectType.Full:
                case ProjectType.FullTVF:
                case ProjectType.FullXamMacTag:
                    Assert.True(mscorlib.EndsWith("lib/mono/4.5/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Full location: " + mscorlib);
                    Assert.True(system.EndsWith("lib/mono/4.5/System.dll", StringComparison.Ordinal), "system not found in expected Full location: " + system);
                    break;

                default:
                    throw new NotImplementedException();
                }

                Assert.False(logs.Item1.Contains("CS1685"), "Binding should not contains CS1685 multiple definition warning:\n" + logs.Item1);

                string bindingName = RemoveCSProj(projects.Item1.ProjectName);
                string appName     = RemoveCSProj(projects.Item2.ProjectName);
                string libPath     = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll");

                Assert.True(File.Exists(libPath));
                string results      = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monop", "--refs -r:" + libPath, "monop");
                string mscorlibLine = results.Split(new char[] { '\n' }).First(x => x.Contains("mscorlib"));

                string expectedVersion = GetExpectedBCLVersion(type);
                Assert.True(mscorlibLine.Contains(expectedVersion), $"{mscorlibLine} did not contain expected version {expectedVersion}");
            });
        }
コード例 #2
0
        public static string CreateThinFramework(string tmpDir, bool sixtyFourBits = true)
        {
            Func <string, string> f = x => Path.Combine(tmpDir, x);

            File.WriteAllText(f("foo.c"), "int Answer () { return 42; }");
            File.WriteAllText(f("Info.plist"), PListText);

            string bitnessArg = sixtyFourBits ? "-m64" : "-m32";

            TI.RunAndAssert($"clang {bitnessArg} -c -o {f ("foo.o")} {f ("foo.c")}");
            TI.RunAndAssert($"clang {bitnessArg} -dynamiclib -o {f ("Foo")} {f ("foo.o")}");
            TI.RunAndAssert($"install_name_tool -id @rpath/Foo.framework/Foo {f ("Foo")}");
            TI.RunAndAssert($"mkdir -p {f ("Foo.framework/Versions/A/Resources")}");
            TI.RunAndAssert($"cp {f ("Foo")} {f ("Foo.framework/Versions/A/Foo")}");
            TI.RunAndAssert($"cp {f ("Info.plist")} {f ("Foo.framework/Versions/A/Resources/")}");
            TI.RunAndAssert($"ln -s Versions/A/Foo {f ("Foo.framework/Foo")}");
            TI.RunAndAssert($"ln -s Versions/A/Resources  {f ("Foo.framework/Resources")}");
            TI.RunAndAssert($"ln -s Versions/A  {f ("Foo.framework/Current")}");
            return(f("Foo.framework"));
        }
コード例 #3
0
        public static string CreateFatFramework(string tmpDir)
        {
            Func <string, string> f = x => Path.Combine(tmpDir, x);

            File.WriteAllText(f("foo.c"), "int Answer () { return 42; }");
            File.WriteAllText(f("Info.plist"), PListText);

            TI.RunAndAssert($"clang -m32 -c -o {f ("foo_32.o")} {f ("foo.c")}");
            TI.RunAndAssert($"clang -m64 -c -o {f ("foo_64.o")} {f ("foo.c")}");
            TI.RunAndAssert($"clang -m32 -dynamiclib -o {f ("foo_32.dylib")} {f ("foo_32.o")}");
            TI.RunAndAssert($"clang -m64 -dynamiclib -o {f ("foo_64.dylib")} {f ("foo_64.o")}");
            TI.RunAndAssert($"lipo -create {f ("foo_32.dylib")} {f ("foo_64.dylib")} -output {f ("Foo")}");
            TI.RunAndAssert($"install_name_tool -id @rpath/Foo.framework/Foo {f ("Foo")}");
            TI.RunAndAssert($"mkdir -p {f ("Foo.framework/Versions/A/Resources")}");
            TI.RunAndAssert($"cp {f ("Foo")} {f ("Foo.framework/Versions/A/Foo")}");
            TI.RunAndAssert($"cp {f ("Info.plist")} {f ("Foo.framework/Versions/A/Resources/")}");
            TI.RunAndAssert($"ln -s Versions/A/Foo {f ("Foo.framework/Foo")}");
            TI.RunAndAssert($"ln -s Versions/A/Resources  {f ("Foo.framework/Resources")}");
            TI.RunAndAssert($"ln -s Versions/A  {f ("Foo.framework/Current")}");
            return(f("Foo.framework"));
        }
コード例 #4
0
        public static string CreateFatFramework(string tmpDir)
        {
            Func <string, string> f = x => Path.Combine(tmpDir, x);

            File.WriteAllText(f("foo.c"), "int Answer () { return 42; }");
            File.WriteAllText(f("Info.plist"), PListText);

            TI.RunAndAssert($"clang", "-arch", "arm64", "-c", "-o", $"{f ("foo_arm64.o")}", $"{f ("foo.c")}");
            TI.RunAndAssert($"clang", "-arch", "x86_64", "-c", "-o", $"{f ("foo_x86-64.o")}", $"{f ("foo.c")}");
            TI.RunAndAssert($"clang", "-arch", "arm64", "-dynamiclib", "-o", $"{f ("foo_arm64.dylib")}", $"{f ("foo_arm64.o")}");
            TI.RunAndAssert($"clang", "-arch", "x86_64", "-dynamiclib", "-o", $"{f ("foo_x86-64.dylib")}", $"{f ("foo_x86-64.o")}");
            TI.RunAndAssert($"lipo", "-create", $"{f ("foo_arm64.dylib")}", $"{f ("foo_x86-64.dylib")}", "-output", $"{f ("Foo")}");
            TI.RunAndAssert($"install_name_tool", "-id", "@rpath/Foo.framework/Foo", $"{f ("Foo")}");
            TI.RunAndAssert($"mkdir", "-p", $"{f ("Foo.framework/Versions/A/Resources")}");
            TI.RunAndAssert($"cp", $"{f ("Foo")}", $"{f ("Foo.framework/Versions/A/Foo")}");
            TI.RunAndAssert($"cp", $"{f ("Info.plist")}", $"{f ("Foo.framework/Versions/A/Resources/")}");
            TI.RunAndAssert($"ln", "-s", "Versions/A/Foo", $"{f ("Foo.framework/Foo")}");
            TI.RunAndAssert($"ln", "-s", "Versions/A/Resources", $"{f ("Foo.framework/Resources")}");
            TI.RunAndAssert($"ln", "-s", "Versions/A", $"{f ("Foo.framework/Current")}");
            return(f("Foo.framework"));
        }
コード例 #5
0
        static void NetStandardTestCore(string tmpDir, bool full)
        {
            if (!File.Exists("/usr/local/share/dotnet/dotnet"))
            {
                Assert.Ignore(".NET Core SDK not installed");
            }

            TI.UnifiedTestConfig config = new TI.UnifiedTestConfig(tmpDir);

            string netStandardProject = TI.GenerateNetStandardProject(config);

            var environment = new Dictionary <string, string> {
                { "MSBUILD_EXE_PATH", null },
                { "MSBuildExtensionsPathFallbackPathsOverride", null },
                { "MSBuildSDKsPath", null },
            };

            TI.RunAndAssert("/usr/local/share/dotnet/dotnet", new [] { "restore", netStandardProject }, "Restore", environment: environment);
            TI.BuildProject(netStandardProject);

            config.ItemGroup = $@"
<ItemGroup>
	<ProjectReference Include=""NetStandard\NetStandardLib.csproj"">
		<Project>{{BEC2D25A-A590-4858-8E07-849539D168B1}}</Project>
		<Name>NetStandardLib</Name>
	</ProjectReference>
</ItemGroup>
";

            if (full)
            {
                config.TargetFrameworkVersion = "<TargetFrameworkVersion>4.6.1</TargetFrameworkVersion>";
            }

            config.TestCode     = "var test = new NetStandardLib.Class1 ().TestMethod ();";
            config.CSProjConfig = "<MonoBundlingExtraArgs>--registrar=dynamic</MonoBundlingExtraArgs>";
            config.XM45         = full;

            TI.TestUnifiedExecutable(config);
        }
コード例 #6
0
        public void BuildingSameSolutionTwice_ShouldNotRunACToolTwice()
        {
            RunMMPTest(tmpDir => {
                TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir)
                {
                    AssetIcons = true
                };

                string project = TI.GenerateUnifiedExecutableProject(test);

                string buildOutput = TI.BuildProject(project, true);
                Assert.True(buildOutput.Contains("actool execution started with arguments"), $"Initial build should run actool");

                buildOutput = TI.BuildProject(project, true);
                Assert.False(buildOutput.Contains("actool execution started with arguments"), $"Second build should not run actool");

                TI.RunAndAssert("touch", Path.Combine(tmpDir, "Assets.xcassets/AppIcon.appiconset/[email protected]"), "touch icon");

                buildOutput = TI.BuildProject(project, true);
                Assert.True(buildOutput.Contains("actool execution started with arguments"), $"Build after touching icon must run actool");
            });
        }
コード例 #7
0
        public void HybridAOT_WithManualStrippingOfAllLibs_SmokeTest()
        {
            MMPTests.RunMMPTest(tmpDir => {
                TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir)
                {
                    CSProjConfig = AOTTestHybridConfig
                };
                string buildResults = TI.TestUnifiedExecutable(test).BuildOutput;

                foreach (var file in GetOutputDirInfo(tmpDir).EnumerateFiles())
                {
                    if (IsFileManagedCode(file))
                    {
                        TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/mono-cil-strip", file.ToString(), "Manually strip IL");
                    }
                }

                ValidateAOTStatus(tmpDir, IsFileManagedCode, buildResults);

                TI.RunEXEAndVerifyGUID(tmpDir, test.guid, GetOutputAppPath(tmpDir));
            });
        }
コード例 #8
0
        public void HybridAOT_WithManualStrippingOfAllLibs_SmokeTest(bool useProjectTags)
        {
            MMPTests.RunMMPTest(tmpDir => {
                TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir)
                {
                    CSProjConfig = GetTestConfig(TestType.Hybrid, useProjectTags)
                };
                TI.TestUnifiedExecutable(test);

                foreach (var file in GetOutputDirInfo(tmpDir).EnumerateFiles())
                {
                    if (IsFileManagedCode(file))
                    {
                        TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/mono-cil-strip", new [] { file.ToString() }, "Manually strip IL");
                    }
                }

                ValidateAOTStatus(tmpDir, IsFileManagedCode);

                TI.RunEXEAndVerifyGUID(tmpDir, test.guid, GetOutputAppPath(tmpDir));
            });
        }
コード例 #9
0
        public void BuildingSameSolutionTwice_ShouldNotRunACToolTwice()
        {
            const string actool = " execution started with arguments: actool --errors --warnings --notices --output-format xml1 --output-partial-info-plist ";

            RunMMPTest(tmpDir => {
                TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir)
                {
                    AssetIcons = true
                };

                string project = TI.GenerateUnifiedExecutableProject(test);

                string buildOutput = TI.BuildProject(project);
                Assert.True(buildOutput.Contains(actool), $"Initial build should run actool");

                buildOutput = TI.BuildProject(project);
                Assert.False(buildOutput.Contains(actool), $"Second build should not run actool");

                TI.RunAndAssert("touch", new [] { Path.Combine(tmpDir, "Assets.xcassets/AppIcon.appiconset/[email protected]") }, "touch icon");

                buildOutput = TI.BuildProject(project);
                Assert.True(buildOutput.Contains(actool), $"Build after touching icon must run actool");
            });
        }
コード例 #10
0
        void RestoreRoslynNuget(string projectType)
        {
            StringBuilder nugetArgs = new StringBuilder("restore " + Path.Combine(RoslynTestProjectRoot + projectType + "/") + "packages.config");

            TI.RunAndAssert(nugetPath, nugetArgs, "Restore Nuget");
        }
コード例 #11
0
        public void ShouldBuildWithoutErrors_AndLinkCorrectFramework(BindingProjectType type, bool noEmbedding = false)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = GenerateTestProject(type, tmpDir);
                if (noEmbedding)
                {
                    SetNoEmbedding(projects.Item1);
                }

                var logs = SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference: false, setupDefaultNativeReference: noEmbedding);

                Assert.True(logs.BindingBuildResult.BuildOutput.Contains("csc"), "Bindings project must use csc:\n" + logs.Item1);

                var bgenInvocation = logs.BindingBuildResult.BuildOutputLines.First(x => x.Contains("bin/bgen"));
                Assert.IsTrue(StringUtils.TryParseArguments(bgenInvocation, out var bgenArguments, out var _), "Parse bgen arguments");
                // unfurl any response files
                var bgenParts     = bgenArguments.ToList();
                var responseFiles = bgenParts.Where(v => v [0] == '@').ToArray();
                bgenParts.RemoveAll(v => v [0] == '@');
                foreach (var rsp in responseFiles)
                {
                    Assert.IsTrue(StringUtils.TryParseArguments(File.ReadAllText(rsp.Substring(1)).Replace('\n', ' '), out var args, out var _), "Parse response file");
                    bgenParts.AddRange(args);
                }
                var mscorlib = bgenParts.First(x => x.Contains("mscorlib.dll"));
                var system   = bgenParts.First(x => x.Contains("System.dll"));

                switch (type)
                {
                case BindingProjectType.Modern:
                case BindingProjectType.ModernNoTag:
                    Assert.That(mscorlib, Does.EndWith("lib/mono/Xamarin.Mac/mscorlib.dll"), "mscorlib not found in expected Modern location: " + mscorlib);
                    Assert.That(system, Does.EndWith("lib/mono/Xamarin.Mac/System.dll"), "system not found in expected Modern location: " + system);
                    break;

                case BindingProjectType.Full:
                case BindingProjectType.FullTVF:
                case BindingProjectType.FullXamMacTag:
                    Assert.That(mscorlib, Does.EndWith("lib/mono/4.5/mscorlib.dll"), "mscorlib not found in expected Full location: " + mscorlib);
                    Assert.That(system, Does.EndWith("lib/mono/4.5/System.dll"), "system not found in expected Full location: " + system);
                    break;

                default:
                    throw new NotImplementedException();
                }

                Assert.False(logs.BindingBuildResult.BuildOutput.Contains("CS1685"), "Binding should not contains CS1685 multiple definition warning.");

                Assert.False(logs.BindingBuildResult.BuildOutput.Contains("MSB9004"), "Binding should not contains MSB9004 warning");

                string bindingName = RemoveCSProj(projects.Item1.ProjectName);
                string appName     = RemoveCSProj(projects.Item2.ProjectName);
                string libPath     = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll");

                Assert.True(File.Exists(libPath));
                string results      = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monop", new [] { "--refs", "-r:" + libPath }, "monop");
                string mscorlibLine = results.Split(new char[] { '\n' }).First(x => x.Contains("mscorlib"));

                string expectedVersion = GetExpectedBCLVersion(type);
                Assert.True(mscorlibLine.Contains(expectedVersion), $"{mscorlibLine} did not contain expected version {expectedVersion}");
            });
        }
コード例 #12
0
 void RestoreRoslynNuget(string projectPath)
 {
     TI.RunAndAssert("/Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget", new [] { "restore", projectPath }, "Restore Nuget");
 }