Home | History | Annotate | Download | only in utils
      1 # SPDX-License-Identifier: Apache-2.0
      2 #
      3 # Copyright (C) 2015, ARM Limited and contributors.
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
      6 # 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, WITHOUT
     13 # 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 import logging
     19 import os
     20 import shutil
     21 import subprocess
     22 from collections import namedtuple
     23 
     24 class Build(object):
     25     """
     26     Collection of Android related build actions
     27     """
     28     def __init__(self, te):
     29         if (te.ANDROID_BUILD_TOP and te.TARGET_PRODUCT and te.TARGET_BUILD_VARIANT):
     30             self._te = te
     31         else:
     32             te._log.warning('Build initialization failed: invalid paramterers')
     33             raise
     34 
     35     def exec_cmd(self, cmd):
     36         ret = subprocess.call(cmd, shell=True)
     37         if ret != 0:
     38             raise RuntimeError('Command \'{}\' returned error code {}'.format(cmd, ret))
     39 
     40     def build_module(self, module_path):
     41         """
     42         Build a module and its dependencies.
     43 
     44         :param module_path: module path
     45         :type module_path: str
     46 
     47         """
     48         cur_dir = os.getcwd()
     49         os.chdir(self._te.ANDROID_BUILD_TOP)
     50         lunch_target = self._te.TARGET_PRODUCT + '-' + self._te.TARGET_BUILD_VARIANT
     51         self.exec_cmd('source build/envsetup.sh && lunch ' +
     52             lunch_target + ' && mmma -j16 ' + module_path)
     53         os.chdir(cur_dir)
     54 
     55 
     56 # vim :set tabstop=4 shiftwidth=4 expandtab
     57