Skip to content

Commit

Permalink
Merge SimulatorInstaller commands to main CLI (#497)
Browse files Browse the repository at this point in the history
This removes the SimulatorInstaller project and moves the file to CLI so that you can do:
```
xharness apple simulators list
```

When installing the simulators, it doesn't accept the same format e.g. `ios-simulator-64` of targets as the CLI, this will be a follow-up.

#478
  • Loading branch information
premun authored Mar 8, 2021
1 parent 6459101 commit 5525052
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 259 deletions.
9 changes: 0 additions & 9 deletions XHarness.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XHarness.i
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XHarness.TestRunners.Tests", "tests\Microsoft.DotNet.XHarness.TestRunners.Tests\Microsoft.DotNet.XHarness.TestRunners.Tests.csproj", "{05AB368F-2B27-426A-B5E9-01F52E297269}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{D7D3EC29-8CF4-4DA5-BF41-FE5A51593753}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XHarness.SimulatorInstaller", "tools\Microsoft.DotNet.XHarness.SimulatorInstaller\Microsoft.DotNet.XHarness.SimulatorInstaller.csproj", "{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XHarness.Common", "src\Microsoft.DotNet.XHarness.Common\Microsoft.DotNet.XHarness.Common.csproj", "{E6E90648-E24D-4681-B082-776DF3F4B8F6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XHarness.Common.Tests", "tests\Microsoft.DotNet.XHarness.Common.Tests\Microsoft.DotNet.XHarness.Common.Tests.csproj", "{EB718364-434C-43F7-AE12-74F272B86C45}"
Expand Down Expand Up @@ -76,10 +72,6 @@ Global
{05AB368F-2B27-426A-B5E9-01F52E297269}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05AB368F-2B27-426A-B5E9-01F52E297269}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05AB368F-2B27-426A-B5E9-01F52E297269}.Release|Any CPU.Build.0 = Release|Any CPU
{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7}.Release|Any CPU.Build.0 = Release|Any CPU
{E6E90648-E24D-4681-B082-776DF3F4B8F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6E90648-E24D-4681-B082-776DF3F4B8F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6E90648-E24D-4681-B082-776DF3F4B8F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -116,7 +108,6 @@ Global
{10A26931-A5C8-4256-B8AC-0984CAAAB93D} = {1018BF4C-BD8F-49D7-9797-758E68B9FC9D}
{3406110E-65B2-4786-B723-C05B0FF66131} = {1018BF4C-BD8F-49D7-9797-758E68B9FC9D}
{05AB368F-2B27-426A-B5E9-01F52E297269} = {1018BF4C-BD8F-49D7-9797-758E68B9FC9D}
{2C1B5C97-7E17-45D4-8337-B4CBD6125CD7} = {D7D3EC29-8CF4-4DA5-BF41-FE5A51593753}
{E6E90648-E24D-4681-B082-776DF3F4B8F6} = {713ACDCF-301D-4C96-8B75-5BF2A35A326D}
{EB718364-434C-43F7-AE12-74F272B86C45} = {1018BF4C-BD8F-49D7-9797-758E68B9FC9D}
{0F780F3E-8D05-428E-9C78-FEDDDA7DD3D1} = {713ACDCF-301D-4C96-8B75-5BF2A35A326D}
Expand Down
76 changes: 35 additions & 41 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,6 @@ stages:
displayName: Build and run tests
condition: succeeded()

- bash: |
targetDir=$(Build.ArtifactStagingDirectory)/Microsoft.DotNet.XHarness.SimulatorInstaller.IntegrationTests.OSX.$(_BuildConfig)
mkdir $targetDir
cp tests/integration-tests/Apple/helix-payloads/simulatorinstaller-integration-tests.sh $targetDir
cp artifacts/packages/$(_BuildConfig)/Shipping/Microsoft.DotNet.XHarness.SimulatorInstaller*.nupkg $targetDir
displayName: Prepare the SimulatorInstaller IntegrationTests artifact
workingDirectory: $(Build.SourcesDirectory)
condition: and(succeeded(), eq(variables['_BuildConfig'], 'Debug'))
- publish: $(Build.ArtifactStagingDirectory)/Microsoft.DotNet.XHarness.SimulatorInstaller.IntegrationTests.OSX.$(_BuildConfig)
artifact: Microsoft.DotNet.XHarness.SimulatorInstaller.IntegrationTests.OSX.$(_BuildConfig)
displayName: Publish the SimulatorInstaller IntegrationTests artifact
condition: and(succeeded(), eq(variables['_BuildConfig'], 'Debug'))

- publish: $(Build.SourcesDirectory)/artifacts/packages/$(_BuildConfig)/Shipping/Microsoft.DotNet.XHarness.CLI.1.0.0-ci.nupkg
artifact: Microsoft.DotNet.XHarness.CLI.$(_BuildConfig)
displayName: Publish XHarness CLI for Helix Testing
Expand Down Expand Up @@ -283,34 +269,42 @@ stages:
displayName: SimulatorInstaller Integration Tests
dependsOn: Build_OSX
jobs:
- job: integration_tests
displayName: SimulatorInstaller Integration Tests
pool:
name: Hosted macOS
variables:
_BuildConfig: debug
steps:
- download: current
artifact: Microsoft.DotNet.XHarness.SimulatorInstaller.IntegrationTests.OSX.Debug
- template: /eng/common/templates/jobs/jobs.yml
parameters:
workspace:
clean: all
jobs:
- job: OSX
pool:
name: Hosted macOS
strategy:
matrix:
Build_Debug:
_BuildConfig: Debug
preSteps:
- checkout: self
clean: true
displayName: Submit Helix Job
steps:
- task: DownloadPipelineArtifact@2
inputs:
source: current
artifact: Microsoft.DotNet.XHarness.CLI.Debug
path: $(Build.SourcesDirectory)/artifacts/packages/$(_BuildConfig)/Shipping/

- template: /eng/common/templates/steps/send-to-helix.yml
parameters:
DisplayNamePrefix: Run Tests
HelixBaseUri: https://helix.dot.net/
HelixType: test/product/
IncludeDotNetCli: true
DotNetCliPackageType: sdk
DotNetCliVersion: 3.1.201
WaitForWorkItemCompletion: true
HelixTargetQueues: osx.1015.amd64.open
Creator: xharness
EnableXUnitReporter: false
WorkItemDirectory: $(Pipeline.Workspace)/Microsoft.DotNet.XHarness.SimulatorInstaller.IntegrationTests.OSX.Debug
WorkItemCommand: sudo ./simulatorinstaller-integration-tests.sh
WorkItemTimeout: 00:05:00
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
HelixAccessToken: ''
- script: eng/common/build.sh
--configuration $(_BuildConfig)
--prepareMachine
--ci
--restore
--test
--projects $(Build.SourcesDirectory)/tests/integration-tests/Apple/SimulatorInstaller.Tests.proj
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/Apple.SimulatorInstaller.Tests.binlog
/p:RestoreUsingNuGetTargets=false
displayName: Run Helix Tests
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
HelixAccessToken: ''

- ${{ if eq(variables._RunAsInternal, True) }}:
- template: eng\common\templates\post-build\post-build.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Linq;
using Mono.Options;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators
{
internal class FindCommandArguments : SimulatorInstallerCommandArguments
internal class FindCommandArguments : SimulatorsCommandArguments
{
public IEnumerable<string> Simulators { get; } = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Linq;
using Mono.Options;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators
{
internal class InstallCommandArguments : SimulatorInstallerCommandArguments
internal class InstallCommandArguments : SimulatorsCommandArguments
{
public IEnumerable<string> Simulators { get; } = new List<string>();
public bool Force { get; private set; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

using Mono.Options;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators
{
internal class ListCommandArguments : SimulatorInstallerCommandArguments
internal class ListCommandArguments : SimulatorsCommandArguments
{
public bool ListInstalledOnly { get; private set; } = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using Microsoft.DotNet.XHarness.Common.Execution;
using Mono.Options;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators
{
internal abstract class SimulatorInstallerCommandArguments : XHarnessCommandArguments
internal abstract class SimulatorsCommandArguments : XHarnessCommandArguments
{
private string? _xcodeRoot;

Expand All @@ -36,7 +36,7 @@ protected sealed override OptionSet GetCommandOptions()
{
var options = GetAdditionalOptions();

options.Add("xcode=", "Path to where Xcode is located, e.g. /Application/Xcode114.app. If not set, xcode-select is used to determine the location", v => XcodeRoot = RootPath(v));
options.Add("xcode=", "Path to where Xcode is located, e.g. /Application/Xcode114.app. If not set, xcode-select is used to determine the location",v => XcodeRoot = RootPath(v));

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators;
using Mono.Options;

namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple
{
// Main iOS command set that contains the plaform specific commands. This allows the command line to
// support different options in different platforms.
// Whenever the behavior does match, the goal is to have the same arguments for both platforms
public class AppleCommandSet : CommandSet
{
public AppleCommandSet() : base("apple")
{
// commond verbs shared with android. We should think a smart way to do this
Add(new AppleTestCommand());
Add(new AppleRunCommand());
Add(new AppleGetStateCommand());
Add(new SimulatorsCommandSet());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments;
using Microsoft.Extensions.Logging;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Commands
namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
internal class FindCommand : SimulatorInstallerCommand
{
Expand All @@ -21,7 +21,7 @@ internal class FindCommand : SimulatorInstallerCommand
protected override string CommandDescription => CommandHelp;

private readonly FindCommandArguments _arguments = new FindCommandArguments();
protected override SimulatorInstallerCommandArguments SimulatorInstallerArguments => _arguments;
protected override SimulatorsCommandArguments SimulatorsArguments => _arguments;

public FindCommand() : base(CommandName, CommandHelp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments;
using Microsoft.Extensions.Logging;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Commands
namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
internal class InstallCommand : SimulatorInstallerCommand
{
Expand All @@ -27,7 +26,7 @@ internal class InstallCommand : SimulatorInstallerCommand
protected override string CommandDescription => CommandHelp;

private readonly InstallCommandArguments _arguments = new InstallCommandArguments();
protected override SimulatorInstallerCommandArguments SimulatorInstallerArguments => _arguments;
protected override SimulatorsCommandArguments SimulatorsArguments => _arguments;

public InstallCommand() : base(CommandName, CommandHelp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments;
using Microsoft.Extensions.Logging;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Commands
namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
internal class ListCommand : SimulatorInstallerCommand
{
Expand All @@ -21,7 +21,7 @@ internal class ListCommand : SimulatorInstallerCommand
protected override string CommandDescription => CommandHelp;

private readonly ListCommandArguments _arguments = new ListCommandArguments();
protected override SimulatorInstallerCommandArguments SimulatorInstallerArguments => _arguments;
protected override SimulatorsCommandArguments SimulatorsArguments => _arguments;

public ListCommand() : base(CommandName, CommandHelp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.DotNet.XHarness.SimulatorInstaller
namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
internal class Simulator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple.Simulators;
using Microsoft.DotNet.XHarness.Common.CLI.CommandArguments;
using Microsoft.DotNet.XHarness.Common.CLI.Commands;
using Microsoft.DotNet.XHarness.Common.Execution;
using Microsoft.DotNet.XHarness.Common.Logging;
using Microsoft.DotNet.XHarness.SimulatorInstaller.Arguments;
using Microsoft.Extensions.Logging;

namespace Microsoft.DotNet.XHarness.SimulatorInstaller.Commands
namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
internal abstract class SimulatorInstallerCommand : XHarnessCommand
{
Expand All @@ -32,9 +32,9 @@ internal abstract class SimulatorInstallerCommand : XHarnessCommand

protected ILogger Logger { get; set; } = null!;

protected override XHarnessCommandArguments Arguments => SimulatorInstallerArguments;
protected override XHarnessCommandArguments Arguments => SimulatorsArguments;

protected abstract SimulatorInstallerCommandArguments SimulatorInstallerArguments { get; }
protected abstract SimulatorsCommandArguments SimulatorsArguments { get; }

protected SimulatorInstallerCommand(string name, string help) : base(name, false, help)
{
Expand All @@ -44,7 +44,7 @@ protected static string TempDirectory
{
get
{
string? path = Path.Combine(Path.GetTempPath(), "simulator-installer");
var path = Path.Combine(Path.GetTempPath(), "simulator-installer");

if (!Directory.Exists(path))
{
Expand All @@ -71,7 +71,7 @@ protected static string TempDirectory
stderrLog,
timeout ?? TimeSpan.FromSeconds(30));

string stderr = stderrLog.ToString();
var stderr = stderrLog.ToString();
if (stderr.Length > 0)
{
Logger.LogDebug("Error output:" + Environment.NewLine + stderr);
Expand All @@ -93,7 +93,7 @@ static string Replace(string value, Dictionary<string, string> replacements)
}

var doc = new XmlDocument();
doc.LoadXml((await GetSimulatorIndexXml()) ?? throw new FailedToGetIndexException());
doc.LoadXml(await GetSimulatorIndexXml() ?? throw new FailedToGetIndexException());

var simulators = new List<Simulator>();

Expand Down Expand Up @@ -196,7 +196,7 @@ static string Replace(string value, Dictionary<string, string> replacements)

private async Task<(string XcodeVersion, string XcodeUuid)> GetXcodeInformation()
{
var plistPath = Path.Combine(SimulatorInstallerArguments.XcodeRoot, "Contents", "Info.plist");
var plistPath = Path.Combine(SimulatorsArguments.XcodeRoot, "Contents", "Info.plist");

var (succeeded, xcodeVersion) = await ExecuteCommand("/usr/libexec/PlistBuddy", TimeSpan.FromSeconds(5), "-c", "Print :DTXcode", plistPath);
if (!succeeded)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Mono.Options;

namespace Microsoft.DotNet.XHarness.CLI.Commands.Apple.Simulators
{
/// <summary>
/// These commands allow management of Xcode iOS/WatchOS/tvOS Simulators on MacOS.
/// Originally taken from: https://github.com/xamarin/xamarin-macios/blob/master/tools/siminstaller
/// </summary>
public class SimulatorsCommandSet : CommandSet
{
public SimulatorsCommandSet() : base("simulators")
{
Add(new ListCommand());
Add(new FindCommand());
Add(new InstallCommand());
}
}
}
Loading

0 comments on commit 5525052

Please sign in to comment.