Skip to content

Commit

Permalink
Merge branch 'bugfix/ikvmc-nowarnerror' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AliveDevil committed Aug 1, 2024
2 parents 547ac5e + 3859829 commit 4434f7d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 275 deletions.
4 changes: 4 additions & 0 deletions src/IKVM.MSBuild.Tasks/IkvmToolTaskDiagnosticWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public Task ReceiveAsync(IkvmToolDiagnosticEvent @event)
logger.LogWarning(@event.Message, @event.MessageArgs);
writer?.WriteLine("ERROR: " + @event.Message, @event.MessageArgs);
break;

case IkvmToolDiagnosticEventLevel.Unknown: // Unknown Level, passthrough message
logger.LogMessage(@event.Message, @event.MessageArgs);
break;
}
}
catch
Expand Down
3 changes: 3 additions & 0 deletions src/IKVM.NET.Sdk/targets/IKVM.Java.Core.NoTasks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ Value = b.ToString();
<_IkvmCompilerArgs Include="-nologo" />
<_IkvmCompilerArgs Include="-bootstrap" Condition=" '$(Bootstrap)' == 'true' " />
<_IkvmCompilerArgs Include="-debug:$(DebugType)" Condition=" '$(DebugType)' != 'none' " />
<_IkvmCompilerArgs Include="-nowarn:$(NoWarn.Replace(';', ','))" Condition=" '$(NoWarn)' != '' " />
<_IkvmCompilerArgs Include="-warnaserror" Condition=" '$(TreatWarningsAsErrors)' == 'true' " />
<_IkvmCompilerArgs Include="-warnaserror:$(WarningsAsErrors.Replace(';', ','))" Condition=" '$(TreatWarningsAsErrors)' != 'true' And '$(WarningsAsErrors)' != '' " />
<_IkvmCompilerArgs Include="-assembly:$(AssemblyName)" />
<_IkvmCompilerArgs Include="-version:$(AssemblyVersion)" />
<_IkvmCompilerArgs Include="-runtime:$(IkvmRuntimeAssembly)" />
Expand Down
3 changes: 3 additions & 0 deletions src/IKVM.NET.Sdk/targets/IKVM.Java.Core.Tasks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
Platform="$(PlatformTarget.ToLowerInvariant())"
Main="$(StartupObject)"
Debug="$(DebugType)"
NoWarn="$(NoWarn.Replace(',', ';'))"
WarnAsError="$(TreatWarningsAsErrors)"
WarnAsErrorWarnings="$(WarningsAsErrors.Replace(',', ';'))"
KeyFile="$(KeyOriginatorFile)"
CompressResources="$(CompressResources)"
ClassLoader="$(ClassLoader)"
Expand Down
8 changes: 4 additions & 4 deletions src/IKVM.Tools.Importer/CompilerClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3411,8 +3411,8 @@ sealed class CompilerOptions
internal uint fileAlignment;
internal bool highentropyva;
internal List<CompilerClassLoader> sharedclassloader; // should *not* be deep copied in Copy(), because we want the list of all compilers that share a class loader
internal Dictionary<string, string> suppressWarnings = new Dictionary<string, string>();
internal Dictionary<string, string> errorWarnings = new Dictionary<string, string>(); // treat specific warnings as errors
internal HashSet<string> suppressWarnings = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
internal HashSet<string> errorWarnings = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
internal bool warnaserror; // treat all warnings as errors
internal FileInfo writeSuppressWarningsFile;
internal List<string> proxies = new List<string>();
Expand All @@ -3434,8 +3434,8 @@ internal CompilerOptions Copy()
{
copy.externalResources = new Dictionary<string, string>(externalResources);
}
copy.suppressWarnings = new Dictionary<string, string>(suppressWarnings);
copy.errorWarnings = new Dictionary<string, string>(errorWarnings);
copy.suppressWarnings = new(suppressWarnings, StringComparer.OrdinalIgnoreCase);
copy.errorWarnings = new(errorWarnings, StringComparer.OrdinalIgnoreCase);
return copy;
}

Expand Down
68 changes: 44 additions & 24 deletions src/IKVM.Tools.Importer/IkvmImporterInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,31 +748,15 @@ void ContinueParseCommandLine(RuntimeContext context, StaticCompiler compiler, I
}
else if (s.StartsWith("-nowarn:"))
{
foreach (var w in s.Substring(8).Split(','))
{
// lame way to chop off the leading zeroes
string ws = w;
while (ws.StartsWith("0"))
ws = ws.Substring(1);

options.suppressWarnings[ws] = ws;
}
HandleWarnArg(options.suppressWarnings, s.Substring(8));
}
else if (s == "-warnaserror")
{
options.warnaserror = true;
}
else if (s.StartsWith("-warnaserror:"))
{
foreach (string w in s.Substring(13).Split(','))
{
// lame way to chop off the leading zeroes
string ws = w;
while (ws.StartsWith("0"))
ws = ws.Substring(1);

options.errorWarnings[ws] = ws;
}
HandleWarnArg(options.errorWarnings, s.Substring(13));
}
else if (s.StartsWith("-runtime:"))
{
Expand Down Expand Up @@ -1449,20 +1433,21 @@ internal static void IssueMessage(StaticCompiler compiler, CompilerOptions optio
return;
}

string key = ((int)msgId).ToString();
var msgIdKey = $"{(int)msgId}";
string key = msgIdKey;
for (int i = 0; ; i++)
{
if (options.suppressWarnings.ContainsKey(key))
if (options.suppressWarnings.Contains(key))
{
return;
}
if (i == values.Length)
{
break;
}
key += ":" + values[i];
key = $"{key}:{values[i]}";
}
options.suppressWarnings.Add(key, key);
options.suppressWarnings.Add(key);
if (options.writeSuppressWarningsFile != null)
{
File.AppendAllText(options.writeSuppressWarningsFile.FullName, "-nowarn:" + key + Environment.NewLine);
Expand Down Expand Up @@ -1668,8 +1653,8 @@ internal static void IssueMessage(StaticCompiler compiler, CompilerOptions optio
}
bool error = msgId >= Message.StartErrors
|| (options.warnaserror && msgId >= Message.StartWarnings)
|| options.errorWarnings.ContainsKey(key)
|| options.errorWarnings.ContainsKey(((int)msgId).ToString());
|| options.errorWarnings.Contains(key)
|| options.errorWarnings.Contains(msgIdKey);
Console.Error.Write("{0} IKVMC{1:D4}: ", error ? "error" : msgId < Message.StartWarnings ? "note" : "warning", (int)msgId);
if (error && Message.StartWarnings <= msgId && msgId < Message.StartErrors)
{
Expand All @@ -1689,6 +1674,41 @@ internal static void IssueMessage(StaticCompiler compiler, CompilerOptions optio
}
}

internal static void HandleWarnArg(ICollection<string> target, string arg)
{
foreach (var w in arg.Split(','))
{
// Strip IKVMC prefix
int prefixStart = w.StartsWith("IKVMC", StringComparison.OrdinalIgnoreCase) ? 5 : 0;
int contextIndex = w.IndexOf(':', prefixStart);
string context = string.Empty;
string parse;
if(contextIndex != -1)
{
// context includes ':' separator
context = w.Substring(contextIndex);
parse = w.Substring(prefixStart, contextIndex - prefixStart);
}
else
{
parse = w.Substring(prefixStart);
}

if (!int.TryParse(parse, out var intResult))
{
if (!Enum.TryParse<Message>(parse, out var namedResult))
{
continue; // silently continue
}

// Warnings are handled as int.
intResult = (int)namedResult;
}

// Check IssueMessage
target.Add($"{intResult}{context}");
}
}
}

}
Loading

0 comments on commit 4434f7d

Please sign in to comment.