Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | import glob from "glob"; import Path from "path"; import { promisify } from "util"; import { ensureDir, copyFile, readFile, pathExists } from "fs-extra"; import { checksumString } from "lib/helpers/checksum"; const globAsync = promisify(glob); interface ParsedInclude { contents: string; referencedFiles: string[]; checksum: string; } type IncludesLookup = Record<string, ParsedInclude>; type GameGlobalsLookup = Record<string, string>; export const objCache = {}; const GAME_GLOBALS_FILE = "data/game_globals.i"; const referencedFiles = (string: string): string[] => { return [...string.matchAll(/include "([^"]+)"/g)].map((m) => m[1]); }; const fileChecksum = async ( filename: string, includesLookup: IncludesLookup, gameGlobalsLookup: GameGlobalsLookup, envChecksum: string ) => { const fileContents = await readFile(filename, "utf8"); const fileChecksum = checksumString(fileContents); const headerFiles = referencedFiles(fileContents); let headerChecksums = ""; // Add includes from headers for (const headerFilePath of headerFiles) { const header = includesLookup[headerFilePath]; Iif (header) { for (const nestedHeader of header.referencedFiles) { Iif (!headerFiles.includes(nestedHeader)) { headerFiles.push(nestedHeader); } } Iif (headerFilePath === GAME_GLOBALS_FILE) { continue; } headerChecksums += header.checksum; } } // Only use addresses of globals that are used in file when generating checksum const usedGlobals = headerFiles.includes(GAME_GLOBALS_FILE) ? Object.keys(gameGlobalsLookup).filter((g) => { return fileContents.includes(g); }) : []; const usedGlobalAddresses = usedGlobals.reduce( (memo, g) => (memo += `${gameGlobalsLookup[g]}_`), "" ); return checksumString( `${fileChecksum}_${headerChecksums}_${usedGlobalAddresses}_${envChecksum}` ); }; const generateIncludesLookup = async (buildIncludeRoot: string) => { const allIncludeFiles = await globAsync(`${buildIncludeRoot}/**/*.{h,i}`); const includesLookup: IncludesLookup = {}; for (const filePath of allIncludeFiles) { const fileContents = await readFile(filePath, "utf8"); const key = Path.relative(buildIncludeRoot, filePath) .split(Path.sep) .join(Path.posix.sep); includesLookup[key] = { contents: fileContents, referencedFiles: referencedFiles(fileContents), checksum: checksumString(fileContents), }; } return includesLookup; }; const generateGameGlobalsLookup = (gameGlobalsContents: string) => { const lookup: GameGlobalsLookup = {}; const globalMatches = [ ...gameGlobalsContents.matchAll(/([A-Za-z_0-9]+)[\s]*=[\s]*([0-9]+)/g), ]; for (const globalMatch of globalMatches) { lookup[globalMatch[1]] = globalMatch[2]; } return lookup; }; export const cacheObjData = async ( buildRoot: string, tmpPath: string, env: NodeJS.ProcessEnv ) => { const cacheRoot = Path.normalize(`${tmpPath}/_gbscache/obj`); const buildObjRoot = Path.normalize(`${buildRoot}/obj`); const buildSrcRoot = Path.normalize(`${buildRoot}/src`); const buildIncludeRoot = Path.normalize(`${buildRoot}/include`); await ensureDir(cacheRoot); const includesLookup = await generateIncludesLookup(buildIncludeRoot); const gameGlobalsLookup = generateGameGlobalsLookup( includesLookup[GAME_GLOBALS_FILE]?.contents ); const objFiles = await globAsync(`${buildObjRoot}/*.o`); const srcFiles = await globAsync(`${buildSrcRoot}/**/*.{c,s}`); const envChecksum = checksumString(JSON.stringify(env)); for (let i = 0; i < objFiles.length; i++) { const objFilePath = objFiles[i]; const fileName = Path.basename(objFilePath, ".o"); Iif ( fileName.indexOf("bank_") !== 0 && fileName.indexOf("music_bank_") !== 0 ) { const matchingSrc = srcFiles.find((file) => { const baseName = Path.basename(file); return baseName === `${fileName}.c` || baseName === `${fileName}.s`; }); Iif (matchingSrc) { const cacheFilename = await fileChecksum( matchingSrc, includesLookup, gameGlobalsLookup, envChecksum ); const outFile = `${cacheRoot}/${cacheFilename}`; await copyFile(objFilePath, outFile); } } } }; export const fetchCachedObjData = async ( buildRoot: string, tmpPath: string, env: NodeJS.ProcessEnv ) => { const cacheRoot = Path.normalize(`${tmpPath}/_gbscache/obj`); const buildObjRoot = Path.normalize(`${buildRoot}/obj`); const buildSrcRoot = Path.normalize(`${buildRoot}/src`); const buildIncludeRoot = Path.normalize(`${buildRoot}/include`); const envChecksum = checksumString(JSON.stringify(env)); const includesLookup = await generateIncludesLookup(buildIncludeRoot); const gameGlobalsLookup = generateGameGlobalsLookup( includesLookup[GAME_GLOBALS_FILE]?.contents ); const srcFiles = await globAsync(`${buildSrcRoot}/**/*.{c,s}`); for (let i = 0; i < srcFiles.length; i++) { const srcFilePath = srcFiles[i]; const fileName = Path.basename(srcFilePath).replace(/\.(s|c)$/, ""); const cacheFilename = await fileChecksum( srcFilePath, includesLookup, gameGlobalsLookup, envChecksum ); const cacheFile = `${cacheRoot}/${cacheFilename}`; Iif (await pathExists(cacheFile)) { const outFile = `${buildObjRoot}/${fileName}.o`; await copyFile(cacheFile, outFile); } } }; |