Skip to content

Commit 8ad7f52

Browse files
[One .NET] define UnixFilePermissions.xml (#6010)
Context: dotnet/sdk#16894 Context: dotnet/sdk#17299 On non-Windows platforms, the `dotnet workload install` command needs to ensure that certain files are executable after extracting them from the workload package, via `chmod 755 FILE`. This is currently done for all files in the `tools` folder for [select workloads][0]. dotnet/sdk/#16894 proposes using a new `data/UnixFilePermissions.xml` file to explicitly specify which files within the workload should have which Unix file permissions applied: <FileList> <File Path="tools/Darwin/aapt2" Permission="755" /> </FileList> Update `Microsoft.Android.Sdk.proj` to create a `data/UnixFilePermissions.xml` file, when building .NET 6+ installers on Linux and macOS platforms. `UnixFilePermissions.xml` is generated with the new `<GenerateUnixFilePermissions/>` task, building upon the `@(AndroidSdkBuildTools)` & related item groups in `create-installers.targets`. This is being done *before* `dotnet workload install` is updated to use `data/UnixFilePermissions.xml`. We also found that the following files should be *removed* from our .NET workload packs: * `aprofutil` * `mono` * `mono-symbolicate` `aprofutil` is needed for AOT use, and AOT is not currently supported under .NET 6. `mono` was only needed for `jnimarshalmethod-gen.exe`, which doesn't work on .NET 6, and `mono-symbolicate` *should* come from Mono-related workload packages, not Android-related packages, and also doesn't work. [0]: https://github.com/dotnet/sdk/blob/17c734cde97c6dde9d4bf298e7a2a7a342263ce6/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs#L186-L191
1 parent 46677fd commit 8ad7f52

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.IO;
2+
using System.Linq;
3+
using System.Xml;
4+
using Microsoft.Build.Framework;
5+
using Microsoft.Build.Utilities;
6+
7+
namespace Xamarin.Android.Tools.BootstrapTasks
8+
{
9+
/// <summary>
10+
/// Creates data/UnixFilePermissions.xml
11+
/// NOTE: not currently intended to run on Windows
12+
/// </summary>
13+
public class GenerateUnixFilePermissions : Task
14+
{
15+
[Required]
16+
public string Output { get; set; }
17+
18+
public string PackagePath { get; set; } = "";
19+
20+
public ITaskItem [] Files { get; set; }
21+
22+
public override bool Execute ()
23+
{
24+
var settings = new XmlWriterSettings {
25+
OmitXmlDeclaration = true,
26+
Indent = true,
27+
};
28+
29+
/*
30+
<FileList>
31+
<File Path="tools/Darwin/aapt2" Permission="755" />
32+
</FileList>
33+
*/
34+
35+
using var xml = XmlWriter.Create (Output, settings);
36+
xml.WriteStartElement ("FileList");
37+
if (Files != null) {
38+
var files =
39+
from f in Files
40+
let path = f.GetMetadata ("RelativePath")
41+
let permission = f.GetMetadata ("Permission")
42+
where !string.IsNullOrEmpty (path) && !string.IsNullOrEmpty (permission)
43+
orderby path
44+
select (path, permission);
45+
foreach (var (path, permission) in files) {
46+
xml.WriteStartElement ("File");
47+
xml.WriteAttributeString ("Path", Path.Combine (PackagePath, path));
48+
xml.WriteAttributeString ("Permission", permission);
49+
xml.WriteEndElement ();
50+
}
51+
}
52+
xml.WriteEndDocument ();
53+
54+
return !Log.HasLoggedErrors;
55+
}
56+
}
57+
}

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ core workload SDK packs imported by WorkloadManifest.targets.
88
-->
99
<Project Sdk="Microsoft.Build.NoTargets">
1010

11+
<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.GenerateUnixFilePermissions" />
12+
1113
<PropertyGroup>
1214
<PackageId>Microsoft.Android.Sdk.$(HostOS)</PackageId>
1315
<Description>C# Tools and Bindings for the Android SDK</Description>
@@ -52,6 +54,13 @@ core workload SDK packs imported by WorkloadManifest.targets.
5254
DestinationFiles="@(AndroidSdkBuildTools->'$(ToolsSourceDir)%(RelativePath)')"
5355
/>
5456

57+
<GenerateUnixFilePermissions
58+
Condition=" '$(HostOS)' != 'Windows' "
59+
Output="$(IntermediateOutputPath)UnixFilePermissions.xml"
60+
PackagePath="tools"
61+
Files="@(AndroidSdkBuildTools)"
62+
/>
63+
5564
<ItemGroup>
5665
<!-- Microsoft.Android.Sdk.ILLink output -->
5766
<_PackageFiles Include="$(XAInstallPrefix)xbuild\Xamarin\Android\Microsoft.Android.Sdk.ILLink.dll" PackagePath="tools" />
@@ -65,6 +74,7 @@ core workload SDK packs imported by WorkloadManifest.targets.
6574
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" PackagePath="Sdk" />
6675
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" PackagePath="PreserveLists" />
6776
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\**" PackagePath="targets" />
77+
<_PackageFiles Include="$(IntermediateOutputPath)UnixFilePermissions.xml" PackagePath="data" Condition=" '$(HostOS)' != 'Windows' " />
6878
<None Include="$(MSBuildThisFileDirectory)SignList.xml" CopyToOutputDirectory="PreserveNewest" />
6979
</ItemGroup>
7080
</Target>

build-tools/installers/create-installers.targets

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
<CodeSign>True</CodeSign>
338338
<HardenRuntime>True</HardenRuntime>
339339
<EntitlementsPath>$(DefaultRuntimeEntitlementsPath)</EntitlementsPath>
340+
<Permission>755</Permission>
340341
</_MSBuildFilesUnixSignAndHarden>
341342
</ItemDefinitionGroup>
342343
<ItemGroup>
@@ -352,12 +353,12 @@
352353
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-as" />
353354
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-ld" />
354355
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-strip" />
355-
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" />
356-
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" />
357-
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" />
358-
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" />
356+
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" Permission="755" />
357+
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" Permission="755" />
358+
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" ExcludeFromAndroidNETSdk="true" />
359+
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" ExcludeFromAndroidNETSdk="true" />
359360
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono.config" />
360-
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" />
361+
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" ExcludeFromAndroidNETSdk="true" />
361362
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\aapt2" />
362363
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libmono-android.debug.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
363364
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libmono-android.release.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />

0 commit comments

Comments
 (0)