• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import sys
25import shutil
26
27from . common import *
28from . config import *
29
30def initBuildDir (config, generator):
31	cfgArgs = []
32
33	# Build base configuration args
34	cfgArgs += config.getArgs()
35
36	# Generator args
37	cfgArgs += generator.getGenerateArgs(config.getBuildType())
38
39	if not os.path.exists(config.buildDir):
40		os.makedirs(config.buildDir)
41
42	pushWorkingDir(config.getBuildDir())
43
44	try:
45		execute([config.getCMakePath(), config.getSrcPath()] + cfgArgs)
46	finally:
47		popWorkingDir()
48
49def build (config, generator, targets = None):
50	if os.path.exists(config.buildDir):
51		try:
52			initBuildDir(config, generator)
53		except Exception as e:
54			print(e)
55			print("WARNING: Using existing build directory failed; re-creating build directory")
56			shutil.rmtree(config.buildDir)
57			initBuildDir(config, generator)
58	else:
59		initBuildDir(config, generator)
60
61	baseCmd		= [config.getCMakePath(), '--build', '.']
62	buildArgs	= generator.getBuildArgs(config.getBuildType())
63
64	pushWorkingDir(config.getBuildDir())
65
66	if targets == None:
67		execute(baseCmd + buildArgs)
68	else:
69		for target in targets:
70			execute(baseCmd + ['--target', target] + buildArgs)
71
72	popWorkingDir()
73