-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from WildernessLabs/develop
Merge to `develop` for 1.9.2 Extension release
- Loading branch information
Showing
153 changed files
with
2,148 additions
and
1,813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.