__init__.py
1 # 2 # Copyright (C) 2008-2020 Advanced Micro Devices, Inc. All rights reserved. 3 # 4 # Redistribution and use in source and binary forms, with or without modification, 5 # are permitted provided that the following conditions are met: 6 # 1. Redistributions of source code must retain the above copyright notice, 7 # this list of conditions and the following disclaimer. 8 # 2. Redistributions in binary form must reproduce the above copyright notice, 9 # this list of conditions and the following disclaimer in the documentation 10 # and/or other materials provided with the distribution. 11 # 3. Neither the name of the copyright holder nor the names of its contributors 12 # may be used to endorse or promote products derived from this software without 13 # specific prior written permission. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 21 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 # POSSIBILITY OF SUCH DAMAGE. 25 26 import os 27 from scripts.cfg import projpath 28 29 def strip_build_path(path, env): 30 path = str(path) 31 build_base = projpath.BUILDDIR 32 variant_base = env['BUILDROOT'] + os.path.sep 33 if path.startswith(variant_base): 34 path = path[len(variant_base):] 35 elif path.startswith(build_base): 36 path = path[len(build_base):] 37 return path 38 39 class Transform(): 40 def __init__(self, tool): 41 self.format = (" [%8s] " % tool) \ 42 + "%s" \ 43 + "%s" \ 44 + " -> " \ 45 + "%s" 46 47 self.max_sources = 99 48 49 def __call__(self, target, source, env, for_signature=None): 50 # truncate source list according to max_sources param 51 source = source[0:self.max_sources] 52 def strip(f): 53 return strip_build_path(str(f), env) 54 if len(source) > 0: 55 srcs = map(strip, source) 56 else: 57 srcs = [''] 58 59 tgts = map(strip, target) 60 # surprisingly, os.path.commonprefix is a dumb char-by-char string 61 # operation that has nothing to do with paths. 62 com_pfx = os.path.commonprefix(srcs + tgts) 63 com_pfx_len = len(com_pfx) 64 65 def fmt(files): 66 f = map(lambda s: s[com_pfx_len:], files) 67 return ', '.join(f) 68 69 return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 70 71 __all__ = ['Transform'] 72