Skip to content

Commit 5f53684

Browse files
authored
don't install testlib.h (#1457)
1 parent b6323f4 commit 5f53684

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

cmscontrib/loaders/polygon.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222

2323
import logging
2424
import os
25+
import shutil
2526
import subprocess
2627
import xml.etree.ElementTree as ET
28+
import importlib.resources
29+
import importlib.util
30+
import tempfile
2731
from datetime import datetime, timedelta
2832

2933
from cms import config
@@ -144,7 +148,6 @@ def get_task(self, get_statement=True):
144148
task_cms_conf = None
145149
if os.path.exists(task_cms_conf_path):
146150
logger.info("Found additional CMS options for task %s.", name)
147-
import importlib.util
148151
spec = importlib.util.spec_from_file_location(
149152
'cms_conf', task_cms_conf_path)
150153
task_cms_conf = importlib.util.module_from_spec(spec)
@@ -181,20 +184,26 @@ def get_task(self, get_statement=True):
181184

182185
if os.path.exists(checker_src):
183186
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)
198207
args["managers"]["checker"] = Manager("checker", digest)
199208
evaluation_param = "comparator"
200209
else:

install.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ def install_config() -> None:
119119
shutil.copyfile(sample, config_path)
120120

121121

122-
def install_testlib() -> None:
123-
progress("Installing testlib")
124-
shutil.copyfile('cmscontrib/loaders/polygon/testlib.h',
125-
target_path / 'include/testlib.h')
126-
127-
128122
def check_isolate(args: Namespace) -> None:
129123
progress('Checking if isolate is available')
130124
isolate = shutil.which('isolate', mode=os.F_OK)
@@ -144,7 +138,6 @@ def install_cms(args: Namespace) -> None:
144138
create_venv()
145139
install_package()
146140
install_config()
147-
install_testlib()
148141

149142

150143
def install_venv_with_deps(args: Namespace) -> None:

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
"cms.locale": [
6060
"*/LC_MESSAGES/*.*",
6161
],
62+
"cmscontrib": [
63+
"loaders/polygon/testlib.h",
64+
],
6265
"cmsranking": [
6366
"static/img/*.*",
6467
"static/lib/*.*",

0 commit comments

Comments
 (0)