Home | History | Annotate | Download | only in emscripten_sdk
      1 #!/usr/bin/env python
      2 #
      3 # Copyright 2017 Google Inc.
      4 #
      5 # Use of this source code is governed by a BSD-style license that can be
      6 # found in the LICENSE file.
      7 
      8 
      9 """Create the asset and upload it."""
     10 
     11 
     12 import argparse
     13 import common
     14 import os
     15 import shutil
     16 import subprocess
     17 import sys
     18 import utils
     19 
     20 
     21 def main():
     22   if 'linux' not in sys.platform:
     23     print >> sys.stderr, 'This script only runs on Linux.'
     24     sys.exit(1)
     25   parser = argparse.ArgumentParser()
     26   parser.add_argument('--gsutil')
     27   parser.add_argument('--sdk_path', '-s', required=True)
     28   args = parser.parse_args()
     29 
     30   upload_script = os.path.join(common.FILE_DIR, 'upload.py')
     31 
     32   try:
     33     # Remove large directories that we don't need to use the sdk
     34     # (e.g. intermediate build products)
     35     rmpath = os.path.join(args.sdk_path, 'clang', 'fastcomp',
     36                           'build_incoming_64')
     37     # We can ignore errors, for example, if the folders were already deleted.
     38     shutil.rmtree(os.path.join(rmpath, 'lib'), ignore_errors=True)
     39     shutil.rmtree(os.path.join(rmpath, 'tools') , ignore_errors=True)
     40 
     41     # Remove the source code, which has lots of small files which slows
     42     # extraction.  We don't need the source code - we mostly care about the
     43     # binaries in $SDK/clang/fastcomp/build_incoming_64/bin.
     44     src = os.path.join(args.sdk_path, 'clang', 'fastcomp', 'src')
     45     for name in os.listdir(src):
     46       p = os.path.join(src, name)
     47       # Purposely don't delete src/emscripten-version.txt, which can cause
     48       # compilation warnings about "can't verify version".
     49       if os.path.isdir(p):
     50         shutil.rmtree(p)
     51 
     52     cmd = ['python', upload_script, '-t', args.sdk_path]
     53     if args.gsutil:
     54       cmd.extend(['--gsutil', args.gsutil])
     55     subprocess.check_call(cmd)
     56   except subprocess.CalledProcessError:
     57     # Trap exceptions to avoid printing two stacktraces.
     58     sys.exit(1)
     59 
     60 
     61 if __name__ == '__main__':
     62   main()
     63