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

[msbuild] Fix how UnpackLibraryResources handles mscorlib.dll (and potentially other framework assemblies) #1011

Merged
merged 3 commits into from
Jan 10, 2017
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
1 change: 1 addition & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ Copyright (C) 2014 Xamarin. All rights reserved.
Prefix="xammac"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(IntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ResolvedFiles)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="FileWrites" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public abstract class UnpackLibraryResourcesTaskBase : Task
[Required]
public ITaskItem[] ReferencedLibraries { get; set; }

[Required]
public ITaskItem[] TargetFrameworkDirectory { get; set; }

#endregion

#region Outputs
Expand All @@ -42,14 +45,17 @@ public override bool Execute ()
Log.LogTaskProperty ("IntermediateOutputPath", IntermediateOutputPath);
Log.LogTaskProperty ("NoOverwrite", NoOverwrite);
Log.LogTaskProperty ("ReferencedLibraries", ReferencedLibraries);
Log.LogTaskProperty ("TargetFrameworkDirectory", TargetFrameworkDirectory);

// TODO: give each assembly its own intermediate output directory
// TODO: use list file to avoid re-extracting assemblies but allow FileWrites to work
var results = new List<ITaskItem> ();
HashSet<string> ignore = null;

foreach (var asm in ReferencedLibraries) {
if (asm.GetMetadata ("ResolvedFrom") == "{TargetFrameworkDirectory}") {
// mscorlib.dll was not coming out with ResolvedFrom == {TargetFrameworkDirectory}
// and what we really care is where it comes from, not how it was resolved
if (IsFrameworkAssembly (asm)) {
Log.LogMessage (MessageImportance.Low, " Skipping framework assembly: {0}", asm.ItemSpec);
} else {
var extracted = ExtractContentAssembly (asm.ItemSpec, IntermediateOutputPath);
Expand Down Expand Up @@ -83,6 +89,16 @@ public override bool Execute ()
return !Log.HasLoggedErrors;
}

bool IsFrameworkAssembly (ITaskItem asm)
{
var asm_path = asm.GetMetadata ("FullPath");
foreach (var dir in TargetFrameworkDirectory) {
if (asm_path.StartsWith (dir.GetMetadata ("FullPath"), StringComparison.OrdinalIgnoreCase))
return true;
Copy link
Member

Choose a reason for hiding this comment

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

Depending on how the TaskItem is created, the ItemSpec may be a relative path so it may be better to use the full path of each item using this approach:

var path = item.GetMetadata ("FullPath");

Obviously we can do this outside the loop for asm as an optimization.

My other suggestion is that we may want to use an OrdinalIgnoreCase compare since the Mac file system is case insensitive by default.

}
return false;
}

IEnumerable<ITaskItem> ExtractContentAssembly (string assembly, string intermediatePath)
{
Log.LogMessage (MessageImportance.Low, " Inspecting assembly: {0}", assembly);
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
Prefix="monotouch"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ReferencePath);@(ReferenceDependencyPaths)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
</UnpackLibraryResources>
Expand Down