Skip to content

perf(js_run_devserver): allow direct file sync #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/private/js_run_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _attrs = dicts.add(js_binary_lib.attrs, {
default = True,
),
"grant_sandbox_write_permissions": attr.bool(),
"direct_sync": attr.bool(),
"allow_execroot_entry_point_with_no_copy_data_to_bin": attr.bool(),
"command": attr.string(),
})
Expand Down Expand Up @@ -91,6 +92,8 @@ def _js_run_devserver_impl(ctx):
config["command"] = ctx.attr.command
if ctx.attr.grant_sandbox_write_permissions:
config["grant_sandbox_write_permissions"] = "1"
if ctx.attr.direct_sync:
config["direct_sync"] = True

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

Expand Down
28 changes: 16 additions & 12 deletions js/private/js_run_devserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async function deleteFiles(previousFiles, updatedFiles, sandbox) {
}

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

Expand All @@ -327,10 +327,15 @@ async function syncFiles(files, sandbox, writePerm) {
)
}

let otherFilesSrcDir = RUNFILES_ROOT
if (directSync) {
otherFilesSrcDir = process.env.BUILD_WORKSPACE_DIRECTORY
}

let totalSynced = (
await Promise.all(
otherFiles.map(async (file) => {
const src = path.join(RUNFILES_ROOT, file)
const src = path.join(otherFilesSrcDir, file)
const dst = path.join(sandbox, file)
return await syncRecursive(src, dst, sandbox, writePerm)
})
Expand Down Expand Up @@ -460,11 +465,13 @@ async function main(args, sandbox) {
async function processChunk(chunk) {
try {
const chunkString = chunk.toString()
if (chunkString.includes('IBAZEL_BUILD_COMPLETED SUCCESS')) {
if (process.env.JS_BINARY__LOG_DEBUG) {
console.error('IBAZEL_BUILD_COMPLETED SUCCESS')
}

const triggerSync = chunkString.includes('IBAZEL_BUILD_COMPLETED SUCCESS') || (chunkString.includes('IBAZEL_BUILD_STARTED') && config.direct_sync)

if (process.env.JS_BINARY__LOG_DEBUG) {
console.error(chunkString)
}

if (triggerSync) {
const oldFiles = config.data_files

// Re-parse the config file to get the latest list of data files to copy
Expand All @@ -483,16 +490,13 @@ async function main(args, sandbox) {
syncFiles(
updatedDataFiles,
sandbox,
config.grant_sandbox_write_permissions
config.grant_sandbox_write_permissions,
config.direct_sync,
),
])

// The latest state of copied data files
config.data_files = updatedDataFiles
} else if (chunkString.includes('IBAZEL_BUILD_STARTED')) {
if (process.env.JS_BINARY__LOG_DEBUG) {
console.error('IBAZEL_BUILD_STARTED')
}
}

// Forward stdin to the subprocess. See comment about
Expand Down