1# 2# Copyright 2016 - The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17import argparse 18import fileinput 19import os 20import os.path 21import re 22 23# Parses the output of make install --dry-run and generates directives in the 24# form 25# 26# install['target'] = [ 'srcfile' ] 27# 28# This output is then fed into gen_android_mk which generates Android.mk. 29# 30# This process is split into two steps so the second step can later be replaced 31# with an Android.bp generator. 32 33 34class MakeInstallParser(object): 35 '''Parses the output of make install --dry-run.''' 36 37 def __init__(self, ltp_root): 38 self.ltp_root = ltp_root 39 40 def ParseFile(self, input_path): 41 '''Parses the text output of make install --dry-run. 42 43 Args: 44 input_text: string, output of make install --dry-run 45 46 Returns: 47 string, directives in form install['target'] = [ 'srcfile' ] 48 ''' 49 pattern = re.compile(r'install -m \d+ "%s%s(.*)" "/opt/ltp/(.*)"' % 50 (os.path.realpath(self.ltp_root), os.sep)) 51 result = [] 52 53 with open(input_path, 'r') as f: 54 for line in f: 55 line = line.strip() 56 57 m = pattern.match(line) 58 if not m: 59 continue 60 61 src, target = m.groups() 62 # If the file isn't in the source tree, it's not a prebuilt 63 if not os.path.isfile( 64 os.path.realpath(self.ltp_root) + os.sep + src): 65 continue 66 67 result.append("install['%s'] = ['%s']" % (target, src)) 68 69 return result 70