-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] Turn class-redirector into a Task #18244
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
415580a
Turn class-redirector into a Task
stephen-hawley b4fc3c2
updates-before-move-to-tasks
stephen-hawley 902a545
moved namespaces, moved files, removed dead using
stephen-hawley 153a345
[msbuild] Make the ClassRedirectorTask task support remote execution.
rolfbjarne d3dfe41
Merge branch 'main' into taskerize-it
rolfbjarne 87ee10a
Auto-format source code
e5df0be
Merge branch 'main' into taskerize-it
rolfbjarne 170d757
set up OutputDirectory option
stephen-hawley 0219706
task rename
stephen-hawley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
tools/class-redirector/class-redirector/ClassRedirectorTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Xml.Linq; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
#nullable enable | ||
|
||
namespace ClassRedirector | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public class ClassRedirectorTask : Microsoft.Build.Utilities.Task | ||
{ | ||
public override bool Execute () | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (!Directory.Exists (InputDirectory)) { | ||
Log.LogError ($"InputDirectory {InputDirectory} doesn't exist."); | ||
return false; | ||
} | ||
|
||
if (!DirectoryIsWritable (InputDirectory)) { | ||
Log.LogError ($"InputDirectory {InputDirectory} is not writable."); | ||
return false; | ||
} | ||
|
||
if (!File.Exists (ClassMapPath)) { | ||
Log.LogError ($"ClassMapPath file {ClassMapPath} does not exist."); | ||
return false; | ||
} | ||
|
||
var dllsToProcess = CollectDlls (InputDirectory); | ||
var xamarinDll = FindXamarinDll (dllsToProcess); | ||
|
||
if (xamarinDll is null) { | ||
Log.LogError ($"unable to find platform dll in {InputDirectory}"); | ||
return false; | ||
} | ||
|
||
var map = ReadRegistrarFile (ClassMapPath); | ||
|
||
try { | ||
Log.LogMessage ($"Redirecting class_handle usage from directory {InputDirectory} in the following dlls: {string.Join (",", dllsToProcess)}"); | ||
Log.LogMessage ($"Redirecting class_handle usage with the platform dll {xamarinDll}"); | ||
Log.LogMessage ($"Redirecting class_handle usage with the following {nameof (ClassMapPath)}: {ClassMapPath}"); | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var rewriter = new Rewriter (map, xamarinDll, dllsToProcess); | ||
rewriter.Process (); | ||
} catch (Exception e) { | ||
Log.LogErrorFromException (e); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
[Required] | ||
public string InputDirectory { get; set; } = ""; | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[Required] | ||
public string ClassMapPath { get; set; } = ""; | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static bool DirectoryIsWritable (string path) | ||
{ | ||
var info = new DirectoryInfo (path); | ||
return !info.Attributes.HasFlag (FileAttributes.ReadOnly); | ||
} | ||
|
||
static string [] CollectDlls (string dir) | ||
{ | ||
return Directory.GetFiles (dir, "*.dll"); // GetFiles returns full paths | ||
} | ||
|
||
static string [] xamarinDlls = new string [] { | ||
"Microsoft.iOS.dll", | ||
"Microsoft.macOS.dll", | ||
"Microsoft.tvOS.dll", | ||
}; | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static bool IsXamarinDll (string p) | ||
{ | ||
return xamarinDlls.FirstOrDefault (dll => p.EndsWith (dll, StringComparison.Ordinal)) is not null; | ||
rolfbjarne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static string? FindXamarinDll (string [] paths) | ||
{ | ||
return paths.FirstOrDefault (IsXamarinDll); | ||
} | ||
|
||
static CSToObjCMap ReadRegistrarFile (string path) | ||
{ | ||
var doc = XDocument.Load (path); | ||
var map = CSToObjCMap.FromXDocument (doc); | ||
if (map is null) | ||
throw new Exception ($"Unable to read static registrar map file {path}"); | ||
return map; | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSBuild tasks should go in the msbuild/Xamarin.MacDev.Tasks/Tasks directory, together with all our other tasks.