Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / extract_artifacts.py
blobf1748b487f5ec176339d30a8c538139d33edf3fb
1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import argparse
7 import glob
8 import os
9 import sys
11 if sys.version_info < (2, 7, 0):
12 sys.stderr.write("python 2.7 or later is required run this script\n")
13 sys.exit(1)
15 import buildbot_common
16 import build_paths
17 from build_paths import NACL_DIR, SDK_SRC_DIR, EXTRACT_ARCHIVE_DIR
19 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
21 import getos
22 import oshelpers
24 # TODO(binji): The artifacts should be downloaded; until then, point at the
25 # directory where the artifacts are built.
26 DOWNLOAD_ARCHIVE_DIR = build_paths.BUILD_ARCHIVE_DIR
28 PLATFORM = getos.GetPlatform()
29 NEWLIB_X86_TC_DIR = os.path.join('toolchain', '%s_x86_newlib' % PLATFORM)
30 NEWLIB_ARM_TC_DIR = os.path.join('toolchain', '%s_arm_newlib' % PLATFORM)
31 GLIBC_X86_TC_DIR = os.path.join('toolchain', '%s_x86_glibc' % PLATFORM)
32 PNACL_TC_DIR = os.path.join('toolchain', '%s_pnacl' % PLATFORM)
33 PNACL_TRANSLATOR_DIR = os.path.join(PNACL_TC_DIR, 'translator')
34 BIONIC_TC_DIR = os.path.join('toolchain', '%s_arm_bionic' % PLATFORM)
36 CYGTAR = os.path.join(NACL_DIR, 'build', 'cygtar.py')
37 TAR = oshelpers.FindExeInPath('tar')
39 options = None
42 PPAPI_ARCHIVE = os.path.join(DOWNLOAD_ARCHIVE_DIR,
43 '%s_ppapi.tar.bz2' % PLATFORM)
46 NEWLIB_ARCHIVE_MAP = [
47 ('newlib', NEWLIB_X86_TC_DIR),
48 ('arm', NEWLIB_ARM_TC_DIR),
49 ('newlib_headers', [
50 os.path.join(NEWLIB_X86_TC_DIR, 'x86_64-nacl', 'include'),
51 os.path.join(NEWLIB_ARM_TC_DIR, 'arm-nacl', 'include')]),
52 ('newlib_arm_libs', os.path.join(NEWLIB_ARM_TC_DIR, 'arm-nacl', 'lib')),
53 ('newlib_x86_32_libs',
54 os.path.join(NEWLIB_X86_TC_DIR, 'x86_64-nacl', 'lib32')),
55 ('newlib_x86_64_libs', os.path.join(NEWLIB_X86_TC_DIR, 'x86_64-nacl', 'lib'))]
57 GLIBC_ARCHIVE_MAP = [
58 ('glibc', GLIBC_X86_TC_DIR),
59 ('glibc_headers', os.path.join(GLIBC_X86_TC_DIR, 'x86_64-nacl', 'include')),
60 ('glibc_x86_32_libs', os.path.join(GLIBC_X86_TC_DIR, 'x86_64-nacl', 'lib32')),
61 ('glibc_x86_64_libs', os.path.join(GLIBC_X86_TC_DIR, 'x86_64-nacl', 'lib'))]
63 PNACL_ARCHIVE_MAP = [
64 ('pnacl', PNACL_TC_DIR),
65 ('newlib_headers', os.path.join(PNACL_TC_DIR, 'le32-nacl', 'include')),
66 ('pnacl_libs', os.path.join(PNACL_TC_DIR, 'le32-nacl', 'lib')),
67 ('pnacl_translator_arm_libs',
68 os.path.join(PNACL_TRANSLATOR_DIR, 'arm', 'lib')),
69 ('pnacl_translator_x86_32_libs',
70 os.path.join(PNACL_TRANSLATOR_DIR, 'x86-32', 'lib')),
71 ('pnacl_translator_x86_64_libs',
72 os.path.join(PNACL_TRANSLATOR_DIR, 'x86-64', 'lib'))]
74 BIONIC_ARCHIVE_MAP = [
75 ('bionic', BIONIC_TC_DIR),
76 ('bionic_headers', os.path.join(BIONIC_TC_DIR, 'arm-nacl', 'include')),
77 ('bionic_arm_libs', os.path.join(BIONIC_TC_DIR, 'arm-nacl', 'lib'))]
80 TOOLCHAIN_ARCHIVE_MAPS = {
81 'newlib': NEWLIB_ARCHIVE_MAP,
82 'glibc': GLIBC_ARCHIVE_MAP,
83 'pnacl': PNACL_ARCHIVE_MAP,
84 'bionic': BIONIC_ARCHIVE_MAP,
87 TOOLS_ARCHIVE_MAP = [('tools', 'tools')]
90 def Untar(archive, destdir):
91 if os.path.exists(TAR):
92 cmd = [TAR]
93 else:
94 cmd = [sys.executable, CYGTAR]
96 if options.verbose:
97 cmd.extend(['-xvf', archive])
98 else:
99 cmd.extend(['-xf', archive])
101 if not os.path.exists(destdir):
102 buildbot_common.MakeDir(destdir)
103 buildbot_common.Run(cmd, cwd=destdir)
106 def RemoveExt(path):
107 while True:
108 path, ext = os.path.splitext(path)
109 if ext == '':
110 return path
113 def ExtractArchive(archive_path, destdirs):
114 Untar(archive_path, EXTRACT_ARCHIVE_DIR)
115 basename = RemoveExt(os.path.basename(archive_path))
116 srcdir = os.path.join(EXTRACT_ARCHIVE_DIR, basename)
117 if type(destdirs) is not list:
118 destdirs = [destdirs]
120 for destdir in destdirs:
121 if not os.path.exists(destdir):
122 buildbot_common.MakeDir(destdir)
123 src_files = glob.glob(os.path.join(srcdir, '*'))
124 for src_file in src_files:
125 buildbot_common.CopyDir(src_file, destdir)
128 def ExtractAll(archive_dict, archive_dir, destroot):
129 for archive_part, rel_destdirs in archive_dict:
130 archive_name = '%s_%s.tar.bz2' % (PLATFORM, archive_part)
131 archive_path = os.path.join(archive_dir, archive_name)
132 if type(rel_destdirs) is not list:
133 rel_destdirs = [rel_destdirs]
134 destdirs = [os.path.join(destroot, d) for d in rel_destdirs]
135 ExtractArchive(archive_path, destdirs)
138 def main(args):
139 parser = argparse.ArgumentParser(description=__doc__)
140 parser.add_argument('-v', '--verbose')
141 parser.add_argument('-o', '--outdir')
142 parser.add_argument('-t', '--toolchain', action='append', dest='toolchains',
143 default=[])
144 parser.add_argument('--clean', action='store_true')
145 global options
146 options = parser.parse_args(args)
148 if options.clean:
149 buildbot_common.RemoveDir(options.outdir)
150 for toolchain in options.toolchains:
151 ExtractAll(TOOLCHAIN_ARCHIVE_MAPS[toolchain], DOWNLOAD_ARCHIVE_DIR,
152 options.outdir)
153 ExtractAll(TOOLS_ARCHIVE_MAP, DOWNLOAD_ARCHIVE_DIR, options.outdir)
154 Untar(PPAPI_ARCHIVE, EXTRACT_ARCHIVE_DIR)
155 return 0
158 if __name__ == '__main__':
159 try:
160 sys.exit(main(sys.argv[1:]))
161 except KeyboardInterrupt:
162 buildbot_common.ErrorExit('extract_artifacts: interrupted')