-
Notifications
You must be signed in to change notification settings - Fork 517
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
[dotnet] add sourcelink support #20054
Conversation
Fixes xamarin#18968 We provide a mapping to the checked in source files via SourceLink.json and the rest of the generated/untracked sources are embedded into the PDB to provide a more comprehensive debugging experience. Since we invoke CSC directly, there were a few workarounds that had to be implemented (ex: implementing a helper script to account for untracked sources instead of simply using the EmbedUntrackedSources MSBuild property). As for testing, the newly added support was validated via the sourcelink dotnet tool which confirmed all the sources in the PDB either had valid urls or were embedded. sourcelink test Microsoft.MacCatalyst.pdb —> sourcelink test passed: Microsoft.MacCatalyst.pdb The PDB size does increase in size after embedding; for example, Microsoft.MacCatalyst.pdb went from 5 MB to 15.7 MB. But considering it would significantly help improve the debugging experience, be consistent with Android’s offerings, and it’s a highlighted attribute on the NuGet package explorer I think it’s a worthy size increase. Refs: dotnet/android#7298 dotnet/roslyn#12625 https://github.com/dotnet/sourcelink/tree/main/docs
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.
sourcelink test Microsoft.MacCatalyst.pdb —> sourcelink test passed: Microsoft.MacCatalyst.pdb
Jon Pryor mentioned this takes a while to run: how long does it take for you?
It might make sense to create a test to ensure we don't accidentally forget to embed files in the pdb in the future.
src/Makefile
Outdated
@@ -1213,6 +1213,12 @@ dotnet-gen:: dotnet-gen-$(3) | |||
$($(2)_DOTNET_BUILD_DIR)/ILLink.LinkAttributes.xml: $(TOP)/src/ILLink.LinkAttributes.xml.in | $($(2)_DOTNET_BUILD_DIR) | |||
$$(call Q_PROF_GEN,$(3)) sed < $$< > $$@ 's|@PRODUCT_NAME@|Microsoft.$(1)|g;' | |||
|
|||
$($(2)_DOTNET_BUILD_DIR)/SourceLink.json: $($(2)_DOTNET_BUILD_DIR) | |||
$$(Q) $(TOP)/src/generate-sourcelink-json.csharp "$(PACKAGE_HEAD_REV)" "$(abspath $(TOP)/src)" "$$@" >/dev/null 2>&1 |
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.
While I really like quiet build output, piping it all to /dev/null makes diagnosing failures hard... typically I try to not create the output in the first place. Could you explain the exact output you're getting 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.
@rolfbjarne it's printing out the contents of the json file, but i'll explore options on how to prevent that some other 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.
@rolfbjarne opted to use a stream writer as opposed to a string builder so now the build output is a bit less verbose without manually piping it all away!
src/generate-embed-files.sh
Outdated
@@ -0,0 +1,28 @@ | |||
#!/bin/bash -e | |||
|
|||
find_files() { |
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 have a thought: I believe these two variables will contain/list all the source files:
$$($(2)_DOTNET_SOURCES)
@$($(2)_DOTNET_BUILD_DIR)/$(3)-generated-sources
Lines 1288 to 1289 in 02947b2
$$($(2)_DOTNET_SOURCES) \ | |
@$($(2)_DOTNET_BUILD_DIR)/$(3)-generated-sources \ |
So maybe use a very different implementation: create a list of all those files, and then exclude any files in git, which I think should be the list you want to pass as -embed:?
You can get the files in git by doing git ls-files
.
This seems somewhat more future-proof in that it's less likely for us to forget to update this script if we add more custom-generated files to the build.
Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
it's not bad: sure, i can create a test! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
tests/dotnet/UnitTests/Extensions.cs
Outdated
@@ -1,4 +1,5 @@ | |||
using System; | |||
using System.Diagnostics; |
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.
There are no other changes in this file, so I don't think you need to add a using
.
var tool = "sourcelink"; | ||
var toolPath = Directory.GetCurrentDirectory (); | ||
DotNet.InstallTool (tool, toolPath); | ||
var test = DotNet.RunTool ($"{toolPath}/{tool}", "test", $"{pdbFile}"); |
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.
var test = DotNet.RunTool ($"{toolPath}/{tool}", "test", $"{pdbFile}"); | |
var test = DotNet.RunTool (Path.Combine (toolPath, tool), "test", pdbFile); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💻 [PR Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build] Windows Integration Tests passed 💻✅ All Windows Integration Tests passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11) passed 💻✅ All tests on macOS M1 - Mac Big Sur (11) passed. Pipeline on Agent |
📚 [PR Build] Artifacts 📚Packages generatedView packagesPipeline on Agent |
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 1 tests failed, 169 tests passed. Failures❌ monotouch tests (MacCatalyst)
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Fixes #18968
We provide a mapping to the checked in source files via SourceLink.json and the rest of the generated/untracked sources are embedded into the PDB to provide a more comprehensive debugging experience. Since we invoke CSC directly, there were a few workarounds that had to be implemented (ex: implementing a helper script to account for untracked sources instead of simply using the EmbedUntrackedSources MSBuild property).
As for testing, the newly added support was validated via the dotnet sourcelink tool which confirmed all the sources in the PDB either had valid urls or were embedded.
sourcelink test Microsoft.MacCatalyst.pdb
—>sourcelink test passed: Microsoft.MacCatalyst.pdb
The PDB size does increase in size after embedding; Microsoft.MacCatalyst.pdb went from 5 MB to 15.7 MB.
But considering it would significantly help improve the debugging experience, be consistent with Android’s offerings, and it’s a highlighted attribute on the NuGet package explorer I think it’s a worthy size increase.
Refs:
dotnet/android#7298
dotnet/roslyn#12625
https://github.com/dotnet/sourcelink/tree/main/docs