Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jun 3, 2024
1 parent afccb27 commit 711d5f2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion chibild/chibild.core.Tests/LinkerTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static string RunCore(
ApplyOptimization = false,
CreationOptions = creationOptions,
PrependExecutionSearchPaths = prependExecutionSearchPaths ?? Array.Empty<string>(),
CacheBasePath = null,
//CacheBasePath = null,
},
injectToAssemblyPath,
basePath,
Expand Down
2 changes: 1 addition & 1 deletion chibild/chibild.core/Generating/AssemblyInputFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions chibild/chibild.core/LinkerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ public sealed class LinkerOptions
public string[] PrependExecutionSearchPaths =
CommonUtilities.Empty<string>();


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");
Expand Down
35 changes: 35 additions & 0 deletions toolchain.common/Internal/CommonUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down

0 comments on commit 711d5f2

Please sign in to comment.