Ejemplo n.º 1
0
        public void BindingWithDefaultCompileInclude(ApplePlatform platform)
        {
            var project = "BindingWithDefaultCompileInclude";

            Configuration.IgnoreIfIgnoredPlatform(platform);

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

            Clean(project_path);

            var rv = DotNet.AssertBuild(project_path, GetDefaultProperties());

            var dllPath = Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", platform.ToFramework(), $"{project}.dll");

            Assert.That(dllPath, Does.Exist, "Binding assembly");

            // Verify that the MyNativeClass class exists in the assembly, and that it's actually a class.
            var ad = AssemblyDefinition.ReadAssembly(dllPath, new ReaderParameters {
                ReadingMode = ReadingMode.Deferred
            });
            var myNativeClass = ad.MainModule.Types.FirstOrDefault(v => v.FullName == "MyApiDefinition.MyNativeClass");

            Assert.IsFalse(myNativeClass.IsInterface, "IsInterface");
            var myStruct = ad.MainModule.Types.FirstOrDefault(v => v.FullName == "MyClassLibrary.MyStruct");

            Assert.IsTrue(myStruct.IsValueType, "MyStruct");

            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
        }
Ejemplo n.º 2
0
        public void CreateAndBuildTemplate(TemplateInfo info)
        {
            if (!info.ValidateSuccessfulBuild)
            {
                return;
            }

            Configuration.IgnoreIfIgnoredPlatform(info.Platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, info.Template);

            DotNet.AssertNew(outputDir, info.Template);
            var csproj   = Path.Combine(outputDir, info.Template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");

            if (info.Execute)
            {
                var platform           = info.Platform;
                var runtimeIdentifiers = GetDefaultRuntimeIdentifier(platform);

                Assert.IsTrue(CanExecute(info.Platform, runtimeIdentifiers), "Must be executable to execute!");

                // First add some code to exit the template if it launches successfully.
                var mainFile              = Path.Combine(outputDir, "Main.cs");
                var mainContents          = File.ReadAllText(mainFile);
                var exitSampleWithSuccess = @"NSTimer.CreateScheduledTimer (1, (v) => {
	Console.WriteLine (Environment.GetEnvironmentVariable (""MAGIC_WORD""));
	Environment.Exit (0);
			});
			"            ;
                var modifiedMainContents  = mainContents.Replace("// This is the main entry point of the application.", exitSampleWithSuccess);
                Assert.AreNotEqual(modifiedMainContents, mainContents, "Failed to modify the main content");
                File.WriteAllText(mainFile, modifiedMainContents);

                // Build the sample
                rv = DotNet.AssertBuild(csproj);

                // There should still not be any warnings
                warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);
                Assert.That(warnings, Is.Empty, $"Build warnings (2):\n\t{string.Join ("\n\t", warnings)}");

                var appPath       = GetAppPath(csproj, platform, runtimeIdentifiers);
                var appExecutable = GetNativeExecutable(platform, appPath);
                ExecuteWithMagicWordAndAssert(appExecutable);
            }
        }
Ejemplo n.º 3
0
        public void CreateAndBuildTemplate(string platform, string template)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, template);

            DotNet.AssertNew(outputDir, template);
            var csproj   = Path.Combine(outputDir, template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
        }
Ejemplo n.º 4
0
        public void FilesInAppBundle(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "MySimpleApp";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);

            Clean(project_path);

            var properties = GetDefaultProperties(runtimeIdentifiers);

            // Build
            DotNet.AssertBuild(project_path, properties);

            // Simulate a crash dump
            File.WriteAllText(Path.Combine(appPath, "mono_crash.mem.123456.something.blob"), "A crash dump");
            File.WriteAllText(Path.Combine(appPath, "mono_crash.123456.somethingelse.blob"), "A crash dump");

            // Build again
            DotNet.AssertBuild(project_path, properties);

            // Create a file that isn't a crash report.
            File.WriteAllText(Path.Combine(appPath, "otherfile.txt"), "A file");

            // Build again - this time it'll fail
            var rv       = DotNet.Build(project_path, properties);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).ToArray();

            Assert.AreNotEqual(0, rv.ExitCode, "Unexpected success");
            Assert.AreEqual(1, warnings.Length, "Warning Count");
            Assert.AreEqual("Found files in the root directory of the app bundle. This will likely cause codesign to fail. Files:\nbin/Debug/net6.0-maccatalyst/maccatalyst-x64/MySimpleApp.app/otherfile.txt", warnings [0].Message, "Warning");

            // Remove the offending file
            File.Delete(Path.Combine(appPath, "otherfile.txt"));

            // Build yet again
            DotNet.AssertBuild(project_path, properties);
        }
Ejemplo n.º 5
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);
        }