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] Don't process assemblies over and over again in the UnpackLibraryResources target. Fixes #16377. #16416

Merged
merged 9 commits into from Nov 17, 2022

Conversation

dellis1972
Copy link
Contributor

Fixes #16377

MSbuild has the ability to run Target partially. However in order to make sure we can use this, both the Inputs and Outputs need to have a 1-1 mapping. MSBuild will then use this mapping to figure out which files have actually changed.
Then it will call the Target with only those files.

In Xamarin.Android we make use of stamp files to provide this 1-1 mapping. We have a pre Target which will calculate an ItemGroup which will include a StampFile piece of metadata. We then use this new ItemGroup for both the Inputs and Outputs, thus meeting the 1-1 requirement.

This PR updates the _UnpackLibraryResources to run partially. This will hopefully reduce the build time on incremental builds.

@dellis1972
Copy link
Contributor Author

This is still a work in progress,

@dellis1972 dellis1972 added the enhancement The issue or pull request is an enhancement label Oct 24, 2022
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Member

It fails like this:

/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.CSharp.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.CSharp.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Ref/16.1.530-ci.pr.gh16416/ref/net7.0/Microsoft.iOS.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Ref/16.1.530-ci.pr.gh16416/ref/net7.0/Microsoft.iOS.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.VisualBasic.Core.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.VisualBasic.Core.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
...

@dellis1972
Copy link
Contributor Author

It fails like this:

/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.CSharp.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.CSharp.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Ref/16.1.530-ci.pr.gh16416/ref/net7.0/Microsoft.iOS.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Ref/16.1.530-ci.pr.gh16416/ref/net7.0/Microsoft.iOS.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.iOS.Sdk/16.1.530-ci.pr.gh16416/tools/msbuild/iOS/Xamarin.Shared.targets(1808,3): error MSB3371: The file "obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.VisualBasic.Core.dll.stamp" cannot be created. Could not find a part of the path '/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/obj/Debug/net7.0-ios/ios-arm64/resourcestamps/Users/builder/azdo/_work/1/s/xamarin-macios/builds/downloads/dotnet-sdk-7.0.100-rtm.22531.3/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22511.4/ref/net7.0/Microsoft.VisualBasic.Core.dll.stamp'. [/Users/builder/azdo/_work/1/s/xamarin-macios/msbuild/Xamarin.HotRestart.PreBuilt/Xamarin.PreBuilt.iOS/Xamarin.PreBuilt.iOS.csproj]
...

Yup I accidently used %(Identity) rather than %(FileName) for the stamp file metadata. The Identity contains the full path 🤦

@github-actions
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@dellis1972 dellis1972 marked this pull request as ready for review November 16, 2022 09:47
@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Artifacts were not provided.

Pipeline on Agent XAMBOT-1161.Monterey'
Hash: cee7d283359651e1431d51d451b5c1cc1dafbf7d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: cee7d283359651e1431d51d451b5c1cc1dafbf7d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: cee7d283359651e1431d51d451b5c1cc1dafbf7d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 223 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 23 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: cee7d283359651e1431d51d451b5c1cc1dafbf7d [PR build]

@rolfbjarne rolfbjarne changed the title Don't process assemblies over and over again in the UnpackLibraryResources target [msbuild] Don't process assemblies over and over again in the UnpackLibraryResources target. Fixes #16377. Nov 17, 2022
@rolfbjarne rolfbjarne merged commit 30405fd into xamarin:main Nov 17, 2022
@rolfbjarne
Copy link
Member

/sudo backport release/7.0.2xx

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Backport Job to branch release/7.0.2xx Created! The magic is happening here

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Hooray! Backport succeeded! Please see https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=7195173 for more details.

rolfbjarne added a commit that referenced this pull request Jan 17, 2023
…ain in the UnpackLibraryResources target. Fixes #16377. (#17234)

Fixes #16377 

MSbuild has the ability to run `Target` partially. However in order to make sure we can use this, both the `Inputs` and `Outputs` need to have a 1-1 mapping. MSBuild will then use this mapping to figure out which files have actually changed. Then it will call the Target with only those files. 

In Xamarin.Android we make use of stamp files to provide this 1-1 mapping. We have a `pre` Target which will calculate an ItemGroup which will include a StampFile piece of metadata. We then use this new ItemGroup for both the `Inputs` and `Outputs`, thus meeting the 1-1 requirement. 

This PR updates the `_UnpackLibraryResources` to run partially. This will hopefully reduce the build time on incremental builds. 

Backport of #16416

Co-authored-by: Dean Ellis <dellis1972@googlemail.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue or pull request is an enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't process assemblies over and over again in the UnpackLibraryResources target
5 participants