|
22 | 22 |
|
23 | 23 | import logging
|
24 | 24 | import os
|
| 25 | +import shutil |
25 | 26 | import subprocess
|
26 | 27 | import xml.etree.ElementTree as ET
|
| 28 | +import importlib.resources |
| 29 | +import importlib.util |
| 30 | +import tempfile |
27 | 31 | from datetime import datetime, timedelta
|
28 | 32 |
|
29 | 33 | from cms import config
|
@@ -144,7 +148,6 @@ def get_task(self, get_statement=True):
|
144 | 148 | task_cms_conf = None
|
145 | 149 | if os.path.exists(task_cms_conf_path):
|
146 | 150 | logger.info("Found additional CMS options for task %s.", name)
|
147 |
| - import importlib.util |
148 | 151 | spec = importlib.util.spec_from_file_location(
|
149 | 152 | 'cms_conf', task_cms_conf_path)
|
150 | 153 | task_cms_conf = importlib.util.module_from_spec(spec)
|
@@ -181,20 +184,26 @@ def get_task(self, get_statement=True):
|
181 | 184 |
|
182 | 185 | if os.path.exists(checker_src):
|
183 | 186 | logger.info("Checker found, compiling")
|
184 |
| - checker_exe = os.path.join( |
185 |
| - os.path.dirname(checker_src), "checker") |
186 |
| - testlib_path = os.path.join(config.base_dir, 'include') |
187 |
| - testlib_include = os.path.join(testlib_path, "testlib.h") |
188 |
| - code = subprocess.call(["g++", "-x", "c++", "-O2", "-static", |
189 |
| - "-DCMS", "-I", testlib_path, |
190 |
| - "-include", testlib_include, |
191 |
| - "-o", checker_exe, checker_src]) |
192 |
| - if code != 0: |
193 |
| - logger.critical("Could not compile checker") |
194 |
| - return None |
195 |
| - digest = self.file_cacher.put_file_from_path( |
196 |
| - checker_exe, |
197 |
| - "Manager for task %s" % name) |
| 187 | + with tempfile.TemporaryDirectory() as tempdir: |
| 188 | + # We need to override the testlib.h from the polygon |
| 189 | + # package with our patched version. Since the package |
| 190 | + # includes a testlib.h too, the easiest way to achieve this |
| 191 | + # is to copy the checker source to a temporary directory. |
| 192 | + testlib_res = importlib.resources.files("cmscontrib.loaders").joinpath("polygon/testlib.h") |
| 193 | + with testlib_res.open('rb') as src, open(tempdir + "/testlib.h", "wb") as dst: |
| 194 | + shutil.copyfileobj(src, dst) |
| 195 | + new_checker_src = tempdir + '/check.cpp' |
| 196 | + output_path = tempdir + '/check' |
| 197 | + shutil.copyfile(checker_src, new_checker_src) |
| 198 | + code = subprocess.call(["g++", "-x", "c++", "-O2", |
| 199 | + "-static", "-DCMS", "-o", |
| 200 | + output_path, new_checker_src]) |
| 201 | + if code != 0: |
| 202 | + logger.critical("Could not compile checker") |
| 203 | + return None |
| 204 | + digest = self.file_cacher.put_file_from_path( |
| 205 | + output_path, |
| 206 | + "Manager for task %s" % name) |
198 | 207 | args["managers"]["checker"] = Manager("checker", digest)
|
199 | 208 | evaluation_param = "comparator"
|
200 | 209 | else:
|
|
0 commit comments