Skip to content

Commit 467b9c2

Browse files
author
Frank Robijn
committed
Native assemblies sorted by name, LocalInstance => PathToCLRInstance verified & bug fixed.
1 parent b88878f commit 467b9c2

File tree

5 files changed

+137
-133
lines changed

5 files changed

+137
-133
lines changed

targets/netcore/nanoFramework.nanoCLR.CLI/ClrInstanceOperationsProcessor.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
6868

6969
if (options.GetNativeAssemblies)
7070
{
71-
List<NativeAssemblyDetails>? nativeAssemblies = hostBuilder.GetNativeAssemblies();
71+
List<NativeAssemblyDetails> nativeAssemblies = hostBuilder.GetNativeAssemblies();
7272

7373
if (nativeAssemblies is not null)
7474
{
@@ -99,7 +99,9 @@ private static void OutputNativeAssembliesList(List<NativeAssemblyDetails> nativ
9999
int maxAssemblyNameLength = nativeAssemblies.Max(assembly => assembly.Name.Length);
100100
int maxAssemblyVersionLength = nativeAssemblies.Max(assembly => assembly.Version.ToString().Length);
101101

102-
foreach (NativeAssemblyDetails assembly in nativeAssemblies)
102+
foreach (NativeAssemblyDetails assembly in from na in nativeAssemblies
103+
orderby na.Name
104+
select na)
103105
{
104106
Console.WriteLine($" {assembly.Name.PadRight(maxAssemblyNameLength)} v{assembly.Version.ToString().PadRight(maxAssemblyVersionLength)} 0x{assembly.CheckSum:X8}");
105107
}

targets/netcore/nanoFramework.nanoCLR.CLI/CommonOptions.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.IO;
56
using CommandLine;
67

78
namespace nanoFramework.nanoCLR.CLI
@@ -26,7 +27,10 @@ public string LocalInstance
2627
{
2728
set
2829
{
29-
PathToCLRInstance = value;
30+
if (!string.IsNullOrEmpty(value))
31+
{
32+
PathToCLRInstance = Path.GetDirectoryName(Path.GetFullPath(value));
33+
}
3034
}
3135
}
3236

targets/netcore/nanoFramework.nanoCLR.CLI/ExecuteCommandProcessor.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
//
2-
// Copyright (c) .NET Foundation and Contributors
3-
// See LICENSE file in the project root for full license information.
4-
//
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
53

6-
using nanoFramework.nanoCLR.Host;
7-
using nanoFramework.nanoCLR.Host.Port.TcpIp;
84
using System;
95
using System.Diagnostics;
106
using System.IO;
117
using System.Linq;
128
using System.Runtime.Versioning;
9+
using nanoFramework.nanoCLR.Host;
10+
using nanoFramework.nanoCLR.Host.Port.TcpIp;
1311

1412
namespace nanoFramework.nanoCLR.CLI
1513
{
@@ -33,7 +31,7 @@ public static int ProcessVerb(
3331
throw new CLIException(ExitCode.E9009);
3432
}
3533

36-
hostBuilder = nanoCLRHost.CreateBuilder(Path.GetDirectoryName(options.PathToCLRInstance));
34+
hostBuilder = nanoCLRHost.CreateBuilder(options.PathToCLRInstance);
3735
}
3836
else
3937
{

targets/netcore/nanoFramework.nanoCLR.Host/NanoClrHostBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public nanoCLRHostBuilder UseWireProtocolPort(IPort port)
9191
public string GetCLRVersion() =>
9292
Interop.nanoCLR.nanoCLR_GetVersion();
9393

94-
public List<NativeAssemblyDetails>? GetNativeAssemblies() =>
95-
=> NativeAssemblyDetails.Get();
94+
public List<NativeAssemblyDetails> GetNativeAssemblies() =>
95+
NativeAssemblyDetails.Get();
9696

9797
public nanoCLRHostBuilder UseSerialPortWireProtocol(string comPort) =>
9898
UseWireProtocolPort(new SerialPort(comPort));

targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs

+121-121
Original file line numberDiff line numberDiff line change
@@ -8,125 +8,125 @@
88

99
namespace nanoFramework.nanoCLR.Host
1010
{
11-
/// <summary>
12-
/// Information about a native assembly.
13-
/// </summary>
14-
public sealed class NativeAssemblyDetails
15-
{
16-
#region Properties
17-
/// <summary>
18-
/// Gets the name of the assembly.
19-
/// </summary>
20-
public string Name
21-
{
22-
get;
23-
}
24-
25-
/// <summary>
26-
/// Gets the version of the assembly.
27-
/// </summary>
28-
public Version Version
29-
{
30-
get;
31-
}
32-
33-
/// <summary>
34-
/// Gets the checksum of the assembly.
35-
/// </summary>
36-
public uint CheckSum
37-
{
38-
get;
39-
}
40-
#endregion
41-
42-
#region Construction
43-
/// <summary>
44-
/// Get the assembly information from the nanoCLR instance.
45-
/// </summary>
46-
/// <returns>Returns a list with the metadata of native assemblies. If the runtime does
47-
/// not support this, <c>null</c> is returned.</returns>
48-
public static List<NativeAssemblyDetails>? Get ()
49-
{
50-
var result = new List<NativeAssemblyDetails> ();
51-
52-
ushort numAssemblies;
53-
try
54-
{
55-
numAssemblies = Interop.nanoCLR.nanoCLR_GetNativeAssemblyCount ();
56-
}
57-
catch (EntryPointNotFoundException)
58-
{
59-
return null;
60-
}
61-
62-
if (numAssemblies == 0)
63-
{
64-
return result;
65-
}
66-
67-
// assembly data size is coming from debugger library: NativeAssemblyDetails.Size
68-
const int assemblyDataSize = 4 + 4 * 2 + 128 * 1;
69-
70-
byte[] data = new byte[numAssemblies * assemblyDataSize];
71-
72-
if (!Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation (data, data.Length))
73-
{
74-
return null;
75-
}
76-
77-
using var buffer = new MemoryStream (data);
78-
using var reader = new BinaryReader (buffer);
79-
for (int i = 0; i < numAssemblies; i++)
80-
{
81-
result.Add (new NativeAssemblyDetails (reader));
82-
}
83-
84-
return result;
85-
}
86-
87-
/// <summary>
88-
/// Deserialize the description of the native assembly.
89-
/// In nf-debugger this is done via a converter. The code in this
90-
/// constructor is essentially the same.
91-
/// </summary>
92-
/// <param name="reader"></param>
93-
private NativeAssemblyDetails (BinaryReader reader)
94-
{
95-
CheckSum = reader.ReadUInt32 ();
96-
Version = new Version (
97-
reader.ReadUInt16 (),
98-
reader.ReadUInt16 (),
99-
reader.ReadUInt16 (),
100-
reader.ReadUInt16 ()
101-
);
102-
Name = GetZeroTerminatedString (reader.ReadBytes (128), true);
103-
}
104-
#endregion
105-
106-
#region Helpers
107-
/// <summary>
108-
/// Original is in nf-debugger\nanoFramework.Tools.DebugLibrary.Shared\WireProtocol\Commands.cs
109-
/// </summary>
110-
/// <param name="buf"></param>
111-
/// <param name="fUTF8"></param>
112-
/// <returns></returns>
113-
private static string GetZeroTerminatedString (byte[] buf, bool fUTF8)
114-
{
115-
if (buf is null)
116-
{
117-
return null;
118-
}
119-
120-
int len = 0;
121-
int num = buf.Length;
122-
123-
while (len < num && buf[len] != 0)
124-
{
125-
len++;
126-
}
127-
128-
return fUTF8 ? Encoding.UTF8.GetString (buf, 0, len) : Encoding.ASCII.GetString (buf, 0, len);
129-
}
130-
#endregion
131-
}
11+
/// <summary>
12+
/// Information about a native assembly.
13+
/// </summary>
14+
public sealed class NativeAssemblyDetails
15+
{
16+
#region Properties
17+
/// <summary>
18+
/// Gets the name of the assembly.
19+
/// </summary>
20+
public string Name
21+
{
22+
get;
23+
}
24+
25+
/// <summary>
26+
/// Gets the version of the assembly.
27+
/// </summary>
28+
public Version Version
29+
{
30+
get;
31+
}
32+
33+
/// <summary>
34+
/// Gets the checksum of the assembly.
35+
/// </summary>
36+
public uint CheckSum
37+
{
38+
get;
39+
}
40+
#endregion
41+
42+
#region Construction
43+
/// <summary>
44+
/// Get the assembly information from the nanoCLR instance.
45+
/// </summary>
46+
/// <returns>Returns a list with the metadata of native assemblies. If the runtime does
47+
/// not support this, <c>null</c> is returned.</returns>
48+
public static List<NativeAssemblyDetails> Get()
49+
{
50+
var result = new List<NativeAssemblyDetails>();
51+
52+
ushort numAssemblies;
53+
try
54+
{
55+
numAssemblies = Interop.nanoCLR.nanoCLR_GetNativeAssemblyCount();
56+
}
57+
catch (EntryPointNotFoundException)
58+
{
59+
return null;
60+
}
61+
62+
if (numAssemblies == 0)
63+
{
64+
return result;
65+
}
66+
67+
// assembly data size is coming from debugger library: NativeAssemblyDetails.Size
68+
const int assemblyDataSize = 4 + 4 * 2 + 128 * 1;
69+
70+
byte[] data = new byte[numAssemblies * assemblyDataSize];
71+
72+
if (!Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation(data, data.Length))
73+
{
74+
return null;
75+
}
76+
77+
using var buffer = new MemoryStream(data);
78+
using var reader = new BinaryReader(buffer);
79+
for (int i = 0; i < numAssemblies; i++)
80+
{
81+
result.Add(new NativeAssemblyDetails(reader));
82+
}
83+
84+
return result;
85+
}
86+
87+
/// <summary>
88+
/// Deserialize the description of the native assembly.
89+
/// In nf-debugger this is done via a converter. The code in this
90+
/// constructor is essentially the same.
91+
/// </summary>
92+
/// <param name="reader"></param>
93+
private NativeAssemblyDetails(BinaryReader reader)
94+
{
95+
CheckSum = reader.ReadUInt32();
96+
Version = new Version(
97+
reader.ReadUInt16(),
98+
reader.ReadUInt16(),
99+
reader.ReadUInt16(),
100+
reader.ReadUInt16()
101+
);
102+
Name = GetZeroTerminatedString(reader.ReadBytes(128), true);
103+
}
104+
#endregion
105+
106+
#region Helpers
107+
/// <summary>
108+
/// Original is in nf-debugger\nanoFramework.Tools.DebugLibrary.Shared\WireProtocol\Commands.cs
109+
/// </summary>
110+
/// <param name="buf"></param>
111+
/// <param name="fUTF8"></param>
112+
/// <returns></returns>
113+
private static string GetZeroTerminatedString(byte[] buf, bool fUTF8)
114+
{
115+
if (buf is null)
116+
{
117+
return null;
118+
}
119+
120+
int len = 0;
121+
int num = buf.Length;
122+
123+
while (len < num && buf[len] != 0)
124+
{
125+
len++;
126+
}
127+
128+
return fUTF8 ? Encoding.UTF8.GetString(buf, 0, len) : Encoding.ASCII.GetString(buf, 0, len);
129+
}
130+
#endregion
131+
}
132132
}

0 commit comments

Comments
 (0)