Repository navigation
[gx] Fix for included file location #239
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import type { Log } from "~/log"; | |
| import { KnownError } from "~/error"; | ||
| import type { Target } from "~/target"; | ||
| import { | ||
| IGOR_PLATFORM_DIRS, | ||
| installRuntime, | ||
| listRuntimes, | ||
| ModuleSchema, | ||
|
|
@@ -304,7 +305,10 @@ export async function installRuntimeIfNeeded( | |
| } | ||
| log.success("Runtime installed"); | ||
|
|
||
| runtimeLocation = await findRuntimeLocation(ctx, runtimeDir); | ||
| // Keep honouring the requested version: without it we'd hand back whatever | ||
| // runtime in the cache happens to be newest, which is rarely the one we just | ||
| // installed. | ||
| runtimeLocation = await findRuntimeLocation(ctx, runtimeDir, version); | ||
| if (!runtimeLocation) { | ||
| throw new Error("Invariant broken: no runtime found after installation"); | ||
| } | ||
|
|
@@ -325,3 +329,77 @@ export async function getInstalledRuntimeModules( | |
| .filter((result) => result.success) | ||
| .map((result) => result.data); | ||
| } | ||
|
|
||
| const MIN_RUNTIME_WITH_USABLE_IGOR: Gms2Version = [2026, 0, 0, 0]; | ||
|
|
||
| /** | ||
| * Every runtime ships the Igor that was built alongside it, at | ||
| * `bin/igor/<platform>/<arch>/Igor`. That copy is the one that agrees with the | ||
| * runner about where files belong on disk, so it's what we build with. | ||
| * | ||
| * The standalone Igor we download to bootstrap (fetch a license, list and | ||
| * install runtimes) is versioned separately from the runtimes and lags behind | ||
| * them, which silently breaks targets where Igor does the packaging. For | ||
| * example on OperaGX, external assets such as `.yytex` texture pages moved into | ||
| * an `assets` subfolder of the package, and a runner from a runtime newer than | ||
| * the bootstrap Igor 404s on every one of them. | ||
| * See https://github.com/YoYoGames/GameMaker-Bugs/issues/15930 | ||
| * | ||
| * Returns undefined when the runtime has no usable Igor, in which case the | ||
| * caller should stick with the bootstrap one. | ||
| */ | ||
| export async function findRuntimeIgor( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit sad that we need to do this, but makes a lot of sense! 👍 |
||
| ctx: Context, | ||
| runtimeLocation: string, | ||
| ): Promise<string | undefined> { | ||
| const runtimeVersion = parseRuntimeVersionFromDirName( | ||
| ctx.path.basename(runtimeLocation), | ||
| ); | ||
| // Older runtimes predate the Igor flags we build with (-projectool, -prefabs, | ||
| // -jsonErrors), so for those the bootstrap Igor really is the better choice. | ||
| if ( | ||
| runtimeVersion === undefined || | ||
| gms2VersionCompare(runtimeVersion, MIN_RUNTIME_WITH_USABLE_IGOR) < 0 | ||
| ) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const platform = ctx.process.platform; | ||
| const platformDir = IGOR_PLATFORM_DIRS[platform] ?? platform; | ||
| // We use x64 builds on ARM Windows, and fall back to the x64 build under | ||
| // Rosetta on Apple Silicon, matching downloadIgor(). | ||
| const archDirs = | ||
| platform === "win32" | ||
| ? ["x64"] | ||
| : platform === "darwin" | ||
| ? [ctx.process.arch, "x64"] | ||
| : [ctx.process.arch]; | ||
|
|
||
| for (const archDir of archDirs) { | ||
| const igorPath = ctx.path.join( | ||
| runtimeLocation, | ||
| "bin", | ||
| "igor", | ||
| platformDir, | ||
| archDir, | ||
| platform === "win32" ? "Igor.exe" : "Igor", | ||
| ); | ||
| if (!(await exists(ctx, igorPath))) { | ||
| continue; | ||
| } | ||
| if (platform !== "win32") { | ||
| // installationFixup() already does this for runtimes we installed | ||
| // ourselves, but be safe about runtimes left behind by other tools. | ||
| try { | ||
| await ctx.fs.chmod(igorPath, 0o755); | ||
| } catch { | ||
| // Read-only cache, or someone else owns the file: if it's already | ||
| // executable the spawn below still works, and if it isn't we'd rather | ||
| // report the spawn failure than this one. | ||
| } | ||
| } | ||
| return igorPath; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| */ | ||
|
|
||
| import type { Cache } from "./cache"; | ||
| import type { Context } from "./context"; | ||
| import { exists, type Context } from "./context"; | ||
| import type { Log } from "./log"; | ||
| import type { ProjectPath } from "./project"; | ||
| import { spawnProcess } from "./spawn"; | ||
|
|
@@ -39,6 +39,7 @@ export async function restorePrefabs( | |
| }, | ||
| ): Promise<string> { | ||
| const prefabsDir = await cache.getSubDirPath(ctx, "prefabs"); | ||
| await seedPrefabsFromIdeStores(ctx, log, { projectPath, prefabsDir }); | ||
| // TODO LATER: add options to pick registry etc. | ||
| const args = [ | ||
| "PREFABS", | ||
|
|
@@ -57,3 +58,145 @@ export async function restorePrefabs( | |
| }); | ||
| return prefabsDir; | ||
| } | ||
|
|
||
| /** | ||
| * Directories the GameMaker IDE unpacks prefab packages into, one | ||
| * `<name>-<version>` folder per package. The IDE keeps this store per machine | ||
| * rather than per project, so a project built in the IDE looks, to us, like it | ||
| * has no prefabs at all. | ||
| * | ||
| * Each entry is a directory that may hold several `GameMakerStudio2*` installs | ||
| * (stable, Beta, Dev, LTS2026, ...), each with its own `Prefabs` folder. | ||
| */ | ||
| function idePrefabStoreRoots(ctx: Context): string[] { | ||
| switch (ctx.process.platform) { | ||
| case "win32": | ||
| return [ctx.env.PROGRAMDATA ?? "C:\\ProgramData"]; | ||
| case "darwin": | ||
| return ["/Users/Shared"]; | ||
| default: | ||
| return [ctx.path.join(ctx.os.homedir(), ".config")]; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Copy any prefab package the project references out of the IDE's store and | ||
| * into the folder we hand to ProjectTool, so it doesn't have to fetch them. | ||
| * | ||
| * This is a workaround: fetching is PackageTool's job, but the newest published | ||
| * package-tool binds to gmpm by reflection and no longer matches the gmpm we | ||
| * install alongside it, so every fetch dies with "Parameter count mismatch". | ||
| * Seeding from the IDE store sidesteps the fetch entirely on machines that have | ||
| * the IDE. Once package-tool is republished against the current gmpm this only | ||
|
Comment on lines
+86
to
+90
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to avoid coupling the CLI to the IDE. (Especially since the CLI expects to run in CI environments where there is no pre-existing IDE installation.) But I think it's up to you and @stuckie to decide if this workaround is needed for now, or if an upstream changed can be made in either gmpm or package-tool instead. |
||
| * saves a download and can go away. | ||
| * | ||
| * Best effort throughout: anything we can't work out is left to ProjectTool, | ||
| * which reports missing prefabs far better than we could here. | ||
| */ | ||
| async function seedPrefabsFromIdeStores( | ||
| ctx: Context, | ||
| log: Log, | ||
| { projectPath, prefabsDir }: { projectPath: ProjectPath; prefabsDir: string }, | ||
| ): Promise<void> { | ||
| try { | ||
| const referenced = await readPrefabReferences(ctx, projectPath); | ||
| if (referenced.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // ProjectTool looks next to the project as well as in the folder we pass, | ||
| // so a package in either place is already accounted for. | ||
| const projectPrefabsDir = ctx.path.join( | ||
| ctx.path.dirname(projectPath), | ||
| "prefabs", | ||
| ); | ||
| const missing: string[] = []; | ||
| for (const name of referenced) { | ||
| if ( | ||
| !(await exists(ctx, ctx.path.join(prefabsDir, name))) && | ||
| !(await exists(ctx, ctx.path.join(projectPrefabsDir, name))) | ||
| ) { | ||
| missing.push(name); | ||
| } | ||
| } | ||
| if (missing.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const stores = await findIdePrefabStores(ctx); | ||
| if (stores.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| let copied = 0; | ||
| for (const name of missing) { | ||
| for (const store of stores) { | ||
| const src = ctx.path.join(store, name); | ||
| if (!(await exists(ctx, src))) { | ||
| continue; | ||
| } | ||
| await ctx.fs.cp(src, ctx.path.join(prefabsDir, name), { | ||
| recursive: true, | ||
| }); | ||
| log.message(`Copied prefab ${name} from ${store}`); | ||
| copied++; | ||
| break; | ||
| } | ||
| } | ||
| if (copied > 0) { | ||
| log.message( | ||
| `Seeded ${String(copied)} of ${String(missing.length)} missing prefabs from the GameMaker IDE`, | ||
| ); | ||
| } | ||
| } catch (e) { | ||
| log.message(`Could not read prefabs from the GameMaker IDE: ${String(e)}`); | ||
| } | ||
| } | ||
|
|
||
| /** Every `GameMakerStudio2*` install's `Prefabs` folder that exists on this machine. */ | ||
| async function findIdePrefabStores(ctx: Context): Promise<string[]> { | ||
| const stores: string[] = []; | ||
| for (const root of idePrefabStoreRoots(ctx)) { | ||
| let entries: string[]; | ||
| try { | ||
| entries = await ctx.fs.readdir(root); | ||
| } catch { | ||
| // Root doesn't exist (no IDE installed, or not where we look on this OS). | ||
| continue; | ||
| } | ||
| for (const entry of entries.sort()) { | ||
| if (!entry.startsWith("GameMakerStudio2")) { | ||
| continue; | ||
| } | ||
| const store = ctx.path.join(root, entry, "Prefabs"); | ||
| if (await exists(ctx, store)) { | ||
| stores.push(store); | ||
| } | ||
| } | ||
| } | ||
| return stores; | ||
| } | ||
|
|
||
| /** | ||
| * Names of the prefab packages a project pulls in, read out of the .yyp's | ||
| * `ForcedPrefabProjectReferences`. The .yyp is JSON with trailing commas, so we | ||
| * pick the names out with a regex rather than teaching the CLI to parse it. | ||
| */ | ||
| async function readPrefabReferences( | ||
| ctx: Context, | ||
| projectPath: ProjectPath, | ||
| ): Promise<string[]> { | ||
| const yyp = await ctx.fs.readFile(projectPath, "utf-8"); | ||
| const block = /"ForcedPrefabProjectReferences"\s*:\s*\[([\s\S]*?)\]/.exec( | ||
| yyp, | ||
| )?.[1]; | ||
| if (!block) { | ||
| return []; | ||
| } | ||
| const names = new Set<string>(); | ||
| for (const match of block.matchAll(/"name"\s*:\s*"([^"\\/]+)"/g)) { | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| names.add(match[1]!); | ||
| } | ||
| return [...names]; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Good catch 👍