bool SwiftRunner::ProcessArgument()

in tools/worker/swift_runner.cc [267:346]


bool SwiftRunner::ProcessArgument(
    Iterator &itr, const std::string &arg,
    std::function<void(const std::string &)> consumer) {
  bool changed = false;
  if (arg[0] == '@') {
    changed = ProcessPossibleResponseFile(arg, consumer);
  } else {
    std::string new_arg = arg;
    if (StripPrefix("-Xwrapped-swift=", new_arg)) {
      if (new_arg == "-debug-prefix-pwd-is-dot") {
        // Get the actual current working directory (the workspace root), which
        // we didn't know at analysis time.
        consumer("-debug-prefix-map");
        consumer(GetCurrentDirectory() + "=.");
        changed = true;
      } else if (new_arg == "-coverage-prefix-pwd-is-dot") {
        // Get the actual current working directory (the workspace root), which
        // we didn't know at analysis time.
        consumer("-coverage-prefix-map");
        consumer(GetCurrentDirectory() + "=.");
        changed = true;
      } else if (new_arg == "-ephemeral-module-cache") {
        // Create a temporary directory to hold the module cache, which will be
        // deleted after compilation is finished.
        auto module_cache_dir =
            TempDirectory::Create("swift_module_cache.XXXXXX");
        consumer("-module-cache-path");
        consumer(module_cache_dir->GetPath());
        temp_directories_.push_back(std::move(module_cache_dir));
        changed = true;
      } else if (StripPrefix("-generated-header-rewriter=", new_arg)) {
        changed = true;
      } else if (StripPrefix("-global-index-store-import-path=", new_arg)) {
        changed = true;
      } else {
        // TODO(allevato): Report that an unknown wrapper arg was found and give
        // the caller a way to exit gracefully.
        changed = true;
      }
    } else {
      // Process default arguments
      if (arg == "-index-store-path") {
        consumer("-index-store-path");
        ++itr;

        // If there was a global index store set, pass that to swiftc.
        // Otherwise, pass the users. We later copy index data onto the users.
        if (global_index_store_import_path_ != "") {
          new_arg = global_index_store_import_path_;
        } else {
          new_arg = index_store_path_;
        }
        changed = true;
      } else if (arg == "-output-file-map") {
        // Save the output file map to the value proceeding
        // `-output-file-map`
        consumer("-output-file-map");
        ++itr;
        new_arg = output_file_map_path_;
        changed = true;
      } else if (is_dump_ast_ && ArgumentEnablesWMO(arg)) {
        // WMO is invalid for -dump-ast,
        // so omit the argument that enables WMO
        return true;  // return to avoid consuming the arg
      }

      // Apply any other text substitutions needed in the argument (i.e., for
      // Apple toolchains).
      //
      // Bazel doesn't quote arguments in multi-line params files, so we need
      // to ensure that our defensive quoting kicks in if an argument contains
      // a space, even if no other changes would have been made.
      changed = bazel_placeholder_substitutions_.Apply(new_arg) ||
                new_arg.find_first_of(' ') != std::string::npos;
      consumer(new_arg);
    }
  }

  return changed;
}