leave none of an output a failure stopped writing

A failed -C -o left the file truncated, which make would take for done.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent 5afe32a888
commit 83282adfb9
2 changed files with 14 additions and 3 deletions

View File

@@ -164,8 +164,12 @@
(define (write-to-file-or-stdout output what) (define (write-to-file-or-stdout output what)
(if (stdout-output? output) (if (stdout-output? output)
(what) (what)
(with-output-to-file output ;; a failure part way through leaves none of the file, which make
(fn (what))))) ;; would take for done
(handle-exceptions exn
(begin (delete-file* output) (abort exn))
(with-output-to-file output
(fn (what))))))
(define (emit-c-or-sex sex-forms output args) (define (emit-c-or-sex sex-forms output args)
(write-to-file-or-stdout output (write-to-file-or-stdout output

View File

@@ -3,7 +3,8 @@
;;; Each needs a process to show itself, so none fits the unit suite: ;;; Each needs a process to show itself, so none fits the unit suite:
;;; sexc has to fail when cc fails -- exiting 0 after a failed compile ;;; sexc has to fail when cc fails -- exiting 0 after a failed compile
;;; makes every driver, sextest included, read it as success -- it has to ;;; makes every driver, sextest included, read it as success -- it has to
;;; clean up its temporary .c when its own emission throws, and it has to ;;; clean up its temporary .c, and any output it began, when its own
;;; emission throws, and it has to
;;; refuse `-o -' for an executable, which cc would write to a file named ;;; refuse `-o -' for an executable, which cc would write to a file named
;;; `-'. ;;; `-'.
;;; ;;;
@@ -61,6 +62,12 @@
(sexc-succeeds? "nested-pointer.sex" "-o" out) (sexc-succeeds? "nested-pointer.sex" "-o" out)
(glob (make-pathname scratch "*.c")))) (glob (make-pathname scratch "*.c"))))
;; and none of a file it was writing out, which make would take for done
(test "a failed emission leaves no part of its output" #f
(begin
(sexc-succeeds? "nested-pointer.sex" "-C" "-o" (make-pathname scratch "out.c"))
(file-exists? (make-pathname scratch "out.c"))))
(test "a failed cc fails sexc" #f (test "a failed cc fails sexc" #f
(sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag")) (sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))