Skip to content

Fix modScriptPackages holding full paths instead of package names#93

Open
marlonrichert wants to merge 1 commit into
X2CommunityCore:mainfrom
marlonrichert:fix-modscriptpackages-paths
Open

Fix modScriptPackages holding full paths instead of package names#93
marlonrichert wants to merge 1 commit into
X2CommunityCore:mainfrom
marlonrichert:fix-modscriptpackages-paths

Conversation

@marlonrichert

Copy link
Copy Markdown
Contributor

$this.modScriptPackages is typed [string[]], but was assigned the raw Get-ChildItem -Directory results (DirectoryInfo objects). PowerShell coerces each to its full path via ToString(), not just the folder name, so every later "$name.u" package-copy step built a garbage path. Platform-independent bug, not Linux-specific.

@robojumper

robojumper commented Jul 11, 2026

Copy link
Copy Markdown
Member

Can you clarify whether this is specific to the cross-platform Powershell?

@marlonrichert

marlonrichert commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

It's not specific to cross-platform PowerShell. Rather, it's specific to the code in build_common.ps1 that deals with Highlander cooking.

$this.modScriptPackages is declared as [string[]] here:

[string[]] $modScriptPackages

_SetupUtils() tries to populate it here:

$this.modScriptPackages = @(Get-ChildItem "$($this.modSrcRoot)/Src" -Directory)

But @(Get-ChildItem "$($this.modSrcRoot)/Src" -Directory) does not return [string[]]; it returns [System.IO.DirectoryInfo[]].

To make the assignment work, PowerShell silently converts each DirectoryInfo to string by calling ToString() on it. However, DirectoryInfo.ToString() does not return the name of the directory; it returns the path of the directory.

This becomes a problem in _HasNativePackages() and _CopyScriptPackages(). They try to detect native packages by comparing elements from $this.modScriptPackages against the contents of $global:nativescriptpackages, but the latter does not contain paths:

$global:nativescriptpackages = @("XComGame", "Core", "Engine", "GFxUI", "AkAudio", "GameFramework", "UnrealEd", "GFxUIEditor", "IpDrv", "OnlineSubsystemPC", "OnlineSubsystemLive", "OnlineSubsystemSteamworks", "OnlineSubsystemPSN")

Thus, _HasNativePackages() always returns false, since the if in its foreach cannot succeed:

	[bool]_HasNativePackages() {
		# Check if this is a Highlander and we need to cook things
		$anynative = $false
		foreach ($name in $this.modScriptPackages) 
		{
			if ($global:nativescriptpackages.Contains($name)) {
				$anynative = $true
				break
			}
		}
		return $anynative
	}

Likewise, _CopyScriptPackages() will copy only non-native packages, because the if in its foreach cannot succeed either:

	[void]_CopyScriptPackages() {
		# copy packages to staging
		foreach ($name in $this.modScriptPackages) {
			if ($this.cookHL -and $global:nativescriptpackages.Contains($name))
			{
				# This is a native (cooked) script package -- copy important upks
				Copy-Item "$($this.cookerOutputPath)\$name.upk" "$($this.stagingPath)\CookedPCConsole" -Force -WarningAction SilentlyContinue
				Copy-Item "$($this.cookerOutputPath)\$name.upk.uncompressed_size" "$($this.stagingPath)\CookedPCConsole" -Force -WarningAction SilentlyContinue
				Write-Host "$($this.cookerOutputPath)\$name.upk"
			}
			else
			{
				# Or this is a non-native package
				Copy-Item "$($this.sdkPath)\XComGame\Script\$name.u" "$($this.stagingPath)\Script" -Force -WarningAction SilentlyContinue
				Write-Host "$($this.sdkPath)\XComGame\Script\$name.u"
			}
		}
	}

My commit fixes this by populating $this.modScriptPackages with directory names instead of paths.

@robojumper

robojumper commented Jul 12, 2026

Copy link
Copy Markdown
Member

Right, but the Highlander X2ModBuildCommon (which has an older version) already has this line:

https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/blob/1e872694b4f383d2a2232755612bc782363fec0f/.scripts/X2ModBuildCommon/build_common.ps1#L207-L209

If your explanation is right, then the current Highlander build should also be completely broken, but it isn't, at least with the classic powershell.

@marlonrichert

Copy link
Copy Markdown
Contributor Author

OK, interesting. I'll have to investigate further.

$this.modScriptPackages is typed [string[]], but was assigned the raw
Get-ChildItem -Directory results (DirectoryInfo objects). PowerShell
coerces each to its full path via ToString(), not just the folder
name, so every later "$name.u" package-copy step built a garbage path.
Because $ErrorActionPreference is "Stop", the resulting Copy-Item
file-not-found is fatal, so the build fails outright.

X2WOTCCommunityHighlander's build_common.ps1 has the same pattern
(thismodpackages, assigned the same way) yet reportedly builds fine
under classic Windows PowerShell 5.1. This project can only build
under PowerShell Core/pwsh, and fails to build there without this fix
- so the coercion behavior differs between those two PowerShell
editions/runtimes. This is not platform-independent; it's specific to
PowerShell Core/pwsh.
@marlonrichert marlonrichert force-pushed the fix-modscriptpackages-paths branch from a276b8d to 4c43074 Compare July 12, 2026 21:18
@marlonrichert

marlonrichert commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

I need your help to resolve your question: Can you add a Write-Host before the return in _HasNativePackages() on a Windows PowerShell build and confirm whether it returns true or false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants