1#!/usr/bin/env python3
2#
3# Copyright 2019 The Hafnium Authors.
4#
5# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/BSD-3-Clause.
8
9"""Runs make to build a target."""
10
11import argparse
12import os
13import shutil
14import subprocess
15import sys
16
17
18def Main():
19    parser = argparse.ArgumentParser()
20    parser.add_argument("--directory", required=True)
21    parser.add_argument("--copy_out_file", nargs=2,
22                        help="Copy file after building. Takes two params: <src> <dest>")
23    args, make_args = parser.parse_known_args()
24
25    os.chdir(args.directory)
26    os.environ["PWD"] = args.directory
27    status = subprocess.call(["make"] + make_args)
28    if status != 0:
29        return status
30
31    if args.copy_out_file is not None:
32        shutil.copyfile(args.copy_out_file[0], args.copy_out_file[1])
33    return 0
34
35
36if __name__ == "__main__":
37    sys.exit(Main())
38