From 711d5f27d93965a2c6d607f427d4c6f6e09f05a7 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Mon, 3 Jun 2024 20:35:35 +0900 Subject: [PATCH] WIP --- .../chibild.core.Tests/LinkerTestRunner.cs | 2 +- .../Generating/AssemblyInputFragment.cs | 2 +- chibild/chibild.core/LinkerOptions.cs | 5 ++- toolchain.common/Internal/CommonUtilities.cs | 35 +++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/chibild/chibild.core.Tests/LinkerTestRunner.cs b/chibild/chibild.core.Tests/LinkerTestRunner.cs index 1a566c9..c78cd41 100644 --- a/chibild/chibild.core.Tests/LinkerTestRunner.cs +++ b/chibild/chibild.core.Tests/LinkerTestRunner.cs @@ -119,7 +119,7 @@ public static string RunCore( ApplyOptimization = false, CreationOptions = creationOptions, PrependExecutionSearchPaths = prependExecutionSearchPaths ?? Array.Empty(), - CacheBasePath = null, + //CacheBasePath = null, }, injectToAssemblyPath, basePath, diff --git a/chibild/chibild.core/Generating/AssemblyInputFragment.cs b/chibild/chibild.core/Generating/AssemblyInputFragment.cs index 5c4940d..18e72a6 100644 --- a/chibild/chibild.core/Generating/AssemblyInputFragment.cs +++ b/chibild/chibild.core/Generating/AssemblyInputFragment.cs @@ -415,7 +415,7 @@ private static string GetAssemblyHash(string assemblyPath) using var fileStream = StreamUtilities.OpenStream( assemblyPath, false); - using var alg = SHA1.Create(); + using var alg = MD5.Create(); return BitConverter.ToString(alg.ComputeHash(fileStream)). Replace("-", string.Empty). ToLowerInvariant(); diff --git a/chibild/chibild.core/LinkerOptions.cs b/chibild/chibild.core/LinkerOptions.cs index d14da7f..bfd70cf 100644 --- a/chibild/chibild.core/LinkerOptions.cs +++ b/chibild/chibild.core/LinkerOptions.cs @@ -229,11 +229,10 @@ public sealed class LinkerOptions public string[] PrependExecutionSearchPaths = CommonUtilities.Empty(); + public string? CacheBasePath = Path.Combine( - Environment.GetEnvironmentVariable("HOMEPATH") is { } homePath1 ? homePath1 : - Environment.GetEnvironmentVariable("HOME") is { } homePath2 ? homePath2 : - Environment.CurrentDirectory, + CommonUtilities.GetHomePath(), ".cache", "chibild-cil", "symtab"); diff --git a/toolchain.common/Internal/CommonUtilities.cs b/toolchain.common/Internal/CommonUtilities.cs index 13f238b..8164c94 100644 --- a/toolchain.common/Internal/CommonUtilities.cs +++ b/toolchain.common/Internal/CommonUtilities.cs @@ -55,6 +55,41 @@ internal static class CommonUtilities public static readonly bool IsInWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; + public static string GetHomePath() + { + if (IsInWindows) + { + var homeDrive = Environment.GetEnvironmentVariable("HOMEDRIVE"); + var homePath = Environment.GetEnvironmentVariable("HOMEPATH"); + if (!string.IsNullOrWhiteSpace(homeDrive) && + !string.IsNullOrWhiteSpace(homePath)) + { + var path = Path.GetFullPath( + $"{homeDrive}{homePath}". + TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); + if (Directory.Exists(path)) + { + return path; + } + } + } + else + { + if (Environment.GetEnvironmentVariable("HOME") is { } path && + !string.IsNullOrWhiteSpace(path)) + { + path = Path.GetFullPath( + path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); + if (Directory.Exists(path)) + { + return path; + } + } + } + + return Path.GetFullPath("."); + } + public static string GetDirectoryPath(string path) => Path.GetDirectoryName(path) is { } d ? Path.GetFullPath(string.IsNullOrWhiteSpace(d) ? "." : d) :