Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Created October 16, 2020 00:51
Show Gist options
  • Select an option

  • Save jasonLaster/f97290a7ba29aee36ecea0b982bfdd98 to your computer and use it in GitHub Desktop.

Select an option

Save jasonLaster/f97290a7ba29aee36ecea0b982bfdd98 to your computer and use it in GitHub Desktop.
diff --git a/build.js b/build.js
index e70c275..37c8f5d 100644
--- a/build.js
+++ b/build.js
@@ -11,6 +11,7 @@ const { checkForFile, killContainers } = require("./src/shared/instanceUtils");
killContainers();
const driverOnly = process.argv[2] == "--driver-only";
+const dispatcherOnly = process.argv[2] == "--dispatcher-only";
// The protocol repo is needed in a neighboring directory.
const protocol = `${__dirname}/../protocol`;
@@ -30,14 +31,19 @@ let linkerVersion;
if (spawnSync("git", ["diff"]).stdout.toString().length) {
linkerVersion = `linker-${platform}-custom`;
} else {
- const version = spawnSync("git", ["rev-parse", "--short", "HEAD"]).stdout.toString().trim();
+ const version = spawnSync("git", ["rev-parse", "--short", "HEAD"])
+ .stdout.toString()
+ .trim();
linkerVersion = `linker-${platform}-${version}`;
}
-spawnSync("rm", ["-rf", "out"]);
-spawnSync("mkdir", ["out"]);
+if (!dispatcherOnly) {
+ spawnSync("rm", ["-rf", "out"]);
+ spawnSync("mkdir", ["out"]);
+}
if (!driverOnly) {
+ console.log(`>>> docker stuff.... 1`);
// Build the build container image.
spawnSync(
"docker",
@@ -46,24 +52,28 @@ if (!driverOnly) {
);
// Build protocol.json
- spawnSync(
- "git",
- ["pull"],
- { cwd: protocol, stdio: "inherit" }
- );
- spawnSync(
- "cp",
- [`${protocol}/json/protocol.json`, "out/protocol.json"]
- );
+ if (!dispatcherOnly) {
+ spawnSync("git", ["pull"], { cwd: protocol, stdio: "inherit" });
+ spawnSync("cp", [`${protocol}/json/protocol.json`, "out/protocol.json"]);
+ }
// Build other output files.
- spawnSync("docker", [
- "run",
- "-e", `PLATFORM=${platform}`,
- "-v", `${process.cwd()}/out:/out`,
- "--rm",
- "recordreplay-build",
- ], { stdio: "inherit" });
+ const dispatcherArgs = dispatcherOnly ? ["-e", `DISPATCHER_ONLY=1`] : [];
+
+ spawnSync(
+ "docker",
+ [
+ "run",
+ "-e",
+ `PLATFORM=${platform}`,
+ ...dispatcherArgs,
+ "-v",
+ `${process.cwd()}/out:/out`,
+ "--rm",
+ "recordreplay-build",
+ ],
+ { stdio: "inherit" }
+ );
// Copy lib binaries to output so docker can access them.
for (const file of ["7z", "7z.so", "libc++.dylib", "libsystem_c.dylib"]) {
@@ -76,79 +86,104 @@ if (!driverOnly) {
["build", "-f", "src/build/Dockerfile.control", "-t", "recordreplay-control", "out"],
{ stdio: "inherit" }
);
- spawnSync(
- "docker",
- ["build", "-f", "src/build/Dockerfile.dispatch", "-t", "recordreplay-dispatch", "out"],
- { stdio: "inherit" }
- );
- spawnSync(
- "docker",
- ["build", "-f", "src/build/Dockerfile.standalone", "-t", "recordreplay-standalone", "out"],
- { stdio: "inherit" }
- );
-}
-// Non-mac driver support is WIP
-if (platform != "macOS") {
- process.exit(0);
+ if (!dispatcherOnly) {
+ spawnSync(
+ "docker",
+ [
+ "build",
+ ...dispatcherArgs,
+ "-f",
+ "src/build/Dockerfile.dispatch",
+ "-t",
+ "recordreplay-dispatch",
+ "out",
+ ],
+ { stdio: "inherit" }
+ );
+ spawnSync(
+ "docker",
+ [
+ "build",
+ ...dispatcherArgs,
+ "-f",
+ "src/build/Dockerfile.standalone",
+ "-t",
+ "recordreplay-standalone",
+ "out",
+ ],
+ { stdio: "inherit" }
+ );
+ }
}
-// Build recording driver.
-fs.writeFileSync("out/LinkerVersion.cpp", `
+if (!dispatcherOnly) {
+ // Non-mac driver support is WIP
+ if (platform != "macOS") {
+ process.exit(0);
+ }
+
+ // Build recording driver.
+ fs.writeFileSync(
+ "out/LinkerVersion.cpp",
+ `
#include "recording/Recording.h"
const char recordreplay::gLinkerVersion[] = "${linkerVersion}";
-`);
-
-const extraArgs = [];
-if (platform == "macOS") {
- extraArgs.push(
- "-framework", "Security",
- "-framework", "Foundation",
- // macOS makes it hard to use OpenSSL, we have to specify paths manually.
- "-I/usr/local/opt/openssl/include",
- "-L/usr/local/opt/openssl/lib",
- // Websocket and dependent libraries.
- "/usr/local/lib/libwebsockets.a",
- "/usr/local/lib/libevent.a",
- "/usr/local/lib/libuv.a",
- "/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libcrypto.a",
- "/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libssl.a",
+`
);
-}
-const driverFile = `${platform}-recordreplay.so`;
-const driverJSON = `${platform}-recordreplay.json`;
-
-spawnSync(
- "clang",
- [
- "-shared",
- "-std=c++17",
- "-O3", "-g",
- "-o", `out/${driverFile}`,
- "-Isrc/cpp",
- "-Isrc/cpp/json",
- "-lc++",
- "-DRECORDING=1",
- ...platformDefines[platform],
- "out/LinkerVersion.cpp",
- ...driverFiles(platform).map(f => `src/cpp/${f}`),
- "-lz",
- ...extraArgs,
- ],
- { stdio: "inherit" }
-);
-
-fs.writeFileSync(
- `out/${driverJSON}`,
- `{ "version": "${linkerVersion}" }`
-);
-
-// Write a manifest with the platform-dependent output files we've written,
-// for use by the deploy script.
-const manifest = {
- linkerVersion,
- driverFile,
- driverJSON,
-};
-fs.writeFileSync("out/manifest.json", JSON.stringify(manifest));
+ const extraArgs = [];
+ if (platform == "macOS") {
+ extraArgs.push(
+ "-framework",
+ "Security",
+ "-framework",
+ "Foundation",
+ // macOS makes it hard to use OpenSSL, we have to specify paths manually.
+ "-I/usr/local/opt/openssl/include",
+ "-L/usr/local/opt/openssl/lib",
+ // Websocket and dependent libraries.
+ "/usr/local/lib/libwebsockets.a",
+ "/usr/local/lib/libevent.a",
+ "/usr/local/lib/libuv.a",
+ "/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libcrypto.a",
+ "/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libssl.a"
+ );
+ }
+
+ const driverFile = `${platform}-recordreplay.so`;
+ const driverJSON = `${platform}-recordreplay.json`;
+
+ spawnSync(
+ "clang",
+ [
+ "-shared",
+ "-std=c++17",
+ "-O3",
+ "-g",
+ "-o",
+ `out/${driverFile}`,
+ "-Isrc/cpp",
+ "-Isrc/cpp/json",
+ "-lc++",
+ "-DRECORDING=1",
+ ...platformDefines[platform],
+ "out/LinkerVersion.cpp",
+ ...driverFiles(platform).map(f => `src/cpp/${f}`),
+ "-lz",
+ ...extraArgs,
+ ],
+ { stdio: "inherit" }
+ );
+
+ fs.writeFileSync(`out/${driverJSON}`, `{ "version": "${linkerVersion}" }`);
+
+ // Write a manifest with the platform-dependent output files we've written,
+ // for use by the deploy script.
+ const manifest = {
+ linkerVersion,
+ driverFile,
+ driverJSON,
+ };
+ fs.writeFileSync("out/manifest.json", JSON.stringify(manifest));
+}
diff --git a/src/build/package.js b/src/build/package.js
index 53dd5f3..2929726 100644
--- a/src/build/package.js
+++ b/src/build/package.js
@@ -9,6 +9,8 @@ const fs = require("fs");
const { spawnSync } = require("child_process");
const { readSymbols } = require("../shared/instanceUtils");
const { linkerFiles, platformDefines } = require("../cpp/buildFiles");
+const dispatcherOnly = process.env.DISPATCHER_ONLY;
+console.log(`>>>>>> PACKAGE YAY`, process.env, { dispatcherOnly });
const gWebpacks = [
"build/webpack.control.js",
@@ -24,46 +26,44 @@ for (const webpack of gWebpacks) {
});
}
-spawnSync("chmod", [
- "-w",
- "/out/control.js",
- "/out/dispatch.js",
- "/out/standalone.js",
-]);
+spawnSync("chmod", ["-w", "/out/control.js", "/out/dispatch.js", "/out/standalone.js"]);
const generatedFiles = [];
const platform = process.env.PLATFORM;
-const sharedFlags = [
- "-O3",
- "-fno-omit-frame-pointer",
- "-g",
- "-Icpp",
- "-Icpp/json",
- ...platformDefines[platform],
-];
-for (const file of linkerFiles(platform)) {
- const generated = file.substring(0, file.length - 4).replace(/\//g, "_") + ".o";
- generatedFiles.push(generated);
+if (!dispatcherOnly) {
+ const sharedFlags = [
+ "-O3",
+ "-fno-omit-frame-pointer",
+ "-g",
+ "-Icpp",
+ "-Icpp/json",
+ ...platformDefines[platform],
+ ];
- spawnSync("g++", [...sharedFlags, "-c", "-o", `/out/${generated}`, `cpp/${file}`], {
- stdio: "inherit",
- });
-}
+ for (const file of linkerFiles(platform)) {
+ const generated = file.substring(0, file.length - 4).replace(/\//g, "_") + ".o";
+ generatedFiles.push(generated);
+
+ spawnSync("g++", [...sharedFlags, "-c", "-o", `/out/${generated}`, `cpp/${file}`], {
+ stdio: "inherit",
+ });
+ }
-spawnSync(
- "g++",
- [
- ...sharedFlags,
- "-o",
- "/out/linker",
- "-ldl",
- "-lpthread",
- ...generatedFiles.map(f => `/out/${f}`),
- ],
- { stdio: "inherit" }
-);
+ spawnSync(
+ "g++",
+ [
+ ...sharedFlags,
+ "-o",
+ "/out/linker",
+ "-ldl",
+ "-lpthread",
+ ...generatedFiles.map(f => `/out/${f}`),
+ ],
+ { stdio: "inherit" }
+ );
-const linkerSymbols = readSymbols("/out/linker");
-fs.writeFileSync("/out/linker.symbols.json", JSON.stringify({ linker: linkerSymbols }));
+ const linkerSymbols = readSymbols("/out/linker");
+ fs.writeFileSync("/out/linker.symbols.json", JSON.stringify({ linker: linkerSymbols }));
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment