1#!/usr/bin/env python
2#
3# Copyright 2018 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."""
10
11
12import argparse
13import common
14import multiprocessing
15import os
16import shutil
17import subprocess
18import utils
19
20def create_asset(target_dir):
21  """Create the asset."""
22  # Check out and build the Intel NEO driver. Following instructions here:
23  # https://github.com/intel/compute-runtime/blob/master/documentation/BUILD_Ubuntu.md
24  with utils.tmp_dir():
25    # Install build deps.
26    neo_build_deps = ['ccache', 'flex', 'bison', 'clang-4.0', 'cmake', 'g++',
27                      'git', 'patch', 'zlib1g-dev', 'autoconf', 'xutils-dev',
28                      'libtool', 'pkg-config', 'libpciaccess-dev']
29    apt_get_cmd = ['sudo', 'apt-get', 'install'] + neo_build_deps
30    print 'Running "%s"' % ' '.join(apt_get_cmd)
31    subprocess.check_call(apt_get_cmd)
32    # Check out repos.
33    for [repo, branch, local_name] in [
34        ['llvm-mirror/clang',             'release_40', 'clang_source'],
35        ['intel/opencl-clang',            'master',     'common_clang'],
36        ['intel/llvm-patches',            'master',     'llvm_patches'],
37        ['llvm-mirror/llvm',              'release_40', 'llvm_source'],
38        ['intel/gmmlib',                  'master',     'gmmlib'],
39        ['intel/intel-graphics-compiler', 'master',     'igc'],
40        ['KhronosGroup/OpenCL-Headers',   'master',     'opencl_headers'],
41        ['intel/compute-runtime',         'master',     'neo']
42    ]:
43      subprocess.check_call(['git', 'clone', '--depth', '1', '--branch', branch,
44                             'https://github.com/' + repo, local_name])
45    # Configure the build.
46    build_dir = os.path.join(os.getcwd(), 'build')
47    os.mkdir(build_dir)
48    os.chdir(build_dir)
49    subprocess.check_call(['cmake', '-DBUILD_TYPE=Release',
50                           '-DCMAKE_BUILD_TYPE=Release', '../neo'])
51    # Build and package the library.
52    subprocess.check_call(['make', '-j%d' % multiprocessing.cpu_count(),
53                           'package'])
54    # Extract library and move necessary files to target_dir. We ignore the ICD
55    # file because it's generated on the bot after we know the path to the CIPD
56    # package.
57    subprocess.check_call(['dpkg-deb', '--extract',
58                           'intel-opencl-1.0-0.x86_64-igdrcl.deb', build_dir])
59    lib_dir = os.path.join(build_dir, 'usr', 'local', 'lib')
60    for f in os.listdir(lib_dir):
61      shutil.move(os.path.join(lib_dir, f), target_dir)
62
63
64def main():
65  parser = argparse.ArgumentParser()
66  parser.add_argument('--target_dir', '-t', required=True)
67  args = parser.parse_args()
68  create_asset(args.target_dir)
69
70
71if __name__ == '__main__':
72  main()
73