mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-15 06:53:48 +00:00
Improved Pandoc handling on dev environments (#634)
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
This commit is contained in:
1 parent
f84ea772b4
commit
c9f037bb2c
6 files changed
+251
-50
No files matched your search
@@ -13,8 +13,15 @@ public sealed class PandocProcessBuilder
|
||||
{
|
||||
private static readonly Assembly ASSEMBLY = Assembly.GetExecutingAssembly();
|
||||
private static readonly MetaDataArchitectureAttribute META_DATA_ARCH = ASSEMBLY.GetCustomAttribute<MetaDataArchitectureAttribute>()!;
|
||||
private static readonly RID CPU_ARCHITECTURE = META_DATA_ARCH.Architecture.ToRID();
|
||||
|
||||
|
||||
// Use runtime detection instead of metadata to ensure correct RID on dev machines:
|
||||
private static readonly RID CPU_ARCHITECTURE = RIDExtensions.GetCurrentRID();
|
||||
private static readonly RID METADATA_ARCHITECTURE = META_DATA_ARCH.Architecture.ToRID();
|
||||
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(PandocProcessBuilder));
|
||||
|
||||
// Tracks whether the first log has been written to avoid log spam on repeated calls:
|
||||
private static bool HAS_LOGGED_ONCE;
|
||||
|
||||
private string? providedInputFile;
|
||||
private string? providedOutputFile;
|
||||
private string? providedInputFormat;
|
||||
@@ -112,30 +119,107 @@ public sealed class PandocProcessBuilder
|
||||
private static async Task<PandocExecutable> PandocExecutablePath(RustService rustService)
|
||||
{
|
||||
//
|
||||
// First, we try to find the pandoc executable in the data directory.
|
||||
// Any local installation should be preferred over the system-wide installation.
|
||||
// Determine if we should log (only on the first call):
|
||||
//
|
||||
var localInstallationRootDirectory = await Pandoc.GetPandocDataFolder(rustService);
|
||||
var shouldLog = !HAS_LOGGED_ONCE;
|
||||
|
||||
try
|
||||
{
|
||||
var executableName = PandocExecutableName;
|
||||
var subdirectories = Directory.GetDirectories(localInstallationRootDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (var subdirectory in subdirectories)
|
||||
//
|
||||
// Log a warning if the runtime-detected RID differs from the metadata RID.
|
||||
// This can happen on dev machines where the metadata.txt contains stale values.
|
||||
// We always use the runtime-detected RID for correct behavior.
|
||||
//
|
||||
if (shouldLog && CPU_ARCHITECTURE != METADATA_ARCHITECTURE)
|
||||
{
|
||||
var pandocPath = Path.Combine(subdirectory, executableName);
|
||||
if (File.Exists(pandocPath))
|
||||
return new(pandocPath, true);
|
||||
LOGGER.LogWarning(
|
||||
"Runtime-detected RID '{RuntimeRID}' differs from metadata RID '{MetadataRID}'. Using runtime-detected RID. This is expected on dev machines where metadata.txt may be outdated.",
|
||||
CPU_ARCHITECTURE.ToUserFriendlyName(),
|
||||
METADATA_ARCHITECTURE.ToUserFriendlyName());
|
||||
}
|
||||
|
||||
//
|
||||
// First, we try to find the pandoc executable in the data directory.
|
||||
// Any local installation should be preferred over the system-wide installation.
|
||||
//
|
||||
var localInstallationRootDirectory = await Pandoc.GetPandocDataFolder(rustService);
|
||||
|
||||
//
|
||||
// Check if the data directory path is valid:
|
||||
//
|
||||
if (string.IsNullOrWhiteSpace(localInstallationRootDirectory))
|
||||
{
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("The local data directory path is empty or null. Cannot search for local Pandoc installation.");
|
||||
}
|
||||
else if (!Directory.Exists(localInstallationRootDirectory))
|
||||
{
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("The local Pandoc installation directory does not exist: '{LocalInstallationRootDirectory}'.", localInstallationRootDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// The directory exists, search for the pandoc executable:
|
||||
//
|
||||
var executableName = PandocExecutableName;
|
||||
if (shouldLog)
|
||||
LOGGER.LogInformation("Searching for Pandoc executable '{ExecutableName}' in: '{LocalInstallationRootDirectory}'.", executableName, localInstallationRootDirectory);
|
||||
|
||||
try
|
||||
{
|
||||
//
|
||||
// First, check the root directory itself:
|
||||
//
|
||||
var rootExecutablePath = Path.Combine(localInstallationRootDirectory, executableName);
|
||||
if (File.Exists(rootExecutablePath))
|
||||
{
|
||||
if (shouldLog)
|
||||
LOGGER.LogInformation("Found local Pandoc installation at the root path: '{Path}'.", rootExecutablePath);
|
||||
|
||||
HAS_LOGGED_ONCE = true;
|
||||
return new(rootExecutablePath, true);
|
||||
}
|
||||
|
||||
//
|
||||
// Then, search all subdirectories:
|
||||
//
|
||||
var subdirectories = Directory.GetDirectories(localInstallationRootDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (var subdirectory in subdirectories)
|
||||
{
|
||||
var pandocPath = Path.Combine(subdirectory, executableName);
|
||||
if (File.Exists(pandocPath))
|
||||
{
|
||||
if (shouldLog)
|
||||
LOGGER.LogInformation("Found local Pandoc installation at: '{Path}'.", pandocPath);
|
||||
|
||||
HAS_LOGGED_ONCE = true;
|
||||
return new(pandocPath, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("No Pandoc executable found in local installation directory or its subdirectories.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning(ex, "Error while searching for a local Pandoc installation in: '{LocalInstallationRootDirectory}'.", localInstallationRootDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// When no local installation was found, we assume that the pandoc executable is in the system PATH:
|
||||
//
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("Falling back to system PATH for the Pandoc executable: '{ExecutableName}'.", PandocExecutableName);
|
||||
|
||||
return new(PandocExecutableName, false);
|
||||
}
|
||||
catch
|
||||
finally
|
||||
{
|
||||
// ignored
|
||||
HAS_LOGGED_ONCE = true;
|
||||
}
|
||||
|
||||
//
|
||||
// When no local installation was found, we assume that the pandoc executable is in the system PATH.
|
||||
//
|
||||
return new(PandocExecutableName, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user