Skip to content

Commit

Permalink
Merge pull request #529 from WildernessLabs/develop
Browse files Browse the repository at this point in the history
Merge to `develop` for 1.9.2 Extension release
  • Loading branch information
CartBlanche authored Mar 15, 2024
2 parents f2b7ca2 + b41a8fc commit 602c2f6
Show file tree
Hide file tree
Showing 153 changed files with 2,148 additions and 1,813 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Meadow.CLI Packaging
env:
CLI_RELEASE_VERSION_1: 1.9.0.0
CLI_RELEASE_VERSION_1: 1.9.2.0
CLI_RELEASE_VERSION_2: 2.0.17.0
IDE_TOOLS_RELEASE_VERSION: 1.9.0
MEADOW_OS_VERSION: 1.9.0.0
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Meadow.CLI.Core
{
public static class Constants
{
public const string CLI_VERSION = "1.9.0.0";
public const string CLI_VERSION = "1.9.2.0";
public const ushort HCOM_PROTOCOL_PREVIOUS_VERSION_NUMBER = 0x0007;
public const ushort HCOM_PROTOCOL_CURRENT_VERSION_NUMBER = 0x0008; // Used for transmission
public const string WILDERNESS_LABS_USB_VID = "2E6A";
Expand Down
24 changes: 19 additions & 5 deletions Meadow.CLI.Core/Devices/MeadowSerialDevice.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow.CLI.Core.Exceptions;
using Meadow.CLI.Core.Internals.MeadowCommunication;
using System;
using System.IO;
using System.IO.Ports;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,7 +44,7 @@ private protected override void Dispose(bool disposing)

if (SerialPort != null)
{
lock(lockObject)
lock (lockObject)
{
if (SerialPort.IsOpen)
{
Expand All @@ -52,7 +53,7 @@ private protected override void Dispose(bool disposing)
SerialPort.Dispose();
SerialPort = null;
}
}
}
}
}

Expand Down Expand Up @@ -115,7 +116,7 @@ private static SerialPort OpenSerialPort(string portName)
{
if (string.IsNullOrEmpty(portName))
{
throw new ArgumentException("Serial Port name cannot be empty");
throw new ArgumentException("Serial Port name cannot be empty", nameof(portName));
}

// Create a new SerialPort object with default settings
Expand All @@ -136,7 +137,7 @@ private static SerialPort OpenSerialPort(string portName)
if (port.IsOpen)
port.Close();

int retries = 15;
int retries = 10;

for (int i = 0; i < retries; i++)
{
Expand All @@ -146,10 +147,23 @@ private static SerialPort OpenSerialPort(string portName)
port.BaseStream.ReadTimeout = 0;
break;
}
catch
catch (FileNotFoundException)
{
throw new Exception($"Serial port '{portName}' not found");
}
catch (UnauthorizedAccessException uae)
{
if (i == retries - 1)
{
throw new Exception($"{uae.Message} Another application may have access to '{portName}'. ");
}
Thread.Sleep(500);
}
catch (Exception ex)
{
// We don't know what happened, best to bail and let the user know.
throw new Exception($"Unable to open port '{portName}'. {ex.Message}");
}
}

return port;
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.9.0.0</Version>
<Version>1.9.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.9.0.0</Version>
<Version>1.9.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.9.0.0</Version>
<Version>1.9.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.9.0.0</Version>
<Version>1.9.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI/Meadow.CLI.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.9.0.0</PackageVersion>
<PackageVersion>1.9.2.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.9.0.0</PackageVersion>
<PackageVersion>1.9.2.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down
12 changes: 6 additions & 6 deletions Source/v2/Meadow.CLI.v2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Linker", "Meadow.Lin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Dfu", "Meadow.Dfu\Meadow.Dfu.csproj", "{6AE8C9EA-87AF-49AC-A63B-9A9416DD76E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Package", "Meadow.Package\Meadow.Package.csproj", "{E34A4BFA-1E92-4951-A5F9-B847EAAB05F8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Firmware", "Meadow.Firmware\Meadow.Firmware.csproj", "{D2274F30-A001-482A-99E3-0AB1970CF695}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meadow.Firmware", "Meadow.Firmware\Meadow.Firmware.csproj", "{D2274F30-A001-482A-99E3-0AB1970CF695}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meadow.Tooling.Core", "Meadow.Tooling.Core\Meadow.Tooling.Core.csproj", "{A22DBF4A-E472-445E-96C0-930C126039C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -116,14 +116,14 @@ Global
{6AE8C9EA-87AF-49AC-A63B-9A9416DD76E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AE8C9EA-87AF-49AC-A63B-9A9416DD76E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AE8C9EA-87AF-49AC-A63B-9A9416DD76E0}.Release|Any CPU.Build.0 = Release|Any CPU
{E34A4BFA-1E92-4951-A5F9-B847EAAB05F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E34A4BFA-1E92-4951-A5F9-B847EAAB05F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E34A4BFA-1E92-4951-A5F9-B847EAAB05F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E34A4BFA-1E92-4951-A5F9-B847EAAB05F8}.Release|Any CPU.Build.0 = Release|Any CPU
{D2274F30-A001-482A-99E3-0AB1970CF695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2274F30-A001-482A-99E3-0AB1970CF695}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2274F30-A001-482A-99E3-0AB1970CF695}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2274F30-A001-482A-99E3-0AB1970CF695}.Release|Any CPU.Build.0 = Release|Any CPU
{A22DBF4A-E472-445E-96C0-930C126039C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A22DBF4A-E472-445E-96C0-930C126039C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A22DBF4A-E472-445E-96C0-930C126039C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A22DBF4A-E472-445E-96C0-930C126039C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
97 changes: 97 additions & 0 deletions Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using CliFx.Infrastructure;
using Meadow.Hcom;
using Meadow.Package;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

internal static class AppTools
{
internal static string ValidateAndSanitizeAppPath(string? path)
{
path ??= Directory.GetCurrentDirectory();

path = path.Trim('\"');
path = path.TrimEnd('\"');
path = path.TrimEnd(Path.DirectorySeparatorChar);

if (!File.Exists(path))
{ // is it a valid directory?
if (!Directory.Exists(path))
{
throw new CommandException($"{Strings.InvalidApplicationPath} '{path}'", CommandExitCode.FileNotFound);
}
}

//sanitize path
return Path.GetFullPath(path);
}

internal static async Task DisableRuntimeIfEnabled(IMeadowConnection connection, ILogger? logger, CancellationToken cancellationToken)
{
var isRuntimeEnabled = await connection.IsRuntimeEnabled();

if (isRuntimeEnabled)
{
logger?.LogInformation($"{Strings.DisablingRuntime}...");

await connection.RuntimeDisable(cancellationToken);
}
}

internal static async Task<bool> TrimApplication(string path,
IPackageManager packageManager,
string? configuration,
IEnumerable<string>? noLinkAssemblies,
ILogger? logger,
IConsole? console,
CancellationToken cancellationToken)
{
// it's a directory - we need to determine the latest build (they might have a Debug and a Release config)
var candidates = PackageManager.GetAvailableBuiltConfigurations(path, "App.dll");

if (candidates.Length == 0)
{
logger?.LogError($"{Strings.NoCompiledApplicationFound} at '{path}'");
return false;
}

FileInfo? file;

if (configuration is not null)
{
file = candidates.Where(c => c.DirectoryName.Contains(configuration)).OrderByDescending(c => c.LastWriteTime).First();

if (file == null)
{
logger?.LogError($"{Strings.NoCompiledApplicationFound} at '{path}'");
return false;
}
}
else
{
file = candidates.OrderByDescending(c => c.LastWriteTime).First();
}

var cts = new CancellationTokenSource();

if (console is not null)
{
ConsoleSpinner.Spin(console, cancellationToken: cts.Token);
}

logger?.LogInformation($"Trimming application {file.FullName}...");
if (noLinkAssemblies != null && noLinkAssemblies.Count() > 0)
{
logger?.LogInformation($"Skippping assemblies: {string.Join(", ", noLinkAssemblies)}");
}

await packageManager.TrimApplication(file, false, noLinkAssemblies, cancellationToken);
cts.Cancel();

// illink returns before all files are written - attempt a delay of 1s
await Task.Delay(1000, cancellationToken);

return true;
}
}
Loading

0 comments on commit 602c2f6

Please sign in to comment.