Skip to content

Commit

Permalink
Improve projectAssembliesOnly option. Remove the `CopyLocalLockFile…
Browse files Browse the repository at this point in the history
…Assemblies` parameter
  • Loading branch information
JaneySprings committed Apr 20, 2024
1 parent 87bc9e9 commit ab9d7ea
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 76 deletions.
109 changes: 109 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# This file is the top-most EditorConfig file
root = true

# All Files
[*]
indent_size = 4
indent_style = space
tab_width = 4
insert_final_newline = false
trim_trailing_whitespace = true

[*.cs]
# Code analyzers
dotnet_analyzer_diagnostic.category-Style.severity = silent
dotnet_analyzer_diagnostic.category-Design.severity = suggestion
dotnet_analyzer_diagnostic.category-Interoperability.severity = suggestion
dotnet_analyzer_diagnostic.category-Performance.severity = warning
dotnet_analyzer_diagnostic.category-Reliability.severity = suggestion
dotnet_analyzer_diagnostic.category-Security.severity = warning
dotnet_analyzer_diagnostic.category-Usage.severity = suggestion

# CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1001.severity = none
# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = none
# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = none
# IDE0066: Use 'switch' expression
dotnet_diagnostic.IDE0066.severity = none
# IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0028.severity = none
# IDE0058: Expression value is never used
dotnet_diagnostic.IDE0058.severity = none

# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true

# Namespace preferences
csharp_style_namespace_declarations = file_scoped:suggestion

# var preferences
csharp_style_var_elsewhere = false:none
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = false:none

# new preferences
csharp_style_implicit_object_creation_when_type_is_apparent = false:none

# Modifier preferences
csharp_prefer_static_local_function = true:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# Code-block preferences
csharp_prefer_simple_method = true:none
csharp_prefer_braces = false:silent
csharp_prefer_simple_using_statement = true:suggestion

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:warning

# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
2 changes: 1 addition & 1 deletion src/DotNet.Meteor.Debug/Agents/DebugLaunchAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Connect(SoftDebuggerSession session) {

var debuggerStartInfo = new SoftDebuggerStartInfo(arguments);
if (Configuration.DebuggerSessionOptions.ProjectAssembliesOnly)
debuggerStartInfo.SetUserAssemblyNames(Path.GetDirectoryName(Configuration.OutputAssembly));
debuggerStartInfo.SetUserAssemblyNames(Configuration.GetApplicationAssembliesDirectory());

ArgumentNullException.ThrowIfNull(arguments, "Debugger connection arguments not implemented.");
session.Run(debuggerStartInfo, Configuration.DebuggerSessionOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace DotNet.Meteor.Debug;

public class DebuggerOptions {
public class DebugOptions {
[JsonPropertyName("evaluation_timeout")]
public int EvaluationTimeout { get; set; } = ServerExtensions.DefaultDebuggerOptions.EvaluationOptions.EvaluationTimeout;

Expand Down Expand Up @@ -57,5 +57,5 @@ internal static IntegerDisplayFormat GetIntegerDisplayFormat(string value) {
}
}

[JsonSerializable(typeof(DebuggerOptions))]
[JsonSerializable(typeof(DebugOptions))]
internal partial class DebuggerOptionsContext : JsonSerializerContext {}
13 changes: 7 additions & 6 deletions src/DotNet.Meteor.Debug/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using MonoClient = Mono.Debugging.Client;
using DebugProtocol = Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using DotNet.Meteor.Debug.Logging;

namespace DotNet.Meteor.Debug;

Expand All @@ -21,7 +22,7 @@ public class DebugSession : Session {
private readonly Handles<MonoClient.ObjectValue[]> variableHandles = new Handles<MonoClient.ObjectValue[]>();
private readonly SoftDebuggerSession session = new SoftDebuggerSession();

public DebugSession(Stream input, Stream output): base(input, output) {
public DebugSession(Stream input, Stream output) : base(input, output) {
MonoClient.DebuggerLoggingService.CustomLogger = new MonoLogger();

session.LogWriter = OnSessionLog;
Expand Down Expand Up @@ -163,7 +164,7 @@ protected override SetExceptionBreakpointsResponse HandleSetExceptionBreakpoints
if (!string.IsNullOrEmpty(option.Condition))
exceptionFilter = option.Condition;

foreach(var exception in exceptionFilter.Split(','))
foreach (var exception in exceptionFilter.Split(','))
session.Breakpoints.AddCatchpoint(exception);
}
}
Expand All @@ -178,11 +179,11 @@ protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpo

// Remove all file breakpoints
var fileBreakpoints = session.Breakpoints.GetBreakpointsAtFile(sourcePath);
foreach(var fileBreakpoint in fileBreakpoints)
foreach (var fileBreakpoint in fileBreakpoints)
session.Breakpoints.Remove(fileBreakpoint);

// Add all new breakpoints
foreach(var breakpointInfo in breakpointsInfos) {
foreach (var breakpointInfo in breakpointsInfos) {
MonoClient.Breakpoint breakpoint = session.Breakpoints.Add(sourcePath, breakpointInfo.Line, breakpointInfo.Column ?? 1);
// Conditional breakpoint
if (!string.IsNullOrEmpty(breakpointInfo.Condition))
Expand All @@ -201,7 +202,7 @@ protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpo
breakpoints.Add(new DebugProtocol.Breakpoint() {
Id = breakpoint.GetHashCode(),
Verified = false, // updated by event
Line = breakpoint.Line,
Line = breakpoint.Line,
Column = breakpoint.Column
});
}
Expand Down Expand Up @@ -375,7 +376,7 @@ protected override ThreadsResponse HandleThreadsRequest(ThreadsArguments argumen
int tid = (int)thread.Id;
threads[tid] = new DebugProtocol.Thread(tid, thread.Name.ToThreadName(tid));
}
return new ThreadsResponse(threads.Values.ToList());
});
}
Expand Down
9 changes: 4 additions & 5 deletions src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Mono.Debugging.Client;
using Mono.Debugging.Soft;

Expand All @@ -24,12 +23,12 @@ public static string ToDisplayValue(this ObjectValue value) {
return dv;
}
public static StackFrame GetFrameSafe(this Backtrace bt, int n) {
try {
try {
return bt.GetFrame(n);
} catch (Exception) {
return null;
}
}
}
public static ThreadInfo FindThread(this SoftDebuggerSession session, long id) {
var process = session.GetProcesses().FirstOrDefault();
if (process == null)
Expand Down Expand Up @@ -61,10 +60,10 @@ public static void SetUserAssemblyNames(this SoftDebuggerStartInfo startInfo, st
var files = assembliesPaths.Where(it => File.Exists(Path.ChangeExtension(it, ".pdb")));
if (!files.Any())
return;

var pathMap = new Dictionary<string, string>();
var names = new List<AssemblyName>();

foreach (var file in files) {
try {
using var asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(file);
Expand Down
29 changes: 28 additions & 1 deletion src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using DotNet.Meteor.Shared;
using Mono.Debugging.Soft;
using System.IO.Compression;
using System;
using System.Linq;

namespace DotNet.Meteor.Debug.Extensions;

public static class ServerExtensions {
public static DebuggerSessionOptions DefaultDebuggerOptions = new DebuggerSessionOptions {
public static DebuggerSessionOptions DefaultDebuggerOptions { get; } = new DebuggerSessionOptions {
EvaluationOptions = new EvaluationOptions {
EvaluationTimeout = 5000,
MemberEvaluationTimeout = 5000,
Expand Down Expand Up @@ -51,6 +54,30 @@ public static bool TryDeleteFile(string path) {
public static void ThrowException(string message) {
throw new ProtocolException(message, 0, message, url: $"file://{LogConfig.DebugLogFile}");
}
public static string ExtractAndroidAssemblies(string assemblyPath) {
var targetDirectory = Path.GetDirectoryName(assemblyPath)!;
try {
using var archive = new ZipArchive(File.OpenRead(assemblyPath));
var assembliesEntry = archive.Entries.Where(entry => entry.FullName.StartsWith("assemblies", StringComparison.OrdinalIgnoreCase));
if (!assembliesEntry.Any())
return targetDirectory;

foreach (var entry in assembliesEntry) {
Console.WriteLine(entry.Name);
var targetPath = Path.Combine(targetDirectory, entry.Name);
if (File.Exists(targetPath))
File.Delete(targetPath);

using var fileStream = File.Create(targetPath);
using var stream = entry.Open();
stream.CopyTo(fileStream);
}
return targetDirectory;
} catch (Exception ex) {
DebuggerLoggingService.CustomLogger.LogError(ex.Message, ex);
return targetDirectory;
}
}

public static T ToObject<T>(this JToken jtoken, JsonTypeInfo<T> type) {
if (jtoken == null)
Expand Down
36 changes: 23 additions & 13 deletions src/DotNet.Meteor.Debug/LaunchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public class LaunchConfiguration {
public string TempDirectoryPath => Path.Combine(Path.GetDirectoryName(Project.Path), ".meteor");

public LaunchConfiguration(Dictionary<string, JToken> configurationProperties) {
Project = configurationProperties["selectedProject"].ToObject<Project>(TrimmableContext.Default.Project);
Device = configurationProperties["selectedDevice"].ToObject<DeviceData>(TrimmableContext.Default.DeviceData);
Target = configurationProperties["selectedTarget"].ToObject<string>(TrimmableContext.Default.String);
UninstallApp = configurationProperties["uninstallApp"].ToObject<bool>(TrimmableContext.Default.Boolean);
SkipDebug = configurationProperties["skipDebug"].ToObject<bool>(TrimmableContext.Default.Boolean);
Project = configurationProperties["selectedProject"].ToObject(TrimmableContext.Default.Project);
Device = configurationProperties["selectedDevice"].ToObject(TrimmableContext.Default.DeviceData);
Target = configurationProperties["selectedTarget"].ToObject(TrimmableContext.Default.String);
UninstallApp = configurationProperties["uninstallApp"].ToObject(TrimmableContext.Default.Boolean);
SkipDebug = configurationProperties["skipDebug"].ToObject(TrimmableContext.Default.Boolean);

DebugPort = configurationProperties["debuggingPort"].ToObject<int>(TrimmableContext.Default.Int32);
ReloadHostPort = configurationProperties["reloadHost"].ToObject<int>(TrimmableContext.Default.Int32);
ProfilerPort = configurationProperties["profilerPort"].ToObject<int>(TrimmableContext.Default.Int32);
DebugPort = configurationProperties["debuggingPort"].ToObject(TrimmableContext.Default.Int32);
ReloadHostPort = configurationProperties["reloadHost"].ToObject(TrimmableContext.Default.Int32);
ProfilerPort = configurationProperties["profilerPort"].ToObject(TrimmableContext.Default.Int32);

DebuggerSessionOptions = GetDebuggerSessionOptions(configurationProperties["debuggerOptions"]);
OutputAssembly = Project.FindOutputApplication(Target, Device, message => {
ServerExtensions.ThrowException(message);
return string.Empty;
});

if (configurationProperties.TryGetValue("profilerMode", out var profilerModeToken))
ProfilerMode = profilerModeToken.ToObject<string>(TrimmableContext.Default.String);
ProfilerMode = profilerModeToken.ToObject(TrimmableContext.Default.String);

DebugPort = DebugPort == 0 ? ServerExtensions.FindFreePort() : DebugPort;
ReloadHostPort = ReloadHostPort == 0 ? ServerExtensions.FindFreePort() : ReloadHostPort;
Expand All @@ -56,6 +56,16 @@ public string GetApplicationName() {
var assemblyName = Path.GetFileNameWithoutExtension(OutputAssembly);
return assemblyName.Replace("-Signed", "");
}
public string GetApplicationAssembliesDirectory() {
if (Device.IsMacCatalyst)
return Path.Combine(OutputAssembly, "Contents", "MonoBundle");
if (Device.IsIPhone)
return OutputAssembly;
if (Device.IsAndroid)
return ServerExtensions.ExtractAndroidAssemblies(OutputAssembly);

throw new NotSupportedException();
}
public BaseLaunchAgent GetLauchAgent() {
if (ProfilerMode.EqualsInsensitive("trace"))
return new TraceLaunchAgent(this);
Expand All @@ -67,9 +77,9 @@ public BaseLaunchAgent GetLauchAgent() {
return new NoDebugLaunchAgent(this);
}

private DebuggerSessionOptions GetDebuggerSessionOptions(JToken debuggerJsonToken) {
private static DebuggerSessionOptions GetDebuggerSessionOptions(JToken debuggerJsonToken) {
var debuggerOptions = ServerExtensions.DefaultDebuggerOptions;
var options = debuggerJsonToken.ToObject<DebuggerOptions>(DebuggerOptionsContext.Default.DebuggerOptions);
var options = debuggerJsonToken.ToObject(DebuggerOptionsContext.Default.DebugOptions);
if (options == null)
return debuggerOptions;

Expand All @@ -85,7 +95,7 @@ private DebuggerSessionOptions GetDebuggerSessionOptions(JToken debuggerJsonToke
debuggerOptions.EvaluationOptions.CurrentExceptionTag = options.CurrentExceptionTag;
debuggerOptions.EvaluationOptions.EllipsizeStrings = options.EllipsizeStrings;
debuggerOptions.EvaluationOptions.EllipsizedLength = options.EllipsizedLength;
debuggerOptions.EvaluationOptions.IntegerDisplayFormat = DebuggerOptions.GetIntegerDisplayFormat(options.IntegerDisplayFormat);
debuggerOptions.EvaluationOptions.IntegerDisplayFormat = DebugOptions.GetIntegerDisplayFormat(options.IntegerDisplayFormat);
debuggerOptions.ProjectAssembliesOnly = options.ProjectAssembliesOnly;

return debuggerOptions;
Expand Down
17 changes: 2 additions & 15 deletions src/DotNet.Meteor.Debug/Logging/MonoLogger.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
using System;
using Mono.Debugging.Client;
using NLog;

namespace DotNet.Meteor.Debug;
namespace DotNet.Meteor.Debug.Logging;

public class MonoLogger : ICustomLogger {
private readonly Logger logger = LogManager.GetCurrentClassLogger();

public string GetNewDebuggerLogFilename() => nameof(MonoLogger);
public void LogMessage(string format, params object[] args) => logger.Debug(format, args);
public void LogAndShowException(string message, Exception ex) => LogError(message, ex);
public void LogError(string message, Exception ex) {
if (ex == null) {
logger.Error(message);
return;
}
logger.Error(ex, message + Environment.NewLine + ex.StackTrace);
var innerException = ex.InnerException;

while (innerException != null) {
logger.Error(innerException);
innerException = innerException.InnerException;
}
}
public void LogError(string message, Exception ex) => logger.Error($"{message}: {ex}");
}
Loading

0 comments on commit ab9d7ea

Please sign in to comment.