Skip to content

Commit ab8db9b

Browse files
committed
Merge branch 'main' into dev/grendel/xxhash3
* main: Bump to xamarin/xamarin-android-tools/main@37d79c9 (#8752) Bump to dotnet/installer@d070660282 9.0.100-preview.3.24126.2 (#8763) Bump to xamarin/java.interop/main@14a9470 (#8766) $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (#8765) [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (#8764) Bump com.android.tools:r8 from 8.2.42 to 8.2.47 (#8761) [Mono.Android] fix a set of the "easiest" trimmer warnings (#8731) Bump to dotnet/installer@0a73f814e1 9.0.100-preview.2.24122.3 (#8716) [ci] Always run the MAUI test job (#8750) Add a property required by #8478 (#8749) [xamarin-android-tools] import $(LibZipSharpVersion) value (#8738) Bump to xamarin/Java.Interop/main@c825dcad (#8701) Bump to xamarin/monodroid@cb01503327 (#8742) Bump to xamarin/Java.Interop/main@ae65609 (#8744) Bring in changes from PR #8478 (#8727) [xaprepare] Make 7zip work with "dangerous" symlinks in ZIPs (#8737) Bump NDK to r26c (#8732) Debugging MSBuild Tasks (#8730)
2 parents b86a1c5 + 4a2179c commit ab8db9b

Some content is hidden

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

46 files changed

+1070
-345
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
xamarin/monodroid:main@848d1277b76a599d8a280d58ec06e95477b4a7e5
1+
xamarin/monodroid:main@cb01503327f7723ec138ec4cc051610fecee1bf7

.vscode/launch.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"port": 10000,
4545
"preLaunchTask": "run-sample-under-dotnet",
4646
},
47+
{
48+
"name": "Attach to Process",
49+
"type": "coreclr",
50+
"request": "attach",
51+
"processId": "${input:processid}"
52+
}
4753
],
4854
"inputs": [
4955
{
@@ -52,6 +58,12 @@
5258
"default": "Debug",
5359
"description": "The Build Configuration",
5460
"options": [ "Debug", "Release"]
55-
}
61+
},
62+
{
63+
"id": "processid",
64+
"type": "promptString",
65+
"default": "0",
66+
"description": "Enter dotnet build process id reported when setting the env var MSBUILDDEBUGONSTART=2",
67+
},
5668
]
5769
}

.vscode/tasks.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127
"label": "build-sample-under-dotnet",
128128
"type": "shell",
129129
"windows": { "command": "dotnet-local.cmd build ${input:project} -p:Configuration=${input:configuration} -t:${input:target} -bl:${input:target}.binlog", },
130-
"linux": { "command": "./dotnet-local.sh build ${input:project} -p:Configuration=${input:configuration} -t:${input:target} -bl:${input:target}.binlog",},
131-
"osx": { "command": "./dotnet-local.sh build ${input:project} -p:Configuration=${input:configuration} -t:${input:target} -bl:${input:target}.binlog",},
130+
"linux": { "command": "${input:debugbuildtasks} ./dotnet-local.sh build ${input:project} -p:Configuration=${input:configuration} -t:${input:target} -bl:${input:target}.binlog",},
131+
"osx": { "command": "${input:debugbuildtasks} ./dotnet-local.sh build ${input:project} -p:Configuration=${input:configuration} -t:${input:target} -bl:${input:target}.binlog",},
132132
"group": {
133133
"kind": "build",
134134
"isDefault": true
@@ -141,8 +141,8 @@
141141
"label": "run-sample-under-dotnet",
142142
"type": "shell",
143143
"windows": { "command": "dotnet-local.cmd build ${input:project} \"-t:Run\" --no-restore -p:TargetFramework=${input:targetframework} -p:Configuration=${input:configuration} -p:AndroidAttachDebugger=${input:attach} -bl:run.binlog", },
144-
"linux": { "command": "./dotnet-local.sh build ${input:project} \"-t:Run\" --no-restore -p:TargetFramework=${input:targetframework} -p:Configuration=${input:configuration} -p:AndroidAttachDebugger=${input:attach} -bl:run.binlog",},
145-
"osx": { "command": "./dotnet-local.sh build ${input:project} \"-t:Run\" --no-restore -p:TargetFramework=${input:targetframework} -p:Configuration=${input:configuration} -p:AndroidAttachDebugger=${input:attach} -bl:run.binlog",},
144+
"linux": { "command": "${input:debugbuildtasks} ./dotnet-local.sh build ${input:project} \"-t:Run\" --no-restore -p:TargetFramework=${input:targetframework} -p:Configuration=${input:configuration} -p:AndroidAttachDebugger=${input:attach} -bl:run.binlog",},
145+
"osx": { "command": "${input:debugbuildtasks} ./dotnet-local.sh build ${input:project} \"-t:Run\" --no-restore -p:TargetFramework=${input:targetframework} -p:Configuration=${input:configuration} -p:AndroidAttachDebugger=${input:attach} -bl:run.binlog",},
146146
"group": {
147147
"kind": "build",
148148
"isDefault": true
@@ -220,5 +220,15 @@
220220
"Everything",
221221
]
222222
},
223+
{
224+
"id": "debugbuildtasks",
225+
"type": "pickString",
226+
"default": "",
227+
"description": "Debug Build Tasks?",
228+
"options": [
229+
"",
230+
"MSBUILDDEBUGONSTART=2"
231+
]
232+
},
223233
]
224234
}

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Bump first digit of the patch version for feature releases (and reset the first two digits to 0)
3737
-->
3838
<AndroidPackVersion>34.99.0</AndroidPackVersion>
39-
<AndroidPackVersionSuffix>preview.2</AndroidPackVersionSuffix>
39+
<AndroidPackVersionSuffix>preview.3</AndroidPackVersionSuffix>
4040
</PropertyGroup>
4141

4242
<!-- Common <PackageReference/> versions -->

Documentation/guides/MSBuildBestPractices.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,74 @@ This guide is a work-in-progress, but really has two main goals:
55
- What are good MSBuild practice in relation to what we already have
66
going on in Xamarin.Android MSBuild targets?
77

8+
## Debugging MSBuild Tasks
9+
10+
One thing that is very useful is the ability to debug your Tasks while
11+
they are being run on a build process. This is possible thanks to the
12+
`MSBUILDDEBUGONSTART` environment variable. When set to `2` this will
13+
force MSBuild to wait for a debugger connection before continuing.
14+
You will see the following prompt.
15+
16+
```dotnetcli
17+
Waiting for debugger to attach (dotnet PID 13001). Press enter to continue...
18+
```
19+
20+
You can then use VS or VSCode to attach to this process and debug you tasks.
21+
22+
In the case of .NET Android we need to do a couple of thing first though. Firstly
23+
we need to disable the use of `ILRepacker` on the `Xamarin.Android.Build.Tasks`
24+
assembly. This is because `ILRepacker` does NOT handle debug symbols very well.
25+
Assemblies it generates seem to be JIT optimized so the debugger will not load
26+
the symbols. A new MSBuild property has been introduced to disable this feature
27+
while debugging. `_ILRepackEnabled` can be set as an environment variable which
28+
MSBuild will pickup. You will also need to build the `Debug` Configuration.
29+
30+
```dotnetcli
31+
export CONFIGURATION=Debug
32+
make prepare && _ILRepackEnabled=false make jenkins
33+
```
34+
35+
This will disable the `ILRepacker` for the build.
36+
37+
You can then start your test app with the `dotnet-local` script (so it uses your build)
38+
39+
### [MacOS](#tab/macos)
40+
41+
```dotnetcli
42+
MSBUILDDEBUGONSTART=2 ~/<some xamarin.android checkout>/dotnet-local.sh build -m:1
43+
```
44+
45+
### [Linux](#tab/linux)
46+
47+
```dotnetcli
48+
MSBUILDDEBUGONSTART=2 ~/<some xamarin.android checkout>/dotnet-local.sh build -m:1
49+
```
50+
51+
### [Windows](#tab/windows)
52+
53+
```dotnetcli
54+
set MSBUILDDEBUGONSTART=2
55+
~/<some xamarin.android checkout>/dotnet-local.cmd build -m:1
56+
```
57+
58+
---
59+
60+
Note: the `-m:1` is important as it restricts MSBuild to 1 node.
61+
62+
Once MSBuild starts it will print the following
63+
64+
```dotnetcli
65+
Waiting for debugger to attach (dotnet PID xxxx). Press enter to continue...
66+
```
67+
68+
You need to copy the PID value so we can use this in the IDE. For Visual Studio you can use the `Attach to Process` menu option, while you have the Xamarin.Android.sln solution open. For VSCode open the workspace then use the `Attach to Process` Run and Debug option. You will be prompted for the PID and it will then connect.
69+
70+
Once connected go back to your command prompt and press ENTER so that the MSBuild process can continue.
71+
72+
You will be able to set breakpoints in Tasks (but not Targets) and step through code from this point on.
73+
74+
If you want to test in-tree using the same the `build-sample-under-dotnet` command will ask you if you want to debug MSBuild tasks and fill in the `MSBUILDDEBUGONSTART` for you. The PID text will appear in the `Terminal` window in VSCode. In addition the `run-sample-under-dotnet` command will ask the same.
75+
876
## Naming
977

1078
MSBuild targets, properties, and item groups are prefixed with an

build-tools/automation/azure-pipelines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ stages:
317317
- stage: maui_tests
318318
displayName: MAUI Tests
319319
dependsOn: mac_build
320-
condition: and(eq(dependencies.mac_build.result, 'Succeeded'), eq(variables['System.PullRequest.TargetBranch'], 'main'))
320+
condition: and(eq(dependencies.mac_build.result, 'Succeeded'), eq(variables['RunMAUITestJob'], 'true'))
321321
jobs:
322322
# Check - "Xamarin.Android (MAUI Tests MAUI Integration)"
323323
- job: maui_tests_integration

build-tools/automation/yaml-templates/variables.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ variables:
5252
value: 34
5353
- name: ExcludedNightlyNUnitCategories
5454
value: 'cat != SystemApplication & cat != TimeZoneInfo & cat != Localization'
55+
- name: RunMAUITestJob
56+
value: true

build-tools/xaprepare/xaprepare/Application/RegexProgramVersionParser.cs

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,78 @@ namespace Xamarin.Android.Prepare
1212
/// <see cref="VersionOutputLine"/> is set to any other value only that line is taken into consideration. This is
1313
/// done to make processing less ambiguous and faster.
1414
/// </summary>
15-
class RegexProgramVersionParser : ProgramVersionParser
16-
{
17-
const string VersionGroupName = "Version";
18-
static readonly char[] LineSeparator = new [] { '\n' };
15+
class RegexProgramVersionParser : ProgramVersionParser
16+
{
17+
public const string VersionGroupName = "Version";
18+
public static readonly char[] LineSeparator = new [] { '\n' };
1919

20-
Regex rx;
20+
Regex rx;
2121

22-
public RegexProgramVersionParser (string programName, string versionArguments, Regex regex, uint versionOutputLine = 0, Log? log = null)
23-
: base (programName, versionArguments, versionOutputLine, log)
24-
{
25-
if (regex == null)
26-
throw new ArgumentNullException (nameof (regex));
27-
rx = regex;
28-
}
22+
public RegexProgramVersionParser (string programName, string versionArguments, Regex regex, uint versionOutputLine = 0, Log? log = null)
23+
: base (programName, versionArguments, versionOutputLine, log)
24+
{
25+
if (regex == null)
26+
throw new ArgumentNullException (nameof (regex));
27+
rx = regex;
28+
}
2929

30-
public RegexProgramVersionParser (string programName, string versionArguments, string regex, uint versionOutputLine = 0, Log? log = null)
31-
: base (programName, versionArguments, versionOutputLine, log)
32-
{
33-
if (String.IsNullOrEmpty (regex))
34-
throw new ArgumentException ("must not be null or empty", nameof (regex));
30+
public RegexProgramVersionParser (string programName, string versionArguments, string regex, uint versionOutputLine = 0, Log? log = null)
31+
: base (programName, versionArguments, versionOutputLine, log)
32+
{
33+
if (String.IsNullOrEmpty (regex))
34+
throw new ArgumentException ("must not be null or empty", nameof (regex));
3535

36-
rx = new Regex (regex, RegexOptions.Compiled);
37-
}
36+
rx = new Regex (regex, RegexOptions.Compiled);
37+
}
3838

39-
protected override string ParseVersion (string programOutput)
40-
{
41-
string output = programOutput.Trim ();
42-
if (String.IsNullOrEmpty (output)) {
43-
Log.WarningLine ($"Unable to parse version of {ProgramName} because version output was empty");
44-
return DefaultVersionString;
45-
}
39+
protected override string ParseVersion (string programOutput)
40+
{
41+
string output = programOutput.Trim ();
42+
if (String.IsNullOrEmpty (output)) {
43+
Log.WarningLine ($"Unable to parse version of {ProgramName} because version output was empty");
44+
return DefaultVersionString;
45+
}
4646

47-
string ret = String.Empty;
48-
string[] lines = programOutput.Split (LineSeparator);
49-
if (VersionOutputLine > 0) {
50-
if (lines.Length < VersionOutputLine) {
51-
Log.WarningLine ($"Not enough lines in version output of {ProgramName}: version number was supposed to be found on line {VersionOutputLine} but there are only {lines.Length} lines");
52-
return DefaultVersionString;
53-
}
47+
string ret = String.Empty;
48+
string[] lines = programOutput.Split (LineSeparator);
49+
if (VersionOutputLine > 0) {
50+
if (lines.Length < VersionOutputLine) {
51+
Log.WarningLine ($"Not enough lines in version output of {ProgramName}: version number was supposed to be found on line {VersionOutputLine} but there are only {lines.Length} lines");
52+
return DefaultVersionString;
53+
}
5454

55-
if (TryMatch (lines [VersionOutputLine - 1], out ret) && !String.IsNullOrEmpty (ret)) {
56-
return ret;
57-
}
55+
if (TryMatch (rx, lines [VersionOutputLine - 1], out ret) && !String.IsNullOrEmpty (ret)) {
56+
return ret;
57+
}
5858

59-
return DefaultVersionString;
60-
}
59+
return DefaultVersionString;
60+
}
6161

62-
foreach (string line in lines) {
63-
if (TryMatch (line, out ret))
64-
break;
65-
}
62+
foreach (string line in lines) {
63+
if (TryMatch (rx, line, out ret))
64+
break;
65+
}
6666

67-
return ret ?? DefaultVersionString;
68-
}
67+
return ret ?? DefaultVersionString;
68+
}
6969

70-
bool TryMatch (string line, out string version)
71-
{
72-
version = String.Empty;
70+
public static bool TryMatch (Regex regex, string line, out string version)
71+
{
72+
version = String.Empty;
7373

74-
Match match = rx.Match (line);
75-
if (!match.Success || match.Groups.Count <= 0) {
76-
return false;
77-
}
74+
Match match = regex.Match (line);
75+
if (!match.Success || match.Groups.Count <= 0) {
76+
return false;
77+
}
7878

79-
foreach (Group group in match.Groups) {
80-
if (String.Compare (group.Name, VersionGroupName, StringComparison.OrdinalIgnoreCase) == 0) {
81-
version = group.Value;
82-
return true;
83-
}
84-
}
79+
foreach (Group group in match.Groups) {
80+
if (String.Compare (group.Name, VersionGroupName, StringComparison.OrdinalIgnoreCase) == 0) {
81+
version = group.Value;
82+
return true;
83+
}
84+
}
8585

86-
return false;
87-
}
88-
}
86+
return false;
87+
}
88+
}
8989
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
4+
namespace Xamarin.Android.Prepare;
5+
6+
class SevenZipVersionParser : ProgramVersionParser
7+
{
8+
const string VersionArgument = "--help";
9+
readonly Regex fallbackRegex;
10+
readonly Regex modernRegex;
11+
12+
public SevenZipVersionParser (string programName, Regex fallbackRegex, Log? log = null)
13+
: base (programName, VersionArgument, 0, log)
14+
{
15+
this.fallbackRegex = fallbackRegex;
16+
modernRegex = VersionFetchers.MakeRegex (@"^7-Zip (\(a\) ){0,1}(?<Version>[\d]+\.[\d]+)");
17+
}
18+
19+
protected override string ParseVersion (string programOutput)
20+
{
21+
string output = programOutput.Trim ();
22+
if (String.IsNullOrEmpty (output)) {
23+
Log.WarningLine ($"Unable to parse version of {ProgramName} because version output was empty");
24+
return DefaultVersionString;
25+
}
26+
27+
string ret = String.Empty;
28+
string[] lines = programOutput.Split (RegexProgramVersionParser.LineSeparator);
29+
30+
// First try to find the official 7zip release version
31+
foreach (string l in lines) {
32+
string line = l.Trim ();
33+
34+
if (line.Length == 0) {
35+
continue;
36+
}
37+
38+
if (line.StartsWith ("7-Zip", StringComparison.OrdinalIgnoreCase)) {
39+
// Strings of the form:
40+
// 7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20
41+
// 7-Zip (a) 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20
42+
// 7-Zip (a) 18.01 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
43+
// 7-Zip (a) 18.01 (x86) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
44+
if (RegexProgramVersionParser.TryMatch (modernRegex, line, out ret)) {
45+
return ret;
46+
}
47+
}
48+
49+
// Since we know we're dealing with `--help` option output, we can short-circuit things
50+
if (line.StartsWith ("Usage:", StringComparison.OrdinalIgnoreCase)) {
51+
break;
52+
}
53+
}
54+
55+
// Modern version wasn't found, try again with the fallback one
56+
foreach (string l in lines) {
57+
string line = l.Trim ();
58+
59+
if (line.Length == 0) {
60+
continue;
61+
}
62+
63+
if (RegexProgramVersionParser.TryMatch (fallbackRegex, line, out ret)) {
64+
return ret;
65+
}
66+
}
67+
68+
return DefaultVersionString;
69+
}
70+
}

0 commit comments

Comments
 (0)