int SwiftRunner::Run()

in tools/worker/swift_runner.cc [114:176]


int SwiftRunner::Run(std::ostream *stderr_stream, bool stdout_to_stderr) {
  int exit_code = RunSubProcess(args_, stderr_stream, stdout_to_stderr);

  if (exit_code != 0) {
    return exit_code;
  }

  if (!generated_header_rewriter_path_.empty()) {
#if __APPLE__
    // Skip the `xcrun` argument that's added when running on Apple platforms.
    int initial_args_to_skip = 1;
#else
    int initial_args_to_skip = 0;
#endif

    std::vector<std::string> rewriter_args;
    rewriter_args.reserve(args_.size() + 2 - initial_args_to_skip);
    rewriter_args.push_back(generated_header_rewriter_path_);
    rewriter_args.push_back("--");
    rewriter_args.insert(rewriter_args.end(),
                         args_.begin() + initial_args_to_skip, args_.end());

    exit_code = RunSubProcess(rewriter_args, stderr_stream, stdout_to_stderr);
  }

  auto enable_global_index_store = global_index_store_import_path_ != "";
  if (enable_global_index_store) {
    OutputFileMap output_file_map;
    output_file_map.ReadFromPath(output_file_map_path_);

    auto outputs = output_file_map.incremental_outputs();
    std::map<std::string, std::string>::iterator it;

    std::vector<std::string> ii_args;
// The index-import runfile path is passed as a define
#if defined(INDEX_IMPORT_PATH)
    ii_args.push_back(INDEX_IMPORT_PATH);
#else
    // Logical error
    std::cerr << "Incorrectly compiled work_processor.cc";
    exit_code = EXIT_FAILURE;
    return exit_code;
#endif

    for (it = outputs.begin(); it != outputs.end(); it++) {
      // Need the actual output paths of the compiler - not bazel
      auto output_path = it->first;
      auto file_type = output_path.substr(output_path.find_last_of(".") + 1);
      if (file_type == "o") {
        ii_args.push_back("-import-output-file");
        ii_args.push_back(output_path);
      }
    }

    auto exec_root = GetCurrentDirectory();
    // Copy back from the global index store to bazel's index store
    ii_args.push_back(exec_root + "/" + global_index_store_import_path_);
    ii_args.push_back(exec_root + "/" + index_store_path_);
    exit_code =
        RunSubProcess(ii_args, stderr_stream, /*stdout_to_stderr=*/true);
  }
  return exit_code;
}