コード例 #1
0
        public static IList <string> GetRuntimeIdentifiers(ApplePlatform platform)
        {
            // variables with more than one value are wrapped in ', get the var remove the '' and split
            var variable = GetVariable($"DOTNET_{platform.AsString ().ToUpper ()}_RUNTIME_IDENTIFIERS", string.Empty).Trim('\'');

            return(variable.Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
        }
コード例 #2
0
        public void BuildBindingsTest2(ApplePlatform platform)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);
            var assemblyName        = "bindings-test2";
            var dotnet_bindings_dir = Path.Combine(Configuration.SourceRoot, "tests", assemblyName, "dotnet");
            var project_dir         = Path.Combine(dotnet_bindings_dir, platform.AsString());
            var project_path        = Path.Combine(project_dir, $"{assemblyName}.csproj");

            Clean(project_path);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            var result = DotNet.AssertBuild(project_path, verbosity);
            var lines  = BinLog.PrintToLines(result.BinLogPath);
            // Find the resulting binding assembly from the build log
            var assemblies = FilterToAssembly(lines, assemblyName);

            Assert.That(assemblies, Is.Not.Empty, "Assemblies");
            // Make sure there's no other assembly confusing our logic
            Assert.That(assemblies.Distinct().Count(), Is.EqualTo(1), "Unique assemblies");
            var asm = assemblies.First();

            Assert.That(asm, Does.Exist, "Assembly existence");

            // Verify that there's one resource in the binding assembly, and its name
            var ad = AssemblyDefinition.ReadAssembly(asm, new ReaderParameters {
                ReadingMode = ReadingMode.Deferred
            });

            Assert.That(ad.MainModule.Resources.Count, Is.EqualTo(0), "no embedded resources");
            var resourceBundle = Path.Combine(project_dir, "bin", "Debug", platform.ToFramework(), assemblyName + ".resources");

            Assert.That(resourceBundle, Does.Exist, "Bundle existence");
        }
コード例 #3
0
        public void DisableLinker(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "MySimpleApp";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = GetProjectPath(project, platform: platform);

            Clean(project_path);
            var properties = GetDefaultProperties(runtimeIdentifiers);

            properties ["PublishTrimmed"] = "false";

            var rv     = DotNet.AssertBuildFailure(project_path, properties);
            var errors = BinLog.GetBuildLogErrors(rv.BinLogPath).ToArray();

            Assert.AreEqual(1, errors.Length, "Error count");
            Assert.AreEqual($"{platform.AsString ()} projects must build with PublishTrimmed=true. Current value: false.", errors [0].Message, "Error message");
        }
コード例 #4
0
        public void Build(ApplePlatform platform, string runtimeIdentifiers, CodeSignature signature, string configuration)
        {
            var project = "BundleStructure";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration);
            var project_dir  = Path.GetDirectoryName(Path.GetDirectoryName(project_path)) !;

            Clean(project_path);

            var properties = GetDefaultProperties(runtimeIdentifiers);

            properties ["_IsAppSigned"] = signature != CodeSignature.None ? "true" : "false";
            if (!string.IsNullOrWhiteSpace(configuration))
            {
                properties ["Configuration"] = configuration;
            }
            var rv              = DotNet.AssertBuild(project_path, properties);
            var warnings        = BinLog.GetBuildLogWarnings(rv.BinLogPath).ToArray();
            var warningMessages = FilterWarnings(warnings);

            var isReleaseBuild   = string.Equals(configuration, "Release", StringComparison.OrdinalIgnoreCase);
            var platformString   = platform.AsString();
            var tfm              = platform.ToFramework();
            var testsDirectory   = Path.GetDirectoryName(Path.GetDirectoryName(project_dir));
            var expectedWarnings = new string [] {
                $"The 'PublishFolderType' metadata value 'Unknown' on the item '{project_dir}/{platformString}/SomewhatUnknownI.bin' is not recognized. The file will not be copied to the app bundle. If the file is not supposed to be copied to the app bundle, remove the 'CopyToOutputDirectory' metadata on the item.",
                $"The 'PublishFolderType' metadata value 'Unknown' on the item '{project_dir}/{platformString}/UnknownI.bin' is not recognized. The file will not be copied to the app bundle. If the file is not supposed to be copied to the app bundle, remove the 'CopyToOutputDirectory' metadata on the item.",
                $"The file '{project_dir}/{platformString}/NoneA.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/{platformString}/NoneI.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/{platformString}/NoneJ.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/{platformString}/NoneK.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/{platformString}/NoneM.unknown' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/{platformString}/Sub/NoneG.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
                $"The file '{project_dir}/NoneH.txt' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.",
            }.ToList();

            var rids = runtimeIdentifiers.Split(';');

            if (rids.Length > 1)
            {
                // All warnings show up twice if we're building for multiple architectures
                expectedWarnings.AddRange(expectedWarnings);
            }

            var zippedFrameworks = platform == ApplePlatform.MacCatalyst || platform == ApplePlatform.MacOSX;

            foreach (var rid in rids)
            {
                if (zippedFrameworks)
                {
                    expectedWarnings.Add($"The framework obj/{configuration}/{tfm}/{rid}/bindings-framework-test.resources.zip/XStaticObjectTest.framework is a framework of static libraries, and will not be copied to the app.");
                    expectedWarnings.Add($"The framework obj/{configuration}/{tfm}/{rid}/bindings-framework-test.resources.zip/XStaticArTest.framework is a framework of static libraries, and will not be copied to the app.");
                }
                else
                {
                    expectedWarnings.Add($"The framework {testsDirectory}/bindings-framework-test/dotnet/{platformString}/bin/{configuration}/{tfm}/bindings-framework-test.resources/XStaticObjectTest.framework is a framework of static libraries, and will not be copied to the app.");
                    expectedWarnings.Add($"The framework {testsDirectory}/bindings-framework-test/dotnet/{platformString}/bin/{configuration}/{tfm}/bindings-framework-test.resources/XStaticArTest.framework is a framework of static libraries, and will not be copied to the app.");
                }
            }

            if (signature == CodeSignature.None && (platform == ApplePlatform.MacCatalyst || platform == ApplePlatform.MacOSX))
            {
                expectedWarnings.Add($"Found files in the root directory of the app bundle. This will likely cause codesign to fail. Files:\nbin/{configuration}/{tfm}{(runtimeIdentifiers.IndexOf (';') >= 0 ? string.Empty : "/" + runtimeIdentifiers)}/BundleStructure.app/UnknownJ.bin");
            }

            // Sort the messages so that comparison against the expected array is faster
            expectedWarnings = expectedWarnings
                               .OrderBy(v => v)
                               .ToList();

            var appExecutable = GetNativeExecutable(platform, appPath);

            CheckAppBundleContents(platform, appPath, rids, signature, isReleaseBuild);
            CollectionAssert.AreEqual(expectedWarnings, warningMessages, "Warnings");
            ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable);

            // touch AppDelegate.cs, and rebuild should succeed and do the right thing
            var appDelegatePath = Path.Combine(project_dir, "AppDelegate.cs");

            Configuration.Touch(appDelegatePath);

            rv              = DotNet.AssertBuild(project_path, properties);
            warnings        = BinLog.GetBuildLogWarnings(rv.BinLogPath).ToArray();
            warningMessages = FilterWarnings(warnings);

            CheckAppBundleContents(platform, appPath, rids, signature, isReleaseBuild);
            CollectionAssert.AreEqual(expectedWarnings, warningMessages, "Warnings Rebuild 1");
            ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable);

            // remove the bin directory, and rebuild should succeed and do the right thing
            var binDirectory = Path.Combine(Path.GetDirectoryName(project_path) !, "bin");

            Directory.Delete(binDirectory, true);

            rv              = DotNet.AssertBuild(project_path, properties);
            warnings        = BinLog.GetBuildLogWarnings(rv.BinLogPath).ToArray();
            warningMessages = FilterWarnings(warnings);

            CheckAppBundleContents(platform, appPath, rids, signature, isReleaseBuild);
            CollectionAssert.AreEqual(expectedWarnings, warningMessages, "Warnings Rebuild 2");
            ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable);

            // a simple rebuild should succeed
            rv              = DotNet.AssertBuild(project_path, properties);
            warnings        = BinLog.GetBuildLogWarnings(rv.BinLogPath).ToArray();
            warningMessages = FilterWarnings(warnings);

            CheckAppBundleContents(platform, appPath, rids, signature, isReleaseBuild);
            CollectionAssert.AreEqual(expectedWarnings, warningMessages, "Warnings Rebuild 3");
            ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable);
        }
コード例 #5
0
        public void BuildFatMonoTouchTest(ApplePlatform platform, string runtimeIdentifiers, params string[] additionalProperties)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = Path.Combine(Configuration.SourceRoot, "tests", "monotouch-test", "dotnet", platform.AsString(), "monotouch-test.csproj");

            Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(Path.GetDirectoryName(project_path)));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "bindings-test", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "bindings-test2", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "EmbeddedResources", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "fsharplibrary", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "external", "Touch.Unit", "Touch.Client", "dotnet"));
            Clean(project_path);
            var properties = GetDefaultProperties(runtimeIdentifiers);

            if (additionalProperties != null)
            {
                foreach (var prop in additionalProperties)
                {
                    var eq    = prop.IndexOf('=');
                    var name  = prop.Substring(0, eq);
                    var value = prop.Substring(eq + 1);
                    properties [name] = value;
                }
            }
            var result        = DotNet.AssertBuild(project_path, properties);
            var appPath       = Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", platform.ToFramework(), "monotouchtest.app");
            var infoPlistPath = GetInfoPListPath(platform, appPath);

            Assert.That(infoPlistPath, Does.Exist, "Info.plist");
            var infoPlist = PDictionary.FromFile(infoPlistPath);

            Assert.AreEqual("com.xamarin.monotouch-test", infoPlist.GetString("CFBundleIdentifier").Value, "CFBundleIdentifier");
            Assert.AreEqual("MonoTouchTest", infoPlist.GetString("CFBundleDisplayName").Value, "CFBundleDisplayName");
        }
コード例 #6
0
ファイル: PackTest.cs プロジェクト: cwensley/xamarin-macios
        public void BindingFrameworksProject(ApplePlatform platform, bool noBindingEmbedding)
        {
            var project = "bindings-framework-test";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = Path.Combine(Configuration.RootPath, "tests", project, "dotnet", platform.AsString(), $"{project}.csproj");

            Clean(project_path);
            Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(project_path));

            var tmpdir                 = Cache.CreateTemporaryDirectory();
            var outputPath             = Path.Combine(tmpdir, "OutputPath");
            var intermediateOutputPath = Path.Combine(tmpdir, "IntermediateOutputPath");
            var properties             = GetDefaultProperties();

            properties ["OutputPath"]             = outputPath + Path.DirectorySeparatorChar;
            properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar;
            properties ["NoBindingEmbedding"]     = noBindingEmbedding ? "true" : "false";

            DotNet.AssertPack(project_path, properties);

            var nupkg = Path.Combine(outputPath, project + ".1.0.0.nupkg");

            Assert.That(nupkg, Does.Exist, "nupkg existence");

            var archive     = ZipFile.OpenRead(nupkg);
            var files       = archive.Entries.Select(v => v.FullName).ToHashSet();
            var hasSymlinks = noBindingEmbedding && (platform == ApplePlatform.MacCatalyst || platform == ApplePlatform.MacOSX);

            if (noBindingEmbedding)
            {
                Assert.That(archive.Entries.Count, Is.EqualTo(hasSymlinks ? 6 : 10), $"nupkg file count - {nupkg}");
            }
            else
            {
                Assert.That(archive.Entries.Count, Is.EqualTo(5), $"nupkg file count - {nupkg}");
            }
            Assert.That(files, Does.Contain(project + ".nuspec"), "nuspec");
            Assert.That(files, Does.Contain("_rels/.rels"), ".rels");
            Assert.That(files, Does.Contain("[Content_Types].xml"), "[Content_Types].xml");
            Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.dll"), $"{project}.dll");
            Assert.That(files, Has.Some.Matches <string> (v => v.StartsWith("package/services/metadata/core-properties/", StringComparison.Ordinal) && v.EndsWith(".psmdcp", StringComparison.Ordinal)), "psmdcp");
            if (noBindingEmbedding)
            {
                if (hasSymlinks)
                {
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources.zip"), $"{project}.resources.zip");
                }
                else
                {
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XStaticArTest.framework/XStaticArTest"), $"XStaticArTest.framework/XStaticArTest");
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XStaticObjectTest.framework/XStaticObjectTest"), $"XStaticObjectTest.framework/XStaticObjectTest");
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XTest.framework/XTest"), $"XTest.framework/XTest");
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XTest.framework/Info.plist"), $"XTest.framework/Info.plist");
                    Assert.That(files, Does.Contain($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/manifest"), $"manifest");
                }
            }
        }
コード例 #7
0
        public void BindingProject(ApplePlatform platform)
        {
            var project = "bindings-test";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = Path.Combine(Configuration.RootPath, "tests", project, "dotnet", platform.AsString(), $"{project}.csproj");

            Clean(project_path);
            Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(project_path));

            var tmpdir                 = Cache.CreateTemporaryDirectory();
            var outputPath             = Path.Combine(tmpdir, "OutputPath");
            var intermediateOutputPath = Path.Combine(tmpdir, "IntermediateOutputPath");
            var properties             = GetDefaultProperties();

            properties ["OutputPath"]             = outputPath + Path.DirectorySeparatorChar;
            properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar;

            var rv     = DotNet.AssertPackFailure(project_path, properties);
            var errors = BinLog.GetBuildLogErrors(rv.BinLogPath).ToArray();

            Assert.AreEqual(1, errors.Length, "Error count");
            Assert.AreEqual($"Creating a NuGet package is not supported for projects that have ObjcBindingNativeLibrary items. Migrate to use NativeReference items instead.", errors [0].Message, "Error message");
        }