File size: 4,525 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
from pathlib import Path
import hashlib, os, shutil, subprocess, sys, json, time
repo = Path("/testbed/nodejs/node")
os.chdir(repo)
source = repo / "deps/v8/src/builtins/builtins-iterator-inl.h"
original_compat = source.read_bytes()
text = original_compat.decode()
include = "#include \"src/base/numerics/safe_conversions.h\"\n"
if include not in text:
    anchor = "#include \"src/base/float16.h\"\n"
    if anchor not in text:
        raise SystemExit("compat anchor missing")
    text = text.replace(anchor, anchor + include, 1)
old = """        } else {                                                            \\\n          static_assert(std::numeric_limits<ctype>::max() <=                \\\n                        std::numeric_limits<int>::max());                   \\\n          static_assert(std::numeric_limits<ctype>::min() >=                \\\n                        std::numeric_limits<int>::min());                   \\\n          if (!int_visitor(static_cast<int>(val))) {                        \\\n            return MaybeDirectHandle<Object>();                             \\\n          }                                                                 \\\n        }                                                                   \\\n"""
new = """        } else if constexpr (std::is_integral_v<ctype> &&                  \\\n                             base::kIsTypeInRangeForNumericType<int, ctype>) {\\\n          auto cast = [](auto v) { return base::strict_cast<int>(v); };      \\\n          if (!int_visitor(cast(val))) {                                     \\\n            return MaybeDirectHandle<Object>();                             \\\n          }                                                                 \\\n        } else {                                                            \\\n          static_assert(base::kIsTypeInRangeForNumericType<double, ctype>); \\\n          auto cast = [](auto v) { return base::strict_cast<double>(v); };   \\\n          if (!double_visitor(cast(val))) {                                  \\\n            return MaybeDirectHandle<Object>();                             \\\n          }                                                                 \\\n        }                                                                   \\\n"""
if old not in text:
    if "kIsTypeInRangeForNumericType" not in text:
        raise SystemExit("compat body anchor missing")
else:
    text = text.replace(old, new, 1)
source.write_text(text)
print("compat_applied", source)
native = repo / "src/js_native_api_v8.cc"
header = repo / "src/js_native_api.h"
before_binary_sha256 = hashlib.sha256(Path("/usr/local/bin/node").read_bytes()).hexdigest()
os.utime(native, None)
started = time.time()
proc = subprocess.run(["make", "-C", "out", "-j4", "BUILDTYPE=Release"], text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(proc.stdout)
print("make_rc", proc.returncode)
if proc.returncode:
    raise SystemExit(proc.returncode)
binary = repo / "out/Release/node"
if not binary.is_file():
    raise SystemExit("missing built node")
shutil.copy2(binary, "/usr/local/bin/node")
os.chmod("/usr/local/bin/node", 0o755)
source.write_bytes(original_compat)
assert "js_native_api_v8.o" in proc.stdout, "actual native API object compilation not observed"
print("installed_node_sha256", hashlib.sha256(Path("/usr/local/bin/node").read_bytes()).hexdigest())
print("node_version", subprocess.check_output(["/usr/local/bin/node", "--version"], text=True).strip())
print("node_symbol")
symbols = subprocess.check_output(["nm", "-D", "/usr/local/bin/node"], text=True)
matching = [line for line in symbols.splitlines() if line.endswith(" node_api_create_object_with_properties")]
assert len(matching) == 1
print(matching[0])
receipt = {"started_at_unix": started, "finished_at_unix": time.time(), "actual_native_api_compilation_observed": True, "candidate_source_sha256": hashlib.sha256(native.read_bytes()).hexdigest(), "candidate_header_sha256": hashlib.sha256(header.read_bytes()).hexdigest(), "binary_sha256": hashlib.sha256(Path("/usr/local/bin/node").read_bytes()).hexdigest(), "previous_binary_sha256": before_binary_sha256, "compiler_compat_original_restored": source.read_bytes() == original_compat, "network": "none"}
Path("/tmp/crossrepo-node-build.json").write_text(json.dumps(receipt, indent=2)+"\n")
print(json.dumps(receipt))
print("worktree_after_compat_reset")
subprocess.run(["git", "status", "--short"], check=True)