From 420071299886a549e90e2c3b447749318082cba1 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 29 Apr 2024 17:07:36 -0700 Subject: [PATCH 1/2] Update to pass correct assemblies path when linking + some strings --- .../Commands/Current/App/AppTools.cs | 3 +- .../Commands/Current/App/AppDeployCommand.cs | 15 +++++-- .../Commands/Current/App/AppRunCommand.cs | 26 +++++++++--- .../Commands/Current/App/AppTrimCommand.cs | 20 ++++++++-- .../Package/CloudPackageCreateCommand.cs | 2 +- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 2 +- .../v2/Meadow.Cli/Properties/AssemblyInfo.cs | 2 +- .../Meadow.Cli/Properties/launchSettings.json | 4 +- Source/v2/Meadow.Cli/Strings.cs | 5 ++- .../F7FirmwarePackageCollection.cs | 5 +++ .../IFirmwarePackageCollection.cs | 1 + .../v2/Meadow.Tooling.Core/App/AppManager.cs | 3 +- .../Package/IPackageManager.cs | 3 +- .../Package/PackageManager.AssemblyManager.cs | 40 +++++++++++-------- .../Package/PackageManager.cs | 5 +-- 15 files changed, 93 insertions(+), 43 deletions(-) diff --git a/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs b/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs index 2b3cd793..1bc9a877 100644 --- a/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs +++ b/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs @@ -41,6 +41,7 @@ internal static async Task DisableRuntimeIfEnabled(IMeadowConnection connection, internal static async Task TrimApplication(string path, IPackageManager packageManager, + string osVersion, string? configuration, IEnumerable? noLinkAssemblies, ILogger? logger, @@ -86,7 +87,7 @@ internal static async Task TrimApplication(string path, logger?.LogInformation($"Skippping assemblies: {string.Join(", ", noLinkAssemblies)}"); } - await packageManager.TrimApplication(file, false, noLinkAssemblies, cancellationToken); + await packageManager.TrimApplication(file, osVersion, false, noLinkAssemblies, cancellationToken); cts.Cancel(); // illink returns before all files are written - attempt a delay of 1s diff --git a/Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs index f18d873c..34d5282e 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs @@ -33,9 +33,16 @@ protected override async ValueTask ExecuteCommand() await AppTools.DisableRuntimeIfEnabled(connection, Logger, CancellationToken); - if (!await DeployApplication(connection, file.FullName, CancellationToken)) + var deviceInfo = await connection.GetDeviceInfo(); + + if (deviceInfo == null || deviceInfo.OsVersion == null) + { + throw new CommandException(Strings.UnableToGetDeviceInfo, CommandExitCode.GeneralError); + } + + if (!await DeployApplication(connection, deviceInfo.OsVersion, file.FullName, CancellationToken)) { - throw new CommandException("Application deploy failed", CommandExitCode.GeneralError); + throw new CommandException(Strings.AppDeployFailed, CommandExitCode.GeneralError); } } @@ -79,7 +86,7 @@ private FileInfo GetMeadowAppFile(string path) return file; } - private async Task DeployApplication(IMeadowConnection connection, string path, CancellationToken GetAvailableBuiltConfigurations) + private async Task DeployApplication(IMeadowConnection connection, string osVersion, string path, CancellationToken GetAvailableBuiltConfigurations) { connection.FileWriteProgress += OnFileWriteProgress; @@ -95,7 +102,7 @@ private async Task DeployApplication(IMeadowConnection connection, string Logger?.LogInformation($"Deploying app from {file.DirectoryName}..."); - await AppManager.DeployApplication(_packageManager, connection, file.DirectoryName!, true, false, Logger, GetAvailableBuiltConfigurations); + await AppManager.DeployApplication(_packageManager, connection, osVersion, file.DirectoryName!, true, false, Logger, GetAvailableBuiltConfigurations); connection.FileWriteProgress -= OnFileWriteProgress; diff --git a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs index 60b08414..7a12c5f7 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs @@ -57,26 +57,33 @@ protected override async ValueTask ExecuteCommand() var connection = await GetCurrentConnection(); + var deviceInfo = await connection.GetDeviceInfo(); + + if (deviceInfo == null || deviceInfo.OsVersion == null) + { + throw new CommandException(Strings.UnableToGetDeviceInfo, CommandExitCode.GeneralError); + } + var lastFile = string.Empty; // in order to deploy, the runtime must be disabled await AppTools.DisableRuntimeIfEnabled(connection, Logger, CancellationToken); - Logger?.LogInformation($"Building {Configuration} configuration of {path}..."); + Logger?.LogInformation($"Building {Configuration} configuration of {path} for Meadow v{deviceInfo.OsVersion}..."); if (!_packageManager.BuildApplication(path, Configuration)) { - throw new CommandException("Application build failed", CommandExitCode.GeneralError); + throw new CommandException(Strings.AppBuildFailed, CommandExitCode.GeneralError); } - if (!await AppTools.TrimApplication(path, _packageManager, Configuration, NoLink, Logger, Console, CancellationToken)) + if (!await AppTools.TrimApplication(path, _packageManager, deviceInfo.OsVersion, Configuration, NoLink, Logger, Console, CancellationToken)) { - throw new CommandException("Application trimming failed", CommandExitCode.GeneralError); + throw new CommandException(Strings.AppTrimFailed, CommandExitCode.GeneralError); } if (!await DeployApplication(connection, path, CancellationToken)) { - throw new CommandException("Application deploy failed", CommandExitCode.GeneralError); + throw new CommandException(Strings.AppDeployFailed, CommandExitCode.GeneralError); } Logger?.LogInformation($"{Strings.EnablingRuntime}..."); @@ -97,6 +104,13 @@ private async Task DeployApplication(IMeadowConnection connection, string { connection.FileWriteProgress += OnFileWriteProgress; + var deviceInfo = await connection.GetDeviceInfo(); + + if (deviceInfo == null || deviceInfo.OsVersion == null) + { + throw new CommandException(Strings.UnableToGetDeviceInfo, CommandExitCode.GeneralError); + } + var candidates = PackageManager.GetAvailableBuiltConfigurations(path, "App.dll"); if (candidates.Length == 0) @@ -109,7 +123,7 @@ private async Task DeployApplication(IMeadowConnection connection, string Logger?.LogInformation($"Deploying app from {file.DirectoryName}..."); - await AppManager.DeployApplication(_packageManager, connection, file.DirectoryName!, true, false, Logger, cancellationToken); + await AppManager.DeployApplication(_packageManager, connection, deviceInfo.OsVersion, file.DirectoryName!, true, false, Logger, cancellationToken); connection.FileWriteProgress -= OnFileWriteProgress; diff --git a/Source/v2/Meadow.Cli/Commands/Current/App/AppTrimCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/App/AppTrimCommand.cs index 0fad09b3..e434be4e 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/App/AppTrimCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/App/AppTrimCommand.cs @@ -6,7 +6,7 @@ namespace Meadow.CLI.Commands.DeviceManagement; [Command("app trim", Description = "Trim a pre-compiled Meadow application")] -public class AppTrimCommand : BaseCommand +public class AppTrimCommand : BaseDeviceCommand { private readonly IPackageManager _packageManager; @@ -21,8 +21,8 @@ public class AppTrimCommand : BaseCommand readonly FileManager _fileManager; - public AppTrimCommand(FileManager fileManager, IPackageManager packageManager, ILoggerFactory loggerFactory) - : base(loggerFactory) + public AppTrimCommand(FileManager fileManager, IPackageManager packageManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) + : base(connectionManager, loggerFactory) { _packageManager = packageManager; _fileManager = fileManager; @@ -57,7 +57,19 @@ protected override async ValueTask ExecuteCommand() } } - await AppTools.TrimApplication(path, _packageManager, Configuration, NoLink, Logger, Console, CancellationToken); + var connection = await GetCurrentConnection(); + + await AppTools.DisableRuntimeIfEnabled(connection, Logger, CancellationToken); + + var deviceInfo = await connection.GetDeviceInfo(); + + if (deviceInfo == null || deviceInfo.OsVersion == null) + { + throw new CommandException(Strings.UnableToGetDeviceInfo, CommandExitCode.GeneralError); + } + + Logger.LogInformation($"Preparing to trim using v{deviceInfo.OsVersion} assemblies..."); + await AppTools.TrimApplication(path, _packageManager, deviceInfo.OsVersion, Configuration, NoLink, Logger, Console, CancellationToken); Logger.LogInformation("Application trimmed successfully"); } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageCreateCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageCreateCommand.cs index 38cb1451..802b9a27 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageCreateCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageCreateCommand.cs @@ -50,7 +50,7 @@ protected override async ValueTask ExecuteCommand() var buildPath = GetAppBuildPath(projectPath); - await AppTools.TrimApplication(projectPath, _packageManager, Configuration, null, Logger, Console, CancellationToken); + await AppTools.TrimApplication(projectPath, _packageManager, osVersion, Configuration, null, Logger, Console, CancellationToken); Logger.LogInformation(string.Format(Strings.TrimmedApplicationForSpecifiedVersion, osVersion)); // package diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 1f847eaf..625606fb 100644 --- a/Source/v2/Meadow.Cli/Meadow.CLI.csproj +++ b/Source/v2/Meadow.Cli/Meadow.CLI.csproj @@ -10,7 +10,7 @@ Wilderness Labs, Inc Wilderness Labs, Inc true - 2.0.35.0 + 2.0.37.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.CLI/ https://github.com/WildernessLabs/Meadow.CLI diff --git a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs index a4b484f9..678f71fa 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ namespace Meadow.CLI; public static class Constants { - public const string CLI_VERSION = "2.0.35.0"; + public const string CLI_VERSION = "2.0.37.0"; } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Properties/launchSettings.json b/Source/v2/Meadow.Cli/Properties/launchSettings.json index 7520674a..c9a7e2fd 100644 --- a/Source/v2/Meadow.Cli/Properties/launchSettings.json +++ b/Source/v2/Meadow.Cli/Properties/launchSettings.json @@ -185,11 +185,11 @@ }, "App Build": { "commandName": "Project", - "commandLineArgs": "app build H:\\AS\\BlockPuzzleGenerator\\src\\MeadowBoulderScape\\" + "commandLineArgs": "app build H:\\WL\\Blinky\\Blinky\\BlinkyCs" }, "App Build Debug": { "commandName": "Project", - "commandLineArgs": "app build F:\\temp\\MeadowApplication1 -c Debug" + "commandLineArgs": "app build H:\\WL\\Blinky\\Blinky\\BlinkyCs -c Debug" }, "App Trim": { "commandName": "Project", diff --git a/Source/v2/Meadow.Cli/Strings.cs b/Source/v2/Meadow.Cli/Strings.cs index 1524cd4b..d329ad15 100644 --- a/Source/v2/Meadow.Cli/Strings.cs +++ b/Source/v2/Meadow.Cli/Strings.cs @@ -23,7 +23,7 @@ public static class Strings 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 AppBuildFailed = "Application build failed"; public const string TrimmingApplicationForSpecifiedVersion = "Trimming application for OS version {0}..."; public const string TrimmedApplicationForSpecifiedVersion = "Trimmed application with OS version {0}"; public const string AssemblingCloudPackage = "Assembling the MPAK..."; @@ -82,4 +82,7 @@ public static class Telemetry public const string AskToParticipate = "Would you like to participate?"; } + + public const string AppDeployFailed = "Application deploy failed"; + public const string AppTrimFailed = "Application trimming failed"; } \ No newline at end of file diff --git a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs index 55aa0b45..e3be5db9 100644 --- a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs @@ -262,6 +262,11 @@ public Task Refresh() return Task.CompletedTask; } + public FirmwarePackage? GetLocalPackage(string osVersion) + { + return _f7Packages.FirstOrDefault(p => p.Version == osVersion); + } + public IEnumerator GetEnumerator() { return _f7Packages.GetEnumerator(); diff --git a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs index 7a688adf..625a2b9d 100644 --- a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs @@ -24,6 +24,7 @@ public interface IFirmwarePackageCollection : IEnumerable Task UpdateAvailable(); Task IsVersionAvailableForDownload(string version); Task RetrievePackage(string version, bool overwrite = false); + FirmwarePackage? GetLocalPackage(string version); FirmwarePackage this[int index] { get; } FirmwarePackage? this[string version] { get; } string PackageFileRoot { get; } diff --git a/Source/v2/Meadow.Tooling.Core/App/AppManager.cs b/Source/v2/Meadow.Tooling.Core/App/AppManager.cs index 2a93e808..d02a4416 100644 --- a/Source/v2/Meadow.Tooling.Core/App/AppManager.cs +++ b/Source/v2/Meadow.Tooling.Core/App/AppManager.cs @@ -36,6 +36,7 @@ private static bool IsXmlDoc(string file) public static async Task DeployApplication( IPackageManager packageManager, IMeadowConnection connection, + string osVersion, string localBinaryDirectory, bool includePdbs, bool includeXmlDocs, @@ -67,7 +68,7 @@ public static async Task DeployApplication( } else { - dependencies = packageManager.GetDependencies(new FileInfo(Path.Combine(processedAppPath, "App.dll"))); + dependencies = packageManager.GetDependencies(new FileInfo(Path.Combine(processedAppPath, "App.dll")), osVersion); } dependencies.Add(Path.Combine(localBinaryDirectory, "App.dll")); diff --git a/Source/v2/Meadow.Tooling.Core/Package/IPackageManager.cs b/Source/v2/Meadow.Tooling.Core/Package/IPackageManager.cs index ef8e4ea1..6a2c3ed7 100644 --- a/Source/v2/Meadow.Tooling.Core/Package/IPackageManager.cs +++ b/Source/v2/Meadow.Tooling.Core/Package/IPackageManager.cs @@ -7,7 +7,7 @@ namespace Meadow.Package; public interface IPackageManager { - List GetDependencies(FileInfo file); + List GetDependencies(FileInfo file, string? osVerion); bool BuildApplication( string projectFilePath, @@ -17,6 +17,7 @@ bool BuildApplication( Task TrimApplication( FileInfo applicationFilePath, + string osVerion, bool includePdbs = false, IEnumerable? noLink = null, CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Tooling.Core/Package/PackageManager.AssemblyManager.cs b/Source/v2/Meadow.Tooling.Core/Package/PackageManager.AssemblyManager.cs index 9a33428e..a8f2094f 100644 --- a/Source/v2/Meadow.Tooling.Core/Package/PackageManager.AssemblyManager.cs +++ b/Source/v2/Meadow.Tooling.Core/Package/PackageManager.AssemblyManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; namespace Meadow.Package; @@ -9,28 +10,33 @@ public partial class PackageManager public const string PostLinkDirectoryName = "postlink_bin"; public const string PackageOutputDirectoryName = "mpak"; - private string _meadowAssembliesPath = string.Empty; - - public List GetDependencies(FileInfo file) + public List GetDependencies(FileInfo file, string? osVerion) { - return _meadowLinker.MapDependencies(file); + var linker = new Linker.MeadowLinker(GetAssemblyPathForOS(osVerion)); + return linker.MapDependencies(file); } - private string GetMeadowAssembliesPath() + private string GetAssemblyPathForOS(string? osVersion) { - if (string.IsNullOrWhiteSpace(_meadowAssembliesPath)) - { // for now we only support F7 - // TODO: add switch and support for other platforms - var store = _fileManager.Firmware["Meadow F7"]; - if (store != null) + if (string.IsNullOrWhiteSpace(osVersion)) + { + osVersion = _fileManager?.Firmware["Meadow F7"]?.DefaultPackage?.Version; + } + + var store = _fileManager?.Firmware["Meadow F7"]; + if (store != null) + { + store.Refresh(); + + var package = store.GetLocalPackage(osVersion!); + + if (package == null) { - store.Refresh(); - if (store.DefaultPackage != null && store.DefaultPackage.BclFolder != null) - { - _meadowAssembliesPath = store.DefaultPackage.GetFullyQualifiedPath(store.DefaultPackage.BclFolder); - } + throw new Exception($"No firmware package found for Meadow F7 with version {osVersion}"); } + return package.GetFullyQualifiedPath(package.BclFolder); } - return _meadowAssembliesPath; + + throw new Exception("No firmware package(s) found for Meadow F7"); } } \ No newline at end of file diff --git a/Source/v2/Meadow.Tooling.Core/Package/PackageManager.cs b/Source/v2/Meadow.Tooling.Core/Package/PackageManager.cs index 444f243d..d79283ce 100644 --- a/Source/v2/Meadow.Tooling.Core/Package/PackageManager.cs +++ b/Source/v2/Meadow.Tooling.Core/Package/PackageManager.cs @@ -22,12 +22,10 @@ public partial class PackageManager : IPackageManager public const string BuildOptionsFileName = "app.build.yaml"; private readonly FileManager _fileManager; - private readonly MeadowLinker _meadowLinker; public PackageManager(FileManager fileManager) { _fileManager = fileManager; - _meadowLinker = new MeadowLinker(GetMeadowAssembliesPath(), null); } private bool CleanApplication(string projectFilePath, string configuration = "Release", CancellationToken? cancellationToken = null) @@ -129,6 +127,7 @@ public bool BuildApplication(string projectFilePath, string configuration = "Rel public Task TrimApplication( FileInfo applicationFilePath, + string osVersion, bool includePdbs = false, IEnumerable? noLink = null, CancellationToken? cancellationToken = null) @@ -164,7 +163,7 @@ public Task TrimApplication( } } - var linker = new MeadowLinker(GetMeadowAssembliesPath()); + var linker = new MeadowLinker(GetAssemblyPathForOS(osVersion)); return linker.Trim(applicationFilePath, includePdbs, noLink); } From 04fe790398bea8ed7de60e5b2a4fc5af930cef0c Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 29 Apr 2024 17:07:58 -0700 Subject: [PATCH 2/2] Change firmware list presentation to assending --- .../Commands/Current/Firmware/FirmwareListCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs index 23591810..00807654 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs @@ -47,7 +47,7 @@ private async Task DisplayVerboseResults(FileManager manager) Logger?.LogInformation($" {name}"); var collection = manager.Firmware[name]; - foreach (var package in collection.OrderByDescending(p => new Version(p.Version))) + foreach (var package in collection.OrderBy(p => new Version(p.Version))) { if (package == collection.DefaultPackage) { @@ -88,7 +88,7 @@ private async Task DisplayTerseResults(FileManager manager) Logger?.LogInformation($" {name}"); var collection = manager.Firmware[name]; - foreach (var package in collection.OrderByDescending(p => new Version(p.Version))) + foreach (var package in collection.OrderBy(p => new Version(p.Version))) { if (package == collection.DefaultPackage) {