blob: de638badd5b3e9c0108ef40b7e91ed56a69ab95f [file] [log] [blame]
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -07001# 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
18import logging
19import os
Suren Baghdasaryan865cf952017-08-31 13:28:47 -070020import shutil
21import subprocess
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070022from collections import namedtuple
23
24class Build(object):
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070025 """
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
Suren Baghdasaryan865cf952017-08-31 13:28:47 -070035 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
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070040 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 """
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070048 cur_dir = os.getcwd()
49 os.chdir(self._te.ANDROID_BUILD_TOP)
50 lunch_target = self._te.TARGET_PRODUCT + '-' + self._te.TARGET_BUILD_VARIANT
Suren Baghdasaryan865cf952017-08-31 13:28:47 -070051 self.exec_cmd('source build/envsetup.sh && lunch ' +
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070052 lunch_target + ' && mmma -j16 ' + module_path)
53 os.chdir(cur_dir)
54
55
Suren Baghdasaryan42fa0e22017-08-28 14:39:54 -070056# vim :set tabstop=4 shiftwidth=4 expandtab