<commit_before>#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import argparse
import subprocess
import sys
import os

buildroot_dir = os.path.abspath(
    os.path.join(os.path.realpath(__file__), '..', '..', '..', '..')
)


def main():
  parser = argparse.ArgumentParser(
      description='Copies architecture-dependent gen_snapshot binaries to output dir'
  )

  parser.add_argument('--dst', type=str, required=True)
  parser.add_argument('--clang-dir', type=str, default='clang_x64')
  parser.add_argument('--x64-out-dir', type=str)
  parser.add_argument('--arm64-out-dir', type=str)
  parser.add_argument('--armv7-out-dir', type=str)
  parser.add_argument('--zip', action="store_true", default=False)

  args = parser.parse_args()

  dst = (
      args.dst
      if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst)
  )

  if args.x64_out_dir:
    x64_out_dir = (
        args.x64_out_dir if os.path.isabs(args.x64_out_dir) else
        os.path.join(buildroot_dir, args.x64_out_dir)
    )
    generate_gen_snapshot(x64_out_dir, os.path.join(dst, 'gen_snapshot_x64'))

  if args.arm64_out_dir:
    arm64_out_dir = (
        args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else
        os.path.join(buildroot_dir, args.arm64_out_dir)
    )
    generate_gen_snapshot(
        os.path.join(arm64_out_dir, args.clang_dir),
        os.path.join(dst, 'gen_snapshot_arm64')
    )

  if args.armv7_out_dir:
    armv7_out_dir = (
        args.armv7_out_dir if os.path.isabs(args.armv7_out_dir) else
        os.path.join(buildroot_dir, args.armv7_out_dir)
    )
    generate_gen_snapshot(
        os.path.join(armv7_out_dir, args.clang_dir),
        os.path.join(dst, 'gen_snapshot_armv7')
    )
  if args.zip:
    zip_archive(dst)


def zip_archive(dst):
  subprocess.check_call([
      'zip',
      '-r',
      'gen_snapshot.zip',
      '.',
  ], cwd=dst)


def generate_gen_snapshot(directory, destination):
  gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
  if not os.path.isfile(gen_snapshot_dir):
    print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
    sys.exit(1)

  subprocess.check_call([
      'xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination
  ])<commit_msg>Print detailed logs on command error. (#36053)<commit_after>#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import argparse
import subprocess
import sys
import os

buildroot_dir = os.path.abspath(
    os.path.join(os.path.realpath(__file__), '..', '..', '..', '..')
)


def main():
  parser = argparse.ArgumentParser(
      description='Copies architecture-dependent gen_snapshot binaries to output dir'
  )

  parser.add_argument('--dst', type=str, required=True)
  parser.add_argument('--clang-dir', type=str, default='clang_x64')
  parser.add_argument('--x64-out-dir', type=str)
  parser.add_argument('--arm64-out-dir', type=str)
  parser.add_argument('--armv7-out-dir', type=str)
  parser.add_argument('--zip', action="store_true", default=False)

  args = parser.parse_args()

  dst = (
      args.dst
      if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst)
  )

  if args.x64_out_dir:
    x64_out_dir = (
        args.x64_out_dir if os.path.isabs(args.x64_out_dir) else
        os.path.join(buildroot_dir, args.x64_out_dir)
    )
    generate_gen_snapshot(x64_out_dir, os.path.join(dst, 'gen_snapshot_x64'))

  if args.arm64_out_dir:
    arm64_out_dir = (
        args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else
        os.path.join(buildroot_dir, args.arm64_out_dir)
    )
    generate_gen_snapshot(
        os.path.join(arm64_out_dir, args.clang_dir),
        os.path.join(dst, 'gen_snapshot_arm64')
    )

  if args.armv7_out_dir:
    armv7_out_dir = (
        args.armv7_out_dir if os.path.isabs(args.armv7_out_dir) else
        os.path.join(buildroot_dir, args.armv7_out_dir)
    )
    generate_gen_snapshot(
        os.path.join(armv7_out_dir, args.clang_dir),
        os.path.join(dst, 'gen_snapshot_armv7')
    )
  if args.zip:
    zip_archive(dst)


def zip_archive(dst):
  subprocess.check_call([
      'zip',
      '-r',
      'gen_snapshot.zip',
      '.',
  ], cwd=dst)


def generate_gen_snapshot(directory, destination):
  gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
  if not os.path.isfile(gen_snapshot_dir):
    print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
    sys.exit(1)

  result = subprocess.run([
      'xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination
  ])
  if result.returncode != 0:
    print(
        'Error processing command with stdout[%s] and stderr[%s]' %
        (result.stdout, result.stderr)
    )
    return 1
{'fraction_non_alphanumeric': 0.13383275966794897, 'fraction_numerical': 0.02085442397246406, 'mean_word_length': 3.414655942806077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7235339', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1852, 'n_words': 318}