#!/usr/bin/env python
# Copyright (C) 2019 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:
# ./trace_processor
# python trace_processor
# bash trace_processor
# cat ./trace_processor | bash
# cat ./trace_processor | python -

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

import hashlib
import os
import sys
import tempfile
import urllib

TRACE_PROCESSOR_SHELL_SHAS = {
    'linux': 'a4852390aa8e02089d125be0cbfea9f2ada7fded',
    'mac': '52710df7fad736a45dc118b3feec3959d6ff3d91',
}
TRACE_PROCESSOR_SHELL_PATH = tempfile.gettempdir()
TRACE_PROCESSOR_SHELL_BASE_URL = ('https://storage.googleapis.com/perfetto/')


def check_hash(file_name, sha_value):
  with open(file_name, 'rb') as fd:
    file_hash = hashlib.sha1(fd.read()).hexdigest()
    return file_hash == sha_value


def load_trace_processor_shell(platform):
  sha_value = TRACE_PROCESSOR_SHELL_SHAS[platform]
  file_name = 'trace_processor_shell-' + platform + '-' + sha_value
  local_file = os.path.join(TRACE_PROCESSOR_SHELL_PATH, file_name)

  if os.path.exists(local_file):
    if not check_hash(local_file, sha_value):
      os.remove(local_file)
    else:
      return local_file

  url = TRACE_PROCESSOR_SHELL_BASE_URL + file_name
  urllib.urlretrieve(url, local_file)
  if not check_hash(local_file, sha_value):
    os.remove(local_file)
    raise ValueError("Invalid signature.")
  os.chmod(local_file, 0o755)
  return local_file


def main(argv):
  platform = None
  if sys.platform.startswith('linux'):
    platform = 'linux'
  elif sys.platform.startswith('darwin'):
    platform = 'mac'
  else:
    print("Invalid platform: {}".format(sys.platform))
    return 1

  trace_processor_shell_binary = load_trace_processor_shell(platform)
  os.execv(trace_processor_shell_binary,
           [trace_processor_shell_binary] + argv[1:])


if __name__ == '__main__':
  sys.exit(main(sys.argv))

#EOF
