def intentbuilderc()

in tools/xctoolrunner/xctoolrunner.py [0:0]


def intentbuilderc(args, toolargs):
  """Assemble the call to "xcrun intentbuilderc"."""
  xcrunargs = ["xcrun", "intentbuilderc"]
  _apply_realpath(toolargs)
  is_swift = args.language == "Swift"

  output_path = None
  objc_output_srcs = None
  objc_output_hdrs = None

  # If the language is Swift, create a temporary directory for codegen output.
  # If the language is Objective-C, ensure the module name directory and headers
  # are created and empty (clean).
  if is_swift:
    output_path = "{}.out.tmp".format(args.swift_output_src)
  else:
    output_path = args.objc_output_srcs
    _ensure_clean_path(args.objc_output_hdrs)

  _ensure_clean_path(output_path)
  output_path = os.path.realpath(output_path)

  toolargs += [
    "-language",
    args.language,
    "-output",
    output_path,
  ]

  xcrunargs += toolargs

  return_code, _, _ = execute.execute_and_filter_output(
      xcrunargs,
      print_output=True)

  if return_code != 0:
    return return_code

  # If the language is Swift, concatenate all the output files into one.
  # If the language is Objective-C, put the headers into the pre-declared
  # headers directory. Because the .m files reference headers via quotes, copy
  # them instead of moving them and doing some -iquote fu.
  if is_swift:
    with open(args.swift_output_src, "w") as output_src:
      for src in _listdir_full(output_path):
        with open(src) as intput_src:
          shutil.copyfileobj(intput_src, output_src)
  else:
    with open(args.objc_public_header, "w") as public_header_f:
      for source_file in _listdir_full(output_path):
        if source_file.endswith(_HEADER_SUFFIX):
          out_hdr = os.path.join(args.objc_output_hdrs, os.path.basename(source_file))
          shutil.copy(source_file, out_hdr)
          public_header_f.write("#import \"{}\"\n".format(os.path.relpath(out_hdr)))

  return return_code