Skip to content

Commit d4c8f07

Browse files
jpobstjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Avoid MSB4018; use XA[A-Z]{3}7[0-9]{3} (#3609)
Changes: https://github.com/xamarin/monodroid/compare/3ed4b1921a43a6bf5718e82c923040e2512dd8cf...623845d44abe5eb7a76d9a63d48b30a27ac1bac2 Bumps to xamarin/monodroid/master@623845d4. Errors and warning *codes* for errors and warnings reported *within Visual Studio* from developers participating in the [Visual Studio Customer Experience Improvement Program][0] are reported "telemetry" events, but *only* the error and warning codes are reported. The warning and error message contents are not sent. Unfortunately all unhandled exceptions not caught within our MSBuild tasks are reported as `MSB4018`, which reduces the utility of telemetry, making it more difficult to better understand where our build system could be improved. Update all of our tasks to inherit from one of the new types `AndroidTask`, `AndroidAsyncTask`, or `AndroidToolTask`. These tasks add catch-all exception handlers that capture and log unhandled exceptions instead of allowing them to leak out to MSBuild, producing more useful error and warning message codes for telemetry. Each error code contains: 1. An `XA` prefix to denote that it is from Xamarin.Android so our codes do not collide with other components. 2. Three-letters to designate which Task is throwing the error. For example, the `<Aot/>` task uses `AOT` while the `<LinkAssemblies/>` task uses `LNK`. 3. A `7` to designate unhandled exceptions. 4. Three digits to specify a particular exception type, or `000` for an unmapped exception type. See `src/Xamarin.Android.Build.Tasks/Utilities/UnhandledExceptionLogger.cs` for the mapping from exception types to numbers. For example, a `NullReferenceException` thrown from the `<LinkAssemblies>` task will now result in an XALNK7001 error (instead of an MSB4018), while a `StackOverflowException` within the `<Aot/>` task will result in an XAAOT7016 error. [0]: https://docs.microsoft.com/en-us/visualstudio/ide/visual-studio-experience-improvement-program?view=vs-2019
1 parent a85dd5b commit d4c8f07

File tree

116 files changed

+713
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+713
-232
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:master@3ed4b1921a43a6bf5718e82c923040e2512dd8cf
1+
xamarin/monodroid:master@623845d44abe5eb7a76d9a63d48b30a27ac1bac2
22
mono/mono:2019-08@29b1ac19c961b959a09097dbc0fe4cd567cc5298

Documentation/guides/messages/README.md

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,150 @@ ms.date: 08/23/2019
103103

104104
## XA6xxx: Internal tools
105105

106-
## XA7xxx: Reserved
106+
## XA7xxx: Unhandled MSBuild Exceptions
107+
108+
Exceptions that have not been gracefully handled yet. Ideally these will be fixed or replaced with better errors in the future.
109+
110+
These take the form of `XACCC7NNN`, where `CCC` is a 3 character code denoting the MSBuild Task that is throwing the exception,
111+
and `NNN` is a 3 digit number indicating the type of the unhandled `Exception`.
112+
113+
**Tasks:**
114+
* `A2C` - `Aapt2Compile`
115+
* `A2L` - `Aapt2Link`
116+
* `AAS` - `AndroidApkSigner`
117+
* `ACD` - `AndroidCreateDebugKey`
118+
* `ACM` - `AppendCustomMetadataToItemGroup`
119+
* `ADB` - `Adb`
120+
* `AJV` - `AdjustJavacVersionArguments`
121+
* `AOT` - `Aot`
122+
* `APT` - `Aapt`
123+
* `ASP` - `AndroidSignPackage`
124+
* `AZA` - `AndroidZipAlign`
125+
* `BAB` - `BuildAppBundle`
126+
* `BAS` - `BuildApkSet`
127+
* `BBA` - `BuildBaseAppBundle`
128+
* `BGN` - `BindingsGenerator`
129+
* `BLD` - `BuildApk`
130+
* `CAL` - `CreateAdditionalLibraryResourceCache`
131+
* `CAR` - `CalculateAdditionalResourceCacheDirectories`
132+
* `CCR` - `CopyAndConvertResources`
133+
* `CCV` - `ConvertCustomView`
134+
* `CDF` - `ConvertDebuggingFiles`
135+
* `CDJ` - `CheckDuplicateJavaLibraries`
136+
* `CFI` - `CheckForInvalidResourceFileNames`
137+
* `CFR` - `CheckForRemovedItems`
138+
* `CGJ` - `CopyGeneratedJavaResourceClasses`
139+
* `CGS` - `CheckGoogleSdkRequirements`
140+
* `CIC` - `CopyIfChanged`
141+
* `CIL` - `CilStrip`
142+
* `CLA` - `CollectLibraryAssets`
143+
* `CLC` - `CalculateLayoutCodeBehind`
144+
* `CLP` - `ClassParse`
145+
* `CLR` - `CreateLibraryResourceArchive`
146+
* `CMD` - `CreateMultiDexMainDexClassList`
147+
* `CML` - `CreateManagedLibraryResourceArchive`
148+
* `CMM` - `CreateMsymManifest`
149+
* `CNA` - `CompileNativeAssembly`
150+
* `CNE` - `CollectNonEmptyDirectories`
151+
* `CNL` - `CreateNativeLibraryArchive`
152+
* `CPD` - `CalculateProjectDependencies`
153+
* `CPF` - `CollectPdbFiles`
154+
* `CPI` - `CheckProjectItems`
155+
* `CPR` - `CopyResource`
156+
* `CPT` - `ComputeHash`
157+
* `CRC` - `ConvertResourcesCases`
158+
* `CRM` - `CreateResgenManifest`
159+
* `CRN` - `Crunch`
160+
* `CRP` - `AndroidComputeResPaths`
161+
* `CTD` - `CreateTemporaryDirectory`
162+
* `CTX` - `CompileToDalvik`
163+
* `DES` - `Desugar`
164+
* `DJL` - `DetermineJavaLibrariesToCompile`
165+
* `DX8` - `D8`
166+
* `FLB` - `FindLayoutsToBind`
167+
* `FLT` - `FilterAssemblies`
168+
* `GAD` - `GetAndroidDefineConstants`
169+
* `GAP` - `GetAndroidPackageName`
170+
* `GAR` - `GetAdditionalResourcesFromAssemblies`
171+
* `GAS` - `GetAppSettingsDirectory`
172+
* `GCB` - `GenerateCodeBehindForLayout`
173+
* `GCJ` - `GetConvertedJavaLibraries`
174+
* `GEP` - `GetExtraPackages`
175+
* `GFT` - `GetFilesThatExist`
176+
* `GIL` - `GetImportedLibraries`
177+
* `GJP` - `GetJavaPlatformJar`
178+
* `GJS` - `GenerateJavaStubs`
179+
* `GLB` - `GenerateLayoutBindings`
180+
* `GLR` - `GenerateLibraryResources`
181+
* `GMA` - `GenerateManagedAidlProxies`
182+
* `GMJ` - `GetMonoPlatformJar`
183+
* `GPM` - `GeneratePackageManagerJava`
184+
* `GRD` - `GenerateResourceDesigner`
185+
* `IAS` - `InstallApkSet`
186+
* `IJD` - `ImportJavaDoc`
187+
* `JDC` - `JavaDoc`
188+
* `JVC` - `Javac`
189+
* `JTX` - `JarToXml`
190+
* `KEY` - `KeyTool`
191+
* `LAS` - `LinkApplicationSharedLibraries`
192+
* `LEF` - `LogErrorsForFiles`
193+
* `LNK` - `LinkAssemblies`
194+
* `LNS` - `LinkAssembliesNoShrink`
195+
* `LNT` - `Lint`
196+
* `LWF` - `LogWarningsForFiles`
197+
* `MBN` - `MakeBundleNativeCodeExternal`
198+
* `MDC` - `MDoc`
199+
* `MER` - `MergeResources`
200+
* `PAI` - `PrepareAbiItems`
201+
* `PAW` - `ParseAndroidWearProjectAndManifest`
202+
* `PRO` - `Proguard`
203+
* `PWA` - `PrepareWearApplicationFiles`
204+
* `R8D` - `R8`
205+
* `RAM` - `ReadAndroidManifest`
206+
* `RAR` - `ReadAdditionalResourcesFromAssemblyCache`
207+
* `RAT` - `ResolveAndroidTooling`
208+
* `RDF` - `RemoveDirFixed`
209+
* `RIL` - `ReadImportedLibrariesCache`
210+
* `RJJ` - `ResolveJdkJvmPath`
211+
* `RLC` - `ReadLibraryProjectImportsCache`
212+
* `RLP` - `ResolveLibraryProjectImports`
213+
* `RRA` - `RemoveRegisterAttribute`
214+
* `RSA` - `ResolveAssemblies`
215+
* `RSD` - `ResolveSdks`
216+
* `RUF` - `RemoveUnknownFiles`
217+
* `SPL` - `SplitProperty`
218+
* `SVM` - `SetVsMonoAndroidRegistryKey`
219+
* `UNZ` - `Unzip`
220+
* `VJV` - `ValidateJavaVersion`
221+
* `WLF` - `WriteLockFile`
222+
223+
**Exceptions:**
224+
225+
* `7000` - Other Exception
226+
* `7001` - `NullReferenceException`
227+
* `7002` - `ArgumentOutOfRangeException`
228+
* `7003` - `ArgumentNullException`
229+
* `7004` - `ArgumentException`
230+
* `7005` - `FormatException`
231+
* `7006` - `IndexOutOfRangeException`
232+
* `7007` - `InvalidCastException`
233+
* `7008` - `ObjectDisposedException`
234+
* `7009` - `InvalidOperationException`
235+
* `7010` - `InvalidProgramException`
236+
* `7011` - `KeyNotFoundException`
237+
* `7012` - `TaskCanceledException`
238+
* `7013` - `OperationCanceledException`
239+
* `7014` - `OutOfMemoryException`
240+
* `7015` - `NotSupportedException`
241+
* `7016` - `StackOverflowException`
242+
* `7017` - `TimeoutException`
243+
* `7018` - `TypeInitializationException`
244+
* `7019` - `UnauthorizedAccessException`
245+
* `7020` - `ApplicationException`
246+
* `7021` - `KeyNotFoundException`
247+
* `7022` - `PathTooLongException`
248+
* `7023` - `DirectoryNotFoundException`
249+
* `7024` - `IOException`
107250

108251
## XA8xxx: Reserved
109252

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
namespace Xamarin.Android.Tasks
1919
{
20-
public class Aapt : AsyncTask
20+
public class Aapt : AndroidAsyncTask
2121
{
22+
public override string TaskPrefix => "APT";
23+
2224
public ITaskItem[] AdditionalAndroidResourcePaths { get; set; }
2325

2426
public string AndroidComponentResgenFlagFile { get; set; }
@@ -212,7 +214,7 @@ void ProcessManifest (ITaskItem manifestFile)
212214
return;
213215
}
214216

215-
public override bool Execute ()
217+
public override bool RunTask ()
216218
{
217219
resourceDirectory = ResourceDirectory.TrimEnd ('\\');
218220
if (!Path.IsPathRooted (resourceDirectory))
@@ -223,7 +225,7 @@ public override bool Execute ()
223225

224226
task.ContinueWith (Complete);
225227

226-
base.Execute ();
228+
base.RunTask ();
227229
} finally {
228230
Reacquire ();
229231
}
@@ -400,7 +402,7 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
400402
if (string.IsNullOrEmpty (singleLine))
401403
return;
402404

403-
var match = AndroidToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
405+
var match = AndroidRunToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
404406

405407
if (match.Success) {
406408
var file = match.Groups["file"].Value;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace Xamarin.Android.Tasks {
2020

21-
public class Aapt2 : AsyncTask {
21+
public abstract class Aapt2 : AndroidAsyncTask {
2222

2323
protected Dictionary<string, string> resource_name_case_map;
2424

@@ -97,7 +97,7 @@ protected bool RunAapt (string commandLine, IList<OutputLine> output)
9797

9898
bool IsAapt2Warning (string singleLine)
9999
{
100-
var match = AndroidToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
100+
var match = AndroidRunToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
101101
if (match.Success) {
102102
var file = match.Groups ["file"].Value;
103103
var level = match.Groups ["level"].Value.ToLowerInvariant ();
@@ -117,7 +117,7 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me
117117
if (string.IsNullOrEmpty (singleLine))
118118
return true;
119119

120-
var match = AndroidToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
120+
var match = AndroidRunToolTask.AndroidErrorRegex.Match (singleLine.Trim ());
121121

122122
if (match.Success) {
123123
var file = match.Groups ["file"].Value;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Xamarin.Android.Tasks {
1717

1818
public class Aapt2Compile : Aapt2 {
19+
public override string TaskPrefix => "A2C";
1920

2021
List<ITaskItem> archives = new List<ITaskItem> ();
2122

@@ -28,15 +29,15 @@ public class Aapt2Compile : Aapt2 {
2829
[Output]
2930
public ITaskItem [] CompiledResourceFlatArchives => archives.ToArray ();
3031

31-
public override bool Execute ()
32+
public override bool RunTask ()
3233
{
3334
Yield ();
3435
try {
3536
var task = this.RunTask (DoExecute);
3637

3738
task.ContinueWith (Complete);
3839

39-
base.Execute ();
40+
base.RunTask ();
4041
} finally {
4142
Reacquire ();
4243
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Xamarin.Android.Tasks {
1717

1818
//aapt2 link -o resources.apk.bk --manifest Foo.xml --java . --custom-package com.infinitespace_studios.blankforms -R foo2 -v --auto-add-overlay
1919
public class Aapt2Link : Aapt2 {
20+
public override string TaskPrefix => "A2L";
21+
2022
[Required]
2123
public ITaskItem [] ManifestFiles { get; set; }
2224

@@ -75,15 +77,15 @@ public class Aapt2Link : Aapt2 {
7577
AssemblyIdentityMap assemblyMap = new AssemblyIdentityMap ();
7678
List<string> tempFiles = new List<string> ();
7779

78-
public override bool Execute ()
80+
public override bool RunTask ()
7981
{
8082
Yield ();
8183
try {
8284
var task = this.RunTask (DoExecute);
8385

8486
task.ContinueWith (Complete);
8587

86-
base.Execute ();
88+
base.RunTask ();
8789
} finally {
8890
Reacquire ();
8991
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Xamarin.Android.Tasks
99
{
10-
public class AdjustJavacVersionArguments : Task
10+
public class AdjustJavacVersionArguments : AndroidTask
1111
{
12+
public override string TaskPrefix => "AJV";
13+
1214
[Required]
1315
public string JdkVersion { get; set; }
1416

@@ -27,7 +29,7 @@ public class AdjustJavacVersionArguments : Task
2729
[Output]
2830
public string SourceVersion { get; set; }
2931

30-
public override bool Execute ()
32+
public override bool RunTask ()
3133
{
3234
if (JdkVersion.StartsWith ("9", StringComparison.OrdinalIgnoreCase)) {
3335
TargetVersion = SourceVersion = DefaultJdkVersion;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Xamarin.Android.Tasks
88
{
99
public class AndroidApkSigner : JavaToolTask
1010
{
11+
public override string TaskPrefix => "AAS";
12+
1113
[Required]
1214
public string ApkSignerJar { get; set; }
1315

@@ -49,14 +51,14 @@ public class AndroidApkSigner : JavaToolTask
4951

5052
public string AdditionalArguments { get; set; }
5153

52-
public override bool Execute ()
54+
public override bool RunTask ()
5355
{
5456
if (!File.Exists (GenerateFullPathToTool ())) {
5557
Log.LogError ($"'{GenerateFullPathToTool ()}' does not exist. You need to install android-sdk build-tools 26.0.1 or above.");
5658
return false;
5759
}
5860

59-
return base.Execute ();
61+
return base.RunTask ();
6062
}
6163

6264
void AddStorePass (CommandLineBuilder cmd, string cmdLineSwitch, string value)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Xamarin.Android.Tasks
77
{
88
public class AndroidCreateDebugKey : KeyTool
99
{
10+
public override string TaskPrefix => "ACD";
11+
1012
public int Validity { get; set; }
1113

1214
public string KeyAlgorithm { get; set; }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
namespace Xamarin.Android.Tasks
77
{
8-
public class AndroidSignPackage : AndroidToolTask
8+
public class AndroidSignPackage : AndroidRunToolTask
99
{
10+
public override string TaskPrefix => "ASP";
11+
1012
bool hasWarnings;
1113

1214
[Required]

0 commit comments

Comments
 (0)