hermes-agent/apps/desktop/scripts/build-command-screenshot-monitor.mjs
ethernet bb86a74b67 Merge origin/main into ethie/pm-clean
Conflicts:
- hermes_bootstrap.py: main calls install_never_free_environ() in the
  apply-on-import block right after the console fixes, where pm-clean runs its
  PM block (activation, relaunch, environ writes) instead of
  activate_durable_lazy_target(). It now runs ahead of the whole PM block,
  main's order, so the glibc < 2.41 guard is in before anything writes
  os.environ.
- tests/test_hermes_bootstrap.py: pm-clean dissolved the entry-point class and
  dropped its source-reading test; main's new
  test_library_imports_of_dual_use_entry_modules_stay_side_effect_free lands
  as a module-level function.
2026-09-23 22:39:57 -04:00

49 lines
2 KiB
JavaScript

#!/usr/bin/env node
// Build-time only: the shipped app never needs clang or Xcode tools.
import { execFileSync } from 'node:child_process'
import { chmodSync, mkdirSync, renameSync, rmSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { macosSysroot, xcrunClangArgv } from './macos-sysroot.mjs'
const script = fileURLToPath(import.meta.url)
const root = resolve(dirname(script), '..')
// `platform` and `sysroot` are injectable so tests can exercise the branches
// without redefining process.platform or shelling out to xcode-select.
export function buildCommandScreenshotMonitor({
source = resolve(root, '../..'),
distDir = resolve(source, 'apps/desktop/dist'),
platform = process.platform,
sysroot,
} = {}) {
if (platform !== 'darwin') return null
const output = resolve(distDir, 'native/command-screenshot-monitor')
const staging = `${output}.${process.pid}.tmp`
mkdirSync(dirname(output), { recursive: true })
const sdk = sysroot === undefined ? macosSysroot() : sysroot
try {
execFileSync('xcrun', [
...xcrunClangArgv(sdk),
'-arch', 'arm64', '-arch', 'x86_64', '-mmacosx-version-min=11.0',
'-fobjc-arc', '-fblocks', '-O2', '-Wall', '-Wextra',
'-framework', 'Cocoa', '-framework', 'CoreGraphics',
resolve(source, 'apps/desktop/electron/native/command-screenshot-monitor.m'), '-o', staging,
], { stdio: 'inherit', timeout: 120_000 })
chmodSync(staging, 0o755)
renameSync(staging, output)
// electron-builder signs this Mach-O with the app; dist/** is already asarUnpack.
console.log(`built ${output} (arm64 + x86_64)`)
return output
} finally {
rmSync(staging, { force: true })
}
}
if (process.argv[1] && resolve(process.argv[1]) === script) {
const args = process.argv.slice(2)
if (args.length && (args.length !== 2 || args[0] !== '--out-dir')) {
throw new Error('Usage: build-command-screenshot-monitor.mjs [--out-dir PATH]')
}
buildCommandScreenshotMonitor(args.length ? { distDir: resolve(args[1]) } : {})
}