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

Fix build break because of missing metdata #8364

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,44 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk
{
public class ChooseBestTargetFrameworksTask : BuildTask
{
[Required]
public string[] BuildTargetFrameworks { get; set; }
public ITaskItem[] BuildTargetFrameworks { get; set; }

[Required]
public string RuntimeGraph { get; set; }

[Required]
public string[] SupportedTargetFrameworks { get; set; }

// Returns distinct items only. Compares the include values. Metadata is ignored.
public bool Distinct { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to turn this off or on and why can't the behavior just be that we always return a Distinct value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Details are in the top comment. The binplacing logic which also uses this task requires non distinct values where-as the DispatchToInnerBuild logic which is responsible for filtering out non applicable inner builds requires distinct values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, makes sense.


[Output]
public string[] BestTargetFrameworks { get; set; }
public ITaskItem[] BestTargetFrameworks { get; set; }

public override bool Execute()
{
var bestTargetFrameworkList = new HashSet<string>(BuildTargetFrameworks.Length);
var bestTargetFrameworkList = new List<ITaskItem>(BuildTargetFrameworks.Length);
var targetframeworkResolver = new TargetFrameworkResolver(RuntimeGraph);

foreach (string buildTargetFramework in BuildTargetFrameworks)
foreach (ITaskItem buildTargetFramework in BuildTargetFrameworks)
{
string bestTargetFramework = targetframeworkResolver.GetBestSupportedTargetFramework(SupportedTargetFrameworks, buildTargetFramework);
if (bestTargetFramework != null)
string bestTargetFramework = targetframeworkResolver.GetBestSupportedTargetFramework(SupportedTargetFrameworks, buildTargetFramework.ItemSpec);
if (bestTargetFramework != null && (!Distinct || !bestTargetFrameworkList.Any(b => b.ItemSpec == bestTargetFramework)))
{
bestTargetFrameworkList.Add(bestTargetFramework);
var item = new TaskItem(bestTargetFramework);
buildTargetFramework.CopyMetadataTo(item);
bestTargetFrameworkList.Add(item);
}
}

BestTargetFrameworks = new string[bestTargetFrameworkList.Count];
bestTargetFrameworkList.CopyTo(BestTargetFrameworks);

BestTargetFrameworks = bestTargetFrameworkList.ToArray();
return !Log.HasLoggedErrors;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

<ChooseBestTargetFrameworksTask BuildTargetFrameworks="@(_BuildTargetFrameworkWithTargetOS);$(AdditionalBuildTargetFrameworks)"
SupportedTargetFrameworks="$(TargetFrameworks)"
RuntimeGraph="$(RuntimeGraph)">
RuntimeGraph="$(RuntimeGraph)"
Distinct="true">
<Output TaskParameter="BestTargetFrameworks" ItemName="_BestTargetFramework" />
</ChooseBestTargetFrameworksTask>

Expand Down