Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/pup/graph/dag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ auto get_file_node(Graph const& graph, NodeId id) -> FileNode const*;
[[nodiscard]]
auto get_command_node(Graph const& graph, NodeId id) -> CommandNode const*;

/// Get the type of a node (File, Generated, Ghost, Directory, Group, Command, etc.)
[[nodiscard]]
auto get_node_type(Graph const& graph, NodeId id) -> NodeType;

/// Check if all guards on a command are satisfied
[[nodiscard]]
auto is_guard_satisfied(Graph const& graph, CommandNode const& cmd) -> bool;
Expand Down
3 changes: 1 addition & 2 deletions src/cli/cmd_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,7 @@ auto validate_output_targets(
veprint(variant_name, "Error: %.*s is not in build graph\n", static_cast<int>(target_sv.size()), target_sv.data());
return std::nullopt;
}
auto const* node = pup::graph::get_file_node(state.graph, *node_id);
if (!node || node->type != pup::NodeType::Generated) {
if (pup::graph::get_node_type(state.graph, *node_id) != pup::NodeType::Generated) {
veprint(variant_name, "Error: %.*s is not a build output\n", static_cast<int>(target_sv.size()), target_sv.data());
return std::nullopt;
}
Expand Down
7 changes: 2 additions & 5 deletions src/cli/cmd_show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ auto cmd_export_script(Options const& opts, std::string_view variant_name) -> in

auto output_dirs = Vec<StringId> {};
for (auto id : graph::all_nodes(ctx.graph().graph)) {
auto const* node = graph::get_file_node(ctx.graph().graph, id);
if (!node) {
continue;
}
if (node->type != pup::NodeType::Generated && node->type != pup::NodeType::File) {
auto node_type = graph::get_node_type(ctx.graph().graph, id);
if (node_type != pup::NodeType::Generated && node_type != pup::NodeType::File) {
continue;
}

Expand Down
7 changes: 1 addition & 6 deletions src/cli/config_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ auto collect_command_dependencies(
};

for (auto oo_id : graph::get_order_only(g, cmd_id)) {
auto const* oo_node = graph::get_file_node(g, oo_id);
if (!oo_node) {
continue;
}

if (oo_node->type == NodeType::Group) {
if (graph::get_node_type(g, oo_id) == NodeType::Group) {
for (auto member_id : graph::get_inputs(g, oo_id)) {
add_producers(member_id);
}
Expand Down
17 changes: 3 additions & 14 deletions src/exec/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,8 @@ auto build_dependency_map(
// Case 3: Order-only inputs (groups and files)
// These establish ordering without creating true data dependencies.
for (auto oo_id : graph::get_order_only(graph, cmd_id)) {
auto const* oo_node = graph::get_file_node(graph, oo_id);
if (!oo_node) {
continue;
}

// For Group nodes, get member files and find their producers
if (oo_node->type == NodeType::Group) {
if (graph::get_node_type(graph, oo_id) == NodeType::Group) {
for (auto member_id : graph::get_inputs(graph, oo_id)) {
add_producer_dependencies(graph, cmd_to_job, jobs, member_id, j, dependencies);
}
Expand Down Expand Up @@ -587,8 +582,7 @@ auto Scheduler::build_job_list(
auto& cache = state.path_cache;

for (auto id : topo_result.order) {
auto const* node = graph::get_file_node(g, id);
if (node && node->type == NodeType::Ghost && !graph::get_outputs(g, id).empty()) {
if (graph::get_node_type(g, id) == NodeType::Ghost && !graph::get_outputs(g, id).empty()) {
auto path_sv = graph::get_full_path(g, id, cache);
auto build_root_name = graph::get_build_root_name(g);
auto file_path_sv = pool.get(pup::path::join(output_root_sv, path_sv));
Expand Down Expand Up @@ -691,12 +685,7 @@ auto Scheduler::build_job_list(
// Collect order-only input paths
// For Group nodes, expand to member file paths
for (auto oi_id : graph::get_order_only(g, id)) {
auto const* oi_node = graph::get_file_node(g, oi_id);
if (!oi_node) {
continue;
}

if (oi_node->type == NodeType::Group) {
if (graph::get_node_type(g, oi_id) == NodeType::Group) {
for (auto member_id : graph::get_inputs(g, oi_id)) {
auto member_path = graph::get_full_path(g, member_id, cache);
if (!member_path.empty()) {
Expand Down
9 changes: 9 additions & 0 deletions src/graph/dag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ auto get_command_node(Graph const& graph, NodeId id) -> CommandNode const*
return node.id == id ? &node : nullptr;
}

auto get_node_type(Graph const& graph, NodeId id) -> NodeType
{
if (node_id::is_command(id)) {
return NodeType::Command;
}
auto const* node = get_file_node(graph, id);
return node ? node->type : NodeType::File;
}

auto add_condition_node(Graph& graph, ConditionNode node) -> Result<NodeId>
{
auto const id = graph.next_condition_id;
Expand Down
Loading