@@ -329,113 +329,6 @@ auto validate_guard_dependencies(
329329 return {};
330330}
331331
332- // / Collect all commands required to build the given target nodes.
333- // / Uses reverse traversal: starts at targets, walks backward through inputs.
334- auto collect_required_commands (
335- graph::Graph const & graph,
336- Vec<NodeId> const & target_ids
337- ) -> NodeIdMap32
338- {
339- auto visited = NodeIdMap32 {};
340- auto commands = NodeIdMap32 {};
341- auto stack = Vec<NodeId> {};
342- for (auto id : target_ids) {
343- stack.push_back (id);
344- }
345-
346- while (!stack.empty ()) {
347- auto id = stack.back ();
348- stack.pop_back ();
349-
350- if (visited.contains (id)) {
351- continue ;
352- }
353- visited.set (id, 1 );
354-
355- if (node_id::is_command (id) && graph::get_command_node (graph, id)) {
356- commands.set (id, 1 );
357- }
358-
359- for (auto input_id : graph::get_inputs (graph, id)) {
360- stack.push_back (input_id);
361- }
362-
363- for (auto dep_id : graph::get_order_only (graph, id)) {
364- stack.push_back (dep_id);
365- }
366- }
367-
368- return commands;
369- }
370-
371- // / Compute all commands affected by the given changed files.
372- // / Uses forward traversal: starts at changed inputs, walks forward through outputs.
373- auto collect_affected_commands (
374- graph::Graph const & graph,
375- Vec<StringId> const & changed_files
376- ) -> NodeIdMap32
377- {
378- auto & pool = global_pool ();
379-
380- auto path_to_id = Vec<std::pair<std::string_view, NodeId>> {};
381- for (auto id : graph::all_nodes (graph)) {
382- auto path_id = graph::get_full_path (graph, id);
383- if (!is_empty (path_id)) {
384- path_to_id.emplace_back (pool.get (path_id), id);
385- }
386- }
387- std::sort (path_to_id.begin (), path_to_id.end ());
388-
389- auto affected = NodeIdMap32 {};
390- auto to_process = Vec<NodeId> {};
391-
392- for (auto file_id : changed_files) {
393- auto file_path = pool.get (file_id);
394- auto it = std::lower_bound (path_to_id.begin (), path_to_id.end (), file_path, [](auto const & p, auto const & k) { return p.first < k; });
395- if (it != path_to_id.end () && it->first == file_path) {
396- auto id = it->second ;
397- if (!affected.contains (id)) {
398- affected.set (id, 1 );
399- to_process.push_back (id);
400- }
401-
402- auto const * node = graph::get_file_node (graph, id);
403- if (node && node->type == NodeType::Generated) {
404- for (auto input_id : graph::get_inputs (graph, id)) {
405- if (!affected.contains (input_id)) {
406- affected.set (input_id, 1 );
407- to_process.push_back (input_id);
408- }
409- }
410- }
411- }
412- }
413-
414- // Expand to include all dependent commands (including order-only).
415- // get_outputs() excludes sticky edges by design (Tupfile/config dependencies
416- // are parse-time deps, not build-time deps).
417- while (!to_process.empty ()) {
418- auto id = NodeId { to_process.back () };
419- to_process.pop_back ();
420-
421- for (auto dep_id : graph::get_outputs (graph, id)) {
422- if (!affected.contains (dep_id)) {
423- affected.set (dep_id, 1 );
424- to_process.push_back (dep_id);
425- }
426- }
427-
428- for (auto dep_id : graph::get_order_only_dependents (graph, id)) {
429- if (!affected.contains (dep_id)) {
430- affected.set (dep_id, 1 );
431- to_process.push_back (dep_id);
432- }
433- }
434- }
435-
436- return affected;
437- }
438-
439332struct JobSlot {
440333 pup::platform::AsyncProcess process = {};
441334 HeapBuf stdout_buf = {};
@@ -609,45 +502,7 @@ auto Scheduler::stats() const -> BuildStats
609502// Public build API
610503// ---------------------------------------------------------------------------
611504
612- auto Scheduler::build (graph::BuildState const & state) -> Result<BuildStats>
613- {
614- return run (state, nullptr );
615- }
616-
617- auto Scheduler::build_incremental (
618- graph::BuildState const & state,
619- Vec<StringId> const & changed_files
620- ) -> Result<BuildStats>
621- {
622- auto affected = collect_affected_commands (state.graph , changed_files);
623- return run (state, &affected);
624- }
625-
626- auto Scheduler::build_subset (
627- graph::BuildState const & state,
628- NodeIdMap32 const & command_ids
629- ) -> Result<BuildStats>
630- {
631- return run (state, &command_ids);
632- }
633-
634- auto Scheduler::build_targets (
635- graph::BuildState const & state,
636- Vec<NodeId> const & target_ids
637- ) -> Result<BuildStats>
638- {
639- auto cmds = collect_required_commands (state.graph , target_ids);
640- return run (state, &cmds);
641- }
642-
643- // ---------------------------------------------------------------------------
644- // Private implementation
645- // ---------------------------------------------------------------------------
646-
647- auto Scheduler::run (
648- graph::BuildState const & state,
649- NodeIdMap32 const * filter
650- ) -> Result<BuildStats>
505+ auto Scheduler::build (graph::BuildState const & state, NodeIdMap32 const * filter) -> Result<BuildStats>
651506{
652507 impl_->cancelled = false ;
653508 impl_->stats = BuildStats {};
0 commit comments