Skip to content

Commit

Permalink
[msbuild] Port the BTouch task to subclass XamarinTask. (#21616)
Browse files Browse the repository at this point in the history
This has a few advantages:

* We simplify and unify more of our code.
* We have more control over the error reporting / logging behavior.

Additionally:

* Rename the tool to 'BGen', since that's what the .NET version of the tool is called, and update properties and item groups accordingly.
* Allow for overriding the path to the command-line tool in question.
* Add support for cancellation.
* Fix nullability.
* Add documentation for the relevant properties and item groups.
  • Loading branch information
rolfbjarne authored Nov 22, 2024
1 parent 65d7b8c commit 585d811
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 139 deletions.
7 changes: 7 additions & 0 deletions docs/build-apps/build-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ See also:
* The [AppIcon](build-properties.md#AppIcon) property.
* The [IncludeAllAppIcons](build-properties.md#IncludeAllAppIcons) property.

## BGenReferencePath

The list of assembly references to pass to the `bgen` tool (binding generator).

Typically this is handled automatically by adding references as
`ProjectReference` or `PackageReference` items instead.

## PartialAppManifest

`PartialAppManifest` can be used to add additional partial app manifests that
Expand Down
22 changes: 22 additions & 0 deletions docs/build-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ See also:
* The [AlternateAppIcon](build-items.md#AlternateAppIcon) item group.
* The [IncludeAllAppIcons](#IncludeAllAppIcons) property.

### BGenEmitDebugInformation

Whether the `bgen` tool (the binding generator) should emit debug information or not.

The default behavior is `true` when the `Debug` property is set to `true`.

## BGenExtraArgs

Any extra arguments to the `bgen` tool (the binding generator).

## BGenToolExe

The name of the `bgen` executable (a tool used by binding projects to generate bindings).

The default behavior is to use the `bgen` tool shipped with our workload.

## BGenToolPath

The directory to where the `bgen` ([BGenToolExe](#BGenToolExe)) is located.

The default behavior is to use the `bgen` tool shipped with our workload.

## DittoPath

The full path to the `ditto` executable.
Expand Down
4 changes: 2 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,8 @@

<Target Name="_ComputeBindingVariables" DependsOnTargets="_ComputeFrameworkVariables" Condition="'$(IsBindingProject)' == 'true'">
<PropertyGroup>
<BTouchToolExe>bgen.dll</BTouchToolExe>
<BTouchToolPath>$(_XamarinSdkRootDirectory)\tools\lib\bgen</BTouchToolPath>
<BGenToolExe>bgen.dll</BGenToolExe>
<BGenToolPath>$(_XamarinSdkRootDirectory)\tools\lib\bgen</BGenToolPath>
<BaseLibDllPath>$(_XamarinRefAssemblyPath)</BaseLibDllPath>
<_GeneratorAttributeAssembly>$(_XamarinSdkRootDirectory)/tools/lib/Xamarin.Apple.BindingAttributes.dll</_GeneratorAttributeAssembly>
<_DotNetCscCompiler>$(RoslynTargetsPath)\bincore\csc.dll</_DotNetCscCompiler>
Expand Down
28 changes: 28 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/CommandLineArgumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;

Expand Down Expand Up @@ -229,5 +230,32 @@ public string CreateResponseFile (Task task, string responseFilePath, IList<stri
// Generate the command line
return actualArgs.ToString ();
}

public static List<string> CreateResponseFile (Task task, string responseFilePath, IList<string> responseArguments, IList<string> nonResponseArguments)
{
// Generate a response file
var responseFile = Path.GetFullPath (responseFilePath);

if (File.Exists (responseFile))
File.Delete (responseFile);

try {
File.WriteAllLines (responseFile, StringUtils.Quote (responseArguments.ToArray ()));
} catch (Exception ex) {
task.Log.LogWarning ("Failed to create response file '{0}': {1}", responseFile, ex);
}

// Some arguments can not safely go in the response file and are
// added separately. They must go _after_ the response file
// as they may override options passed in the response file
var actualArgs = new List<string> ();

actualArgs.Add ($"@{responseFile}");
if (nonResponseArguments is not null)
actualArgs.AddRange (nonResponseArguments);

// Generate the command line
return actualArgs;
}
}
}
Loading

6 comments on commit 585d811

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.