<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

namespace Microsoft.DotNet.Cli.Build
{
    public class Crossgen
    {
        private string _coreClrVersion;
        private string _jitVersion;
        private string _crossGenPath;
        private string _targetRID;
        private static readonly string[] s_excludedLibraries =
        {
            "mscorlib.dll",
            "mscorlib.ni.dll",
            "System.Private.CoreLib.dll",
            "System.Private.CoreLib.ni.dll"
        };

        // This is not always correct. The version of crossgen we need to pick up is whatever one was restored as part
        // of the Microsoft.NETCore.Runtime.CoreCLR package that is part of the shared library. For now, the version hardcoded
        // in CompileTargets and the one in the shared library project.json match and are updated in lock step, but long term
        // we need to be able to look at the project.lock.json file and figure out what version of Microsoft.NETCore.Runtime.CoreCLR
        // was used, and then select that version.
        public Crossgen(string coreClrVersion, string jitVersion, string targetRID = null)
        {
            _coreClrVersion = coreClrVersion;
            _jitVersion = jitVersion;
            _targetRID = targetRID;
            _crossGenPath = GetCrossgenPathForVersion();
        }

        private string GetCrossgenPathForVersion()
        {
            var crossgenPackagePath = GetCrossGenPackagePathForVersion();
            string ridCrossgen = null;

            if (crossgenPackagePath == null)
            {
                return ridCrossgen;
            }

            // TODO-ARM-Crossgen: Add ubuntu.14.04-arm and ubuntu.16.04-arm
            if (_targetRID == "win8-arm")
            {
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x86_arm", $"crossgen{Constants.ExeSuffix}");
            }
            else if (_targetRID == "win10-arm64")
            {
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x64_arm64", $"crossgen{Constants.ExeSuffix}");
            }
            else
            {
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", $"crossgen{Constants.ExeSuffix}");
            }

            return ridCrossgen;
        }

        private string GetLibCLRJitPathForVersion()
        {
            var jitRid = _targetRID ?? GetCoreCLRRid();
            var jitPackagePath = GetJitPackagePathForVersion();

            if (jitPackagePath == null)
            {
                return null;
            }

            string jitPath = Path.Combine(jitPackagePath, "runtimes", jitRid, "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            
            // TODO-ARM-Crossgen: Add ubuntu.14.04-arm and ubuntu.16.04-arm
            if (_targetRID == "win8-arm") 
            {
                jitPath = Path.Combine(jitPackagePath, "runtimes", "x86_arm", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            }
            else if (_targetRID == "win10-arm64") 
            {
                jitPath = Path.Combine(jitPackagePath, "runtimes", "x64_arm64", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            }
            
            return jitPath;
        }

        private string GetJitPackagePathForVersion()
        {
            string jitRid = _targetRID ?? GetCoreCLRRid();

            if (jitRid == null)
            {
                return null;
            }

            string packageId = $"runtime.{jitRid}.Microsoft.NETCore.Jit";

            return Path.Combine(
                Dirs.PkgNuGetPackages,
                packageId,
                _jitVersion);
        }

        private string GetCoreLibsDirForVersion()
        {
            string coreclrRid = _targetRID ?? GetCoreCLRRid();

            if (coreclrRid == null)
            {
                return null;
            }<commit_msg>Temporarily change path to crossgen.exe & clrjit.dll<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

namespace Microsoft.DotNet.Cli.Build
{
    public class Crossgen
    {
        private string _coreClrVersion;
        private string _jitVersion;
        private string _crossGenPath;
        private string _targetRID;
        private static readonly string[] s_excludedLibraries =
        {
            "mscorlib.dll",
            "mscorlib.ni.dll",
            "System.Private.CoreLib.dll",
            "System.Private.CoreLib.ni.dll"
        };

        // This is not always correct. The version of crossgen we need to pick up is whatever one was restored as part
        // of the Microsoft.NETCore.Runtime.CoreCLR package that is part of the shared library. For now, the version hardcoded
        // in CompileTargets and the one in the shared library project.json match and are updated in lock step, but long term
        // we need to be able to look at the project.lock.json file and figure out what version of Microsoft.NETCore.Runtime.CoreCLR
        // was used, and then select that version.
        public Crossgen(string coreClrVersion, string jitVersion, string targetRID = null)
        {
            _coreClrVersion = coreClrVersion;
            _jitVersion = jitVersion;
            _targetRID = targetRID;
            _crossGenPath = GetCrossgenPathForVersion();
        }

        private string GetCrossgenPathForVersion()
        {
            var crossgenPackagePath = GetCrossGenPackagePathForVersion();
            string ridCrossgen = null;

            if (crossgenPackagePath == null)
            {
                return ridCrossgen;
            }

            // TODO-ARM-Crossgen: Add ubuntu.14.04-arm and ubuntu.16.04-arm
            if (_targetRID == "win8-arm")
            {
                // workaround https://github.com/dotnet/coreclr/issues/9884
                // ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x86_arm", $"crossgen{Constants.ExeSuffix}");
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x86_AnyCPU", $"crossgen{Constants.ExeSuffix}");
            }
            else if (_targetRID == "win10-arm64")
            {
                // workaround https://github.com/dotnet/coreclr/issues/9884
                // ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x86_arm", $"crossgen{Constants.ExeSuffix}");
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", "x86_AnyCPU", $"crossgen{Constants.ExeSuffix}");
            }
            else
            {
                ridCrossgen = Path.Combine(crossgenPackagePath, "tools", $"crossgen{Constants.ExeSuffix}");
            }

            return ridCrossgen;
        }

        private string GetLibCLRJitPathForVersion()
        {
            var jitRid = _targetRID ?? GetCoreCLRRid();
            var jitPackagePath = GetJitPackagePathForVersion();

            if (jitPackagePath == null)
            {
                return null;
            }

            string jitPath = Path.Combine(jitPackagePath, "runtimes", jitRid, "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            
            // TODO-ARM-Crossgen: Add ubuntu.14.04-arm and ubuntu.16.04-arm
            if (_targetRID == "win8-arm") 
            {
                // workaround https://github.com/dotnet/coreclr/issues/9884
                // jitPath = Path.Combine(jitPackagePath, "runtimes", "x86_arm", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
                jitPath = Path.Combine(jitPackagePath, "runtimes", "x86_AnyCPU", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            }
            else if (_targetRID == "win10-arm64") 
            {
                // workaround https://github.com/dotnet/coreclr/issues/9884
                // jitPath = Path.Combine(jitPackagePath, "runtimes", "x64_arm64", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
                jitPath = Path.Combine(jitPackagePath, "runtimes", "x64_AnyCPU", "native", $"{Constants.DynamicLibPrefix}clrjit{Constants.DynamicLibSuffix}");
            }
            
            return jitPath;
        }

        private string GetJitPackagePathForVersion()
        {
            string jitRid = _targetRID ?? GetCoreCLRRid();

            if (jitRid == null)
            {
                return null;
            }

            string packageId = $"runtime.{jitRid}.Microsoft.NETCore.Jit";

            return Path.Combine(
                Dirs.PkgNuGetPackages,
                packageId,
                _jitVersion);
        }

        private string GetCoreLibsDirForVersion()
        {
            string coreclrRid = _targetRID ?? GetCoreCLRRid();

            if (coreclrRid == null)
            {
                return null;
            }
{'fraction_non_alphanumeric': 0.09517152381976557, 'fraction_numerical': 0.010538767609420368, 'mean_word_length': 1.9665071770334928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6200285', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2598, 'n_words': 559}