Fix mainExe check properly.

This commit is contained in:
Caelan Sayler
2024-03-03 17:06:20 +00:00
parent cab2d5dc26
commit 7530764ce2
3 changed files with 35 additions and 13 deletions

View File

@@ -64,6 +64,13 @@ Categories=Development;
return Task.FromResult(dir.FullName);
}
protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
{
return base.GetMainExeSearchPaths(packDirectory, mainExeName)
.Concat(new[] { Path.Combine(packDirectory, "usr", "bin", mainExeName) })
.ToArray();
}
protected override Task CreatePortablePackage(Action<int> progress, string packDir, string outputPath)
{
progress(-1);

View File

@@ -45,6 +45,15 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
return Task.FromResult(dir.FullName);
}
protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
{
if (packDirectory.EndsWith(".app", StringComparison.OrdinalIgnoreCase)) {
// if the user pre-bundled the app, we need to look in the Contents/MacOS directory
return new[] { Path.Combine(packDirectory, "Contents", "MacOS", mainExeName) };
}
return base.GetMainExeSearchPaths(packDirectory, mainExeName);
}
protected override Task CodeSign(Action<int> progress, string packDir)
{
var helper = new OsxBuildTools(Log);

View File

@@ -70,22 +70,23 @@ public abstract class PackageBuilder<T> : ICommand<T>
// check that entry exe exists
var mainExt = options.TargetRuntime.BaseRID == RuntimeOs.Windows ? ".exe" : "";
var mainExeName = options.EntryExecutableName ?? (options.PackId + mainExt);
var mainExePath = Path.Combine(packDirectory, mainExeName);
// TODO: this is a hack, fix this.
if (!File.Exists(mainExePath) && VelopackRuntimeInfo.IsLinux)
mainExePath = Path.Combine(packDirectory, "usr", "bin", mainExeName);
// TODO: since we already have a hack, here's another...
if (!File.Exists(mainExePath) && VelopackRuntimeInfo.IsOSX && options.PackDirectory.EndsWith(".app"))
mainExePath = Path.Combine(packDirectory, "Contents", "MacOS", mainExeName);
if (!File.Exists(mainExePath)) {
var mainSearchPaths = GetMainExeSearchPaths(packDirectory, mainExeName);
string mainExePath = null;
foreach (var path in mainSearchPaths) {
if (File.Exists(path)) {
mainExePath = path;
break;
}
}
if (mainExePath == null) {
throw new UserInfoException(
$"Could not find main application executable (the one that runs 'VelopackApp.Build().Run()'). " + Environment.NewLine +
$"I searched for '{mainExeName}' in {packDirectory}." + Environment.NewLine +
$"If your main binary is not named '{mainExeName}', please specify the name with the argument: --mainExe {{yourBinary.exe}}");
$"If your main binary is not named '{mainExeName}', please specify the name with the argument: --mainExe {{yourBinary.exe}}" + Environment.NewLine +
$"I searched the following paths and none exist: " + Environment.NewLine +
String.Join(Environment.NewLine, mainSearchPaths)
);
}
MainExeName = mainExeName;
MainExePath = mainExePath;
@@ -177,6 +178,11 @@ public abstract class PackageBuilder<T> : ICommand<T>
return null;
}
protected virtual string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
{
return new[] { Path.Combine(packDirectory, mainExeName) };
}
protected virtual string GenerateNuspecContent()
{
var packId = Options.PackId;