From bfc3d95d0d2ecc463f845ab16d4e06805bc7bdb1 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 30 Jun 2026 09:06:43 -0500 Subject: [PATCH] [xaprepare] Use Microsoft.SourceLink.GitHub instead of hand-rolled SourceLink.json Stop generating bin/Build$(Configuration)/SourceLink.json from xaprepare and stop overriding $(SourceLink) in Configuration.props. Promote Microsoft.SourceLink.GitHub from a PackageReference Update to a broad PackageReference Include in Directory.Build.targets so every project picks it up, then drop the explicit Include from Microsoft.Android.Run.csproj. Verified with 'sourcelink print-json' on bin\Debug\lib\packs\Microsoft.Android.Runtime.37.android\37.0.0\runtimes\android\lib\net11.0\Mono.Android.pdb: the canonical package produces a documents map covering dotnet/android plus every submodule (Java.Interop, xamarin-android-tools, android-api-docs, constexpr-xxh3, debugger-libs, libunwind, lz4, robin-map, termux-elf-cleaner, xxHash) pointing at the correct upstream raw.githubusercontent.com URLs. Step_GenerateCGManifest and GitSubmoduleInfo / GitRunner are intentionally left for a follow-up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Configuration.props | 3 -- Directory.Build.targets | 6 ++- .../xaprepare/Application/GeneratedFile.cs | 12 ----- .../GeneratedSourceLinkJsonFile.cs | 54 ------------------- .../xaprepare/Steps/Step_GenerateFiles.cs | 31 ++--------- .../Microsoft.Android.Run.csproj | 1 - 6 files changed, 8 insertions(+), 99 deletions(-) delete mode 100644 build-tools/xaprepare/xaprepare/Application/GeneratedSourceLinkJsonFile.cs diff --git a/Configuration.props b/Configuration.props index 870a4620286..38f3dcf8526 100644 --- a/Configuration.props +++ b/Configuration.props @@ -190,9 +190,6 @@ $(AndroidNdkDirectory)\ndk-build.cmd $(MicrosoftAndroidSdkOutDir)bundletool.jar - - $(MSBuildThisFileDirectory)bin/Build$(Configuration)/SourceLink.json - - + + + + + diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedFile.cs index a5aa9399fe4..a2c22860c50 100644 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedFile.cs +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedFile.cs @@ -36,16 +36,4 @@ protected void EnsureOutputDir () Utilities.CreateDirectory (Path.GetDirectoryName (OutputPath)); } } - - sealed class SkipGeneratedFile : GeneratedFile { - - public SkipGeneratedFile () - : base (Path.Combine (BuildPaths.XAPrepareSourceDir, "shall-not-exist.txt")) - { - } - - public override void Generate (Context context) - { - } - } } diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedSourceLinkJsonFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedSourceLinkJsonFile.cs deleted file mode 100644 index 060fe510eba..00000000000 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedSourceLinkJsonFile.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace Xamarin.Android.Prepare -{ - class GeneratedSourceLinkJsonFile : GeneratedFile - { - IEnumerable submodules; - string xaCommit; - - public GeneratedSourceLinkJsonFile (IEnumerable submodules, string xaCommit, string outputPath) - : base (outputPath) - { - this.submodules = submodules ?? throw new ArgumentNullException (nameof (submodules)); - this.xaCommit = !string.IsNullOrEmpty (xaCommit) ? xaCommit : throw new ArgumentNullException (nameof (xaCommit)); - } - - public override void Generate (Context context) - { - var json = new StringBuilder (); - json.AppendLine ("{"); - json.AppendLine (" \"documents\": {"); - - foreach (var submodule in submodules.OrderBy (s => s.Name)) { - var localPath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, submodule.LocalPath); - - var contentUri = new UriBuilder (submodule.RepositoryUrl); - contentUri.Host = "raw.githubusercontent.com"; - contentUri.Path += $"/{submodule.CommitHash}"; - - json.AppendLine ($" \"{localPath}/*\": \"{contentUri.Uri}/*\","); - } - json.AppendLine ($" \"{BuildPaths.XamarinAndroidSourceRoot}/*\": \"https://raw.githubusercontent.com/dotnet/android/{xaCommit}/*\""); - json.AppendLine (" }"); - json.AppendLine ("}"); - - EnsureOutputDir (); - string outputData = json.ToString (); - File.WriteAllText (OutputPath, outputData, Utilities.UTF8NoBOM); - - if (!EchoOutput) - return; - - Log.DebugLine (); - Log.DebugLine ("--------------------------------------------"); - Log.DebugLine (outputData); - Log.DebugLine ("--------------------------------------------"); - Log.DebugLine (); - } - } -} diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs index e4e0f188916..96105963689 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs @@ -10,10 +10,6 @@ partial class Step_GenerateFiles : Step bool atBuildStart; bool onlyRequired; - IEnumerable? gitSubmodules; - string? xaCommit; - - public Step_GenerateFiles (bool atBuildStart, bool onlyRequired = false) : base ("Generating files required by the build") { @@ -21,14 +17,8 @@ public Step_GenerateFiles (bool atBuildStart, bool onlyRequired = false) this.onlyRequired = onlyRequired; } - protected override async Task Execute (Context context) + protected override Task Execute (Context context) { - var git = new GitRunner (context); - xaCommit = git.GetTopCommitHash (workingDirectory: BuildPaths.XamarinAndroidSourceRoot, shortHash: false); - var gitSubmoduleInfo = await git.ConfigList (new[]{"--blob", "HEAD:.gitmodules"}); - var gitSubmoduleStatus = await git.SubmoduleStatus (); - gitSubmodules = GitSubmoduleInfo.GetGitSubmodules (gitSubmoduleInfo, gitSubmoduleStatus); - List? filesToGenerate = GetFilesToGenerate (context); if (filesToGenerate != null && filesToGenerate.Count > 0) { foreach (GeneratedFile gf in filesToGenerate) { @@ -46,19 +36,16 @@ protected override async Task Execute (Context context) } } - return true; + return Task.FromResult (true); } List? GetFilesToGenerate (Context context) { if (atBuildStart) { if (onlyRequired) { - return new List { - Get_SourceLink_Json (context), - }; + return null; } else { return new List { - Get_SourceLink_Json (context), Get_Configuration_OperatingSystem_props (context), Get_XABuildConfig_cs (context), }; @@ -156,17 +143,5 @@ static string GetMinor (string value) return value.Substring (dot + 1); } } - - public GeneratedFile Get_SourceLink_Json (Context context) - { - if (gitSubmodules == null || xaCommit == null) { - return new SkipGeneratedFile (); - } - return new GeneratedSourceLinkJsonFile ( - gitSubmodules!, - xaCommit!, - Path.Combine (Configurables.Paths.BuildBinDir, "SourceLink.json") - ); - } } } diff --git a/src/Microsoft.Android.Run/Microsoft.Android.Run.csproj b/src/Microsoft.Android.Run/Microsoft.Android.Run.csproj index 1f2466451e5..8835a942438 100644 --- a/src/Microsoft.Android.Run/Microsoft.Android.Run.csproj +++ b/src/Microsoft.Android.Run/Microsoft.Android.Run.csproj @@ -15,7 +15,6 @@ -