Home | History | Annotate | Download | only in skia-with-swift-shader-base
      1 #!/usr/bin/python
      2 
      3 import subprocess
      4 import os
      5 import argparse
      6 
      7 
      8 # This script compiles and runs a skia app using Swiftshader in a docker container, making it easy
      9 # to use Swiftshade w/o having to over-write /usr/local/lib/libEGL.so and related on the
     10 # host development machine.
     11 
     12 # The Skia repo to be compiled will be the one on the host machine, which will
     13 # default to the one specified by the environment variable $SKIA_ROOT with a fallback to the
     14 # current working directory.
     15 
     16 # Example usage
     17 
     18 # Prove SwiftShader is really being used:
     19 #   build-with-swift-shader-and-run "out/with-swift-shader/fuzz --gpuInfo -t api -n NativeGLCanvas"
     20 
     21 # Notice the output says GL_RENDERER Google SwiftShader
     22 # After running the above, feel free to check out $SKIA_OUT/out/with-swift-shader. It has binaries
     23 # but if you try to run out/with-swift-shader/fuzz --gpuInfo -t api -n NativeGLCanvas w/o using
     24 # Docker, it will use the host's GPU (e.g. GL_VENDOR NVIDIA Corporation).
     25 
     26 # Reproduce a fuzzer bug in SwiftShader:
     27 # First, copy the test case into $SKIA_ROOT, say $SKIA_ROOT/skbug_1234
     28 #    build-with-swift-shader-and-run "out/with-swift-shader/fuzz -t filter_fuzz -b /skia/skbug_1234"
     29 
     30 # $SKIA_ROOT gets mapped to /skia - other than that, the docker container does not have
     31 # access to the host file system.
     32 
     33 
     34 IMAGE = 'gcr.io/skia-public/skia-with-swift-shader-base:prod'
     35 
     36 BUILD_SCRIPT_PATH = '/skia/docker/skia-with-swift-shader-base/build.sh'
     37 EXECUTABLE_DIR = 'out/with-swift-shader/'
     38 
     39 parser = argparse.ArgumentParser()
     40 parser.add_argument('--sync_deps', action='store_true', help='Sync the deps before building?')
     41 parser.add_argument('command', help='A string containing the command to be run '
     42                                     '(e.g. out/with-swift-shader/fuzz --help)')
     43 args = parser.parse_args()
     44 
     45 skia_root = os.environ['SKIA_ROOT'] or os.getcwd()
     46 
     47 print 'Assuming SKIA_ROOT to be %s' % skia_root
     48 
     49 build_cmd = ['docker', 'run', '--rm', '-v', '%s:/skia' % skia_root, IMAGE, BUILD_SCRIPT_PATH]
     50 if args.sync_deps:
     51     build_cmd += ['sync-deps']
     52 
     53 print 'Compiling executables to %s/%s' % (skia_root, EXECUTABLE_DIR)
     54 
     55 print subprocess.check_output(build_cmd)
     56 
     57 supplied_cmd = args.command.split(' ')
     58 print 'Running supplied command %s' % supplied_cmd
     59 run_cmd = ['docker', 'run', '--rm', '-w=/skia', '-v', '%s:/skia' % skia_root, IMAGE] + supplied_cmd
     60 
     61 print subprocess.check_output(run_cmd)