#!/usr/bin/env python3
# Copyright (C) 2021 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file should do the same thing when being invoked in any of these ways:
# ./tracebox
# python tracebox
# bash tracebox
# cat ./tracebox | bash
# cat ./tracebox | python -

BASH_FALLBACK = """ "
exec python3 - "$@" <<'#'EOF
#"""

TOOL_NAME = 'tracebox'

# BEGIN_SECTION_GENERATED_BY(roll-prebuilts)
# Revision: v26.1
PERFETTO_PREBUILT_MANIFEST = [{
    'tool':
        'tracebox',
    'arch':
        'mac-amd64',
    'file_name':
        'tracebox',
    'file_size':
        1382520,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/mac-amd64/tracebox',
    'sha256':
        '445b758fc388998b072bc131aa953d264a35eff1225fe1b5e15766df50cdede4',
    'platform':
        'darwin',
    'machine': ['x86_64']
}, {
    'tool':
        'tracebox',
    'arch':
        'mac-arm64',
    'file_name':
        'tracebox',
    'file_size':
        1275848,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/mac-arm64/tracebox',
    'sha256':
        '78daec93072eeef0086445daf77c691ec12c9d1ab366a4bf03f573ab2c57dd97',
    'platform':
        'darwin',
    'machine': ['arm64']
}, {
    'tool':
        'tracebox',
    'arch':
        'linux-amd64',
    'file_name':
        'tracebox',
    'file_size':
        1790304,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/linux-amd64/tracebox',
    'sha256':
        'd00c0f822b2c0fe3399d1b5763596fe881a387c900326dc9bb62b370c629a691',
    'platform':
        'linux',
    'machine': ['x86_64']
}, {
    'tool':
        'tracebox',
    'arch':
        'linux-arm',
    'file_name':
        'tracebox',
    'file_size':
        1034928,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/linux-arm/tracebox',
    'sha256':
        'df0c86cb3fc8ef0874a57bc8976314408ca836e1f6136058fe4cba20932208e9',
    'platform':
        'linux',
    'machine': ['armv6l', 'armv7l', 'armv8l']
}, {
    'tool':
        'tracebox',
    'arch':
        'linux-arm64',
    'file_name':
        'tracebox',
    'file_size':
        1667112,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/linux-arm64/tracebox',
    'sha256':
        '5d3cb68d29ebb25581a78cc60421ffb89ae9150d9b3d16281c760647962de718',
    'platform':
        'linux',
    'machine': ['aarch64']
}, {
    'tool':
        'tracebox',
    'arch':
        'android-arm',
    'file_name':
        'tracebox',
    'file_size':
        1071060,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/android-arm/tracebox',
    'sha256':
        '76fddaf7e3642a78e47ee03b74c0b955198b6a3131b2a9403ffe78ecd5dfceba'
}, {
    'tool':
        'tracebox',
    'arch':
        'android-arm64',
    'file_name':
        'tracebox',
    'file_size':
        1624744,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/android-arm64/tracebox',
    'sha256':
        '4e0210a7f908d403c84b0fa5d55b2a7934487211c927b566cd77d42eb99ad015'
}, {
    'tool':
        'tracebox',
    'arch':
        'android-x86',
    'file_name':
        'tracebox',
    'file_size':
        1644460,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/android-x86/tracebox',
    'sha256':
        '02ca97fe076fdd85f0560dae643767de50dfd29cd3f3b8376e3437ad6010dcd2'
}, {
    'tool':
        'tracebox',
    'arch':
        'android-x64',
    'file_name':
        'tracebox',
    'file_size':
        1874600,
    'url':
        'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v26.1/android-x64/tracebox',
    'sha256':
        '63e8277820f53017dd5b1682f488b51373f8423fffd02efa195b0912ae42ec86'
}]


# DO NOT EDIT. If you wish to make edits to this code, you need to change only
# //tools/get_perfetto_prebuilt.py and run /tools/roll-prebuilts to regenerate
# all the others scripts this is embedded into.
def get_perfetto_prebuilt(tool_name, soft_fail=False, arch=None):
  """ Downloads the prebuilt, if necessary, and returns its path on disk. """

  # The first time this is invoked, it downloads the |url| and caches it into
  # ~/.perfetto/prebuilts/$tool_name. On subsequent invocations it just runs the
  # cached version.
  def download_or_get_cached(file_name, url, sha256):
    import os, hashlib, subprocess
    dir = os.path.join(
        os.path.expanduser('~'), '.local', 'share', 'perfetto', 'prebuilts')
    os.makedirs(dir, exist_ok=True)
    bin_path = os.path.join(dir, file_name)
    sha256_path = os.path.join(dir, file_name + '.sha256')
    needs_download = True

    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
    # download is cached into file_name.sha256, just check if that matches.
    if os.path.exists(bin_path) and os.path.exists(sha256_path):
      with open(sha256_path, 'rb') as f:
        digest = f.read().decode()
        if digest == sha256:
          needs_download = False

    if needs_download:
      # Either the filed doesn't exist or the SHA256 doesn't match.
      tmp_path = bin_path + '.tmp'
      print('Downloading ' + url)
      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
      with open(tmp_path, 'rb') as fd:
        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
      if actual_sha256 != sha256:
        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
                        (url, actual_sha256, sha256))
      os.chmod(tmp_path, 0o755)
      os.rename(tmp_path, bin_path)
      with open(sha256_path, 'w') as f:
        f.write(sha256)
    return bin_path
    # --- end of download_or_get_cached() ---

  # --- get_perfetto_prebuilt() function starts here. ---
  import os, platform, sys
  plat = sys.platform.lower()
  machine = platform.machine().lower()
  manifest_entry = None
  for entry in PERFETTO_PREBUILT_MANIFEST:
    # If the caller overrides the arch, just match that (for Android prebuilts).
    if arch:
      if entry.get('arch') == arch:
        manifest_entry = entry
        break
      continue
    # Otherwise guess the local machine arch.
    if entry.get('tool') == tool_name and entry.get(
        'platform') == plat and machine in entry.get('machine', []):
      manifest_entry = entry
      break
  if manifest_entry is None:
    if soft_fail:
      return None
    raise Exception(
        ('No prebuilts available for %s-%s\n' % (plat, machine)) +
        'See https://perfetto.dev/docs/contributing/build-instructions')

  return download_or_get_cached(
      file_name=manifest_entry['file_name'],
      url=manifest_entry['url'],
      sha256=manifest_entry['sha256'])


# END_SECTION_GENERATED_BY(roll-prebuilts)

if __name__ == '__main__':
  import sys, subprocess, os
  bin_path = get_perfetto_prebuilt(TOOL_NAME)
  if sys.platform.lower() == 'win32':
    exit(subprocess.check_call([bin_path, *sys.argv[1:]]))
  os.execv(bin_path, [bin_path] + sys.argv[1:])

#EOF
