Skip to content

Commit

Permalink
Compatiblity with more compilers and interpreters
Browse files Browse the repository at this point in the history
  • Loading branch information
Leixb committed Oct 25, 2017
1 parent db74381 commit 254d195
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
50 changes: 42 additions & 8 deletions jutge_cli/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,58 @@ def print_color(text: str, colors: list = None):
else:
source_file = prog.name

if source_file.endswith('.cpp') or source_file.endswith('.cc'):
compiler = dict(
ada='gnat {src} -o {bin}',
bas='fbc {src} -o {bin}',
c='gcc -g {src} -o {bin}',
cc='g++ -std=c++11 -g {src} -o {bin}',
cpp='g++ -std=c++11 -g {src} -o {bin}',
d='gdc {src} -o {bin}',
f='gfortran {src} -o {bin}',
hs='ghc -O3 {src} -o {bin}',
pas='fpc -Sd -Co -Cr -Ct -Ci -v0 {src} -o {bin}',
rs='rustc {src} -o {bin}',
)
interpreter = dict(
bf='beef {src}',
go='go run {src}',
js='node {src}',
lisp='clisp {src}',
lua='lua {src}',
php='php {src}',
pl='perl {src}',
py2='python2 {src}',
py3='python3 {src}',
py='python3 {src}',
r='Rscript {src}',
rb='ruby {src}',
)

extension = source_file.split('.')[-1]

if extension in compiler:
compile_command = compiler[extension].format(src=source_file,
bin=prog_name)
compile_command = compile_command.split()

prog_name = '.'.join(source_file.split('.')[:-1]) + '.x'
LOG.debug('Compiling to %s', prog_name)

process = Popen(
['g++', '-std=c++11', '-g', source_file, '-o', prog_name])
process = Popen(compile_command)
return_code = process.wait()

if return_code:
LOG.error('Compilation returned %d', return_code)
exit(return_code)

else:
prog_name = source_file

if prog_name[0] not in ('.', '/'):
prog_name = './' + prog_name
if extension in interpreter:
run_command = interpreter[extension].format(src=source_file,
bin=prog_name)
run_command = run_command.split()
else:
if prog_name[0] not in ('.', '/'):
run_command = './' + prog_name

cont, cor = 0, 0

Expand All @@ -122,7 +156,7 @@ def print_color(text: str, colors: list = None):

cont += 1

process = Popen(prog_name, stdin=test_input, stdout=test_output,
process = Popen(run_command, stdin=test_input, stdout=test_output,
stderr=PIPE)
return_code = process.wait()

Expand Down
2 changes: 1 addition & 1 deletion jutge_cli/jutge.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
defaults, download, get_code, import_zip, login,\
new, show, test, upload

JUTGE_CLI_VERSION = '2.0.8'
JUTGE_CLI_VERSION = '2.1.0'

CONFIG = defaults.config()
DEFAULT_PARAM = CONFIG['param']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='jutge_cli',
version='2.0.8',
version='2.1.0',

description='CLI to manage jutge.org problems',
long_description=long_description,
Expand Down

0 comments on commit 254d195

Please sign in to comment.