|
| 1 | +//===----- ParseableOutput.h - Helpers for parseable output ------- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +/// |
| 13 | +/// \file |
| 14 | +/// Helpers for emitting the compiler's parseable output. |
| 15 | +/// |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +#ifndef SWIFT_PARSEABLEOUTPUT_H |
| 19 | +#define SWIFT_PARSEABLEOUTPUT_H |
| 20 | + |
| 21 | +#include "swift/Basic/LLVM.h" |
| 22 | +#include "swift/Basic/TaskQueue.h" |
| 23 | +#include "swift/Basic/FileTypes.h" |
| 24 | + |
| 25 | +namespace swift { |
| 26 | + |
| 27 | +namespace parseable_output { |
| 28 | + |
| 29 | +/// Quasi-PIDs are _negative_ PID-like unique keys used to |
| 30 | +/// masquerade batch job constituents as (quasi)processes, when writing |
| 31 | +/// parseable output to consumers that don't understand the idea of a batch |
| 32 | +/// job. They are negative in order to avoid possibly colliding with real |
| 33 | +/// PIDs (which are always positive). We start at -1000 here as a crude but |
| 34 | +/// harmless hedge against colliding with an errno value that might slip |
| 35 | +/// into the stream of real PIDs (say, due to a TaskQueue bug). |
| 36 | +const int QUASI_PID_START = -1000; |
| 37 | + |
| 38 | +struct CommandInput { |
| 39 | + std::string Path; |
| 40 | + CommandInput() {} |
| 41 | + CommandInput(StringRef Path) : Path(Path) {} |
| 42 | +}; |
| 43 | + |
| 44 | +using OutputPair = std::pair<file_types::ID, std::string>; |
| 45 | + |
| 46 | +/// A client-agnostic (e.g. either the compiler driver or `swift-frontend`) |
| 47 | +/// description of a task that is the subject of a parseable-output message. |
| 48 | +struct DetailedTaskDescription { |
| 49 | + std::string Executable; |
| 50 | + SmallVector<std::string, 16> Arguments; |
| 51 | + std::string CommandLine; |
| 52 | + SmallVector<CommandInput, 4> Inputs; |
| 53 | + SmallVector<OutputPair, 8> Outputs; |
| 54 | +}; |
| 55 | + |
| 56 | +/// Emits a "began" message to the given stream. |
| 57 | +void emitBeganMessage(raw_ostream &os, StringRef Name, |
| 58 | + DetailedTaskDescription TascDesc, |
| 59 | + int64_t Pid, sys::TaskProcessInformation ProcInfo); |
| 60 | + |
| 61 | +/// Emits a "finished" message to the given stream. |
| 62 | +void emitFinishedMessage(raw_ostream &os, StringRef Name, |
| 63 | + std::string Output, int ExitStatus, |
| 64 | + int64_t Pid, sys::TaskProcessInformation ProcInfo); |
| 65 | + |
| 66 | +/// Emits a "signalled" message to the given stream. |
| 67 | +void emitSignalledMessage(raw_ostream &os, StringRef Name, StringRef ErrorMsg, |
| 68 | + StringRef Output, Optional<int> Signal, |
| 69 | + int64_t Pid, sys::TaskProcessInformation ProcInfo); |
| 70 | + |
| 71 | +/// Emits a "skipped" message to the given stream. |
| 72 | +void emitSkippedMessage(raw_ostream &os, StringRef Name, |
| 73 | + DetailedTaskDescription TascDesc); |
| 74 | + |
| 75 | +} // end namespace parseable_output |
| 76 | +} // end namespace swift |
| 77 | + |
| 78 | +#endif |
0 commit comments