public BitcodeConverter(string input, string outputFile, ApplePlatform platform, Abi abi, Version deploymentTarget) { this.input = input; this.outputFile = outputFile; this.abi = abi; this.platform = platform; deployment_target = deploymentTarget; }
// Calls Assert.Ignore if the given platform isn't included in the current build. public static void IgnoreIfIgnoredPlatform(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: if (!include_ios) { Assert.Ignore("iOS is not included in this build"); } break; case ApplePlatform.TVOS: if (!include_tvos) { Assert.Ignore("tvOS is not included in this build"); } break; case ApplePlatform.WatchOS: if (!include_watchos) { Assert.Ignore("watchOS is not included in this build"); } #if NET if (!include_dotnet_watchos) { Assert.Ignore("watchOS is not included in this build"); } #endif break; case ApplePlatform.MacOSX: if (!include_mac) { Assert.Ignore("macOS is not included in this build"); } break; case ApplePlatform.MacCatalyst: if (!include_maccatalyst) { Assert.Ignore("Mac Catalyst is not included in this build"); } break; default: throw new ArgumentOutOfRangeException($"Unknown platform: {platform}"); } }
static IBTool CreateIBToolTask(ApplePlatform framework, string projectDir, string intermediateOutputPath, params string[] fileNames) { var ibtool = CreateIBToolTask(framework, projectDir, intermediateOutputPath); var interfaceDefinitions = new List <ITaskItem> (); foreach (var name in fileNames) { interfaceDefinitions.Add(new TaskItem(Path.Combine(projectDir, name))); } ibtool.InterfaceDefinitions = interfaceDefinitions.ToArray(); return(ibtool); }
static IBTool CreateIBToolTask(ApplePlatform framework, string projectDir, string intermediateOutputPath) { var interfaceDefinitions = new List <ITaskItem> (); var sdk = IPhoneSdks.GetSdk(framework); var version = IPhoneSdkVersion.GetDefault(sdk, false); var root = sdk.GetSdkPath(version, false); var usr = Path.Combine(sdk.DeveloperRoot, "usr"); var bin = Path.Combine(usr, "bin"); string platform; switch (framework) { case ApplePlatform.WatchOS: platform = "WatchOS"; break; case ApplePlatform.TVOS: platform = "AppleTVOS"; break; default: platform = "iPhoneOS"; break; } foreach (var item in Directory.EnumerateFiles(projectDir, "*.storyboard", SearchOption.AllDirectories)) { interfaceDefinitions.Add(new TaskItem(item)); } foreach (var item in Directory.EnumerateFiles(projectDir, "*.xib", SearchOption.AllDirectories)) { interfaceDefinitions.Add(new TaskItem(item)); } return(new IBTool { AppManifest = new TaskItem(Path.Combine(projectDir, "Info.plist")), InterfaceDefinitions = interfaceDefinitions.ToArray(), IntermediateOutputPath = intermediateOutputPath, BuildEngine = new TestEngine(), MinimumOSVersion = PDictionary.FromFile(Path.Combine(projectDir, "Info.plist")).GetMinimumOSVersion(), ResourcePrefix = "Resources", ProjectDir = projectDir, SdkPlatform = platform, SdkVersion = version.ToString(), SdkUsrPath = usr, SdkBinPath = bin, SdkRoot = root, }); }
static string Build(string project, ApplePlatform applePlatform, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null, TimeSpan?timeout = null, string [] arguments = null, string targets = "Clean,Build") { return(ExecutionHelper.Execute(ToolPath, new string [] { "--", $"/p:Configuration={configuration}", $"/p:Platform={platform}", $"/verbosity:{(string.IsNullOrEmpty (verbosity) ? "normal" : verbosity)}", "/r:True", // restore nuget packages which are used in some test cases $"/t:{targets}", // clean and then build, in case we left something behind in a shared dir project }.Union(arguments ?? new string [] { }).ToArray(), environmentVariables: Configuration.GetBuildEnvironment(applePlatform), timeout: timeout)); }
public void NativeLink(ApplePlatform platform, string runtimeIdentifiers) { Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GenerateProject(platform, name: nameof(NativeLink), runtimeIdentifiers: runtimeIdentifiers, out var appPath); var properties = new Dictionary <string, string> (verbosity); SetRuntimeIdentifiers(properties, runtimeIdentifiers); var mainContents = @" class MainClass { static int Main () { return 123; } } "; var mainFile = Path.Combine(Path.GetDirectoryName(project_path), "Main.cs"); File.WriteAllText(mainFile, mainContents); // Build the first time var rv = DotNet.AssertBuild(project_path, properties); var allTargets = BinLog.GetAllTargets(rv.BinLogPath); AssertTargetExecuted(allTargets, "_AOTCompile", "A"); AssertTargetExecuted(allTargets, "_CompileNativeExecutable", "A"); AssertTargetExecuted(allTargets, "_LinkNativeExecutable", "A"); // Capture the current time var timestamp = DateTime.UtcNow; File.WriteAllText(mainFile, mainContents + "\n"); // Build again rv = DotNet.AssertBuild(project_path, properties); // Check that some targets executed allTargets = BinLog.GetAllTargets(rv.BinLogPath); AssertTargetExecuted(allTargets, "_AOTCompile", "B"); AssertTargetNotExecuted(allTargets, "_CompileNativeExecutable", "B"); AssertTargetExecuted(allTargets, "_LinkNativeExecutable", "B"); // Verify that the timestamp of the executable has been updated var executable = GetNativeExecutable(platform, appPath); Assert.That(File.GetLastWriteTimeUtc(executable), Is.GreaterThan(timestamp), "B: Executable modified"); }
public void InvalidRuntimeIdentifiers(ApplePlatform platform, string runtimeIdentifiers) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, platform: platform); Clean(project_path); var properties = GetDefaultProperties(runtimeIdentifiers); var rv = DotNet.AssertBuildFailure(project_path, properties); var errors = BinLog.GetBuildLogErrors(rv.BinLogPath).ToArray(); Assert.AreEqual(1, errors.Length, "Error count"); Assert.AreEqual($"Building for all the runtime identifiers '{runtimeIdentifiers}' at the same time isn't possible, because they represent different platform variations.", errors [0].Message, "Error message"); }
[TestCase(ApplePlatform.MacCatalyst, "osx-x64")] // valid RID for another platform public void InvalidRuntimeIdentifier(ApplePlatform platform, string runtimeIdentifier) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, platform: platform); Clean(project_path); var properties = GetDefaultProperties(runtimeIdentifier); var rv = DotNet.AssertBuildFailure(project_path, properties); var errors = BinLog.GetBuildLogErrors(rv.BinLogPath).ToArray(); Assert.AreEqual(1, errors.Length, "Error count"); Assert.AreEqual($"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.", errors [0].Message, "Error message"); }
public void AppWithGenericLibraryReference(ApplePlatform platform, string runtimeIdentifiers) { var project = "AppWithGenericLibraryReference"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); Clean(project_path); DotNet.AssertBuild(project_path, GetDefaultProperties(runtimeIdentifiers)); var appExecutable = GetNativeExecutable(platform, appPath); ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable); }
public static string GetMinimumOSVersionKey(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(ManifestKeys.MinimumOSVersion); case ApplePlatform.MacOSX: return(ManifestKeys.LSMinimumSystemVersion); default: throw new InvalidOperationException($"Invalid platform: {platform}"); } }
public static string GetTargetDirectory(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(TargetDirectoryXI); case ApplePlatform.MacOSX: return(TargetDirectoryXM); default: throw new InvalidOperationException(platform.ToString()); } }
protected string GetResourcesDirectory(ApplePlatform platform, string app_directory) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(app_directory); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine(app_directory, "Contents", "Resources")); default: throw new NotImplementedException($"Unknown platform: {platform}"); } }
protected string GetRelativeAssemblyDirectory(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(string.Empty); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine("Contents", "MonoBundle")); default: throw new NotImplementedException($"Unknown platform: {platform}"); } }
protected string GetRelativeResourcesDirectory(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return("Resources"); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine("Contents", "Resources")); default: throw new ArgumentOutOfRangeException($"Unknown platform: {platform}"); } }
void AssertAppContents (ApplePlatform platform, string app_directory) { string info_plist_path; switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: info_plist_path = Path.Combine (app_directory, "Info.plist"); break; case ApplePlatform.MacOSX: info_plist_path = Path.Combine (app_directory, "Contents", "Info.plist"); break; default: throw new NotImplementedException ($"Unknown platform: {platform}"); } Assert.That (info_plist_path, Does.Exist, "Info.plist"); }
string GetInfoPListPath(ApplePlatform platform, string app_directory) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(Path.Combine(app_directory, "Info.plist")); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine(app_directory, "Contents", "Info.plist")); default: throw new NotImplementedException($"Unknown platform: {platform}"); } }
public static string GetMinimumOSVersionKey(ApplePlatform platform) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(ManifestKeys.MinimumOSVersion); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(ManifestKeys.LSMinimumSystemVersion); default: throw new InvalidOperationException(string.Format(MSBStrings.InvalidPlatform, platform)); } }
public static string GetAppManifestPath(ApplePlatform platform, string appBundlePath) { switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(Path.Combine(appBundlePath, "Info.plist")); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine(appBundlePath, "Contents", "Info.plist")); default: throw new InvalidOperationException(string.Format(MSBStrings.InvalidPlatform, platform)); } }
public static AppleSdk GetSdk(ApplePlatform framework) { switch (framework) { case ApplePlatform.iOS: return(IOS); case ApplePlatform.WatchOS: return(Watch); case ApplePlatform.TVOS: return(TVOS); default: throw new InvalidOperationException(string.Format(MSBStrings.InvalidFramework, framework)); } }
public void SimpleAppWithOldReferences(ApplePlatform platform, string runtimeIdentifiers) { var project = "SimpleAppWithOldReferences"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); Clean(project_path); DotNet.AssertBuild(project_path, GetDefaultProperties(runtimeIdentifiers)); var appExecutable = GetNativeExecutable(platform, appPath); Assert.That(appExecutable, Does.Exist, "There is an executable"); ExecuteWithMagicWordAndAssert(platform, runtimeIdentifiers, appExecutable); }
public static AppleSdk GetSdk(ApplePlatform framework) { switch (framework) { case ApplePlatform.iOS: return(IPhoneSdks.Native); case ApplePlatform.WatchOS: return(IPhoneSdks.Watch); case ApplePlatform.TVOS: return(IPhoneSdks.TVOS); default: throw new InvalidOperationException(string.Format("Invalid framework: {0}", framework)); } }
void AssertDynamicLibraryId(ApplePlatform platform, string appPath, string dylibDirectory, string library) { var dylibPath = Path.Combine(appPath, dylibDirectory, library); Assert.That(dylibPath, Does.Exist, "dylib existence"); var invalidLoadCommands = new List <string> (); var appExecutable = GetNativeExecutable(platform, appPath); foreach (var file in MachO.Read(appExecutable)) { foreach (var lc in file.load_commands) { if (lc is DylibLoadCommand loadCommand) { if (!IsValidLoadLibrary(loadCommand.name)) { invalidLoadCommands.Add($"Invalid load library '{loadCommand.name}' in '{file.Filename}'"); } } } } var dylibs = Directory.GetFiles(Path.Combine(appPath, dylibDirectory), "*.dylib"); foreach (var dylib in dylibs) { foreach (var file in MachO.Read(dylib)) { foreach (var lc in file.load_commands) { if (lc is DylibIdCommand loadCommand) { if (!IsValidLoadLibrary(loadCommand.name)) { invalidLoadCommands.Add($"Invalid id '{loadCommand.name}' for library '{file.Filename}'"); } } } } } Assert.That(invalidLoadCommands, Is.Empty); }
public void AssemblyStripping(ApplePlatform platform, string runtimeIdentifiers, bool shouldStrip) { 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); // Force EnableAssemblyILStripping since we are building debug which never will by default properties ["EnableAssemblyILStripping"] = shouldStrip ? "true" : "false"; DotNet.AssertBuild(project_path, properties); AssertBundleAssembliesStripStatus(appPath, shouldStrip); }
// [TestCase ("MacCatalyst", "")] - No extension support yet public void BuildProjectsWithExtensions(ApplePlatform platform, string appPath) { Configuration.IgnoreIfIgnoredPlatform(platform); var consumingProjectDir = GetProjectPath("ExtensionConsumer", platform: platform); var extensionProjectDir = GetProjectPath("ExtensionProject", platform: platform); Clean(extensionProjectDir); Clean(consumingProjectDir); Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(extensionProjectDir)); Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(consumingProjectDir)); DotNet.AssertBuild(consumingProjectDir, verbosity); var extensionPath = Path.Combine(Path.GetDirectoryName(consumingProjectDir), appPath); Assert.That(Directory.Exists(extensionPath), $"App extension directory does not exist: {extensionPath}"); }
[TestCase(ApplePlatform.MacCatalyst, "osx-x64")] // valid RID for another platform public void InvalidRuntimeIdentifier(ApplePlatform platform, string runtimeIdentifier) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, platform: platform); Clean(project_path); var properties = new Dictionary <string, string> (verbosity); properties ["RuntimeIdentifier"] = runtimeIdentifier; var rv = DotNet.AssertBuildFailure(project_path, properties); var errors = BinLog.GetBuildMessages(rv.BinLogPath).Where(v => v.Type == BuildLogEventType.Error).ToArray(); Assert.AreEqual(1, errors.Length, "Error count"); Assert.AreEqual($"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.", errors [0].Message, "Error message"); }
public void BuildAndExecuteNativeReferencesTestApp(string project, ApplePlatform platform, string runtimeIdentifier) { Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath); Clean(project_path); var properties = GetDefaultProperties(runtimeIdentifier); DotNet.AssertBuild(project_path, properties); if (platform == ApplePlatform.MacOSX || platform == ApplePlatform.MacCatalyst) { var appExecutable = Path.Combine(appPath, "Contents", "MacOS", Path.GetFileNameWithoutExtension(project_path)); Assert.That(appExecutable, Does.Exist, "There is an executable"); ExecuteWithMagicWordAndAssert(appExecutable); } }
public void AssemblyStripping(string project, ApplePlatform platform, string runtimeIdentifiers, bool shouldStrip) { Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); Clean(project_path); var properties = GetDefaultProperties(runtimeIdentifiers); // Force EnableAssemblyILStripping since we are building debug which never will by default properties ["EnableAssemblyILStripping"] = shouldStrip ? "true" : "false"; DotNet.AssertBuild(project_path, properties); AssertBundleAssembliesStripStatus(appPath, shouldStrip); Assert.That(Path.Combine(appPath, $"{project}.dll"), Does.Exist, "Application Assembly"); Assert.That(Path.Combine(appPath, "Microsoft.iOS.dll"), Does.Exist, "Platform Assembly"); }
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"); }
CompileAppManifest CreateTask(string?tmpdir = null, ApplePlatform platform = ApplePlatform.iOS) { if (string.IsNullOrEmpty(tmpdir)) { tmpdir = Cache.CreateTemporaryDirectory(); } var task = CreateTask <CompileAppManifest> (); task.AssemblyName = "AssemblyName"; task.AppBundleName = "AppBundleName"; task.CompiledAppManifest = new TaskItem(Path.Combine(tmpdir, "TemporaryAppManifest.plist")); task.DefaultSdkVersion = Sdks.GetAppleSdk(platform).GetInstalledSdkVersions(false).First().ToString(); task.SdkPlatform = PlatformFrameworkHelper.GetSdkPlatform(platform, false); task.SdkVersion = task.DefaultSdkVersion; task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework(platform, true).ToString(); return(task); }
protected string GetNativeExecutable(ApplePlatform platform, string app_directory) { var executableName = Path.GetFileNameWithoutExtension(app_directory); switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: return(Path.Combine(app_directory, executableName)); case ApplePlatform.MacOSX: case ApplePlatform.MacCatalyst: return(Path.Combine(app_directory, "Contents", "MacOS", executableName)); default: throw new NotImplementedException($"Unknown platform: {platform}"); } }
public void BuildPackageTest(string project, ApplePlatform platform, string runtimeIdentifiers) { var projectVersion = "3.14"; Configuration.IgnoreIfIgnoredPlatform(platform); var project_path = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); Clean(project_path); var properties = GetDefaultProperties(runtimeIdentifiers); properties ["CreatePackage"] = "true"; DotNet.AssertBuild(project_path, properties); var pkgPath = Path.Combine(appPath, "..", $"{project}-{projectVersion}.pkg"); Assert.That(pkgPath, Does.Exist, "pkg creation"); }
protected override void OnElementChanged(ElementChangedEventArgs<Image> e) { base.OnElementChanged(e); if (_formsControl != null) { var svgStream = _formsControl.SvgAssembly.GetManifestResourceStream(_formsControl.SvgPath); if (svgStream == null) { throw new Exception(string.Format("Error retrieving {0} make sure Build Action is Embedded Resource", _formsControl.SvgPath)); } var r = new SvgReader(new StreamReader(svgStream), new StylesParser(new ValuesParser()), new ValuesParser()); var graphics = r.Graphic; var width = _formsControl.WidthRequest <= 0 ? 100 : _formsControl.WidthRequest; var height = _formsControl.HeightRequest <= 0 ? 100 : _formsControl.HeightRequest; var scale = 1.0; if (height >= width) { scale = height/graphics.Size.Height; } else { scale = width/graphics.Size.Width; } var scaleFactor = UIScreen.MainScreen.Scale; var canvas = new ApplePlatform().CreateImageCanvas(graphics.Size, scale*scaleFactor); graphics.Draw(canvas); var image = canvas.GetImage(); var uiImage = image.GetUIImage(); Control.Image = uiImage; } }