-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Users/haiz/add verbosity for target circular dependence #5711
Users/haiz/add verbosity for target circular dependence #5711
Conversation
|
@@ -689,7 +689,7 @@ private async Task<bool> PushTargets(IList<TargetSpecification> targets, TargetE | |||
} | |||
|
|||
// We are already building this target on this request. That's a circular dependency. | |||
ProjectErrorUtilities.ThrowInvalidProject(targetLocation, "CircularDependency", targetSpecification.TargetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to log the parent graph of these, too? Maybe log what it currently logs at normal verbosity and log the parents at diagnostic verbosity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some investigation here. I think it is hard to get the parent graph here.
Here are my reasons:
- We use
_requestEntry.RequestConfiguration.ActivelyBuildingTargets
to store the targets are being executed. If the current target is in this dictionary, which means we can't find the circular by checking the currentparentTargetEntry
. - Since the target is in
_requestEntry.RequestConfiguration.ActivelyBuildingTargets
, this also means we have lost the previous parent information to add it to_requestEntry.RequestConfiguration.ActivelyBuildingTargets
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the reason you gave to not use parentTargetEntry. You're saying that we already would have checked for a cycle via parentTargetEntry, so if it gets here, that way to figure out the cycle won't work? Or are you saying the parentTargetEntry is often null?
If there is no way to get the parent information, then I think this is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean "we already would have checked for a cycle via parentTargetEntry, so if it gets here, that way to figure out the cycle won't work". So I think currently we have no way to get the parent information.
src/Build/Resources/Strings.resx
Outdated
<value>MSB4006: There is a circular dependency in the target dependency graph involving target "{0}".</value> | ||
<comment>{StrBegin="MSB4006: "}UE: This message is shown when the build engine detects a target referenced in a circular manner -- a project cannot | ||
request a target to build itself (perhaps via a chain of other targets).</comment> | ||
</data> | ||
<data name="CircularDependencyInTargetGraphWithVerbosity" xml:space="preserve"> | ||
<value>MSB4006: There is a circular dependency in the target dependency graph involving target "{0}". Target "{1}" has a "{2}" dependency on it, but it is depended upon by {3}.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up with a different error, we'd need a new error code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this is the same error: Target Circular dependence. The only one reason why I add a new error message format is that the output is totally different from the old one. And I have no good idea to merge the different message output format into one. Any suggestions here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One idea is that if we can print the dependence graph when circular dependence failer is triggered. let me do more investigation and I will get back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to add a new error code because this is a circular error of targets. I modify the key of the error message to improve the readability and merge the message format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm convinced.
if (String.Equals(currentParent.Name, targetSpecification.TargetName, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// We are already building this target on this request. That's a circular dependency. | ||
ProjectErrorUtilities.ThrowInvalidProject(targetLocation, "CircularDependency", targetSpecification.TargetName); | ||
ProjectErrorUtilities.ThrowInvalidProject(targetLocation, "CircularDependencyInTargetGraphWithVerbosity", targetSpecification.TargetName, parentTargetEntry.Name, buildReason, string.Join("<-", parentChain)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you account for verbosity in any way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve the format of circular target dependence error message.
if (String.Equals(currentParent.Name, targetSpecification.TargetName, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// We are already building this target on this request. That's a circular dependency. | ||
ProjectErrorUtilities.ThrowInvalidProject(targetLocation, "CircularDependency", targetSpecification.TargetName); | ||
string errorMessage = $"Since \"{parentTargetEntry.Name}\" has \"{buildReason}\" dependence on \"{targetSpecification.TargetName}\", the circular is {string.Join("<-", parentChain)}."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's better to have this sort of thing in strings (and having two separate but almost identical error messages) is that there, it gets translated into a variety of different languages. If we leave it here, everyone worldwide would see it in English.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, as much of the error message should exist within the resource as possible. Though I see the reason it is in its current state.
I propose we have two resources here with the same error code: ``` and CircularDependencyInTargetGraph
. Same error code, different message where `CircularDependencyInTargetGraph` has most of the message listed here with many more required arguments. And `CircularDependency` remains the same.
Of course, the ThrowInvalidProject
calls that pass null will no longer need to pass null, so long as they revert to the CircularDependency
resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Forgind , I agree with @benvillalobos 's proposal. I once did this in previous commits. Do you have any concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's fine. I was pushing for two separate error messages in strings, but although it wasn't clear, I'm fine with them sharing an error code in this case.
if (String.Equals(currentParent.Name, targetSpecification.TargetName, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// We are already building this target on this request. That's a circular dependency. | ||
ProjectErrorUtilities.ThrowInvalidProject(targetLocation, "CircularDependency", targetSpecification.TargetName); | ||
string errorMessage = $"Since \"{parentTargetEntry.Name}\" has \"{buildReason}\" dependence on \"{targetSpecification.TargetName}\", the circular is {string.Join("<-", parentChain)}."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, as much of the error message should exist within the resource as possible. Though I see the reason it is in its current state.
I propose we have two resources here with the same error code: ``` and CircularDependencyInTargetGraph
. Same error code, different message where `CircularDependencyInTargetGraph` has most of the message listed here with many more required arguments. And `CircularDependency` remains the same.
Of course, the ThrowInvalidProject
calls that pass null will no longer need to pass null, so long as they revert to the CircularDependency
resource.
Co-authored-by: Forgind <Forgind@users.noreply.github.com> Co-authored-by: Ben Villalobos <4691428+BenVillalobos@users.noreply.github.com>
…circular dependence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for this!
|
||
while (currentParent != null) | ||
{ | ||
if (String.Equals(currentParent.Name, targetSpecification.TargetName, StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's relevant which StringComparison you're using here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct.
Co-authored-by: Forgind <Forgind@users.noreply.github.com>
Thank you very much for your contribution! |
As issue #3181 mentioned, add more information for debugging target circular dependence.
For example,
The error message will be:
There is a circular dependency in the target dependency graph involving target "TargetA". Since "TargetC" has "DependsOn" dependence on "TargetA", the circular is "TargetA<-TargetC<-TargetB<-TargetA."