Skip to content
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

Merged

Conversation

haiyuzhu
Copy link
Contributor

@haiyuzhu haiyuzhu commented Sep 4, 2020

As issue #3181 mentioned, add more information for debugging target circular dependence.
For example,

    <Target Name="TargetA" AfterTargets="Build" DependsOnTargets="TargetB">
        <Message Text="TargetA"></Message>
    </Target>
    <Target Name="TargetB" DependsOnTargets="TargetC">
        <Message Text="TargetB"></Message>
    </Target>
    <Target Name="TargetC" DependsOnTargets="TargetA">
        <Message Text="TargetC"></Message>
    </Target>

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."

@dnfadmin
Copy link

dnfadmin commented Sep 4, 2020

CLA assistant check
All CLA requirements met.

@dnfadmin
Copy link

dnfadmin commented Sep 4, 2020

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ haiyuzhu sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

src/Build.UnitTests/BackEnd/TargetBuilder_Tests.cs Outdated Show resolved Hide resolved
@@ -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);
Copy link
Member

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?

Copy link
Contributor Author

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:

  1. 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 current parentTargetEntry.
  2. 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.

Copy link
Member

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.

Copy link
Contributor Author

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.

<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>
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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));
Copy link
Member

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?

Copy link
Contributor Author

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.

src/Build.UnitTests/BackEnd/TargetBuilder_Tests.cs Outdated Show resolved Hide resolved
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)}.";
Copy link
Member

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.

Copy link
Member

@benvillalobos benvillalobos Oct 30, 2020

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.

Copy link
Contributor Author

@haiyuzhu haiyuzhu Nov 18, 2020

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?

Copy link
Member

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.

src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs Outdated Show resolved Hide resolved
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)}.";
Copy link
Member

@benvillalobos benvillalobos Oct 30, 2020

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.

Copy link
Member

@Forgind Forgind left a 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))
Copy link
Member

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?

Copy link
Contributor Author

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>
@kg kg merged commit 743c545 into dotnet:master Dec 15, 2020
@kg
Copy link
Contributor

kg commented Dec 15, 2020

Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants