tarballs
Depends on source tarballs of all packages.
-cmdline
- This target is an internal representation of the command line. Trying to
- add it to the command line will cause Builder to abort.
+goals
+ Depends on all targets on the command line. Trying to add this target to the
+ command line will cause Builder to abort due to a circular dependency.
-------------------------------------------------------------------------------
row.push_back("Rebuild");
table.push_back(row);
- Target &cmdline = *builder.get_build_graph().get_target("cmdline");
+ Target &goals = builder.get_build_graph().get_goals();
if(mode==RDEPS)
{
- const Target::Dependencies &deps = cmdline.get_dependencies();
+ const Target::Dependencies &deps = goals.get_dependencies();
for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
build_depend_table(**i, 0);
}
else
- build_depend_table(cmdline, 0);
+ build_depend_table(goals, 0);
print_table();
}
cmdline_targets.push_back(*i);
}
- if(cmdline_targets.empty())
- cmdline_targets.push_back("default");
-
if(!work_dir.empty())
FS::chdir(work_dir);
{
package_manager.get_main_package().prepare();
- // Make the cmdline target depend on all targets mentioned on the command line
- Target *cmdline = new VirtualTarget(*this, "cmdline");
+ // Add targets from command line as goals
for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
{
Target *tgt = build_graph.get_target(*i);
return false;
}
- cmdline->add_dependency(*tgt);
+ build_graph.add_goal(*tgt);
}
- cmdline->prepare();
+ build_graph.prepare();
// Apply what-ifs
for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
}
if(build_all)
- {
- for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->is_buildable() && !i->second->needs_rebuild())
- i->second->force_rebuild();
- }
+ build_graph.force_full_rebuild();
if(!dry_run)
{
int Builder::do_build()
{
- Target *cmdline = build_graph.get_target("cmdline");
-
- unsigned total = 0;
- const BuildGraph::TargetMap &targets = build_graph.get_targets();
- for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->is_buildable() && i->second->needs_rebuild())
- ++total;
+ unsigned total = build_graph.count_rebuild_targets();
if(!total)
{
{
if(tasks.size()<jobs && !fail && !starved)
{
- Target *tgt = cmdline->get_buildable_target();
+ Target *tgt = build_graph.get_buildable_target();
if(tgt)
{
if(tgt->get_tool())
using namespace std;
BuildGraph::BuildGraph(Builder &b):
- builder(b)
+ builder(b),
+ goals(new VirtualTarget(builder, "goals"))
{
Target *world = new VirtualTarget(builder, "world");
world->add_dependency(*new VirtualTarget(builder, "default"));
inst_tgt = builder.get_toolchain().get_tool("CP").create_target(t);
get_target("install")->add_dependency(*inst_tgt);
}
+
+void BuildGraph::add_goal(Target &t)
+{
+ goals->add_dependency(t);
+}
+
+void BuildGraph::prepare()
+{
+ if(goals->get_dependencies().empty())
+ add_goal(*get_target("default"));
+ goals->prepare();
+}
+
+void BuildGraph::force_full_rebuild()
+{
+ for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->is_buildable() && !i->second->needs_rebuild())
+ i->second->force_rebuild();
+}
+
+unsigned BuildGraph::count_rebuild_targets() const
+{
+ unsigned count = 0;
+ for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->is_buildable() && i->second->needs_rebuild())
+ ++count;
+ return count;
+}
+
+Target *BuildGraph::get_buildable_target() const
+{
+ return goals->get_buildable_target();
+}
private:
Builder &builder;
TargetMap targets;
+ Target *goals;
public:
BuildGraph(Builder &);
/** Adds a target that will be installed. A new InstalledFile target is
created and added as a dependency to the "install" virtual target. */
void add_installed_target(Target &);
+
+ /** Adds a target as a toplevel goal. These are stored as dependencies of
+ the "goals" virtual target. */
+ void add_goal(Target &);
+
+ Target &get_goals() const { return *goals; }
+
+ /** Prepares all toplevel goals for building. If no goals are defined, the
+ "default" target is added as a goal. */
+ void prepare();
+
+ /** Marks all buildable targets to be rebuilt. The graph must be prepared
+ first. */
+ void force_full_rebuild();
+
+ /** Returns the number of targets that are going to be rebuilt. The graph
+ must be prepared first. */
+ unsigned count_rebuild_targets() const;
+
+ /** Returns a target that can be built and is needed for building the goal
+ targets. Null */
+ Target *get_buildable_target() const;
};
#endif