Skip to content

Commit 0778165

Browse files
grendellojonpryor
authored andcommitted
[api-merge] Normalize paths for comparisons (#1278)
The [macOS+xbuild build][0] is [broken][1]: obj/Debug/android-10/mcw/Android.Content.ContentProvider.cs(282,84): error CS0234: The type or namespace name 'Collections' does not exist in the namespace 'Android.System' (are you missing an assembly reference?) ...and 1271 other similar errors... [0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/855/ [1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/855/consoleText The apparent cause is 7d705bf, which updated the build process to generate `api.xml` files from `android-*.jar` at build time, instead of requiring pre-generated paths within `src/Mono.Android/Profiles`, as the `api-merge.exe` invocation was altered. The *actual* cause is a latent bug in `api-merge.exe`: when using `api-merge FILES --last-description=FILE`, `FILE` is incorrectly compared with the list of `FILES`. When building with `xbuild`, the `@(_AndroidProfile)` item group contains *full path names*, while the `--last-description` option is a relative path: Executing: mono ../../bin/BuildDebug/api-merge.exe -o "obj/Debug/android-10/mcw/api.xml" \ -s '../../bin/BuildDebug/api/api-*.xml.in' \ …/xamarin-android/bin/BuildDebug/api/api-10.xml.in \ ... --last-description=../../bin/BuildDebug/api/api-10.xml.in Because `api-merge` didn't normalize the path names, it attempted to compare `…/xamarin-android/bin/BuildDebug/api/api-10.xml.in` to `../../bin/BuildDebug/api/api-10.xml.in`, which *always failed*. Consequently, the resulting `obj/Debug/android-10/mcw/api.xml` file contained *all* API levels, including the `android.system` package (introduced in API-21), while not containing the namespace renaming logic to map `android.system` to `Android.Systems`. The result is that e.g. obj/Debug/android-10/mcw/Android.Content.ContentProvider.cs` contained "innocuous" identifiers such as `System.Collections.Generic.IList<Android.Content.ContentProviderOperation>` which were being incorrectly resolved to `Android.System.Collections.Generic.IList<Android.Content.ContentProviderOperation>`, which doesn't exist. Fix `api-merge` so that it compares *full paths* to `api-merge --last-description=FILE`, allowing the `api-merge` command to properly stop merging APIs once it's hit (in this case) `api-10.xml.in`.
1 parent d46abe8 commit 0778165

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build-tools/api-merge/api-merge.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static int Main (string[] args)
3232
v => glob = v },
3333
{ "last-description=",
3434
"Last {DESCRIPTION} to process. Any later descriptions are ignored.",
35-
v => lastDescription = v },
35+
v => lastDescription = NormalizePath (v) },
3636
{ "version",
3737
"Output version information and exit.",
3838
v => show_version = v != null },
@@ -69,14 +69,22 @@ public static int Main (string[] args)
6969
SortSources (sources, glob);
7070
ApiDescription context = new ApiDescription (sources [0]);
7171
for (int i = 1; i < sources.Count; i++) {
72-
if (sources [i-1] == lastDescription)
72+
if (NormalizePath (sources [i-1]) == lastDescription)
7373
break;
7474
context.Merge (sources [i]);
7575
}
7676
context.Save (dest);
7777
return 0;
7878
}
7979

80+
static string NormalizePath (string path)
81+
{
82+
if (String.IsNullOrEmpty (path))
83+
return path;
84+
85+
return Path.GetFullPath (path);
86+
}
87+
8088
static void SortSources (List<string> sources, string globPattern)
8189
{
8290
if (globPattern == null)

0 commit comments

Comments
 (0)