Additional SuperIlc fixes for running composite R2R images (#32665)
authorTomáš Rylek <trylek@microsoft.com>
Sat, 22 Feb 2020 08:56:47 +0000 (09:56 +0100)
committerGitHub <noreply@github.com>
Sat, 22 Feb 2020 08:56:47 +0000 (09:56 +0100)
As an expedite way to run "non-shared" composite R2R images
(including the frameworK) I have added support to SuperIlc to
copy corerun, coreclr, clrjit and mscorrc next to the compiled
composite executable and supplying that as the CORE_ROOT
folder; otherwise corerun in the normal Tests/Core_Root
automatically grabs the framework next to it, not the composite
rewritten versions.

Thanks

Tomas

src/coreclr/src/tools/ReadyToRun.SuperIlc/BuildFolder.cs
src/coreclr/src/tools/ReadyToRun.SuperIlc/BuildOptions.cs
src/coreclr/src/tools/ReadyToRun.SuperIlc/CompilerRunner.cs
src/coreclr/src/tools/ReadyToRun.SuperIlc/CpaotRunner.cs
src/coreclr/src/tools/ReadyToRun.SuperIlc/CrossgenRunner.cs
src/coreclr/src/tools/ReadyToRun.SuperIlc/PathHelpers.cs

index 567242b..c667d42 100644 (file)
@@ -12,6 +12,21 @@ namespace ReadyToRun.SuperIlc
 {
     public class BuildFolder
     {
+        private static string[] s_runtimeExecutables =
+        {
+            "corerun"
+        };
+
+        private static string[] s_runtimeLibraries =
+        {
+            "coreclr",
+            "clrjit",
+            "mscorrc",
+            "mscorrc.debug",
+            "mscordaccore",
+            "mscordbi",
+        };
+
         private List<string> _compilationInputFiles;
 
         private List<string> _mainExecutables;
@@ -134,6 +149,21 @@ namespace ReadyToRun.SuperIlc
                 return null;
             }
 
+            if (options.Composite)
+            {
+                // In composite mode we copy the native runtime to the app folder and pretend that is CORE_ROOT,
+                // otherwise CoreRun picks up the original MSIL versions of framework assemblies from CORE_ROOT
+                // instead of the rewritten ones next to the app.
+                foreach (string exe in s_runtimeExecutables)
+                {
+                    passThroughFiles.Add(Path.Combine(options.CoreRootDirectory.FullName, exe.AppendOSExeSuffix()));
+                }
+                foreach (string lib in s_runtimeLibraries)
+                {
+                    passThroughFiles.Add(Path.Combine(options.CoreRootDirectory.FullName, lib.AppendOSDllSuffix()));
+                }
+            }
+
             foreach (CompilerRunner runner in compilerRunners)
             {
                 string runnerOutputPath = runner.GetOutputPath(outputRoot);
index 08abd1d..70cb2ce 100644 (file)
@@ -111,7 +111,7 @@ namespace ReadyToRun.SuperIlc
         public string CoreRunPath(CompilerIndex index, bool isFramework)
         {
             string coreRunDir = CoreRootOutputPath(index, isFramework);
-            string coreRunExe = "corerun".OSExeSuffix();
+            string coreRunExe = "corerun".AppendOSExeSuffix();
             string coreRunPath = Path.Combine(coreRunDir, coreRunExe);
             if (!File.Exists(coreRunPath))
             {
index 1ff43da..e37c783 100644 (file)
@@ -187,10 +187,21 @@ namespace ReadyToRun.SuperIlc
                 processParameters.Arguments = "-c " + scriptToRun;
             }
 
+            string coreRootDir;
+            if (_options.Composite)
+            {
+                coreRootDir = GetOutputPath(outputRoot);
+            }
+            else
+            {
+                coreRootDir = _options.CoreRootOutputPath(Index, isFramework: false);
+            }
+
             processParameters.InputFileNames = new string[] { scriptToRun };
             processParameters.OutputFileName = scriptToRun;
             processParameters.LogPath = scriptToRun + ".log";
-            processParameters.EnvironmentOverrides["CORE_ROOT"] = _options.CoreRootOutputPath(Index, isFramework: false);
+            processParameters.EnvironmentOverrides["CORE_ROOT"] = coreRootDir;
+
             return processParameters;
         }
 
index f30e621..b2f22c5 100644 (file)
@@ -19,7 +19,7 @@ namespace ReadyToRun.SuperIlc
 
         protected override string CompilerRelativePath => "crossgen2";
 
-        protected override string CompilerFileName => "crossgen2".OSExeSuffix();
+        protected override string CompilerFileName => "crossgen2".AppendOSExeSuffix();
 
         private List<string> _resolvedReferences;
 
index c483c47..e2e9739 100644 (file)
@@ -19,7 +19,7 @@ namespace ReadyToRun.SuperIlc
 
         protected override string CompilerRelativePath => ".";
 
-        protected override string CompilerFileName => "crossgen".OSExeSuffix();
+        protected override string CompilerFileName => "crossgen".AppendOSExeSuffix();
 
         protected override string CompilerPath
         {
index dc50bbb..8361b34 100644 (file)
@@ -30,7 +30,10 @@ static class PathExtensions
     /// </summary>
     const int DirectoryDeletionBackoffMilliseconds = 500;
 
-    internal static string OSExeSuffix(this string path) => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? path + ".exe" : path);
+    internal static string AppendOSExeSuffix(this string path) => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? path + ".exe" : path);
+
+    internal static string AppendOSDllSuffix(this string path) => path +
+        (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so");
 
     internal static string ToAbsolutePath(this string argValue) => Path.GetFullPath(argValue);