blob: 318ccb105e68153223967635aa9ad203a3b37fb7 [file] [log] [blame]
Isabella Gottardi2181d0a2021-04-07 09:27:38 +01001#!env/bin/python3
2
3# Copyright (c) 2021 Arm Limited. All rights reserved.
4# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import os
19import subprocess
20import shutil
21import multiprocessing
22import logging
23import sys
24from argparse import ArgumentParser
25
26from set_up_default_resources import set_up_resources
27
28
29def run(download_resources, run_vela_on_models):
30 """
31 Run the helpers scripts.
32
33 Parameters:
34 ----------
35 download_resources (bool): Specifies if 'Download resources' step is performed.
36 run_vela_on_models (bool): Only if `download_resources` is True, specifies if run vela on downloaded models.
37 """
38
39 current_file_dir = os.path.dirname(os.path.abspath(__file__))
40 logging.basicConfig(filename='log_build_default.log', level=logging.DEBUG)
41 logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
42
43 # 1. Download models if specified
44 if download_resources is True:
45 logging.info("Downloading resources.")
46 set_up_resources(run_vela_on_models)
47
48 # 2. Build default configuration
49 logging.info("Building default configuration.")
50 target_platform = "mps3"
51 target_subsystem = "sse-300"
52 build_dir = os.path.join(current_file_dir, f"cmake-build-{target_platform}-{target_subsystem}-release")
53 try:
54 os.mkdir(build_dir)
55 except FileExistsError:
56 # Directory already exists, clean it
57 for filename in os.listdir(build_dir):
58 filepath = os.path.join(build_dir, filename)
59 try:
60 if os.path.isfile(filepath) or os.path.islink(filepath):
61 os.unlink(filepath)
62 elif os.path.isdir(filepath):
63 shutil.rmtree(filepath)
64 except Exception as e:
65 logging.error('Failed to delete %s. Reason: %s' % (filepath, e))
66 os.chdir(build_dir)
67 cmake_toolchain_file = os.path.join(current_file_dir, "scripts", "cmake", "bare-metal-toolchain.cmake")
68 cmake_command = (f"cmake .. -DTARGET_PLATFORM={target_platform} -DTARGET_SUBSYSTEM={target_subsystem} " +
69 f"-DCMAKE_TOOLCHAIN_FILE={cmake_toolchain_file} ")
70 logging.info(cmake_command)
71 state = subprocess.run(cmake_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
72 logging.info(state.stdout.decode('utf-8'))
73
74 make_command = f"make -j{multiprocessing.cpu_count()}"
75 logging.info(make_command)
76 state = subprocess.run(make_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
77 logging.info(state.stdout.decode('utf-8'))
78
79
80if __name__ == '__main__':
81 parser = ArgumentParser()
82 parser.add_argument("--skip-download",
83 help="Do not download resources: models and test vectors",
84 action="store_true")
85 parser.add_argument("--skip-vela",
86 help="Do not run Vela optimizer on downloaded models.",
87 action="store_true")
88 args = parser.parse_args()
89 run(not args.skip_download, not args.skip_vela)