mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
tsort: Suppress warnings with -q
This commit is contained in:
parent
9caa3d2b55
commit
0dd8066a79
1 changed files with 10 additions and 6 deletions
|
@ -26,24 +26,26 @@ struct Node {
|
||||||
using NodeMap = OrderedHashMap<StringView, Node>;
|
using NodeMap = OrderedHashMap<StringView, Node>;
|
||||||
using NodeStack = Vector<Node&>;
|
using NodeStack = Vector<Node&>;
|
||||||
|
|
||||||
static void handle_cycle(NodeStack& stack, Node& duplicated_node)
|
static void handle_cycle(NodeStack& stack, Node& duplicated_node, bool quiet)
|
||||||
{
|
{
|
||||||
// Report on a cycle by moving down the stack of dependencies, logging every node
|
// Report on a cycle by moving down the stack of dependencies, logging every node
|
||||||
// between the implicit top of the stack (represented by duplicate_node) and that
|
// between the implicit top of the stack (represented by duplicate_node) and that
|
||||||
// node's first appearance.
|
// node's first appearance.
|
||||||
|
|
||||||
warnln("tsort: The following nodes form a cycle");
|
if (!quiet)
|
||||||
|
warnln("tsort: The following nodes form a cycle");
|
||||||
|
|
||||||
for (auto it = stack.rbegin(); it != stack.rend(); ++it) {
|
for (auto it = stack.rbegin(); it != stack.rend(); ++it) {
|
||||||
auto node = *it;
|
auto node = *it;
|
||||||
node.status = NodeStatus::NotSeen;
|
node.status = NodeStatus::NotSeen;
|
||||||
warnln("tsort: {}", node.name);
|
if (!quiet)
|
||||||
|
warnln("tsort: {}", node.name);
|
||||||
if (node.name == duplicated_node.name)
|
if (node.name == duplicated_node.name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prioritize_nodes(Node& start, NodeMap& node_map, NodeStack& stack)
|
static void prioritize_nodes(Node& start, NodeMap& node_map, NodeStack& stack, bool quiet)
|
||||||
{
|
{
|
||||||
// Prioritize (topologically sort) a subset of a directed graph using a depth first
|
// Prioritize (topologically sort) a subset of a directed graph using a depth first
|
||||||
// search. The "deepest" nodes are the earliest ancestors of all other nodes and
|
// search. The "deepest" nodes are the earliest ancestors of all other nodes and
|
||||||
|
@ -81,7 +83,7 @@ static void prioritize_nodes(Node& start, NodeMap& node_map, NodeStack& stack)
|
||||||
// the graph. To avoid an infinite loop, the duplicate node is not added
|
// the graph. To avoid an infinite loop, the duplicate node is not added
|
||||||
// to the stack a second time. Instead, the edge is deliberately ignored,
|
// to the stack a second time. Instead, the edge is deliberately ignored,
|
||||||
// and the topological sort proceeds as though the cycle did not exist.
|
// and the topological sort proceeds as though the cycle did not exist.
|
||||||
handle_cycle(stack, next_ancestor);
|
handle_cycle(stack, next_ancestor, quiet);
|
||||||
else
|
else
|
||||||
// Recursively prioritize all ancestors.
|
// Recursively prioritize all ancestors.
|
||||||
stack.append(next_ancestor);
|
stack.append(next_ancestor);
|
||||||
|
@ -94,9 +96,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
TRY(Core::System::pledge("stdio rpath"));
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
|
|
||||||
StringView path;
|
StringView path;
|
||||||
|
bool quiet;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(path, "Path to file", "path", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(path, "Path to file", "path", Core::ArgsParser::Required::No);
|
||||||
|
args_parser.add_option(quiet, "Suppress warnings about cycles", "quiet", 'q');
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read));
|
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read));
|
||||||
|
@ -138,7 +142,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
for (auto& entry : node_map) {
|
for (auto& entry : node_map) {
|
||||||
auto& node_to_prioritize = entry.value;
|
auto& node_to_prioritize = entry.value;
|
||||||
if (node_to_prioritize.status == NodeStatus::NotSeen)
|
if (node_to_prioritize.status == NodeStatus::NotSeen)
|
||||||
prioritize_nodes(node_to_prioritize, node_map, stack);
|
prioritize_nodes(node_to_prioritize, node_map, stack, quiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue