Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ProcessWorklist.cpp File Reference
#include "src/base/SkStringView.h"
#include "tools/skslc/ProcessWorklist.h"
#include <algorithm>
#include <fstream>
#include <vector>

Go to the source code of this file.

Functions

ResultCode ProcessWorklist (const char *worklistPath, const std::function< ResultCode(SkSpan< std::string > args)> &processCommandFn)
 

Function Documentation

◆ ProcessWorklist()

ResultCode ProcessWorklist ( const char *  worklistPath,
const std::function< ResultCode(SkSpan< std::string > args)> &  processCommandFn 
)

Processes multiple inputs in a single invocation by reading a worklist file. The processCommand is invoked with a set of arguments, read from the worklist. A blank line is used to separate one group of arguments from the next group.

Definition at line 15 of file ProcessWorklist.cpp.

17 {
18 std::string inputPath(worklistPath);
19 if (!skstd::ends_with(inputPath, ".worklist")) {
20 printf("expected .worklist file, found: %s\n\n", worklistPath);
22 }
23
24 // The worklist contains one line per argument to pass. When a blank line is reached, those
25 // arguments will be passed to `processCommandFn`.
26 auto resultCode = ResultCode::kSuccess;
27 std::vector<std::string> args = {"sksl"};
28 std::ifstream in(worklistPath);
29 for (std::string line; std::getline(in, line); ) {
30 if (in.rdstate()) {
31 printf("error reading '%s'\n", worklistPath);
33 }
34
35 if (!line.empty()) {
36 // We found an argument. Remember it.
37 args.push_back(std::move(line));
38 } else {
39 // We found a blank line. If we have any arguments stored up, process them as a command.
40 if (!args.empty()) {
41 ResultCode outcome = processCommandFn(args);
42 resultCode = std::max(resultCode, outcome);
43
44 // Clear every argument except the first.
45 args.resize(1);
46 }
47 }
48 }
49
50 // If the worklist ended with a list of arguments but no blank line, process those now.
51 if (args.size() > 1) {
52 ResultCode outcome = processCommandFn(args);
53 resultCode = std::max(resultCode, outcome);
54 }
55
56 // Return the "worst" status we encountered. For our purposes, compilation errors are the least
57 // serious, because they are expected to occur in unit tests. Other types of errors are not
58 // expected at all during a build.
59 return resultCode;
60}
ResultCode
@ kConfigurationError
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
constexpr bool ends_with(std::string_view str, std::string_view suffix)