Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Building NMA with System Extractor #1919

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

<!--
Listing of all build flags.
i.e. for `dotnet build -p:DefineConstants="FLAGS"`
Functionality:
NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR: Use system `7z` binary for extraction.
- This is intended for Linux package maintainers.
- Alternatively, this is available with `-p:UseSystemExtractor=true`
Deployment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,16 @@ private static string GetExtractorExecutableFileName()

private static string GetExtractorExecutable(IFileSystem fileSystem)
{
var fileName = GetExtractorExecutableFileName();
if (UseSystemExtractor) return fileName;
if (UseSystemExtractor)
{
// Depending on the user's distro and package of choice, 7z
// may have different names, so we'll check for the common ones.
return !OSInformation.IsLinux
? GetExtractorExecutableFileName() :
FindSystem7zOnLinux();
}

var fileName = GetExtractorExecutableFileName();
var directory = OSInformation.MatchPlatform(
onWindows: static () => "runtimes/win-x64/native/",
onLinux: static () => "runtimes/linux-x64/native/",
Expand All @@ -221,9 +228,24 @@ private static string GetExtractorExecutable(IFileSystem fileSystem)
/// See https://github.com/Nexus-Mods/NexusMods.App/issues/1306 for details.
/// </remarks>
private const bool UseSystemExtractor =
#if USE_SYSTEM_EXTRACTOR
#if NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR
true;
#else
false;
#endif

private static string FindSystem7zOnLinux()
{
string[] potentialBinaryNames = ["7z", "7zz", "7zzs"];
var pathDirectories = Environment.GetEnvironmentVariable("PATH")!.Split(':');
Sewer56 marked this conversation as resolved.
Show resolved Hide resolved

foreach (var pathDir in pathDirectories)
foreach (var binaryName in potentialBinaryNames)
{
if (File.Exists(Path.Combine(pathDir, binaryName)))
return binaryName;
}

throw new Exception("Cannot find system 7z binary in PATH");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<_NativeRuntime Condition=" '$(_NativeRuntime)' == '' And '$(_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'true' Or '$(PlatformTarget)' == 'x86')">win-x86</_NativeRuntime>
<_NativeRuntime Condition=" '$(_NativeRuntime)' == '' And '$(_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">win-x64</_NativeRuntime>

<_UseSystemExtractor Condition="'$(NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR)' == '1'">true</_UseSystemExtractor>
<_UseSystemExtractor Condition="$([System.String]::new('$(DefineConstants)').Contains('NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR'))">true</_UseSystemExtractor>
</PropertyGroup>

<PropertyGroup Condition="'$(_UseSystemExtractor)' == 'true'">
<DefineConstants>USE_SYSTEM_EXTRACTOR</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$(UseSystemExtractor) == 'true'">
<DefineConstants>$(DefineConstants);NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR</DefineConstants>
<_UseSystemExtractor>true</_UseSystemExtractor>
</PropertyGroup>

<ItemGroup Condition="'$(_UseSystemExtractor)' == '' Or '$(_UseSystemExtractor)' == 'false'">
<!-- Copy all if platform not specified -->
<None Condition="'$(PlatformTarget)' == 'AnyCPU' Or '$(PlatformTarget)' == ''" Include="$(MSBuildThisFileDirectory)../runtimes/**" Exclude="$(MSBuildThisFileDirectory)*.targets">
Expand Down
Loading