def main()

in build/fuchsia/fidl_gen_cpp.py [0:0]


def main():
  parser = argparse.ArgumentParser();

  parser.add_argument('--fidlc-bin', dest='fidlc_bin', action='store', required=True)
  parser.add_argument('--fidlgen-bin', dest='fidlgen_bin', action='store', required=False)

  parser.add_argument('--sdk-base', dest='sdk_base', action='store', required=True)
  parser.add_argument('--root', dest='root', action='store', required=True)
  parser.add_argument('--json', dest='json', action='store', required=True)
  parser.add_argument('--fidlgen-output-root', dest='fidlgen_output_root', action='store', required=False)
  parser.add_argument('--output-c-tables', dest='output_c_tables', action='store', required=True)

  args = parser.parse_args()

  assert os.path.exists(args.fidlc_bin)
  # --fidlgen-bin and --fidlgen-output-root should be passed in together.
  assert os.path.exists(args.fidlgen_bin or '') == bool(args.fidlgen_output_root)

  fidl_files_by_name = GetFIDLFilesByLibraryName(args.sdk_base, args.root)

  fidlc_command = [
    args.fidlc_bin,
    '--experimental',
    'new_syntax_only',
    '--tables',
    args.output_c_tables,
    '--json',
    args.json
  ]

  # Create an iterator that works on both python3 and python2
  try:
    fidl_files_by_name_iter = list(fidl_files_by_name.items())
  except AttributeError:
    fidl_files_by_name_iter = iter(fidl_files_by_name.items())

  for _, fidl_files in fidl_files_by_name_iter:
    fidlc_command.append('--files')
    for fidl_file in fidl_files:
      fidl_abspath = os.path.abspath('%s/%s' % (args.sdk_base, fidl_file))
      fidlc_command.append(fidl_abspath)

  subprocess.check_call(fidlc_command)

  if args.fidlgen_output_root:
    assert os.path.exists(args.json)
    fidlgen_command = [
      args.fidlgen_bin,
      '-json',
      args.json,
      '-root',
      args.fidlgen_output_root
    ]

    subprocess.check_call(fidlgen_command)

  return 0