Skip to content

Commit 60b031c

Browse files
Normalize reverse-mapped Java source paths
Convert manifest-style JNI paths to the native directory separator at the filesystem copy boundary. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent ed2522d commit 60b031c

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ internal ITaskItem [] CopyJavaSourcesFromInputDirectory (IReadOnlyList<Generated
366366
if (relativePath == null) {
367367
continue;
368368
}
369+
relativePath = NormalizeJavaSourceRelativePath (relativePath, Path.DirectorySeparatorChar);
369370
string inputPath = Path.Combine (JavaSourceInputDirectory ?? "", relativePath);
370371
if (!File.Exists (inputPath)) {
371372
Log.LogCodedError ("XA4255", Properties.Resources.XA4255, inputPath);
@@ -385,6 +386,9 @@ internal ITaskItem [] CopyJavaSourcesFromInputDirectory (IReadOnlyList<Generated
385386
return items.ToArray ();
386387
}
387388

389+
internal static string NormalizeJavaSourceRelativePath (string relativePath, char directorySeparator)
390+
=> relativePath.Replace ('/', directorySeparator);
391+
388392
string? GetOriginalJavaSourceRelativePath (string generatedRelativePath)
389393
{
390394
if (r8Mapping == null || reverseR8Mapping == null || !generatedRelativePath.EndsWith (".java", StringComparison.OrdinalIgnoreCase)) {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GenerateTrimmableTypeMapTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ public void CopyJavaSources_ReverseMapsObfuscatedNestedClassPath ()
178178
FileAssert.DoesNotExist (Path.Combine (outputDir, "g.java"));
179179
}
180180

181+
[TestCase ('/', "com/example/Outer$Inner.java")]
182+
[TestCase ('\\', "com\\example\\Outer$Inner.java")]
183+
public void NormalizeJavaSourceRelativePath_UsesDirectorySeparator (char directorySeparator, string expected)
184+
{
185+
Assert.AreEqual (
186+
expected,
187+
GenerateTrimmableTypeMap.NormalizeJavaSourceRelativePath ("com/example/Outer$Inner.java", directorySeparator));
188+
}
189+
181190
[TestCase ("C\tcom/example/First\nC\tcom/example/Second\n", TestName = "CopyJavaSources_MergedClassIsAmbiguous")]
182191
[TestCase ("C\tcom/example/Unrelated\n", TestName = "CopyJavaSources_MissingRequiredReverseEntry")]
183192
public void CopyJavaSources_InvalidReverseMappingUsesXA4327 (string manifest)

0 commit comments

Comments
 (0)