| ... | @@ -96,9 +96,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { | ... | @@ -96,9 +96,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { |
| 96 | const args1 = [][]const u8{"llvm-config-5.0", "--libs", "--system-libs"}; | 96 | const args1 = [][]const u8{"llvm-config-5.0", "--libs", "--system-libs"}; |
| 97 | const args2 = [][]const u8{"llvm-config", "--libs", "--system-libs"}; | 97 | const args2 = [][]const u8{"llvm-config", "--libs", "--system-libs"}; |
| 98 | const max_output_size = 10 * 1024; | 98 | const max_output_size = 10 * 1024; |
| 99 | const good_result = exec(b.allocator, args1, null, null, max_output_size) %% |err| { | 99 | const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| { |
| 100 | if (err == error.FileNotFound) { | 100 | if (err == error.FileNotFound) { |
| 101 | exec(b.allocator, args2, null, null, max_output_size) %% |err2| { | 101 | os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| { |
| 102 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); | 102 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); |
| 103 | } | 103 | } |
| 104 | } else { | 104 | } else { |
| ... | @@ -121,9 +121,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { | ... | @@ -121,9 +121,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { |
| 121 | const args1 = [][]const u8{"llvm-config-5.0", "--includedir"}; | 121 | const args1 = [][]const u8{"llvm-config-5.0", "--includedir"}; |
| 122 | const args2 = [][]const u8{"llvm-config", "--includedir"}; | 122 | const args2 = [][]const u8{"llvm-config", "--includedir"}; |
| 123 | const max_output_size = 10 * 1024; | 123 | const max_output_size = 10 * 1024; |
| 124 | const good_result = exec(b.allocator, args1, null, null, max_output_size) %% |err| { | 124 | const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| { |
| 125 | if (err == error.FileNotFound) { | 125 | if (err == error.FileNotFound) { |
| 126 | exec(b.allocator, args2, null, null, max_output_size) %% |err2| { | 126 | os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| { |
| 127 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); | 127 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); |
| 128 | } | 128 | } |
| 129 | } else { | 129 | } else { |
| ... | @@ -146,9 +146,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { | ... | @@ -146,9 +146,9 @@ fn findLLVM(b: &Builder) -> LibraryDep { |
| 146 | const args1 = [][]const u8{"llvm-config-5.0", "--libdir"}; | 146 | const args1 = [][]const u8{"llvm-config-5.0", "--libdir"}; |
| 147 | const args2 = [][]const u8{"llvm-config", "--libdir"}; | 147 | const args2 = [][]const u8{"llvm-config", "--libdir"}; |
| 148 | const max_output_size = 10 * 1024; | 148 | const max_output_size = 10 * 1024; |
| 149 | const good_result = exec(b.allocator, args1, null, null, max_output_size) %% |err| { | 149 | const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| { |
| 150 | if (err == error.FileNotFound) { | 150 | if (err == error.FileNotFound) { |
| 151 | exec(b.allocator, args2, null, null, max_output_size) %% |err2| { | 151 | os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| { |
| 152 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); | 152 | std.debug.panic("unable to spawn {}: {}\n", args2[0], err2); |
| 153 | } | 153 | } |
| 154 | } else { | 154 | } else { |
| ... | @@ -203,41 +203,3 @@ fn findLLVM(b: &Builder) -> LibraryDep { | ... | @@ -203,41 +203,3 @@ fn findLLVM(b: &Builder) -> LibraryDep { |
| 203 | } | 203 | } |
| 204 | return result; | 204 | return result; |
| 205 | } | 205 | } |
| 206 | | | |
| 207 | | | |
| 208 | // TODO move to std lib | | |
| 209 | const ExecResult = struct { | | |
| 210 | term: os.ChildProcess.Term, | | |
| 211 | stdout: []u8, | | |
| 212 | stderr: []u8, | | |
| 213 | }; | | |
| 214 | | | |
| 215 | fn exec(allocator: &std.mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult { | | |
| 216 | const child = %%os.ChildProcess.init(argv, allocator); | | |
| 217 | defer child.deinit(); | | |
| 218 | | | |
| 219 | child.stdin_behavior = os.ChildProcess.StdIo.Ignore; | | |
| 220 | child.stdout_behavior = os.ChildProcess.StdIo.Pipe; | | |
| 221 | child.stderr_behavior = os.ChildProcess.StdIo.Pipe; | | |
| 222 | child.cwd = cwd; | | |
| 223 | child.env_map = env_map; | | |
| 224 | | | |
| 225 | %return child.spawn(); | | |
| 226 | | | |
| 227 | var stdout = Buffer.initNull(allocator); | | |
| 228 | var stderr = Buffer.initNull(allocator); | | |
| 229 | defer Buffer.deinit(&stdout); | | |
| 230 | defer Buffer.deinit(&stderr); | | |
| 231 | | | |
| 232 | var stdout_file_in_stream = io.FileInStream.init(&??child.stdout); | | |
| 233 | var stderr_file_in_stream = io.FileInStream.init(&??child.stderr); | | |
| 234 | | | |
| 235 | %return stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); | | |
| 236 | %return stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size); | | |
| 237 | | | |
| 238 | return ExecResult { | | |
| 239 | .term = %return child.wait(), | | |
| 240 | .stdout = stdout.toOwnedSlice(), | | |
| 241 | .stderr = stderr.toOwnedSlice(), | | |
| 242 | }; | | |
| 243 | } | | |