Skip to content

Commit 29ce861

Browse files
committed
perf(js_run_devserver): allow direct file sync
1 parent bfddcb3 commit 29ce861

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

js/private/js_run_devserver.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _attrs = dicts.add(js_binary_lib.attrs, {
1717
default = True,
1818
),
1919
"grant_sandbox_write_permissions": attr.bool(),
20+
"direct_sync": attr.bool(),
2021
"allow_execroot_entry_point_with_no_copy_data_to_bin": attr.bool(),
2122
"command": attr.string(),
2223
})
@@ -91,6 +92,8 @@ def _js_run_devserver_impl(ctx):
9192
config["command"] = ctx.attr.command
9293
if ctx.attr.grant_sandbox_write_permissions:
9394
config["grant_sandbox_write_permissions"] = "1"
95+
if ctx.attr.direct_sync:
96+
config["direct_sync"] = True
9497

9598
ctx.actions.write(config_file, json.encode(config))
9699

js/private/js_run_devserver.mjs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ async function deleteFiles(previousFiles, updatedFiles, sandbox) {
305305
}
306306

307307
// Sync list of files to the sandbox
308-
async function syncFiles(files, sandbox, writePerm) {
308+
async function syncFiles(files, sandbox, writePerm, directSync) {
309309
console.error(`+ Syncing ${files.length} files & folders...`)
310310
const startTime = perf_hooks.performance.now()
311311

@@ -327,10 +327,15 @@ async function syncFiles(files, sandbox, writePerm) {
327327
)
328328
}
329329

330+
let otherFilesSrcDir = RUNFILES_ROOT
331+
if (directSync) {
332+
otherFilesSrcDir = process.env.BUILD_WORKSPACE_DIRECTORY
333+
}
334+
330335
let totalSynced = (
331336
await Promise.all(
332337
otherFiles.map(async (file) => {
333-
const src = path.join(RUNFILES_ROOT, file)
338+
const src = path.join(otherFilesSrcDir, file)
334339
const dst = path.join(sandbox, file)
335340
return await syncRecursive(src, dst, sandbox, writePerm)
336341
})
@@ -460,11 +465,13 @@ async function main(args, sandbox) {
460465
async function processChunk(chunk) {
461466
try {
462467
const chunkString = chunk.toString()
463-
if (chunkString.includes('IBAZEL_BUILD_COMPLETED SUCCESS')) {
464-
if (process.env.JS_BINARY__LOG_DEBUG) {
465-
console.error('IBAZEL_BUILD_COMPLETED SUCCESS')
466-
}
467-
468+
const triggerSync = chunkString.includes('IBAZEL_BUILD_COMPLETED SUCCESS') || (chunkString.includes('IBAZEL_BUILD_STARTED') && config.direct_sync)
469+
470+
if (process.env.JS_BINARY__LOG_DEBUG) {
471+
console.error(chunkString)
472+
}
473+
474+
if (triggerSync) {
468475
const oldFiles = config.data_files
469476

470477
// Re-parse the config file to get the latest list of data files to copy
@@ -483,16 +490,13 @@ async function main(args, sandbox) {
483490
syncFiles(
484491
updatedDataFiles,
485492
sandbox,
486-
config.grant_sandbox_write_permissions
493+
config.grant_sandbox_write_permissions,
494+
config.direct_sync,
487495
),
488496
])
489497

490498
// The latest state of copied data files
491499
config.data_files = updatedDataFiles
492-
} else if (chunkString.includes('IBAZEL_BUILD_STARTED')) {
493-
if (process.env.JS_BINARY__LOG_DEBUG) {
494-
console.error('IBAZEL_BUILD_STARTED')
495-
}
496500
}
497501

498502
// Forward stdin to the subprocess. See comment about

0 commit comments

Comments
 (0)