Implement /WarnAsError to treat specified warnings as errors#1355
Implement /WarnAsError to treat specified warnings as errors#1355jeffkl merged 1 commit intodotnet:xplatfrom
Conversation
rainersigwald
left a comment
There was a problem hiding this comment.
Biggest concern is the additive-vs-override nature of multiple arguments.
There was a problem hiding this comment.
Is there a named constant somewhere for the magic -1?
There was a problem hiding this comment.
I did a quick search and didn't find anything. I saw this line and figured it was okay to use -1. Should I declare a constant like NullSubmissionId ?
There was a problem hiding this comment.
Is there a good way to abstract this logic? It's pretty repetitive in here. Maybe EnsureFailureIfWarningsAsErrors(BuildResult, ILoggingService)?
There was a problem hiding this comment.
Good idea, I can make a method that does this for two of the places.
There was a problem hiding this comment.
It's probably not worth changing this, but I would hazard a guess that for this use case (small sets of inputs), a SortedSet might actually be faster.
There was a problem hiding this comment.
I did some limited research on what was faster and from what I could tell there was no difference. Do you know of any guidance on which is faster? I wanted the fastest possible lookup for sure.
There was a problem hiding this comment.
AFAIK it's highly dependent on the individual use case, so we probably can't tell for this case without extensive benchmarking.
My understanding is based on Pike's third rule: Fancy algorithms are slow when n is small, and n is usually small. In this case, a hashtable is awesomely super fast, linear lookup . . . but requires hashing and indirection/pointer-following. A sorted set that is small, as I expect this thing to be, could easily use fewer instructions per lookup.
But we'd have to measure to know (Rule 2!) and I don't think this will be worth worrying about, so I'd say to leave it as-is.
There was a problem hiding this comment.
I just did some benchmarks. If you have 10 warnings to set as errors and your build logs 10,000 warnings, the fastest is to use HashSet<T>(StringComparer.OrdinalIgnoreCase). I tried doing a case sensitive search but things placed in the set are upper case and the item being checked for is uppercased before the check but that was slower. The SortedSet<T> was just a little bit slower.
In my scenario, it took 1.04 milliseconds to check 10,000 times for the 10 items. I think the perf here is good enough but at least know we know. :emoji-for-the-'the-more-you-know'-public-service-annoncement:
There was a problem hiding this comment.
Alternatively, declare this as an ImmutableHashset and just copy the reference rather than cloning a new one. Theoretically they are slower, with logn lookup. Can you benchmark this one as well? :)
In reply to: 88770185 [](ancestors = 88770185)
There was a problem hiding this comment.
Hmm. The double-use here seems a bit mysterious, in a way it doesn't on the command line. But it's not wrong . . .
There was a problem hiding this comment.
I was trying to avoid having another property like bool HasUserSpecifiedWarningsAsErrors so I am using the three states of a reference type; null, not null; or has a value. The usages of these are all internal so we can change it later. I made this decision for simplicity but am open to suggestions.
There was a problem hiding this comment.
Yikes! But I guess it's not worth implementing IEquatable just for this test.
There was a problem hiding this comment.
Yeah I thought about making a Clone() method as well but I didn't want to go there... This unit test made sure I was properly copying every single property when I mutate the warning into an error (and I did miss one 😄)
There was a problem hiding this comment.
"but the overall build will fail." seems a bit clearer.
There was a problem hiding this comment.
Haha that's what I had originally and then I second guessed myself :sad:
There was a problem hiding this comment.
Is this test implying that the switches are additive? I find that a bit surprising. And definitely I find it surprising that if the last one is a no-code-specified-turn-everything-on setting, that doesn't win.
There was a problem hiding this comment.
I was imaging a scenario where the list of warning codes was specified in one or more response files, an environment variable and the command-line. I figured I would just conglomerate them into one set. If this is the case, then specifying the switch by itself doesn't add any more codes and some codes already exist so the functionality is to only treat the specified codes as errors.
This is sort of how /p:foo=bar works minus the ability to clear them all by specifying just /p. Let's discuss this tomorrow.
There was a problem hiding this comment.
For posterity: we discussed, and decided that the additive model makes sense, but a new no-code-specified setting should override previous specific ones. If you need to clear the setting you can do /warnaserror /warnaserror:X to get back to a "just X" state.
There was a problem hiding this comment.
ResourceManager.GetResourceSet() doesn't exist on .NET core. This test is just making sure I typed up the new command-line argument usage correctly and so it technically doesn't matter if it isn't running on .NET Core since it's testing all of the switches. The RESX resources are not #ifdef'd out, only the display of them.
Should I put a comment?
src/XMakeCommandLine/XMake.cs
Outdated
5be587d to
25c00b7
Compare
There was a problem hiding this comment.
This originally said "an empty string", thanks for catching it
There was a problem hiding this comment.
For posterity: we discussed, and decided that the additive model makes sense, but a new no-code-specified setting should override previous specific ones. If you need to clear the setting you can do /warnaserror /warnaserror:X to get back to a "just X" state.
src/XMakeCommandLine/XMake.cs
Outdated
There was a problem hiding this comment.
I don't feel strongly about this. Doesn't seem worth it.
|
I'm going to squash this and re-push. When we're ready I'd like to do a merge commit so I can start on the /NoWarn switch and not have any merge conflicts. |
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn. * Feature switch FEATURE_RESOURCEMANAGER_GETRESOURCESET * Support for command-line arguments having empty values
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail.
Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail.
Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure.
Related to #68 and will close in my next change to add /NoWarn.
Help text should be reviewed as well: