You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.1 KiB

readonly SCRIPT=`realpath "$0"`
sbcl --noinform --disable-debugger --load "$SCRIPT" --eval '(toplevel)' --quit
(in-package #:cl-user)
(defun cmake (file)
(let* ((dir (sb-ext:native-namestring (uiop:pathname-directory-pathname file)))
(src (first (directory (make-pathname :name :wild :type "cpp" :defaults dir)))))
(sb-posix:chdir dir)
(unless (probe-file (merge-pathnames "CMakeLists.txt" dir))
(with-open-file (stream (merge-pathnames "CMakeLists.txt" dir) :direction :output)
(format stream "project( algorithms_ )
cmake_minimum_required(VERSION 2.8.10)
find_package(CGAL QUIET COMPONENTS Core )
find_package(Boost COMPONENTS graph thread REQUIRED)
include( ${CGAL_USE_FILE} )
add_executable(~a \"~a\")
target_link_libraries(~a CGAL::CGAL ${Boost_LIBRARIES})
set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wall -pedantic\")
" (pathname-name src) (file-namestring src) (pathname-name src)))
(sb-ext:run-program "cmake" (list "." "-DCMAKE_BUILD_TYPE=Debug")
:search T :output T :error T))
(sb-ext:run-program "make" ()
:search T :output T :error T)
(make-pathname :type NIL :defaults file)))
(defun run (exec in)
(with-output-to-string (stream)
(sb-ext:run-program exec () :input in :output stream :error T)))
(defun test (exec in out)
(with-input-from-string (in (run exec in))
(with-open-file (out out)
(loop with passed = T
for expected = (read-line out NIL)
for result = (read-line in NIL)
for line from 1
while (or expected result)
do (unless (equal expected result)
(setf passed NIL)
(format T "~& Mismatch on line ~d:
Expected: ~a
Got: ~a~%"
line expected result))
finally (return passed)))))
(defun print-source (source)
(with-open-file (stream source)
(loop for line = (read-line stream NIL)
while line
do (if (string= line "#include \"../../common.cpp\"")
(print-source (merge-pathnames "../../common.cpp" source))
(format T "~a~%" line)))))
(defun run-in (directory)
(let ((source (first (directory (make-pathname :name :wild :type "cpp" :defaults directory))))
(testset (merge-pathnames "testsets/" directory)))
(unless source (error "No source files found in~% ~a" directory))
(format T "~& --> Compiling ~a~%" source)
(let ((exec (cmake source))
(ins (directory (make-pathname :name :wild :type "in" :defaults testset)))
(outs (directory (make-pathname :name :wild :type "out" :defaults testset))))
(when (loop for in in (sort (mapcar #'sb-ext:native-namestring ins) #'string<)
for out in (sort (mapcar #'sb-ext:native-namestring outs) #'string<)
do (format T "~& --> Test ~a~%" in)
(test exec in out))
(format T "~& --> Submission source:~%~%")
(print-source source)))))
(defun toplevel ()
(run-in (format NIL "~a/" (sb-posix:getcwd))))