First version
This commit is contained in:
commit
243e92a9dd
84 files changed
+4012
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python3
|
||||
"""GCC 15 driver used by IDE toolchains, with the contest language and link options."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
def expand_response_files(arguments, depth=0):
|
||||
# CLion also puts its language/standard probes in GCC response files.
|
||||
# Inspect their contents before choosing C vs C++ or replacing flags.
|
||||
if depth > 16:
|
||||
raise SystemExit('ACPC: response files are nested too deeply')
|
||||
expanded = []
|
||||
for arg in arguments:
|
||||
if arg.startswith('@') and Path(arg[1:]).is_file():
|
||||
expanded.extend(expand_response_files(shlex.split(Path(arg[1:]).read_text()), depth + 1))
|
||||
else:
|
||||
expanded.append(arg)
|
||||
return expanded
|
||||
|
||||
args = expand_response_files(sys.argv[1:])
|
||||
name = Path(sys.argv[0]).name
|
||||
sources = [a for a in args if Path(a).suffix in ('.c', '.C', '.cc', '.cpp', '.cxx', '.c++')]
|
||||
explicit_cxx = any(a.startswith('-xc++') or (a == '-x' and i + 1 < len(args) and args[i + 1].startswith('c++'))
|
||||
for i, a in enumerate(args))
|
||||
cxx = name.endswith(('g++', 'c++')) or explicit_cxx or (name not in ('acpc-gcc', 'gcc', 'cc') and any(not a.endswith('.c') for a in sources))
|
||||
compiler = '/usr/bin/g++-15' if cxx else '/usr/bin/gcc-15'
|
||||
query = any(a in ('--version', '-dumpversion', '-dumpfullversion', '-dumpmachine', '-print-search-dirs')
|
||||
or a.startswith(('-print-file-name=', '-print-prog-name=')) for a in args)
|
||||
if not query:
|
||||
args = [a for a in args if not a.startswith('-std=') and not re.fullmatch(r'-O(?:[0-3sgz]|fast)?', a)]
|
||||
args = ['-g', '-O2', '-std=gnu++23' if cxx else '-std=gnu23'] + args
|
||||
if not any(a in args for a in ('-c', '-S', '-E', '-M', '-MM', '-fsyntax-only', '-shared')):
|
||||
args += ['-static']
|
||||
args += ['-lrt', '-Wl,--whole-archive', '-lpthread', '-Wl,--no-whole-archive'] if cxx else ['-lm']
|
||||
cmd = [compiler] + args
|
||||
if not query and sources:
|
||||
print('ACPC: ' + shlex.join(cmd), file=sys.stderr, flush=True)
|
||||
if log := os.environ.get('ACPC_COMPILER_LOG'):
|
||||
with open(log, 'a') as f:
|
||||
f.write(json.dumps({'cwd': os.getcwd(), 'argv': cmd}) + '\n')
|
||||
os.execv(compiler, cmd)
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
# Initialize the supplied contest workspace once, also after a team-home reset.
|
||||
set -eu
|
||||
export PATH="/usr/local/lib/acpc-toolchain:$PATH"
|
||||
workspace="$HOME/eclipse-workspace"
|
||||
mkdir -p "$workspace"
|
||||
if [ ! -f "$workspace/.acpc-imported" ]; then
|
||||
/opt/eclipse/eclipse -nosplash -data "$workspace" \
|
||||
-application org.eclipse.cdt.managedbuilder.core.headlessbuild \
|
||||
-import "$HOME/contest" -no-indexer > "$workspace/import.log" 2>&1
|
||||
touch "$workspace/.acpc-imported"
|
||||
fi
|
||||
exec /opt/eclipse/eclipse -data "$workspace" "$@"
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python3
|
||||
"""Build or build-and-run the active contest source from an IDE task."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import resource
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 3 or sys.argv[1] not in ('build', 'run'):
|
||||
raise SystemExit('Usage: acpc-solution build|run SOURCE')
|
||||
action, arg = sys.argv[1:]
|
||||
src = Path(arg).resolve(strict=True)
|
||||
os.chdir(src.parent)
|
||||
ext = src.suffix
|
||||
if ext == '.c':
|
||||
build = ['/usr/local/bin/acpc-gcc', src.name, '-o', src.stem]
|
||||
run = [str(src.with_suffix(''))]
|
||||
elif ext in ('.cpp', '.cc', '.C', '.cxx', '.c++'):
|
||||
build = ['/usr/local/bin/acpc-g++', src.name, '-o', src.stem]
|
||||
run = [str(src.with_suffix(''))]
|
||||
elif ext == '.java':
|
||||
build = ['/usr/lib/jvm/java-25-openjdk-amd64/bin/javac', '-encoding', 'UTF-8',
|
||||
'-sourcepath', '.', '-cp', './*', '-d', '.', src.name]
|
||||
run = ['/usr/local/bin/runjava', src.stem]
|
||||
elif ext in ('.py', '.py3'):
|
||||
build = ['/usr/local/bin/pypy3', '-m', 'py_compile', src.name]
|
||||
run = ['/usr/local/bin/pypy3', src.name]
|
||||
else:
|
||||
raise SystemExit('Use a C, C++, Java or Python source file.')
|
||||
print('Build: ' + shlex.join(build), flush=True)
|
||||
result = subprocess.run(build)
|
||||
if result.returncode:
|
||||
raise SystemExit(result.returncode)
|
||||
if action == 'run':
|
||||
print('Run: ' + shlex.join(run), flush=True)
|
||||
soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
|
||||
resource.setrlimit(resource.RLIMIT_STACK, (hard, hard))
|
||||
os.execv(run[0], run)
|
||||
Reference in new issue
Block a user