File: link-test-programs.scm.in

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (279 lines) | stat: -rw-r--r-- 11,187 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!@theme_d_guile@ \
-e main -s
!#

;; Copyright (C) 2008-2018, 2021, 2025 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.


(import (rnrs exceptions))
(import (rnrs conditions))
(import (rnrs base))
(import (theme-d common theme-d-config))
(import (theme-d testing test-info))
(import (th-scheme-utilities hrecord))
(import (th-scheme-utilities parse-command-line))


(define (get-test-name i)
  (string-append "test" (number->string i)))


(define (get-source-filename i s-unit-type)
  (let ((str-ext (if (eq? s-unit-type 'script) ".tcs" ".tcp")))
    (string-append "test" (number->string i) str-ext)))


(define (get-interm-filename i s-intermediate-language)
  (let ((s-ext
         (case s-intermediate-language
           ((tree-il) ".tree-il")
           ((guile) ".scm")
           ((guile0) ".scm")
           (else (raise 'invalid-intermediate-language)))))
    (string-append "test" (number->string i) s-ext)))


(define (get-target-filename i)
  (string-append "test" (number->string i) ".go"))


(define (get-test-path filename)
  (string-append "../theme-d-code/tests/" filename))


(define (get-split-dir i)
  (string-append "../theme-d-code/tests/test" (number->string i) ".build"))


(define (link-program index output-file str-link-command
                      s-intermediate-language keep-intermediate?
                      str-extra-link-options)
  (assert (integer? index))
  (assert (output-port? output-file))
  (assert (and (string? str-link-command)
               (not (string-null? str-link-command))))
  (assert (and (symbol? s-intermediate-language)
               (memq s-intermediate-language '(tree-il guile guile0))))
  (assert (boolean? keep-intermediate?))
  (assert (string? str-extra-link-options))
  (let* ((s-unit-type (if (member index scripts) 'script 'proper-program))
         (source-filename (get-source-filename index s-unit-type))
         (interm-filename (get-interm-filename index
                                               s-intermediate-language))
         (str-interm-type
          (case s-intermediate-language
            ((tree-il)
             "-i tree-il")
            ((guile)
             "-i guile")
            ((guile0)
             (string-append "-i guile --no-optimization"))
            (else (raise 'invalid-intermediate-language))))
         (str-keep-option
          (if keep-intermediate?
            (string-append
             "--keep-intermediate -n "
             (get-test-path interm-filename))
            ""))
         (target-filename (get-target-filename index)))
    (display (string-append "Linking program "))
    (display source-filename)
    (newline)
    (flush-all-ports)
    (let ((source-path (get-test-path source-filename))
          (target-path (get-test-path target-filename))
          (str-extra-modules
           (cond
             ((member index custom1-programs)
              "-x \"(theme-d testing custom1)\"")
             ((member index custom2-programs)
              "-x \"(theme-d testing custom2)\"")
             (else ""))))
      (let ((str-command
             (string-append
              str-link-command
              " -m ../theme-d-code: "
              str-interm-type
              " "
              str-keep-option
              " "
              str-extra-modules
              " "
              str-extra-link-options
              " -o "
              target-path
              " " source-path " 2>&1")))
        (display str-command)
        (newline)
        (let ((result (system str-command)))
          (if (= result 0)
            (begin
             (display "Linking of " output-file)
             (display source-filename output-file)
             (display " succeeded." output-file)
             (newline output-file))
            (begin
             (display "Linking of " output-file)
             (display source-filename output-file)
             (display " failed." output-file)
             (newline output-file))))))))


(define (link-program-split index output-file str-link-command
                            s-intermediate-language keep-intermediate?
                            str-extra-link-options)
  (assert (integer? index))
  (assert (output-port? output-file))
  (assert (and (string? str-link-command)
               (not (string-null? str-link-command))))
  (assert (and (symbol? s-intermediate-language)
               (memq s-intermediate-language '(tree-il guile guile0))))
  (assert (boolean? keep-intermediate?))
  (assert (string? str-extra-link-options))
  (let* ((s-unit-type (if (member index scripts) 'script 'proper-program))
         (source-filename (get-source-filename index s-unit-type))
         (str-interm-type
          (case s-intermediate-language
            ((tree-il)
             "-i tree-il")
            ((guile)
             "-i guile")
            ((guile0)
             (string-append "-i guile --no-optimization"))
            (else (raise 'invalid-intermediate-language))))
         (str-keep-option
          (if keep-intermediate?
            "--keep-intermediate"
            ""))
         (target-filename (get-target-filename index)))
    (display (string-append "Linking program "))
    (display source-filename)
    (newline)
    (flush-all-ports)
    (let ((source-path (get-test-path source-filename))
          (str-split-dir (get-split-dir index))
          (str-extra-modules
           (cond
             ((member index custom1-programs)
              "-x \"(theme-d testing custom1)\"")
             ((member index custom2-programs)
              "-x \"(theme-d testing custom2)\"")
             (else ""))))
      (let ((str-command
             (string-append
              str-link-command
              " -m ../theme-d-code: --split "
              " --split-dir=" str-split-dir " "
              str-interm-type
              " "
              str-keep-option
              " "
              str-extra-modules
              " "
              str-extra-link-options
              " " source-path " 2>&1")))
        (display str-command)
        (newline)
        (let ((result (system str-command)))
          (if (= result 0)
            (begin
             (display "Linking of " output-file)
             (display source-filename output-file)
             (display " succeeded." output-file)
             (newline output-file))
            (begin
             (display "Linking of " output-file)
             (display source-filename output-file)
             (display " failed." output-file)
             (newline output-file))))))))


(define (link-programs output-file str-link-command
                       s-intermediate-language keep-intermediate?
                       str-extra-link-options)
  (do ((i 1 (+ i 1))) ((> i nr-of-tests))
    (if (and (not (member i modules))
             (not (member i l-only-modular-linking)))
      (if (memv i l-split-linking)
        (link-program-split i output-file str-link-command
                            s-intermediate-language keep-intermediate?
                            str-extra-link-options)
        (link-program i output-file str-link-command
                      s-intermediate-language keep-intermediate?
                      str-extra-link-options)))))


(define (main args)
  (init-theme-d-config)
  (let* ((str1 (getenv "EXTRA_LINK_OPTIONS"))
         (str-extra-link-options (if str1 str1 ""))
         (str-link-command0 "")
         (str-mod-linker-path0 "")
         (split? #f)
         (s-intermediate-language 'tree-il)
         (keep-intermediate? #f)
         (argd1 (make-hrecord <argument-descriptor> #\b #t
                              (lambda (str-option-arg)
                                (if (not (and (string-null? str-link-command0)
                                              (string-null? str-mod-linker-path0)))
                                  (display "Duplicate linker setting. Exiting.\n"))
                                (set! str-link-command0 str-option-arg))))
         (argd2 (make-hrecord <argument-descriptor> #\s #t
                              (lambda (str-option-arg)
                                (if (not (and (string-null? str-link-command0)
                                              (string-null? str-mod-linker-path0)))
                                  (display "Duplicate linker setting. Exiting.\n"))
                                (set! str-link-command0 str-option-arg)
                                (set! split? #t))))
         (argd3 (make-hrecord <argument-descriptor> #\B #t
                              (lambda (str-option-arg)
                                (if (not (and (string-null? str-link-command0)
                                              (string-null? str-mod-linker-path0)))
                                  (display "Duplicate linker setting. Exiting.\n"))
                                (set! str-mod-linker-path0 str-option-arg))))
         (argd4 (make-hrecord <argument-descriptor> #\i #t
                              (lambda (str-option-arg)
                                (cond
                                  ((equal? str-option-arg "tree-il")
                                   (set! s-intermediate-language 'tree-il))
                                  ((equal? str-option-arg "guile")
                                   (set! s-intermediate-language 'guile))
                                  ((equal? str-option-arg "guile0")
                                   (set! s-intermediate-language 'guile0))
                                  (else
                                   (display "Invalid intermediate language.\n")
                                   (exit 1))))))
         (argd5 (make-hrecord <argument-descriptor> #\k #f
                              (lambda ()
                                (set! keep-intermediate? #t))))
         (l-arg-descs (list argd1 argd2 argd3 argd4 argd5))
         (handle-proper-args
          (lambda (l-proper-args)
            (if (> (length l-proper-args) 0)
              (begin
               (display "Extra arguments in command line. Exiting.\n")
               (exit 1)))
            #f))
         (l-args-without-cmd (cdr args)))
    (parse-command-line l-args-without-cmd l-arg-descs handle-proper-args)
    (let ((str-link-command
           (cond
             ((not (string-null? str-mod-linker-path0))
              (string-append
               "run-theme-d-program-m -g "
               str-mod-linker-path0
               ": "
               str-mod-linker-path0
               "/theme-d-in-theme-d/theme-d-link-b.go"))
             ((not (string-null? str-link-command0))
              (string-append
               (if split? "run-split-theme-d-program " "run-theme-d-program ")
               str-link-command0))
             (else
              (get-theme-d-config-var 'linker-path)))))
      (call-with-output-file "link-test-programs.log"
                             (lambda (output-file)
                               (link-programs output-file str-link-command s-intermediate-language
                                              keep-intermediate? str-extra-link-options))))))