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

Validate firmware before running or trimming + minor cleanup #551

Merged
merged 1 commit into from
Apr 18, 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
22 changes: 21 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CliFx.Attributes;
using Meadow.Hcom;
using Meadow.Package;
using Meadow.Software;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;
Expand All @@ -23,14 +24,33 @@ public class AppRunCommand : BaseDeviceCommand<AppRunCommand>
[CommandOption("nolink", Description = Strings.NoLinkAssemblies, IsRequired = false)]
public string[]? NoLink { get; private set; }

public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
readonly FileManager _fileManager;
adrianstevens marked this conversation as resolved.
Show resolved Hide resolved

public AppRunCommand(FileManager fileManager, IPackageManager packageManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
_packageManager = packageManager;
_fileManager = fileManager;
}

protected override async ValueTask ExecuteCommand()
{
await _fileManager.Refresh();

// for now we only support F7
// TODO: add switch and support for other platforms
var collection = _fileManager.Firmware["Meadow F7"];

if (collection == null || collection.Count() == 0)
{
throw new CommandException(Strings.NoFirmwarePackagesFound, CommandExitCode.GeneralError);
}

if (collection.DefaultPackage == null)
{
throw new CommandException(Strings.NoDefaultFirmwarePackageSet, CommandExitCode.GeneralError);
}

var path = AppTools.ValidateAndSanitizeAppPath(Path);

Configuration ??= "Release";
Expand Down
22 changes: 21 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/App/AppTrimCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CliFx.Attributes;
using Meadow.Package;
using Meadow.Software;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;
Expand All @@ -18,14 +19,33 @@ public class AppTrimCommand : BaseCommand<AppTrimCommand>
[CommandOption("nolink", Description = Strings.NoLinkAssemblies, IsRequired = false)]
public string[]? NoLink { get; private set; }

public AppTrimCommand(IPackageManager packageManager, ILoggerFactory loggerFactory)
readonly FileManager _fileManager;

public AppTrimCommand(FileManager fileManager, IPackageManager packageManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_packageManager = packageManager;
_fileManager = fileManager;
}

protected override async ValueTask ExecuteCommand()
{
await _fileManager.Refresh();

// for now we only support F7
// TODO: add switch and support for other platforms
var collection = _fileManager.Firmware["Meadow F7"];

if (collection == null || collection.Count() == 0)
{
throw new CommandException(Strings.NoFirmwarePackagesFound, CommandExitCode.GeneralError);
}

if (collection.DefaultPackage == null)
{
throw new CommandException(Strings.NoDefaultFirmwarePackageSet, CommandExitCode.GeneralError);
}

var path = AppTools.ValidateAndSanitizeAppPath(Path);

if (!File.Exists(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ protected override async ValueTask ExecuteCommand()

if (Version == null)
{
if (collection == null || collection.Count() == 0)
{
throw new CommandException(Strings.NoFirmwarePackagesFound, CommandExitCode.GeneralError);
}

Logger?.LogInformation($"Default firmware is '{collection?.DefaultPackage?.Version}'.");
}
else
Expand Down
116 changes: 58 additions & 58 deletions Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<PackAsTool>true</PackAsTool>
<ToolCommandName>meadow</ToolCommandName>
<PackageId>WildernessLabs.Meadow.CLI</PackageId>
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.33.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>Meadow,Meadow.Foundation,Meadow.CLI,CLI,command,line,interface,device,IoT</PackageTags>
<Description>Command-line interface for Meadow</Description>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<AssemblyName>meadow</AssemblyName>
<LangVersion>11.0</LangVersion>
<Copyright>Copyright 2020-2024 Wilderness Labs</Copyright>
<Nullable>enable</Nullable>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<PackAsTool>true</PackAsTool>
<ToolCommandName>meadow</ToolCommandName>
<PackageId>WildernessLabs.Meadow.CLI</PackageId>
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.34.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>Meadow,Meadow.Foundation,Meadow.CLI,CLI,command,line,interface,device,IoT</PackageTags>
<Description>Command-line interface for Meadow</Description>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<AssemblyName>meadow</AssemblyName>
<LangVersion>11.0</LangVersion>
<Copyright>Copyright 2020-2024 Wilderness Labs</Copyright>
<Nullable>enable</Nullable>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="CliFx" Version="*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Meadow.Dfu\Meadow.Dfu.csproj" />
<ProjectReference Include="..\Meadow.Linker\Meadow.Linker.csproj" />
<ProjectReference Include="..\Meadow.Tooling.Core\Meadow.Tooling.Core.csproj" />
<ProjectReference Include="..\Meadow.UsbLib\Meadow.UsbLib.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\icon.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="CliFx" Version="*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Meadow.Dfu\Meadow.Dfu.csproj" />
<ProjectReference Include="..\Meadow.Linker\Meadow.Linker.csproj" />
<ProjectReference Include="..\Meadow.Tooling.Core\Meadow.Tooling.Core.csproj" />
<ProjectReference Include="..\Meadow.UsbLib\Meadow.UsbLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="..\icon.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Meadow.CLI;

public static class Constants
{
public const string CLI_VERSION = "2.0.33.0";
}
public const string CLI_VERSION = "2.0.34.0";
}
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
},
"Firmware Default set": {
"commandName": "Project",
"commandLineArgs": "firmware default 1.3.4.0"
"commandLineArgs": "firmware default 1.10.0.2"
},
"Firmware Delete": {
"commandName": "Project",
"commandLineArgs": "firmware delete 1.9.0.0"
"commandLineArgs": "firmware delete 1.99.0.0"
},
"Firmware Write all": {
"commandName": "Project",
Expand Down
2 changes: 2 additions & 0 deletions Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ public static class Strings
public const string IsDfuUtilInstalled = "Is dfu-util installed?";
public const string RunMeadowDfuInstall = "Run 'meadow dfu install' to install";
public const string NewMeadowDeviceNotFound = "New Meadow device not found";
public const string NoFirmwarePackagesFound = "No firmware packages found, run 'meadow firmware download' to download the latest firmware";
public const string NoDefaultFirmwarePackageSet = "No default firmware package set, run 'meadow firmware default' to set the default firmware";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@ public partial class PackageManager

private string _meadowAssembliesPath = string.Empty;

private string MeadowAssembliesPath
public List<string> GetDependencies(FileInfo file)
{
return _meadowLinker.MapDependencies(file);
}

private string GetMeadowAssembliesPath()
{
get
{
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(_meadowAssembliesPath))
{ // for now we only support F7
// TODO: add switch and support for other platforms
var store = _fileManager.Firmware["Meadow F7"];
if (store != null)
{
store.Refresh();
if (store.DefaultPackage != null && store.DefaultPackage.BclFolder != null)
{
store.Refresh();
if (store.DefaultPackage != null && store.DefaultPackage.BclFolder != null)
{
_meadowAssembliesPath = store.DefaultPackage.GetFullyQualifiedPath(store.DefaultPackage.BclFolder);
}
_meadowAssembliesPath = store.DefaultPackage.GetFullyQualifiedPath(store.DefaultPackage.BclFolder);
}
}
return _meadowAssembliesPath;
}
}

public List<string> GetDependencies(FileInfo file)
{
return _meadowLinker.MapDependencies(file);
return _meadowAssembliesPath;
}
}
5 changes: 2 additions & 3 deletions Source/v2/Meadow.Tooling.Core/Package/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public partial class PackageManager : IPackageManager
public PackageManager(FileManager fileManager)
{
_fileManager = fileManager;

_meadowLinker = new MeadowLinker(MeadowAssembliesPath, null);
_meadowLinker = new MeadowLinker(GetMeadowAssembliesPath(), null);
}

private bool CleanApplication(string projectFilePath, string configuration = "Release", CancellationToken? cancellationToken = null)
Expand Down Expand Up @@ -165,7 +164,7 @@ public Task TrimApplication(
}
}

var linker = new MeadowLinker(MeadowAssembliesPath);
var linker = new MeadowLinker(GetMeadowAssembliesPath());

return linker.Trim(applicationFilePath, includePdbs, noLink);
}
Expand Down
Loading