|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright (c) 2017 Intel Corporation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# |
| 18 | +# |
| 19 | +# |
| 20 | + |
| 21 | +# Provides unified tool for preparing TBB for packaging |
| 22 | + |
| 23 | +from __future__ import print_function |
| 24 | +import os |
| 25 | +import re |
| 26 | +import sys |
| 27 | +import shutil |
| 28 | +import platform |
| 29 | +import argparse |
| 30 | +from glob import glob |
| 31 | +from collections import OrderedDict |
| 32 | + |
| 33 | +jp = os.path.join |
| 34 | +is_win = (platform.system() == 'Windows') |
| 35 | +is_lin = (platform.system() == 'Linux') |
| 36 | +is_mac = (platform.system() == 'Darwin') |
| 37 | + |
| 38 | +default_prefix = os.getenv('PREFIX', 'install_prefix') |
| 39 | +if is_win: |
| 40 | + default_prefix = jp(default_prefix, 'Library') # conda-specific by default on Windows |
| 41 | + |
| 42 | +parser = argparse.ArgumentParser() |
| 43 | +parser.add_argument('--tbbroot', default='.', help='Take Intel TBB from here') |
| 44 | +parser.add_argument('--prefix', default=default_prefix, help='Prefix') |
| 45 | +parser.add_argument('--no-rebuild', default=False, action='store_true', help='do not rebuild') |
| 46 | +parser.add_argument('--install', default=False, action='store_true', help='install all') |
| 47 | +parser.add_argument('--install-libs', default=False, action='store_true', help='install libs') |
| 48 | +parser.add_argument('--install-devel', default=False, action='store_true', help='install devel') |
| 49 | +parser.add_argument('--install-docs', default=False, action='store_true', help='install docs') |
| 50 | +parser.add_argument('--install-python',default=False, action='store_true', help='install python module') |
| 51 | +parser.add_argument('--make-tool', default='make', help='Use different make command instead') |
| 52 | +parser.add_argument('--copy-tool', default=None, help='Use this command for copying ($ tool file dest-dir)') |
| 53 | +parser.add_argument('--build-args', default="", help='specify extra build args') |
| 54 | +parser.add_argument('--build-prefix', default='local', help='build dir prefix') |
| 55 | +if is_win: |
| 56 | + parser.add_argument('--msbuild', default=False, action='store_true', help='Use msbuild') |
| 57 | + parser.add_argument('--vs', default="2012", help='select VS version for build') |
| 58 | + parser.add_argument('--vs-platform', default="x64", help='select VS platform for build') |
| 59 | +parser.add_argument('ignore', nargs='?', help="workaround conda-build issue #2512") |
| 60 | + |
| 61 | +args = parser.parse_args() |
| 62 | + |
| 63 | +if args.install: |
| 64 | + args.install_libs = True |
| 65 | + args.install_devel = True |
| 66 | + args.install_docs = True |
| 67 | + args.install_python= True |
| 68 | + |
| 69 | +def custom_cp(src, dst): |
| 70 | + assert os.system(' '.join([args.copy_tool, src, dst])) == 0 |
| 71 | + |
| 72 | +if args.copy_tool: |
| 73 | + install_cp = custom_cp # e.g. to use install -p -D -m 755 on Linux |
| 74 | +else: |
| 75 | + install_cp = shutil.copy |
| 76 | + |
| 77 | +bin_dir = jp(args.prefix, "bin") |
| 78 | +lib_dir = jp(args.prefix, "lib") |
| 79 | +inc_dir = jp(args.prefix, 'include') |
| 80 | +doc_dir = jp(args.prefix, 'share', 'doc', 'tbb') |
| 81 | +if is_win: |
| 82 | + os.environ["OS"] = "Windows_NT" # make sure TBB will interpret it corretly |
| 83 | + libext = '.dll' |
| 84 | + libpref = '' |
| 85 | + dll_dir = bin_dir |
| 86 | +else: |
| 87 | + libext = '.dylib' if is_mac else '.so.2' |
| 88 | + libpref = 'lib' |
| 89 | + dll_dir = lib_dir |
| 90 | + |
| 91 | +tbb_names = ["tbb", "tbbmalloc", "tbbmalloc_proxy"] |
| 92 | + |
| 93 | +############################################################## |
| 94 | + |
| 95 | +os.chdir(args.tbbroot) |
| 96 | +if is_win and args.msbuild: |
| 97 | + preview_release_dir = release_dir = jp(args.tbbroot, 'build', 'vs'+args.vs, args.vs_platform, 'Release') |
| 98 | + if not args.no_rebuild or not os.path.isdir(release_dir): |
| 99 | + assert os.system('msbuild /m /p:Platform=%s /p:Configuration=Release %s build/vs%s/makefile.sln'% \ |
| 100 | + (args.vs_platform, args.build_args, args.vs)) == 0 |
| 101 | + preview_debug_dir = debug_dir = jp(args.tbbroot, 'build', 'vs'+args.vs, args.vs_platform, 'Debug') |
| 102 | + if not args.no_rebuild or not os.path.isdir(debug_dir): |
| 103 | + assert os.system('msbuild /m /p:Platform=%s /p:Configuration=Debug %s build/vs%s/makefile.sln'% \ |
| 104 | + (args.vs_platform, args.build_args, args.vs)) == 0 |
| 105 | +else: |
| 106 | + release_dir = jp(args.tbbroot, 'build', args.build_prefix+'_release') |
| 107 | + debug_dir = jp(args.tbbroot, 'build', args.build_prefix+'_debug') |
| 108 | + if not args.no_rebuild or not (os.path.isdir(release_dir) and os.path.isdir(debug_dir)): |
| 109 | + assert os.system('%s -j tbb_build_prefix=%s %s'% \ |
| 110 | + (args.make_tool, args.build_prefix, args.build_args)) == 0 |
| 111 | + preview_release_dir = jp(args.tbbroot, 'build', args.build_prefix+'_preview_release') |
| 112 | + preview_debug_dir = jp(args.tbbroot, 'build', args.build_prefix+'_preview_debug') |
| 113 | + if not args.no_rebuild or not (os.path.isdir(preview_release_dir) and os.path.isdir(preview_debug_dir)): |
| 114 | + assert os.system('%s -j tbb_build_prefix=%s_preview %s tbb_cpf=1 tbb'% \ |
| 115 | + (args.make_tool, args.build_prefix, args.build_args)) == 0 |
| 116 | + |
| 117 | + |
| 118 | +filemap = OrderedDict() |
| 119 | +def append_files(files, dst): |
| 120 | + global filemap |
| 121 | + filemap.update(dict(zip(files, [dst]*len(files)))) |
| 122 | + |
| 123 | +if args.install_libs: |
| 124 | + files = [jp(release_dir, libpref+f+libext) for f in tbb_names] |
| 125 | + append_files(files, dll_dir) |
| 126 | + |
| 127 | +if args.install_devel: |
| 128 | + dll_files = [jp(debug_dir, libpref+f+'_debug'+libext) for f in tbb_names] # adding debug libraries |
| 129 | + if not is_win or not args.msbuild: |
| 130 | + dll_files += [jp(preview_release_dir, libpref+"tbb_preview"+libext), |
| 131 | + jp(preview_debug_dir, libpref+"tbb_preview_debug"+libext)] |
| 132 | + if is_win: |
| 133 | + dll_files += sum( [glob(jp(d, 'tbb*.pdb')) for d in # copying debug info |
| 134 | + (release_dir, debug_dir, preview_release_dir, preview_debug_dir)], []) |
| 135 | + if is_lin: |
| 136 | + dll_files += sum( [glob(jp(d, 'libtbb*.so')) for d in # copying linker scripts |
| 137 | + (release_dir, debug_dir, preview_release_dir, preview_debug_dir)], []) |
| 138 | + # symlinks .so -> .so.2 should not be created instead |
| 139 | + # since linking with -ltbb when using links can result in |
| 140 | + # incorrect dependence upon unversioned .so files |
| 141 | + append_files(dll_files, dll_dir) |
| 142 | + if is_win: |
| 143 | + lib_files = sum([glob(jp(d,e)) for d in (release_dir, debug_dir) for e in ('*.lib', '*.def')], []) |
| 144 | + append_files(lib_files, lib_dir) # copying linker libs and defs |
| 145 | + for rootdir, dirnames, filenames in os.walk(jp(args.tbbroot,'include')): |
| 146 | + files = [jp(rootdir, f) for f in filenames if not '.html' in f] |
| 147 | + append_files(files, jp(inc_dir, rootdir.split('include')[1][1:])) |
| 148 | + |
| 149 | +if args.install_python: |
| 150 | + assert os.system('%s -j tbb_build_prefix=%s %s python'% \ |
| 151 | + (args.make_tool, args.build_prefix, args.build_args)) == 0 |
| 152 | + if is_lin: |
| 153 | + append_files([jp(release_dir, 'libirml.so.1')], dll_dir) |
| 154 | + |
| 155 | +if args.install_docs: |
| 156 | + files = [jp(args.tbbroot, *f) for f in ( |
| 157 | + ('CHANGES',), |
| 158 | + ('LICENSE',), |
| 159 | + ('README',), |
| 160 | + ('README.md',), |
| 161 | + ('doc','Release_Notes.txt'), |
| 162 | + )] |
| 163 | + append_files(files, doc_dir) |
| 164 | + |
| 165 | +for f in filemap.keys(): |
| 166 | + assert os.path.exists(f) |
| 167 | + assert os.path.isfile(f) |
| 168 | + |
| 169 | +if filemap: |
| 170 | + print("Copying to prefix =", args.prefix) |
| 171 | +for f, dest in filemap.items(): |
| 172 | + if not os.path.isdir(dest): |
| 173 | + os.makedirs(dest) |
| 174 | + print("+ %s to $prefix%s"%(f,dest.replace(args.prefix, ''))) |
| 175 | + install_cp(f, dest) |
| 176 | + |
| 177 | +print("done") |
0 commit comments