Skip to content

Commit

Permalink
[One .NET] define UnixFilePermissions.xml (#6010)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonathanpeppers authored Jun 10, 2021
1 parent 46677fd commit 8ad7f52
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Xamarin.Android.Tools.BootstrapTasks
{
/// <summary>
/// Creates data/UnixFilePermissions.xml
/// NOTE: not currently intended to run on Windows
/// </summary>
public class GenerateUnixFilePermissions : Task
{
[Required]
public string Output { get; set; }

public string PackagePath { get; set; } = "";

public ITaskItem [] Files { get; set; }

public override bool Execute ()
{
var settings = new XmlWriterSettings {
OmitXmlDeclaration = true,
Indent = true,
};

/*
<FileList>
<File Path="tools/Darwin/aapt2" Permission="755" />
</FileList>
*/

using var xml = XmlWriter.Create (Output, settings);
xml.WriteStartElement ("FileList");
if (Files != null) {
var files =
from f in Files
let path = f.GetMetadata ("RelativePath")
let permission = f.GetMetadata ("Permission")
where !string.IsNullOrEmpty (path) && !string.IsNullOrEmpty (permission)
orderby path
select (path, permission);
foreach (var (path, permission) in files) {
xml.WriteStartElement ("File");
xml.WriteAttributeString ("Path", Path.Combine (PackagePath, path));
xml.WriteAttributeString ("Permission", permission);
xml.WriteEndElement ();
}
}
xml.WriteEndDocument ();

return !Log.HasLoggedErrors;
}
}
}
10 changes: 10 additions & 0 deletions build-tools/create-packs/Microsoft.Android.Sdk.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ core workload SDK packs imported by WorkloadManifest.targets.
-->
<Project Sdk="Microsoft.Build.NoTargets">

<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.GenerateUnixFilePermissions" />

<PropertyGroup>
<PackageId>Microsoft.Android.Sdk.$(HostOS)</PackageId>
<Description>C# Tools and Bindings for the Android SDK</Description>
Expand Down Expand Up @@ -52,6 +54,13 @@ core workload SDK packs imported by WorkloadManifest.targets.
DestinationFiles="@(AndroidSdkBuildTools->'$(ToolsSourceDir)%(RelativePath)')"
/>

<GenerateUnixFilePermissions
Condition=" '$(HostOS)' != 'Windows' "
Output="$(IntermediateOutputPath)UnixFilePermissions.xml"
PackagePath="tools"
Files="@(AndroidSdkBuildTools)"
/>

<ItemGroup>
<!-- Microsoft.Android.Sdk.ILLink output -->
<_PackageFiles Include="$(XAInstallPrefix)xbuild\Xamarin\Android\Microsoft.Android.Sdk.ILLink.dll" PackagePath="tools" />
Expand All @@ -65,6 +74,7 @@ core workload SDK packs imported by WorkloadManifest.targets.
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" PackagePath="Sdk" />
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" PackagePath="PreserveLists" />
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\**" PackagePath="targets" />
<_PackageFiles Include="$(IntermediateOutputPath)UnixFilePermissions.xml" PackagePath="data" Condition=" '$(HostOS)' != 'Windows' " />
<None Include="$(MSBuildThisFileDirectory)SignList.xml" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
Expand Down
11 changes: 6 additions & 5 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<CodeSign>True</CodeSign>
<HardenRuntime>True</HardenRuntime>
<EntitlementsPath>$(DefaultRuntimeEntitlementsPath)</EntitlementsPath>
<Permission>755</Permission>
</_MSBuildFilesUnixSignAndHarden>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -352,12 +353,12 @@
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-as" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-ld" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-strip" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" Permission="755" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" Permission="755" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono.config" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\aapt2" />
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libmono-android.debug.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libmono-android.release.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
Expand Down

0 comments on commit 8ad7f52

Please sign in to comment.