| 1 | (* A compiler host for test/compiler-host.sh: the library is where the |
| 2 | environment's RAZ_TEST_LIBRARY says, raz run is refused and a program |
| 3 | that uses C is not made. With RAZ_TEST_WRITE=refuse the executable |
| 4 | can't be written. Linux still supplies the runtime and the files. *) |
| 5 | module Host; |
| 6 | import Sys, Files; |
| 7 | |
| 8 | type |
| 9 | CLib* = (none, glibc, musl); (* as raz's Host.raz has it *) |
| 10 | |
| 11 | const |
| 12 | RunRefused: ERROR = "this test host cannot run programs"; |
| 13 | CannotWrite = "refuse"; (* RAZ_TEST_WRITE's value that fails the write *) |
| 14 | |
| 15 | (* The library the test sets up *) |
| 16 | proc libraryDir*: []const U8; |
| 17 | begin |
| 18 | return Sys.env("RAZ_TEST_LIBRARY"); |
| 19 | end; |
| 20 | |
| 21 | (* No C *) |
| 22 | proc cLibrary*: CLib; |
| 23 | begin |
| 24 | return none; |
| 25 | end; |
| 26 | |
| 27 | (* The file written as it is, or not at all when the test says so *) |
| 28 | proc writeExecutable*(path, data: []const U8): BOOL; |
| 29 | begin |
| 30 | if Sys.env("RAZ_TEST_WRITE") = CannotWrite then return false; end; |
| 31 | return Files.write(path, data) and (Sys.chmod(path, 1EDH) >= 0); |
| 32 | end; |
| 33 | |
| 34 | (* Refused *) |
| 35 | proc prepareRun*: ([]const U8, ERROR); |
| 36 | begin |
| 37 | return "", RunRefused; |
| 38 | end; |
| 39 | |
| 40 | (* Never reached, since prepareRun refuses *) |
| 41 | proc execute*(_path: []const U8; _first: INT): INT; |
| 42 | begin |
| 43 | return -38; |
| 44 | end; |
| 45 | |
| 46 | end Host. |