|
16 | 16 | """
|
17 | 17 | import re
|
18 | 18 | import shutil
|
19 |
| -from os import remove |
20 |
| -from os.path import splitext, basename, exists |
| 19 | +from os import remove, getcwd, chdir, mkdir |
| 20 | +from os.path import basename, exists |
21 | 21 | from subprocess import Popen, PIPE
|
22 | 22 |
|
23 | 23 | from jinja2.exceptions import TemplateNotFound
|
24 | 24 |
|
25 | 25 | from tools.export.exporters import Exporter, apply_supported_whitelist
|
26 | 26 | from tools.targets import TARGET_MAP
|
27 |
| -from tools.utils import NotSupportedException |
28 | 27 |
|
29 | 28 |
|
30 | 29 | class CMake(Exporter):
|
@@ -126,14 +125,34 @@ def generate(self):
|
126 | 125 | @staticmethod
|
127 | 126 | def build(project_name, log_name="build_log.txt", cleanup=True):
|
128 | 127 | """ Build Make project """
|
129 |
| - # > Make -j |
130 |
| - cmd = ["make", "-j"] |
| 128 | + |
| 129 | + # change into our build directory |
| 130 | + current_dir = getcwd() |
| 131 | + if not exists("BUILD"): |
| 132 | + mkdir("BUILD") |
| 133 | + chdir("BUILD") |
| 134 | + |
| 135 | + # > run cmake initial command |
| 136 | + cmd = ["cmake", ".."] |
131 | 137 |
|
132 | 138 | # Build the project
|
133 | 139 | p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
134 | 140 | out, err = p.communicate()
|
135 | 141 | ret_code = p.returncode
|
136 | 142 |
|
| 143 | + if ret_code == 0: |
| 144 | + # we create the cmake files inside BUILD, change into and run cmake |
| 145 | + |
| 146 | + # > run make -j |
| 147 | + cmd = ["make", "-j"] |
| 148 | + |
| 149 | + p = Popen(cmd, stdout=PIPE, stderr=PIPE) |
| 150 | + out, err = p.communicate() |
| 151 | + ret_code = p.returncode |
| 152 | + |
| 153 | + # go back to the original directory |
| 154 | + chdir(current_dir) |
| 155 | + |
137 | 156 | out_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n"
|
138 | 157 | out_string += out
|
139 | 158 | out_string += "=" * 10 + "STDERR" + "=" * 10 + "\n"
|
@@ -161,6 +180,7 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
|
161 | 180 | if exists('BUILD'):
|
162 | 181 | shutil.rmtree('BUILD')
|
163 | 182 |
|
| 183 | + |
164 | 184 | if ret_code != 0:
|
165 | 185 | # Seems like something went wrong.
|
166 | 186 | return -1
|
|
0 commit comments