Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting OS version when packaging #492

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CloudPackageCreateCommand : BaseCloudCommand<CloudPackageCreateComm
[CommandParameter(0, Description = "Path to project file", IsRequired = false)]
public string? ProjectPath { get; set; }

[CommandOption('c', Description = "The build configuration to compile", IsRequired = false)]
[CommandOption("configuration", 'c', Description = "The build configuration to compile", IsRequired = false)]
public string Configuration { get; init; } = "Release";

[CommandOption("name", 'n', Description = "Name of the mpak file to be created", IsRequired = false)]
Expand All @@ -23,6 +23,9 @@ public class CloudPackageCreateCommand : BaseCloudCommand<CloudPackageCreateComm
IsRequired = false)]
public string Filter { get; init; } = "*";

[CommandOption("osVersion", 'v', Description = "Target OS version for the app", IsRequired = false)]
public string? OsVersion { get; init; } = default!;

private readonly IPackageManager _packageManager;
private readonly FileManager _fileManager;

Expand All @@ -46,14 +49,14 @@ protected override async ValueTask ExecuteCommand()
ProjectPath = Path.GetFullPath(ProjectPath);
if (!Directory.Exists(ProjectPath))
{
throw new CommandException($"Directory not found '{ProjectPath}'. Check path to project file.", CommandExitCode.DirectoryNotFound);
new CommandException($"Directory not found '{ProjectPath}'. Check path to project file.", CommandExitCode.DirectoryNotFound);
}

// build
Logger?.LogInformation($"Building {Configuration} version of application...");
Logger?.LogInformation(string.Format(Strings.BuildingSpecifiedConfiguration, Configuration));
if (!_packageManager.BuildApplication(ProjectPath, Configuration, true, CancellationToken))
{
throw new CommandException($"Build failed");
throw new CommandException(Strings.BuildFailed);
}

var candidates = PackageManager.GetAvailableBuiltConfigurations(ProjectPath, "App.dll");
Expand All @@ -65,27 +68,28 @@ protected override async ValueTask ExecuteCommand()

var store = _fileManager.Firmware["Meadow F7"];
await store.Refresh();
var osVersion = store?.DefaultPackage?.Version ?? "unknown";
var osVersion = OsVersion ?? store?.DefaultPackage?.Version ?? "unknown";

var file = candidates.OrderByDescending(c => c.LastWriteTime).First(); // trim
Logger?.LogInformation($"Trimming application...");
var file = candidates.OrderByDescending(c => c.LastWriteTime).First();
// trim
Logger?.LogInformation(string.Format(Strings.TrimmingApplicationForSpecifiedVersion, osVersion));
await _packageManager.TrimApplication(file, cancellationToken: CancellationToken);

// package
var packageDir = Path.Combine(file.Directory?.FullName ?? string.Empty, PackageManager.PackageOutputDirectoryName);
//TODO - properly manage shared paths
var postlinkDir = Path.Combine(file.Directory?.FullName ?? string.Empty, PackageManager.PostLinkDirectoryName);

Logger?.LogInformation($"Assembling the MPAK...");
Logger?.LogInformation(Strings.AssemblingCloudPackage);
var packagePath = await _packageManager.AssemblePackage(postlinkDir, packageDir, osVersion, MpakName, Filter, true, CancellationToken);

if (packagePath != null)
{
Logger?.LogInformation($"Done. Package is available at {packagePath}");
Logger?.LogInformation(string.Format(Strings.PackageAvailableAtSpecifiedPath, packagePath));
}
else
{
throw new CommandException($"Package assembly failed");
throw new CommandException(Strings.PackageAssemblyFailed);
}
}
}
6 changes: 6 additions & 0 deletions Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ public static class Strings
public const string ProvisioningWithCloud = "Provisioning device with Meadow.Cloud...";
public const string ProvisioningSucceeded = "Device provisioned successfully";
public const string ProvisioningFailed = "Failed to provision device: {0}";
public const string BuildingSpecifiedConfiguration = "Building {0} configuration of application...";
public const string BuildFailed = "Build failed";
public const string TrimmingApplicationForSpecifiedVersion = "Trimming application for OS version {0}...";
public const string AssemblingCloudPackage = "Assembling the MPAK...";
public const string PackageAssemblyFailed = "Package assembly failed";
public const string PackageAvailableAtSpecifiedPath = "Done. Package is available at {0}";
}
Loading