Skip to content

Commit

Permalink
Search up from IKVM.Runtime. Because we need to put IKVM.Runtime in r…
Browse files Browse the repository at this point in the history
…untimes/ now, it's possible that it might not be colocated with ikvm.properties.
  • Loading branch information
wasabii committed Jul 5, 2024
1 parent 69cc6b5 commit c57a24f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/IKVM.Runtime/JVM.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,39 @@ internal record struct IkvmPropEntry(string BasePath, string Value);
/// Gets the raw search paths to examine for ikvm.properties.
/// </summary>
/// <returns></returns>
static IEnumerable<string> GetSeachPathsIter()
static IEnumerable<string> GetIkvmPropertiesSearchPathsIter()
{
if (AppContext.BaseDirectory is string basePath && !string.IsNullOrEmpty(basePath))
yield return basePath;

if (AppDomain.CurrentDomain.BaseDirectory is string appBasePath && !string.IsNullOrEmpty(appBasePath))
yield return appBasePath;

// search upwards from the location of IKVM.Runtime
// we do this because IKVM.Runtime may be in runtimes/{rid}/lib
if (typeof(Properties).Assembly.Location is string runtimeAssemblyPath && !string.IsNullOrEmpty(runtimeAssemblyPath))
yield return Path.GetDirectoryName(runtimeAssemblyPath);
foreach (var parent in GetParentDirs(runtimeAssemblyPath))
yield return parent;
}

/// <summary>
/// Returns an iteration of each parent path of the given path until the root.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
static IEnumerable<string> GetParentDirs(string path)
{
while (string.IsNullOrWhiteSpace(path = Path.GetDirectoryName(path)) == false)
yield return path;
}

/// <summary>
/// Gets the unique search paths to examine for ikvm.properties.
/// </summary>
/// <returns></returns>
static IEnumerable<string> GetSeachPaths()
static IEnumerable<string> GetIkvmPropertiesSearchPaths()
{
return GetSeachPathsIter().Distinct();
return GetIkvmPropertiesSearchPathsIter().Distinct();
}

/// <summary>
Expand All @@ -83,16 +97,18 @@ static IEnumerable<string> GetSeachPaths()
/// <returns></returns>
static Dictionary<string, IkvmPropEntry> GetIkvmProperties()
{
var props = new Dictionary<string, IkvmPropEntry>();

foreach (var basePath in GetSeachPaths())
foreach (var basePath in GetIkvmPropertiesSearchPaths())
{
var ikvmPropertiesPath = Path.Combine(basePath, "ikvm.properties");
if (File.Exists(ikvmPropertiesPath))
{
var props = new Dictionary<string, IkvmPropEntry>();
LoadProperties(basePath, File.ReadAllLines(ikvmPropertiesPath), props);
return props;
}
}

return props;
return null;
}

/// <summary>
Expand Down Expand Up @@ -360,7 +376,7 @@ static string GetLibraryPath()
{
var l = new List<string>();

foreach (var d in GetSeachPaths())
foreach (var d in GetIkvmPropertiesSearchPaths())
{
l.Add(d);
foreach (var rid in RuntimeUtil.SupportedRuntimeIdentifiers)
Expand Down

0 comments on commit c57a24f

Please sign in to comment.