(localValdiPath: string)
| 222 | { name: 'snap_macros', subPath: 'bzl/valdi/snap_macros' }, |
| 223 | { name: 'snap_client_toolchains', subPath: 'bzl/toolchains' }, |
| 224 | { name: 'snap_platforms', subPath: 'bzl/platforms' }, |
| 225 | { name: 'skia_user_config', subPath: 'third-party/skia_user_config' }, |
| 226 | { name: 'rules_hdrs', subPath: 'third-party/rules_hdrs' }, |
| 227 | { name: 'valdi_toolchain', subPath: 'bin' }, |
| 228 | ]; |
| 229 | |
| 230 | function applyLocalOverrides(localValdiPath: string) { |
| 231 | const resolvedPath = path.resolve(localValdiPath); |
| 232 | const registryPath = path.join(resolvedPath, 'registry'); |
| 233 | |
| 234 | const moduleBazelPath = path.join(process.cwd(), 'MODULE.bazel'); |
| 235 | let content = fs.readFileSync(moduleBazelPath, 'utf-8'); |
| 236 | |
| 237 | // Replace Valdi archive variables + override with local_path_override |
| 238 | content = content.replace( |
| 239 | /VALDI_TAG = .*\nVALDI_URL = .*\nVALDI_PREFIX = .*\n\nbazel_dep\(name = "valdi".*\)\narchive_override\(\n\s+module_name = "valdi",\n\s+urls = \[VALDI_URL\],\n\s+strip_prefix = VALDI_PREFIX,\n\)/, |
| 240 | `bazel_dep(name = "valdi", version = "0.1")\nlocal_path_override(module_name = "valdi", path = "${resolvedPath}")`, |
| 241 | ); |
| 242 | |
| 243 | // Replace sub-module archive_overrides with local_path_override, or strip |
| 244 | // them entirely if the sub-module no longer exists in the local checkout |
| 245 | for (const sub of VALDI_SUB_MODULES) { |
| 246 | const subModuleBazel = path.join(resolvedPath, sub.subPath, 'MODULE.bazel'); |
| 247 | const regex = new RegExp(`\\nbazel_dep\\(name = "${sub.name}"\\)\\narchive_override\\(module_name = "${sub.name}".*\\)`); |
| 248 | if (fs.existsSync(subModuleBazel)) { |
| 249 | content = content.replace( |
| 250 | regex, |
| 251 | `\nbazel_dep(name = "${sub.name}")\nlocal_path_override(module_name = "${sub.name}", path = "${resolvedPath}/${sub.subPath}")`, |
| 252 | ); |
| 253 | } else { |
| 254 | content = content.replace(regex, ''); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // Remove Widgets section entirely in local mode (not available locally) |
| 259 | content = content.replace( |
| 260 | /# -- Valdi Widgets.*\nWIDGETS_TAG = .*\n\nbazel_dep\(name = "valdi_widgets"\)\narchive_override\(\n\s+module_name = "valdi_widgets",\n\s+urls = \[.*\],\n\s+strip_prefix = .*,\n\)/, |
| 261 | '', |
| 262 | ); |
| 263 | |
| 264 | fs.writeFileSync(moduleBazelPath, content); |
| 265 | |
| 266 | // Update .bazelrc to use local registry |
| 267 | const bazelrcPath = path.join(process.cwd(), '.bazelrc'); |
| 268 | let bazelrc = fs.readFileSync(bazelrcPath, 'utf-8'); |
| 269 | bazelrc = bazelrc.replace( |
| 270 | /common --registry=https:\/\/raw\.githubusercontent\.com\/Snapchat\/Valdi\/.*\/registry/, |
| 271 | `common --registry=file://${registryPath}`, |
no test coverage detected