private run()

in src/bazel/bazel_query.ts [119:167]


  private run(additionalOptions: string[] = []): Promise<Buffer> {
    const bazelConfig = vscode.workspace.getConfiguration("bazel");
    const queriesShareServer = bazelConfig.get<boolean>("queriesShareServer");
    let additionalStartupOptions: string[] = [];
    if (!queriesShareServer) {
      // If not sharing the Bazel server, use a custom output_base.
      //
      // This helps get the queries out of the way of any other builds (or use
      // of ibazel). The docs suggest using a custom output base for IDE support
      // features, which is what these queries are. See:
      // tslint:disable-next-line: max-line-length
      // https://docs.bazel.build/versions/master/guide.html#choosing-the-output-base
      //
      // NOTE: This does NOT use a random directory for each query instead it
      // uses a generated tmp directory based on the Bazel workspace, this way
      // the server is shared for all the queries.
      const ws = getBazelWorkspaceFolder(this.workingDirectory);
      const hash = crypto.createHash("md5").update(ws).digest("hex");
      const outputBase = path.join(os.tmpdir(), hash);
      additionalStartupOptions = additionalStartupOptions.concat([
        `--output_base=${outputBase}`,
      ]);
    }
    return new Promise((resolve, reject) => {
      const execOptions = {
        cwd: this.workingDirectory,
        // A null encoding causes the callback below to receive binary data as a
        // Buffer instead of text data as strings.
        encoding: null,
        maxBuffer: Number.MAX_SAFE_INTEGER,
      };
      child_process.execFile(
        this.bazelExecutable,
        this.execArgs(additionalOptions, additionalStartupOptions),
        execOptions,
        (error: Error, stdout: Buffer, stderr: Buffer) => {
          if (error) {
            if (this.ignoresErrors) {
              resolve(new Buffer(0));
            } else {
              reject(error);
            }
          } else {
            resolve(stdout);
          }
        },
      );
    });
  }