Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(eht): a generated file cites its author, not the machine that built it

esengine2e28e06d75d5
diff --git a/sdk/src/wasm/constants.generated.ts b/sdk/src/wasm/constants.generated.ts
index 0807aeb48..9a8baed84 100644
--- a/sdk/src/wasm/constants.generated.ts
+++ b/sdk/src/wasm/constants.generated.ts
@@ -11,20 +11,20 @@
* other rather than disagreeing quietly.
*/
-/** C++ `CHUNK_SIZE` in `D:/estella/src/esengine/tilemap/TilemapSystem.hpp`. */
+/** C++ `CHUNK_SIZE` in `src/esengine/tilemap/TilemapSystem.hpp`. */
export const CHUNK_SIZE = 16;
-/** C++ `kColorLutSize` in `D:/estella/src/esengine/particle/ParticleSystem.hpp`. */
+/** C++ `kColorLutSize` in `src/esengine/particle/ParticleSystem.hpp`. */
export const GRADIENT_LUT_SIZE = 32;
-/** C++ `TILE_FLIP_D` in `D:/estella/src/esengine/tilemap/TilemapSystem.hpp`. */
+/** C++ `TILE_FLIP_D` in `src/esengine/tilemap/TilemapSystem.hpp`. */
export const TILE_FLIP_D = 0x8000;
-/** C++ `TILE_FLIP_H` in `D:/estella/src/esengine/tilemap/TilemapSystem.hpp`. */
+/** C++ `TILE_FLIP_H` in `src/esengine/tilemap/TilemapSystem.hpp`. */
export const TILE_FLIP_H = 0x2000;
-/** C++ `TILE_FLIP_V` in `D:/estella/src/esengine/tilemap/TilemapSystem.hpp`. */
+/** C++ `TILE_FLIP_V` in `src/esengine/tilemap/TilemapSystem.hpp`. */
export const TILE_FLIP_V = 0x4000;
-/** C++ `TILE_ID_MASK` in `D:/estella/src/esengine/tilemap/TilemapSystem.hpp`. */
+/** C++ `TILE_ID_MASK` in `src/esengine/tilemap/TilemapSystem.hpp`. */
export const TILE_ID_MASK = 0x1fff;
diff --git a/tools/contract-inventory.mjs b/tools/contract-inventory.mjs
index b5a119059..cce8f693e 100644
--- a/tools/contract-inventory.mjs
+++ b/tools/contract-inventory.mjs
@@ -171,6 +171,28 @@ for (const [p, why] of Object.entries(NOT_CONTRACT)) {
if (!existsSync(path.join(ROOT, p))) findings.push(`NOT_CONTRACT names ${p}, which is gone — ${why}`);
}
+/**
+ * A derivation of an authority and of NOTHING ELSE — least of all of the
+ * machine that ran the generator. `constants.generated.ts` shipped citing
+ * `D:/estella/...`: every rebuild elsewhere rewrote all six lines, and a
+ * regenerate-and-compare over it would have reported the host, not the code.
+ */
+const MACHINE_PATH = /(?:^|[^A-Za-z0-9_])(?:[A-Za-z]:[\\/](?:Users|home|dev|estella)|\/(?:Users|home)\/[A-Za-z0-9._-]+\/)/;
+for (const g of generated) {
+ let text;
+ try {
+ text = read(g);
+ } catch {
+ continue;
+ }
+ const line = text.split('\n').findIndex((l) => MACHINE_PATH.test(l));
+ if (line >= 0) {
+ findings.push(`GROUND: ${g}:${line + 1} carries an absolute path from the machine that`
+ + ' generated it. A generated artifact must come out the same on every checkout,'
+ + ' or its diff reports the host.');
+ }
+}
+
// ── Ground: every hand-copied cross-language pin belongs to a fact ────────────
const PIN_FILE = 'sdk/tests/cpp-contract.test.ts';
if (existsSync(path.join(ROOT, PIN_FILE))) {
diff --git a/tools/eht/constants.py b/tools/eht/constants.py
index 4dac1964d..4020d104c 100644
--- a/tools/eht/constants.py
+++ b/tools/eht/constants.py
@@ -26,6 +26,26 @@ class Constant(NamedTuple):
header: str
+#: The repository the generator and the headers it scans both live in.
+_REPO = Path(__file__).resolve().parents[2]
+
+
+def _cite(header: Path) -> str:
+ """Where a reader finds the declaration, named from the repository root.
+
+ The absolute path of whichever machine generated last is not a citation: it
+ is a whole-file diff for everyone else, and it turns any regenerate-and-
+ compare check into a report about the host rather than about the code. So an
+ unciteable header is a failure, not a fallback to the absolute path.
+ """
+ try:
+ return header.resolve().relative_to(_REPO).as_posix()
+ except ValueError:
+ raise SystemExit(
+ f"[FAIL] ES_CONST: {header} is outside {_REPO}, so the generated file "
+ "cannot cite it by a name every machine agrees on.")
+
+
#: `ES_CONST(attrs)` then a `constexpr` integer on the following line(s).
_DECL = re.compile(
r'ES_CONST\(([^)]*)\)\s*'
@@ -63,7 +83,7 @@ def parse_constants(roots: List[Path]) -> List[Constant]:
ts_name=attrs.get('ts', m.group(2)),
value=int(m.group(3), 0),
hex='hex' in attrs,
- header=header.as_posix(),
+ header=_cite(header),
))
_refuse_duplicates(out)
return sorted(out, key=lambda c: c.ts_name)