-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Migrate SGen task to Task environment API #13457
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
base: main
Are you sure you want to change the base?
Changes from 24 commits
ab5fdde
cf9553b
64509ed
2585b4e
1742662
1d97469
23a3ede
cfd690e
5f74f0e
dbaf184
65f9abc
828e302
aa6ffe2
2480e38
8e595bb
c3ae8c9
4d25a42
b04ea30
831794f
1a588f3
aaf974e
4210def
248a7d1
526b770
28a1145
4456ddc
cbf5548
37f9316
d36d438
0fbac5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ internal interface ISGenTaskContract | |
| } | ||
|
|
||
| #if RUNTIME_TYPE_NETCORE | ||
| [MSBuildMultiThreadableTask] | ||
| public class SGen : ToolTaskExtension, ISGenTaskContract | ||
| { | ||
| #pragma warning disable format // region formatting is different in net7.0 and net472, and cannot be fixed for both | ||
|
|
@@ -138,6 +139,7 @@ public override bool Execute() | |
| /// <summary> | ||
| /// Genererates a serialization assembly containing XML serializers for the input assembly. | ||
| /// </summary> | ||
| [MSBuildMultiThreadableTask] | ||
| public class SGen : ToolTaskExtension, ISGenTaskContract | ||
| { | ||
| private string _buildAssemblyPath; | ||
|
|
@@ -170,7 +172,9 @@ public string BuildAssemblyPath | |
| string thisPath; | ||
| try | ||
| { | ||
| thisPath = Path.GetFullPath(_buildAssemblyPath); | ||
| string absolutePath = !string.IsNullOrEmpty(_buildAssemblyPath) | ||
| ? TaskEnvironment.GetAbsolutePath(_buildAssemblyPath).Value : _buildAssemblyPath; | ||
| thisPath = Path.GetFullPath(absolutePath); | ||
| } | ||
| catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e)) | ||
| { | ||
|
|
@@ -255,16 +259,9 @@ public string SerializationAssemblyName | |
| } | ||
| } | ||
|
|
||
| private string SerializationAssemblyPath | ||
| { | ||
| get | ||
| { | ||
| Debug.Assert(BuildAssemblyPath.Length > 0, "Build assembly path is blank"); | ||
| return Path.Combine(BuildAssemblyPath, SerializationAssemblyName); | ||
| } | ||
| } | ||
| private AbsolutePath SerializationAssemblyPath => new AbsolutePath(Path.Combine(BuildAssemblyPath, SerializationAssemblyName)); | ||
|
|
||
| private string AssemblyFullPath => Path.Combine(BuildAssemblyPath, BuildAssemblyName); | ||
| private AbsolutePath AssemblyFullPath => new AbsolutePath(Path.Combine(BuildAssemblyPath, BuildAssemblyName)); | ||
|
|
||
| public string SdkToolsPath | ||
| { | ||
|
|
@@ -307,17 +304,21 @@ protected override string GenerateFullPathToTool() | |
|
|
||
| // If COMPLUS_InstallRoot\COMPLUS_Version are set (the dogfood world), we want to find it there, instead of | ||
| // the SDK, which may or may not be installed. The following will look there. | ||
| if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("COMPLUS_InstallRoot")) || !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("COMPLUS_Version"))) | ||
| if (!String.IsNullOrEmpty(TaskEnvironment.GetEnvironmentVariable("COMPLUS_InstallRoot")) || !String.IsNullOrEmpty(TaskEnvironment.GetEnvironmentVariable("COMPLUS_Version"))) | ||
| { | ||
| pathToTool = ToolLocationHelper.GetPathToDotNetFrameworkFile(ToolExe, TargetDotNetFrameworkVersion.Latest); | ||
| } | ||
|
|
||
| if (String.IsNullOrEmpty(pathToTool) || !FileSystems.Default.FileExists(pathToTool)) | ||
| if (String.IsNullOrEmpty(pathToTool) || !FileSystems.Default.FileExists(TaskEnvironment.GetAbsolutePath(pathToTool))) | ||
| { | ||
| pathToTool = SdkToolsPathUtility.GeneratePathToTool(SdkToolsPathUtility.FileInfoExists, ProcessorArchitecture.CurrentProcessArchitecture, SdkToolsPath, ToolExe, Log, true); | ||
| pathToTool = SdkToolsPathUtility.GeneratePathToTool( | ||
| f => !string.IsNullOrEmpty(f) | ||
| ? SdkToolsPathUtility.FileInfoExists(TaskEnvironment.GetAbsolutePath(f)) | ||
| : SdkToolsPathUtility.FileInfoExists(f), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the else branch, the f is null or empty, right? why do we call the FileInfoExists in such case? won't it be always false?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to fully preserve the previous behavior. Earlier, the code passed the path directly to |
||
| ProcessorArchitecture.CurrentProcessArchitecture, SdkToolsPath, ToolExe, Log, true); | ||
| } | ||
|
|
||
| return pathToTool; | ||
| return string.IsNullOrEmpty(pathToTool) ? pathToTool : TaskEnvironment.GetAbsolutePath(pathToTool).Value; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -330,7 +331,7 @@ protected override bool ValidateParameters() | |
| { | ||
| foreach (string reference in References) | ||
| { | ||
| if (!FileSystems.Default.FileExists(reference)) | ||
| if (string.IsNullOrEmpty(reference) || !FileSystems.Default.FileExists(TaskEnvironment.GetAbsolutePath(reference))) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SGen.ResourceNotFound", reference); | ||
| return false; | ||
|
|
@@ -365,11 +366,11 @@ protected override string GenerateCommandLineCommands() | |
| { | ||
| Debug.Assert(ShouldGenerateSerializer, "GenerateCommandLineCommands() should not be called if ShouldGenerateSerializer is true and SerializationAssembly is null."); | ||
|
|
||
| SerializationAssembly = [new TaskItem(SerializationAssemblyPath)]; | ||
| SerializationAssembly = [new TaskItem(SerializationAssemblyPath.OriginalValue)]; | ||
| } | ||
|
|
||
| // Add the assembly switch | ||
| commandLineBuilder.AppendSwitchIfNotNull("/assembly:", AssemblyFullPath); | ||
| commandLineBuilder.AppendSwitchIfNotNull("/assembly:", AssemblyFullPath.Value); | ||
OvesN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| commandLineBuilder.AppendWhenTrue("/proxytypes", Bag, "UseProxyTypes"); | ||
|
|
||
|
|
@@ -441,11 +442,11 @@ protected override string GenerateCommandLineCommands() | |
| // leave the earlier produced assembly around to be propagated by later processes. | ||
| catch (UnauthorizedAccessException e) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message); | ||
| Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath.OriginalValue, e.Message); | ||
| } | ||
| catch (IOException e) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message); | ||
| Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath.OriginalValue, e.Message); | ||
| } | ||
| // The DirectoryNotFoundException is safely ignorable since that means that there is no | ||
| // existing serialization assembly. This would be extremely unlikely anyway because we | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.