In remaining cases use auto as a shortcut for the iterator type.
if(mode==RDEPS)
{
rdepends.clear();
- const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ for(const auto &kvp: builder.get_build_graph().get_targets())
{
- const Target::Dependencies &depends = i->second->get_dependencies();
- for(Target::Dependencies::const_iterator j=depends.begin(); j!=depends.end(); ++j)
- rdepends[*j].insert(i->second);
- const Target::Dependencies &tdepends = i->second->get_transitive_dependencies();
- for(Target::Dependencies::const_iterator j=tdepends.begin(); j!=tdepends.end(); ++j)
- rdepends[*j].insert(i->second);
+ for(Target *d: kvp.second->get_dependencies())
+ rdepends[d].insert(kvp.second);
+ for(Target *d: kvp.second->get_transitive_dependencies())
+ rdepends[d].insert(kvp.second);
}
}
Target &goals = builder.get_build_graph().get_goals();
if(mode==RDEPS)
{
- const Target::Dependencies &deps = goals.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- build_depend_table(**i, 0);
+ for(Target *d: goals.get_dependencies())
+ build_depend_table(*d, 0);
}
else
build_depend_table(goals, 0);
depends.sort(full_paths ? target_order_full : target_order);
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
- build_depend_table(**i, depth+1);
+ for(Target *d: depends)
+ build_depend_table(*d, depth+1);
}
}
vector<string::size_type> col_width;
// Determine column widths
- for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+ for(const vector<string> &r: table)
{
- if(col_width.size()<i->size())
- col_width.resize(i->size(), 0);
- for(unsigned j=0; j<i->size(); ++j)
- col_width[j] = max(col_width[j], (*i)[j].size());
+ if(col_width.size()<r.size())
+ col_width.resize(r.size(), 0);
+ for(unsigned j=0; j<r.size(); ++j)
+ col_width[j] = max(col_width[j], r[j].size());
}
- for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+ for(const vector<string> &r: table)
{
string line;
- for(unsigned j=0; j<i->size(); ++j)
+ for(unsigned j=0; j<r.size(); ++j)
{
if(j>0)
line += " ";
- line += lexical_cast<string>((*i)[j], Fmt("%-s").width(col_width[j]));
+ line += lexical_cast<string>(r[j], Fmt("%-s").width(col_width[j]));
}
IO::print("%s\n", line);
}
Builder &builder = package.get_builder();
BuildGraph &build_graph = builder.get_build_graph();
- const BuildGraph::TargetMap &targets = build_graph.get_targets();
list<Target *> contents;
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->get_package()==&package)
- if(InstalledFile *inst = dynamic_cast<InstalledFile *>(i->second))
+ for(const auto &kvp: build_graph.get_targets())
+ if(kvp.second->get_package()==&package)
+ if(InstalledFile *inst = dynamic_cast<InstalledFile *>(kvp.second))
contents.push_back(inst->get_real_target());
AndroidManifestFile *manifest = new AndroidManifestFile(builder, *this);
manifest->set_orientation(orientation);
- for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
- manifest->add_permission(*i);
+ for(const string &p: permissions)
+ manifest->add_permission(p);
list<Target *> resource_sources;
resource_sources.push_back(manifest);
const Toolchain &toolchain = builder.get_toolchain();
Tool © = toolchain.get_tool("CP");
- SourceList source_filenames = collect_source_files();
- for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ for(const FS::Path &s: collect_source_files())
{
- Target *tgt = new AndroidResourceFile(builder, *this, *i);
+ Target *tgt = new AndroidResourceFile(builder, *this, s);
resource_sources.push_back(copy.create_target(*tgt, "//"));
}
lib_dir += arch.get_type();
string assets_dir = "//"+name+"/assets";
- for(list<Target *>::const_iterator i=contents.begin(); i!=contents.end(); ++i)
+ for(Target *t: contents)
{
Target *staged = 0;
- if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(*i))
+ if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(t))
{
manifest->set_native_library(shlib);
- staged = copy.create_target(**i, lib_dir);
+ staged = copy.create_target(*t, lib_dir);
}
else
- staged = copy.create_target(**i, assets_dir);
+ staged = copy.create_target(*t, assets_dir);
apk_sources.push_back(staged);
}
{
AndroidManifestFile *manifest = 0;
list<FileTarget *> resources;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(AndroidManifestFile *m = dynamic_cast<AndroidManifestFile *>(*i))
+ if(AndroidManifestFile *m = dynamic_cast<AndroidManifestFile *>(s))
manifest = m;
- else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
+ else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
resources.push_back(f);
}
argv.push_back("-F");
argv.push_back(FS::relative(res.get_path(), work_dir).str());
- const Target::Dependencies &depends = res.get_dependencies();
list<FS::Path> resource_dirs;
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: res.get_dependencies())
{
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
- Target *real = (*i)->get_real_target();
+ FileTarget *file = dynamic_cast<FileTarget *>(d);
+ Target *real = d->get_real_target();
if(dynamic_cast<AndroidManifestFile *>(real))
{
}
set<string> seen_dirs;
- for(list<FS::Path>::const_iterator i=resource_dirs.begin(); i!=resource_dirs.end(); ++i)
- if(seen_dirs.insert(i->str()).second)
+ for(const FS::Path &d: resource_dirs)
+ if(seen_dirs.insert(d.str()).second)
{
argv.push_back("-S");
- argv.push_back(FS::relative(*i, work_dir).str());
+ argv.push_back(FS::relative(d, work_dir).str());
}
return new ExternalTask(argv, work_dir);
out.write("\t\t</activity>\n");
}
out.write("\t</application>\n");
- const set<string> &permissions = manifest.get_permissions();
- for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
- IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", *i);
+ for(const string &p: manifest.get_permissions())
+ IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", p);
out.write("</manifest>\n");
status = Task::SUCCESS;
component = &c;
add_dependency(resource_bundle);
- for(list<FileTarget *>::const_iterator i=other_files.begin(); i!=other_files.end(); ++i)
- add_dependency(**i);
+ for(FileTarget *f: other_files)
+ add_dependency(*f);
}
component = &c;
add_dependency(manifest);
- for(list<FileTarget *>::const_iterator i=resources.begin(); i!=resources.end(); ++i)
- add_dependency(**i);
+ for(FileTarget *f: resources)
+ add_dependency(*f);
}
return;
builder.get_logger().log("files", format("Traversing %s", platforms_dir.str()));
- vector<string> platforms = list_filtered(platforms_dir, "^android-[1-9][0-9]*$");
-
- for(vector<string>::const_iterator i=platforms.begin(); i!=platforms.end(); ++i)
- supported_api_levels.insert(lexical_cast<unsigned>(i->substr(8)));
+ for(const string &p: list_filtered(platforms_dir, "^android-[1-9][0-9]*$"))
+ supported_api_levels.insert(lexical_cast<unsigned>(p.substr(8)));
}
void AndroidDevKit::select_api_level(unsigned api)
}
builder.get_logger().log("files", format("Traversing %s", bt_dir.str()));
- vector<string> tool_versions = list_files(bt_dir);
-
string use_tools;
unsigned latest_version = 0;
- for(vector<string>::const_iterator i=tool_versions.begin(); i!=tool_versions.end(); ++i)
+ for(const string &v: list_files(bt_dir))
{
- unsigned version = parse_version(*i);
+ unsigned version = parse_version(v);
if(version>latest_version)
{
- use_tools = *i;
+ use_tools = v;
latest_version = version;
}
}
builder.get_logger().log("files", format("Traversing %s", toolchains_dir.str()));
string prefix = architecture.get_cross_prefix()+"-";
- vector<string> toolchains = list_filtered(toolchains_dir, "^"+prefix);
-
string use_toolchain;
unsigned latest_version = 0;
- for(vector<string>::const_iterator i=toolchains.begin(); i!=toolchains.end(); ++i)
+ for(const string &t: list_filtered(toolchains_dir, "^"+prefix))
{
- string version_str = i->substr(prefix.size());
+ string version_str = t.substr(prefix.size());
string compiler = "gcc";
if(!isdigit(version_str[0]))
{
unsigned version = parse_version(version_str);
if(version>latest_version)
{
- use_toolchain = *i;
+ use_toolchain = t;
latest_version = version;
}
}
FS::Path platform_archs_dir = root/"platforms"/format("android-%d", api);
builder.get_logger().log("files", format("Traversing %s", platform_archs_dir.str()));
vector<string> platform_archs = list_filtered(platform_archs_dir, "^arch-");
- for(vector<string>::iterator i=platform_archs.begin(); i!=platform_archs.end(); ++i)
- i->erase(0, 5);
+ for(string &a: platform_archs)
+ a.erase(0, 5);
string use_arch = architecture.best_match(platform_archs);
if(use_arch.empty())
const set<unsigned> &sdk_api_levels = sdk.get_supported_api_levels();
const set<unsigned> &ndk_api_levels = ndk.get_supported_api_levels();
unsigned highest_common = 0;
- for(set<unsigned>::const_reverse_iterator i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i)
+ for(auto i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i)
if(ndk_api_levels.count(*i))
highest_common = *i;
{
AndroidResourceBundle *resource_bundle = 0;
list<FileTarget *> other_files;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(*i))
+ if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(s))
resource_bundle = r;
- else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
+ else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
other_files.push_back(f);
}
AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files);
argv.push_back(executable->get_path().str());
argv.push_back("u");
- const Target::Dependencies &depends = apk.get_dependencies();
FS::Path input_path;
list<FS::Path> files;
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: apk.get_dependencies())
{
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
- Target *real = (*i)->get_real_target();
+ FileTarget *file = dynamic_cast<FileTarget *>(d);
+ Target *real = d->get_real_target();
if(dynamic_cast<AndroidResourceBundle *>(real))
input_path = file->get_path();
FS::Path work_dir = FS::dirname(input_path);
- for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
- argv.push_back(FS::relative(*i, work_dir).str());
+ for(const FS::Path &f: files)
+ argv.push_back(FS::relative(f, work_dir).str());
ExternalTask *task = new ExternalTask(argv, work_dir);
task->set_stdin(FS::basename(input_path));
bool negate = (pattern[0]=='!');
vector<string> parts = split(pattern.substr(negate), "-");
resolve_aliases(parts);
- for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ for(const string &p: parts)
{
- if((*i=="32" && bits==32) || (*i=="64" && bits==64))
+ if((p=="32" && bits==32) || (p=="64" && bits==64))
;
- else if(*i!=type && *i!=cpu && *i!=fpu && *i!=system && *i!=toolchain)
+ else if(p!=type && p!=cpu && p!=fpu && p!=system && p!=toolchain)
return negate;
}
return !negate;
{
string best;
unsigned best_size = 0;
- for(vector<string>::const_iterator i=names.begin(); i!=names.end(); ++i)
- if(match_name(*i))
+ for(const string &n: names)
+ if(match_name(n))
{
/* TODO Do full parse and alias resolution here? Otherwise x86 and
x86_64 are treated as equally good, even though the latter is more
specific. */
unsigned size = 1;
- for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
- size += (*j=='-');
+ for(char c: n)
+ size += (c=='-');
if(size>best_size)
{
- best = *i;
+ best = n;
best_size = size;
}
}
{
vector<string> parts = split(spec, "-");
resolve_aliases(parts);
- for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ for(const string &p: parts)
{
bool ok = false;
for(unsigned j=0; (!ok && types[j]); ++j)
- if(*i==types[j])
+ if(p==types[j])
{
- if(!type.empty() && *i!=type)
+ if(!type.empty() && p!=type)
throw invalid_argument("Conflicting type specification");
- type = *i;
+ type = p;
ok = true;
}
for(unsigned j=0; (!ok && cpus[j]); j+=2)
- if(*i==cpus[j])
+ if(p==cpus[j])
{
if(type.empty())
type = cpus[j+1];
else if(cpus[j+1]!=type)
throw invalid_argument("Conflicting CPU specification");
- cpu = *i;
+ cpu = p;
ok = true;
}
for(unsigned j=0; (!ok && fpus[j]); j+=2)
- if(*i==fpus[j])
+ if(p==fpus[j])
{
if(fpus[j+1]!=type)
throw invalid_argument("Conflicting FPU specification");
- fpu = *i;
+ fpu = p;
ok = true;
}
for(unsigned j=0; (!ok && systems[j]); ++j)
- if(*i==systems[j])
+ if(p==systems[j])
{
- system = *i;
+ system = p;
ok = true;
}
for(unsigned j=0; (!ok && toolchains[j]); ++j)
- if(*i==toolchains[j])
+ if(p==toolchains[j])
{
- toolchain = *i;
+ toolchain = p;
ok = true;
}
- if(!ok && (*i=="32" || *i=="64"))
+ if(!ok && (p=="32" || p=="64"))
{
- bits = lexical_cast<unsigned>(*i);
+ bits = lexical_cast<unsigned>(p);
ok = true;
}
if(!ok)
- throw invalid_argument("Unrecognized part in arch specification: "+*i);
+ throw invalid_argument("Unrecognized part in arch specification: "+p);
}
}
+#include <algorithm>
#include <msp/fs/utils.h>
#include <msp/strings/format.h>
#include <msp/strings/utils.h>
objects(objs)
{
component = &c;
- for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
- add_dependency(**i);
+ for(ObjectFile *o: objects)
+ add_dependency(*o);
nested_build_sig = true;
arch_in_build_sig = true;
void Binary::collect_build_info(BuildInfo &binfo) const
{
- for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
- if(const Tool *obj_tool = (*i)->get_tool())
+ for(ObjectFile *o: objects)
+ if(const Tool *obj_tool = o->get_tool())
binfo.update_from(obj_tool->get_build_info());
Target::collect_build_info(binfo);
list<Target *> dep_libs;
set<string> missing_libs;
queue.push_back(this);
- for(list<Target *>::iterator j=queue.begin(); j!=queue.end(); ++j)
+ for(auto j=queue.begin(); j!=queue.end(); ++j)
{
Target *tgt = *j;
static_binfo.threads = true;
}
- list<Target *>::iterator insert_pos = j;
+ auto insert_pos = j;
++insert_pos;
- for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
+ for(const string &l: binfo.libs)
{
- if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
+ if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework"))
continue;
- BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
- Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
+ BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(l);
+ Target *lib = builder.get_vfs().find_library(l, binfo.libpath, libmode);
if(lib)
{
Target *real = lib->get_real_target();
else
dep_libs.push_back(lib);
}
- else if(missing_libs.insert(*i).second)
- problems.push_back(format("Required library %s not found", *i));
+ else if(missing_libs.insert(l).second)
+ problems.push_back(format("Required library %s not found", l));
}
}
/* Add only the last occurrence of each library to the actual dependencies.
This ensures that static library ordering is correct. */
- for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
- {
- bool last = true;
- for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
- last = (j==i || *j!=*i);
- if(last)
+ for(auto i=dep_libs.begin(); i!=dep_libs.end(); ++i)
+ if(!any_of(next(i), dep_libs.end(), [i](Target *d){ return d==*i; }))
add_dependency(**i);
- }
}
{
Component::create_build_info();
- for(UseList::const_iterator i=uses.begin(); i!=uses.end(); ++i)
+ for(const Component *u: uses)
{
/* Select an include path that contains all the sources for this and the
used component. This should produce a sensible result in most cases. */
FS::Path base;
- for(SourceList::const_iterator j=sources.begin(); j!=sources.end(); ++j)
- base = base.empty() ? *j : FS::common_ancestor(base, *j);
- const SourceList &use_sources = (*i)->get_sources();
- for(SourceList::const_iterator j=use_sources.begin(); j!=use_sources.end(); ++j)
- base = FS::common_ancestor(base, *j);
+ for(const FS::Path &s: sources)
+ base = base.empty() ? s : FS::common_ancestor(base, s);
+ for(const FS::Path &s: u->get_sources())
+ base = FS::common_ancestor(base, s);
build_info.incpath.push_back(base);
- build_info.libs.push_back((*i)->get_name());
- if(!(*i)->get_install())
+ build_info.libs.push_back(u->get_name());
+ if(!u->get_install())
{
- build_info.libmodes[(*i)->get_name()] = BuildInfo::STATIC;
- build_info.libpath.push_back((*i)->get_package().get_output_directory());
+ build_info.libmodes[u->get_name()] = BuildInfo::STATIC;
+ build_info.libpath.push_back(u->get_package().get_output_directory());
}
}
list<Target *> objs;
SourceList source_filenames = collect_source_files();
- for(SourceList::iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ for(auto i=source_filenames.begin(); i!=source_filenames.end(); ++i)
{
string ext = FS::extpart(FS::basename(*i));
Target *src = 0;
if(dynamic_cast<FileTarget *>(src)->is_installable())
build_graph.add_installed_target(*src);
- const Target::Dependencies &side_effects = src->get_side_effects();
- for(Target::Dependencies::const_iterator j=side_effects.begin(); j!=side_effects.end(); ++j)
- if(dynamic_cast<FileTarget *>(*j)->is_installable())
- build_graph.add_installed_target(**j);
+ for(Target *s: src->get_side_effects())
+ if(dynamic_cast<FileTarget *>(s)->is_installable())
+ build_graph.add_installed_target(*s);
}
}
}
else
results.push_back(linker.create_target(objs));
- for(list<Target *>::const_iterator i=results.begin(); i!=results.end(); ++i)
+ for(Target *r: results)
{
- build_graph.add_primary_target(**i);
+ build_graph.add_primary_target(*r);
if(install)
- build_graph.add_installed_target(**i);
+ build_graph.add_installed_target(*r);
}
}
process_flags(flags, pkg->export_binfo);
Flags exclusive_static_flags;
- for(Flags::const_iterator i=static_flags.begin(); i!=static_flags.end(); ++i)
- if(find(flags.begin(), flags.end(), *i)==flags.end())
- exclusive_static_flags.push_back(*i);
+ for(const string &f: static_flags)
+ if(find(flags.begin(), flags.end(), f)==flags.end())
+ exclusive_static_flags.push_back(f);
process_flags(exclusive_static_flags, pkg->static_binfo);
return pkg;
void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo)
{
- for(Flags::const_iterator i=flags.begin(); i!=flags.end(); ++i)
+ for(const string &f: flags)
{
- if(!i->compare(0, 2, "-I"))
- binfo.incpath.push_back(i->substr(2));
- else if(!i->compare(0, 2, "-D"))
+ if(!f.compare(0, 2, "-I"))
+ binfo.incpath.push_back(f.substr(2));
+ else if(!f.compare(0, 2, "-D"))
{
- string::size_type equals = i->find('=');
+ string::size_type equals = f.find('=');
if(equals!=string::npos)
- binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
+ binfo.defines[f.substr(2, equals-2)] = f.substr(equals+1);
else
- binfo.defines[i->substr(2)] = string();
+ binfo.defines[f.substr(2)] = string();
}
- else if(!i->compare(0, 2, "-L"))
- binfo.libpath.push_back(i->substr(2));
- else if(!i->compare(0, 2, "-l"))
- binfo.libs.push_back(i->substr(2));
- else if(*i=="-pthread")
+ else if(!f.compare(0, 2, "-L"))
+ binfo.libpath.push_back(f.substr(2));
+ else if(!f.compare(0, 2, "-l"))
+ binfo.libs.push_back(f.substr(2));
+ else if(f=="-pthread")
binfo.threads = true;
}
}
void BinaryPackage::do_prepare()
{
- bool has_relative_paths = false;
- for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i)
- has_relative_paths = !i->is_absolute();
- for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i)
- has_relative_paths = !i->is_absolute();
+ auto is_relative = [](const FS::Path &p){ return !p.is_absolute(); };
+ bool has_relative_paths = any_of(export_binfo.libpath.begin(), export_binfo.libpath.end(), is_relative) ||
+ any_of(export_binfo.incpath.begin(), export_binfo.incpath.end(), is_relative);
list<FS::Path> bases;
bases.push_back(FS::Path());
bool system = false;
- for(list<FS::Path>::const_iterator i=bases.begin(); i!=bases.end(); ++i)
+ for(const FS::Path &b: bases)
{
- FS::Path prefix = *i;
+ FS::Path prefix = b;
system = prefix.empty();
if(system)
{
BuildInfo::PathList libpath = export_binfo.libpath;
if(!system && libpath.empty())
libpath.push_back("lib");
- for(BuildInfo::PathList::iterator j=libpath.begin(); j!=libpath.end(); ++j)
- *j = prefix/ *j;
+ for(FS::Path &p: libpath)
+ p = prefix/p;
bool all_found = true;
- for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j)
- all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0);
+ for(const string &l: export_binfo.libs)
+ all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0);
BuildInfo::PathList incpath = export_binfo.incpath;
if(!system && incpath.empty())
incpath.push_back("include");
- for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j)
- *j = prefix/ *j;
+ for(FS::Path &p: incpath)
+ p = prefix/p;
- for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j)
- all_found &= (builder.get_vfs().find_header(*j, 0, incpath, system)!=0);
+ for(const string &h: headers)
+ all_found &= (builder.get_vfs().find_header(h, 0, incpath, system)!=0);
if(all_found)
{
if(has_relative_paths)
{
- for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
- *i = base_path/ *i;
- for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
- *i = base_path/ *i;
+ for(FS::Path &p: export_binfo.incpath)
+ p = base_path/p;
+ for(FS::Path &p: export_binfo.libpath)
+ p = base_path/p;
}
if(!static_binfo.libs.empty())
BuildInfo::PathList combined_libpath = static_binfo.libpath;
combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end());
- for(BuildInfo::WordList::const_iterator i=export_binfo.libs.begin(); i!=export_binfo.libs.end(); ++i)
- if(Target *lib = builder.get_vfs().find_library(*i, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
+ for(const string &l: export_binfo.libs)
+ if(Target *lib = builder.get_vfs().find_library(l, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
{
- for(BuildInfo::WordList::const_iterator j=static_binfo.libs.begin(); j!=static_binfo.libs.end(); ++j)
- stlib->add_required_library(*j);
- for(BuildInfo::PathList::const_iterator j=combined_libpath.begin(); j!=combined_libpath.end(); ++j)
- stlib->add_library_path(*j);
+ for(const string &s: static_binfo.libs)
+ stlib->add_required_library(s);
+ for(const FS::Path &p: combined_libpath)
+ stlib->add_library_path(p);
}
}
}
{
string buf;
last_was_op = true;
- for(string::const_iterator i=str.begin();; ++i)
+ for(auto i=str.begin();; ++i)
{
if(i!=str.end() && (isalnum(*i) || (!buf.empty() && (*i=='_' || *i=='-'))))
buf += *i;
{
vector<string> keys;
keys.reserve(build_types.size());
- for(BuildTypeMap::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
- keys.push_back(i->first);
+ for(const auto &kvp: build_types)
+ keys.push_back(kvp.first);
return keys;
}
set<const Component *> broken_components;
set<const Tool *> broken_tools;
- const BuildGraph::TargetMap &targets = build_graph.get_targets();
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->is_broken())
+ for(const auto &kvp: build_graph.get_targets())
+ if(kvp.second->is_broken())
{
- const list<string> &tgt_problems = i->second->get_problems();
- for(list<string>::const_iterator j=tgt_problems.begin(); j!=tgt_problems.end(); ++j)
- problems.push_back(format("%s: %s", i->second->get_name(), *j));
+ for(const string &p: kvp.second->get_problems())
+ problems.push_back(format("%s: %s", kvp.second->get_name(), p));
- const Package *package = i->second->get_package();
+ const Package *package = kvp.second->get_package();
if(package && !package->get_problems().empty())
broken_packages.insert(package);
- const Component *component = i->second->get_component();
+ const Component *component = kvp.second->get_component();
if(component && !component->get_problems().empty())
broken_components.insert(component);
- const Tool *tool = i->second->get_tool();
+ const Tool *tool = kvp.second->get_tool();
if(tool && !tool->get_problems().empty())
broken_tools.insert(tool);
}
// TODO Sort components after their packages, and targets last
- for(set<const Package *>::const_iterator i=broken_packages.begin(); i!=broken_packages.end(); ++i)
- {
- const list<string> &pkg_problems = (*i)->get_problems();
- for(list<string>::const_iterator j=pkg_problems.begin(); j!=pkg_problems.end(); ++j)
- problems.push_back(format("%s: %s", (*i)->get_name(), *j));
- }
+ for(const Package *p: broken_packages)
+ for(const string &b: p->get_problems())
+ problems.push_back(format("%s: %s", p->get_name(), b));
- for(set<const Component *>::const_iterator i=broken_components.begin(); i!=broken_components.end(); ++i)
- {
- const list<string> &comp_problems = (*i)->get_problems();
- for(list<string>::const_iterator j=comp_problems.begin(); j!=comp_problems.end(); ++j)
- problems.push_back(format("%s/%s: %s", (*i)->get_package().get_name(), (*i)->get_name(), *j));
- }
+ for(const Component *c: broken_components)
+ for(const string &b: c->get_problems())
+ problems.push_back(format("%s/%s: %s", c->get_package().get_name(), c->get_name(), b));
- for(set<const Tool *>::const_iterator i=broken_tools.begin(); i!=broken_tools.end(); ++i)
- {
- const list<string> &tool_problems = (*i)->get_problems();
- for(list<string>::const_iterator j=tool_problems.begin(); j!=tool_problems.end(); ++j)
- problems.push_back(format("%s: %s", (*i)->get_tag(), *j));
- }
+ for(const Tool *t: broken_tools)
+ for(const string &b: t->get_problems())
+ problems.push_back(format("%s: %s", t->get_tag(), b));
return problems;
}
void Builder::save_caches()
{
- const PackageManager::PackageMap &packages = package_manager.get_packages();
- for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
- i->second->save_caches();
+ for(const auto &kvp: package_manager.get_packages())
+ kvp.second->save_caches();
}
int Builder::build(unsigned jobs, bool dry_run, bool show_progress)
if(tgt->is_buildable() && (tgt->get_package()==&package_manager.get_main_package() || all))
clean_tgts.insert(tgt);
- const Target::Dependencies &deps = tgt->get_dependencies();
- for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(!clean_tgts.count(*i))
- queue.push_back(*i);
+ for(Target *t: tgt->get_dependencies())
+ if(!clean_tgts.count(t))
+ queue.push_back(t);
}
- for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
+ for(Target *t: clean_tgts)
{
- get_logger().log("tasks", format("RM %s", (*i)->get_name()));
+ get_logger().log("tasks", format("RM %s", t->get_name()));
if(!dry_run)
- (*i)->clean();
+ t->clean();
}
return 0;
logger.enable_channel("files");
logger.enable_channel("auxcommands");
}
- for(list<string>::const_iterator i=log_channels.begin(); i!=log_channels.end(); ++i)
- {
- vector<string> parts = split(*i, ',');
- for(vector<string>::const_iterator j=parts.begin(); j!=parts.end(); ++j)
- logger.enable_channel(*j);
- }
+ for(const string &c: log_channels)
+ for(const string &p: split(c, ','))
+ logger.enable_channel(p);
builder.set_logger(&logger);
if(!analyze_mode.empty())
else if(!clean && !create_makefile)
build = true;
- for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); )
+ for(auto i=cmdline_targets.begin(); i!=cmdline_targets.end(); )
{
string::size_type equal = i->find('=');
if(equal!=string::npos)
list<FS::Path> start_files;
start_files.push_back(FS::get_sys_data_dir()/"builderrc");
start_files.push_back(FS::get_user_data_dir()/"rc");
- for(list<FS::Path>::const_iterator i=start_files.begin(); i!=start_files.end(); ++i)
- if(FS::exists(*i))
- builder.load_build_file(*i);
+ for(const FS::Path &f: start_files)
+ if(FS::exists(f))
+ builder.load_build_file(f);
if(!prefix.empty())
builder.set_prefix(cwd/prefix);
builder.add_default_tools();
const Toolchain &toolchain = builder.get_toolchain();
- for(Config::InputOptions::iterator i=cmdline_options.begin(); i!=cmdline_options.end(); )
+ for(auto i=cmdline_options.begin(); i!=cmdline_options.end(); )
{
if(toolchain.has_tool(i->first))
{
BuildGraph &build_graph = builder.get_build_graph();
PackageManager &package_manager = builder.get_package_manager();
- const PackageManager::PackageMap &packages = package_manager.get_packages();
list<string> package_details;
- for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+ for(const auto &kvp: package_manager.get_packages())
{
- if(!i->second->is_prepared())
+ if(!kvp.second->is_prepared())
continue;
- string line = i->second->get_name();
- if(dynamic_cast<SourcePackage *>(i->second))
+ string line = kvp.second->get_name();
+ if(dynamic_cast<SourcePackage *>(kvp.second))
{
line += '*';
unsigned count = 0;
unsigned to_be_built = 0;
- const BuildGraph::TargetMap &targets = build_graph.get_targets();
- for(BuildGraph::TargetMap::const_iterator j=targets.begin(); j!=targets.end(); ++j)
- if(j->second->get_package()==i->second)
+ for(const auto &kvp2: build_graph.get_targets())
+ if(kvp2.second->get_package()==kvp.second)
{
++count;
- if(j->second->needs_rebuild())
+ if(kvp2.second->needs_rebuild())
++to_be_built;
}
if(count)
}
logger.log("summary", format("%d active packages, %d targets", package_details.size(), build_graph.get_targets().size()));
- for(list<string>::const_iterator i=package_details.begin(); i!=package_details.end(); ++i)
- logger.log("packages", *i);
+ for(const string &d: package_details)
+ logger.log("packages", d);
if(analyzer)
analyzer->analyze();
{
list<string> problems = builder.collect_problems();
IO::print(IO::cerr, "The following problems were detected:\n");
- for(list<string>::const_iterator i=problems.begin(); i!=problems.end(); ++i)
- IO::print(IO::cerr, " %s\n", *i);
+ for(const string &p: problems)
+ IO::print(IO::cerr, " %s\n", p);
if(!analyzer)
IO::print(IO::cerr, "Please fix them and try again.\n");
return 1;
package_manager.get_main_package().prepare();
// Add targets from command line as goals
- for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
+ for(const string &t: cmdline_targets)
{
- Target *tgt = resolve_target(*i);
+ Target *tgt = resolve_target(t);
if(!tgt)
{
- IO::print("I don't know anything about %s\n", *i);
+ IO::print("I don't know anything about %s\n", t);
return false;
}
build_graph.prepare();
// Apply what-ifs
- for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
+ for(const string &w: what_if)
{
- FileTarget *tgt = dynamic_cast<FileTarget *>(resolve_target(*i));
+ FileTarget *tgt = dynamic_cast<FileTarget *>(resolve_target(w));
if(!tgt)
{
- IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
+ IO::print(IO::cerr, "Unknown what-if target %s\n", w);
return false;
}
tgt->touch();
if(!requires.empty())
{
IO::print("\nRequired packages:\n ");
- for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
+ for(auto i=requires.begin(); i!=requires.end(); ++i)
{
if(i!=requires.begin())
IO::print(", ");
if(!options.empty())
{
IO::print("\nPackage configuration:\n");
- for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
+ for(const auto &kvp: options)
{
- const Config::Option &opt = i->second;
+ const Config::Option &opt = kvp.second;
string line = format(" %s: %s (%s)", opt.name, opt.description, opt.value);
if(!opt.choices.empty())
{
line += " {";
- for(list<string>::const_iterator j=opt.choices.begin(); j!=opt.choices.end(); ++j)
- {
- if(j!=opt.choices.begin())
- line += ' ';
- line += *j;
- }
+ line += join(opt.choices.begin(), opt.choices.end(), " ");
line += '}';
}
else if(opt.value!=opt.default_value)
BuildGraph::~BuildGraph()
{
- for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
- delete i->second;
+ for(const auto &kvp: targets)
+ delete kvp.second;
}
Target *BuildGraph::get_target(const string &n) const
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();
+ for(const auto &kvp: targets)
+ if(kvp.second->is_buildable() && !kvp.second->needs_rebuild())
+ kvp.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())
+ for(const auto &kvp: targets)
+ if(kvp.second->is_buildable() && kvp.second->needs_rebuild())
++count;
return count;
}
-#include <algorithm>
#include <set>
+#include <msp/core/algorithm.h>
#include <msp/strings/format.h>
#include "buildinfo.h"
void unique(list<T> &l)
{
set<T> seen;
- for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
+ for(auto i=l.begin(); i!=l.end(); )
{
if(seen.count(*i))
l.erase(i++);
void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
{
- for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
- defines[i->first] = i->second;
+ for(const auto &kvp: bi.defines)
+ defines[kvp.first] = kvp.second;
incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end());
threads = bi.threads;
- for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i)
+ for(const auto &kvp: bi.standards)
{
- StandardMap::iterator j = standards.find(i->first);
+ StandardMap::iterator j = standards.find(kvp.first);
if(j==standards.end())
- standards.insert(*i);
- else if(i->second.type!=j->second.type || i->second.year!=j->second.year)
+ standards.insert(kvp);
+ else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year)
{
- if(!i->second.type.compare(0, 3, "gnu"))
- j->second.type = i->second.type;
- if(i->second.year>j->second.year)
- j->second.year = i->second.year;
+ if(!kvp.second.type.compare(0, 3, "gnu"))
+ j->second.type = kvp.second.type;
+ if(kvp.second.year>j->second.year)
+ j->second.year = kvp.second.year;
}
}
local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
libmode = bi.libmode;
rpath_mode = bi.rpath_mode;
- for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
- libmodes[i->first] = i->second;
+ for(const auto &kvp: bi.libmodes)
+ libmodes[kvp.first] = kvp.second;
keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
debug = bi.debug;
optimize = bi.optimize;
BuildInfo::LanguageStandard::LanguageStandard(const string &std)
{
- string::size_type num = string::npos;
- for(string::size_type i=0; (num==string::npos && i<std.size()); ++i)
- if(isdigit(static_cast<unsigned char>(std[i])))
- num = i;
+ auto i = find_if(std, [](char c){ return isdigit(static_cast<unsigned char>(c)); });
+ string::size_type num = i-std.begin();
type = std.substr(0, num);
year = lexical_cast<unsigned>(std.substr(num));
year += (year<70 ? 2000 : 1900);
package.get_builder().get_logger().log("files", format("Writing %s", filename));
IO::BufferedFile out(filename.str(), IO::M_WRITE);
- for(DataMap::const_iterator i=data.begin(); i!=data.end(); ++i)
+ for(const auto &kvp: data)
{
- write_string(out, i->first.first);
- write_string(out, i->first.second);
- write_count(out, i->second.size());
- for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- write_string(out, *j);
+ write_string(out, kvp.first.first);
+ write_string(out, kvp.first.second);
+ write_count(out, kvp.second.size());
+ for(const string &v: kvp.second)
+ write_string(out, v);
}
changed = false;
+#include <msp/strings/utils.h>
#include "chainedtask.h"
using namespace std;
+using namespace Msp;
ChainedTask::ChainedTask(Task *t):
current(0),
ChainedTask::~ChainedTask()
{
- for(vector<Task *>::iterator i=tasks.begin(); i!=tasks.end(); ++i)
- delete *i;
+ for(Task *t: tasks)
+ delete t;
}
void ChainedTask::add_task(Task *t)
string ChainedTask::get_command() const
{
string cmd;
- for(vector<Task *>::const_iterator i=tasks.begin(); i!=tasks.end(); ++i)
- {
- if(i!=tasks.begin())
- cmd += '\n';
- cmd += (*i)->get_command();
- }
+ for(Task *t: tasks)
+ append(cmd, "\n", t->get_command());
return cmd;
}
IO::print(out, "[");
bool first = true;
- const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->is_buildable() && i->second->get_package()==&spkg)
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(i->second))
+ for(const auto &kvp: builder.get_build_graph().get_targets())
+ if(kvp.second->is_buildable() && kvp.second->get_package()==&spkg)
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(kvp.second))
{
FS::Path src_path = obj->get_source().get_path();
- Task *task = i->second->build();
+ Task *task = kvp.second->build();
if(!first)
out.put(',');
IO::print(out, "\n\t{\n");
void CompileCommandsJson::find_dependencies()
{
- const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->is_buildable() && i->second->get_package()==package && dynamic_cast<ObjectFile *>(i->second))
- i->second->prepare();
+ for(const auto &kvp: builder.get_build_graph().get_targets())
+ if(kvp.second->is_buildable() && kvp.second->get_package()==package && dynamic_cast<ObjectFile *>(kvp.second))
+ kvp.second->prepare();
}
-#include <algorithm>
+#include <msp/core/algorithm.h>
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
void Component::prepare()
{
- for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
- (*i)->prepare();
+ for(Package *r: requires)
+ r->prepare();
}
void Component::create_build_info()
direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end());
Package::Requirements all_reqs = direct_reqs;
- for(Package::Requirements::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+ for(Package *r: all_reqs)
{
BuildInfo::UpdateLevel level = BuildInfo::CHAINED;
- if(find(direct_reqs.begin(), direct_reqs.end(), *i)!=direct_reqs.end())
+ if(find(direct_reqs.begin(), direct_reqs.end(), r)!=direct_reqs.end())
level = BuildInfo::DEPENDENCY;
- final_build_info.update_from((*i)->get_exported_build_info(), level);
+ final_build_info.update_from(r->get_exported_build_info(), level);
- const Package::Requirements &reqs = (*i)->get_required_packages();
- for(Package::Requirements::const_iterator j=reqs.begin(); j!=reqs.end(); ++j)
- if(find(all_reqs.begin(), all_reqs.end(), *j)==all_reqs.end())
- all_reqs.push_back(*j);
+ for(Package *q: r->get_required_packages())
+ if(find(all_reqs.begin(), all_reqs.end(), q)==all_reqs.end())
+ all_reqs.push_back(q);
}
final_build_info.update_from(package.get_build_info());
final_build_info.update_from(build_info);
build_info = final_build_info;
- for(BuildInfo::PathList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
- *i = (package.get_source_directory() / *i).str();
- for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
- *i = (package.get_source_directory() / *i).str();
+ for(FS::Path &p: build_info.incpath)
+ p = (package.get_source_directory()/p).str();
+ for(FS::Path &p: build_info.libpath)
+ p = (package.get_source_directory()/p).str();
}
BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
{
FS::Path dir = FS::dirname(path);
string last = FS::basename(dir);
- for(OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i)
- if(last==*i)
- {
- dir = FS::dirname(dir);
- break;
- }
+ if(any_equals(overlays, last))
+ dir = FS::dirname(dir);
- for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
- if(dir==*i)
- {
- binfo.local_incpath.push_back(dir);
- for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
- binfo.local_incpath.push_back(*i/ *j);
- }
+ if(any_equals(sources, dir))
+ {
+ binfo.local_incpath.push_back(dir);
+ for(const string &o: overlays)
+ binfo.local_incpath.push_back(dir/o);
+ }
}
return binfo;
}
Component::SourceList Component::collect_source_files() const
{
SourceList files;
- for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(const FS::Path &p: sources)
{
- FS::Path path(*i);
- if(FS::is_dir(path))
+ if(FS::is_dir(p))
{
SourceList dirs;
- dirs.push_back(path);
- for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+ dirs.push_back(p);
+ for(const string &o: overlays)
{
- FS::Path opath = path / *j;
+ FS::Path opath = p/o;
if(FS::is_dir(opath))
dirs.push_back(opath);
}
set<string> overlay_files;
- for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j)
+ for(auto j=dirs.begin(); j!=dirs.end(); ++j)
{
package.get_builder().get_logger().log("files", format("Traversing %s", *j));
- vector<string> sfiles = list_files(*j);
- for(vector<string>::iterator k=sfiles.begin(); k!=sfiles.end(); ++k)
+ for(const string &f: list_files(*j))
{
if(j!=dirs.begin())
{
- if(overlay_files.count(*k))
+ if(overlay_files.count(f))
continue;
- overlay_files.insert(*k);
+ overlay_files.insert(f);
}
- FS::Path fn = *j / *k;
+ FS::Path fn = *j/f;
if(!FS::is_dir(fn))
files.push_back(fn);
}
}
else
{
- files.push_back(path);
- for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+ files.push_back(p);
+ for(const string &o: overlays)
{
- FS::Path opath = FS::dirname(path)/ *j/FS::basename(path);
+ FS::Path opath = FS::dirname(p)/o/FS::basename(p);
if(FS::is_reg(opath))
files.push_back(opath);
}
package.get_builder().get_logger().log("files", format("Writing %s", fn));
IO::BufferedFile out(fn.str(), IO::M_WRITE);
- for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
- IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value);
+ for(const auto &kvp: options)
+ IO::print(out, "option \"%s\" \"%s\";\n", kvp.second.name, kvp.second.value);
changed = false;
}
Tool *compiler = builder.get_toolchain().get_tool_for_suffix(FS::extpart(FS::basename(path)), true);
if(compiler)
compiler->prepare();
- for(IncludeList::iterator i=includes.begin(); i!=includes.end(); ++i)
- {
- Target *hdr = builder.get_vfs().find_header(i->substr(1), compiler, ((*i)[0]=='"' ? local_incpath : incpath));
- if(hdr)
+ for(const string &i: includes)
+ if(Target *hdr = builder.get_vfs().find_header(i.substr(1), compiler, (i[0]=='"' ? local_incpath : incpath)))
add_transitive_dependency(*hdr);
- }
}
void CSourceFile::modified()
void DataCollection::find_dependencies()
{
source.prepare();
- const Target::Dependencies &tdeps = source.get_transitive_dependencies();
- for(Target::Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
- add_dependency(**i);
+ for(Target *d: source.get_transitive_dependencies())
+ add_dependency(*d);
}
files(f)
{
component = &c;
- for(list<FileTarget *>::const_iterator i=files.begin(); i!=files.end(); ++i)
- add_dependency(**i);
+ for(FileTarget *t: files)
+ add_dependency(*t);
install_location = Msp::FS::Path("share")/package->get_name();
}
Tool &dcomp = builder.get_toolchain().get_tool("DATA");
list<Target *> files;
- SourceList source_filenames = collect_source_files();
- for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ for(const FS::Path &s: collect_source_files())
{
- string ext = FS::extpart(FS::basename(*i));
+ string ext = FS::extpart(FS::basename(s));
if(ext==".mdt")
{
- Target *src = dcomp.create_source(*this, *i);
+ Target *src = dcomp.create_source(*this, s);
files.push_back(dcomp.create_target(*src, "collection"));
}
- else if(Target *tgt = builder.get_vfs().get_target(*i))
+ else if(Target *tgt = builder.get_vfs().get_target(s))
files.push_back(tgt);
else
- files.push_back(new DataSourceFile(builder, *this, *i));
+ files.push_back(new DataSourceFile(builder, *this, s));
}
Target *result = dcomp.create_target(files, "pack");
else if(arg=="pack")
{
list<FileTarget *> files;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
- files.push_back(&dynamic_cast<FileTarget &>(**i));
+ for(Target *t: sources)
+ files.push_back(&dynamic_cast<FileTarget &>(*t));
DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
pack->set_tool(*this);
return pack;
else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
{
argv.push_back("-p");
- const DataPack::FileList &files = pack->get_files();
- for(DataPack::FileList::const_iterator i=files.begin(); i!=files.end(); ++i)
- argv.push_back(FS::relative((*i)->get_path(), work_dir).str());
+ for(const FileTarget *f: pack->get_files())
+ argv.push_back(FS::relative(f->get_path(), work_dir).str());
}
return new ExternalTask(argv, work_dir);
dir_files = list_files(dir);
}
- for(DataFile::Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
+ for(const DataFile::Value &a: st.args)
{
- Regex re(i->get<string>());
- for(vector<string>::const_iterator j=dir_files.begin(); j!=dir_files.end(); ++j)
- if(re.match(*j))
- files.push_back(*j);
+ Regex re(a.get<string>());
+ for(const string &f: dir_files)
+ if(re.match(f))
+ files.push_back(f);
}
}
else if(st.keyword=="file" && st.args.size()==1)
cache.set_values(this, "files", files);
}
- for(list<string>::iterator i=files.begin(); i!=files.end(); ++i)
+ for(const string &f: files)
{
- FS::Path file_path = FS::dirname(path)/ *i;
+ FS::Path file_path = FS::dirname(path)/f;
if(Target *tgt = builder.get_vfs().get_target(file_path))
add_transitive_dependency(*tgt);
else
FileTarget(b, c.get_package(), generate_target_path(c))
{
component = &c;
- for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
- add_dependency(**i);
+ for(ObjectFile *o: objs)
+ add_dependency(*o);
}
FS::Path ExportDefinitions::generate_target_path(const Component &comp)
string ExternalTask::get_command() const
{
string cmd;
- for(vector<string>::const_iterator i=argv.begin(); i!=argv.end(); ++i)
+ for(const string &a: argv)
{
- if(i!=argv.begin())
+ if(!cmd.empty())
cmd += ' ';
- for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+ for(char c: a)
{
- if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&')
+ if(c=='"' || c=='\'' || c==' ' || c=='\\' || c=='&')
cmd += '\\';
- cmd += *j;
+ cmd += c;
}
}
+#include <msp/core/algorithm.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
#include <msp/strings/format.h>
mark_rebuild("Does not exist");
else
{
- for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
+ for(Target *d: depends)
{
- FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+ FileTarget *ft = dynamic_cast<FileTarget *>(d);
if(ft && ft->get_mtime()>mtime)
- mark_rebuild((*i)->get_name()+" has changed");
- else if((*i)->needs_rebuild())
- mark_rebuild((*i)->get_name()+" needs rebuilding");
+ mark_rebuild(d->get_name()+" has changed");
+ else if(d->needs_rebuild())
+ mark_rebuild(d->get_name()+" needs rebuilding");
+ if(needs_rebuild())
+ break;
}
}
if(!needs_rebuild())
{
// Some side effects might not exist
- for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i)
- if((*i)->needs_rebuild())
- mark_rebuild((*i)->get_name()+" needs rebuilding");
+ auto i = find_if(side_effects, [](const Target *s){ return s->needs_rebuild(); });
+ if(i!=side_effects.end())
+ mark_rebuild((*i)->get_name()+" needs rebuilding");
}
if(!needs_rebuild() && package)
if(nested_build_sig && component)
{
set<const Tool *> depend_tools;
- for(Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
- if((*i)->get_component()==component && (*i)->get_tool())
- depend_tools.insert((*i)->get_tool());
+ for(Target *d: depends)
+ if(d->get_component()==component && d->get_tool())
+ depend_tools.insert(d->get_tool());
- for(set<const Tool *>::const_iterator i=depend_tools.begin(); i!=depend_tools.end(); ++i)
- sigs.push_back((*i)->create_build_signature(binfo));
+ for(const Tool *t: depend_tools)
+ sigs.push_back(t->create_build_signature(binfo));
sigs.sort();
sigs.push_front(tool->create_build_signature(binfo));
}
throw invalid_argument("GnuArchiver::create_target");
list<ObjectFile *> objs;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
objs.push_back(obj);
else
throw invalid_argument("GnuArchiver::create_target");
argv.push_back(relative(lib.get_path(), work_dir).str());
- const Target::Dependencies &deps = lib.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ for(Target *d: lib.get_dependencies())
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
argv.push_back(relative(obj->get_path(), work_dir).str());
return new ExternalTask(argv, work_dir);
const FS::Path &sysroot = binfo.sysroot;
if(!sysroot.empty())
argv.push_back("--sysroot="+sysroot.str());
- for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i)
+ for(const FS::Path &p: binfo.local_incpath)
{
argv.push_back("-iquote");
- argv.push_back(i->str());
+ argv.push_back(p.str());
}
- for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
- argv.push_back("-I"+i->str());
+ for(const FS::Path &p: binfo.incpath)
+ argv.push_back("-I"+p.str());
- for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+ for(const auto &kvp: binfo.defines)
{
- if(i->second.empty())
- argv.push_back(format("-D%s", i->first));
+ if(kvp.second.empty())
+ argv.push_back(format("-D%s", kvp.first));
else
- argv.push_back(format("-D%s=%s", i->first, i->second));
+ argv.push_back(format("-D%s=%s", kvp.first, kvp.second));
}
if(binfo.debug)
throw invalid_argument("GnuLinker::create_target");
list<ObjectFile *> objs;
Linker *linker = default_linker;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
{
objs.push_back(obj);
if(obj->get_tool()->get_tag()=="CXX")
argv.push_back("-Wl,-rpath-link,"+lib_dir.str());
}
- for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
- argv.push_back("-L"+i->str());
+ for(const FS::Path &p: binfo.libpath)
+ argv.push_back("-L"+p.str());
if(binfo.strip)
argv.push_back("-s");
if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
argv.push_back("-o");
argv.push_back(relative(bin.get_path(), work_dir).str());
- for(BuildInfo::WordList::const_iterator i=binfo.keep_symbols.begin(); i!=binfo.keep_symbols.end(); ++i)
- argv.push_back("-u"+*i);
+ for(const string &s: binfo.keep_symbols)
+ argv.push_back("-u"+s);
bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
- const Target::Dependencies &depends = target.get_dependencies();
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: target.get_dependencies())
{
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
- Target *tgt = (*i)->get_real_target();
+ FileTarget *file = dynamic_cast<FileTarget *>(d);
+ Target *tgt = d->get_real_target();
if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
argv.push_back(relative(obj->get_path(), work_dir).str());
}
}
- for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
- if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
+ for(const string &l: binfo.libs)
+ if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework"))
{
argv.push_back("-framework");
- argv.push_back(i->substr(0, i->size()-10));
+ argv.push_back(l.substr(0, l.size()-10));
}
if(static_link_ok)
#include "tool.h"
using namespace std;
+using namespace Msp;
InstallComponent::InstallComponent(SourcePackage &p, const string &n):
Component(p, n)
Target *inst = builder.get_build_graph().get_target("install");
Tool © = builder.get_toolchain().get_tool("CP");
- SourceList source_filenames = collect_source_files();
- for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ for(const FS::Path &s: collect_source_files())
{
- Target *tgt = builder.get_vfs().get_target(*i);
+ Target *tgt = builder.get_vfs().get_target(s);
if(!tgt)
- tgt = new File(builder, package, *i);
+ tgt = new File(builder, package, s);
inst->add_dependency(*copy.create_target(*tgt, name));
}
}
+#include <msp/core/algorithm.h>
#include <msp/fs/utils.h>
#include "component.h"
#include "filetarget.h"
if(comp && !comp->get_overlays().empty())
{
// Check if the target resides in an overlay directory
- const Component::OverlayList &overlays = comp->get_overlays();
string last_dir = FS::basename(FS::dirname(target.get_path()));
- for(Component::OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i)
- if(last_dir==*i)
- overlay_depth = 1;
+ if(any_equals(comp->get_overlays(), last_dir))
+ overlay_depth = 1;
}
FS::Path source = target.get_path();
if(temp_depth>0)
{
// If it is, use the generating template's directory instead
- const Target::Dependencies &deps = target.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(*i))
+ for(Target *d: target.get_dependencies())
+ if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(d))
{
source = FS::dirname(tmpl->get_path())/FS::basename(source);
break;
/* Look for a mapping entry matching both the target's original location
and default install location */
FS::Path install = target.get_install_location();
- for(list<Entry>::const_iterator i=entries.begin(); i!=entries.end(); ++i)
+ for(const Entry &e: entries)
{
- int source_depth = FS::descendant_depth(source, i->source);
+ int source_depth = FS::descendant_depth(source, e.source);
if(source_depth>=0)
{
- FS::Path install_base = FS::common_ancestor(install, i->install);
+ FS::Path install_base = FS::common_ancestor(install, e.install);
if(install_base.size()>1)
{
- install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth);
+ install = e.install/source.subpath(e.source.size(), source_depth-1-overlay_depth);
break;
}
}
SharedLibrary &shlib = dynamic_cast<SharedLibrary &>(*sources.front());
list<ObjectFile *> objs;
- const Target::Dependencies &depends = shlib.get_dependencies();
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ for(Target *d: shlib.get_dependencies())
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
objs.push_back(obj);
ExportDefinitions *exp = new ExportDefinitions(builder, *shlib.get_component(), objs);
}
else
{
- const Target::Dependencies &depends = exp->get_dependencies();
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
- {
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ for(Target *d: exp->get_dependencies())
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
argv.push_back(relative(obj->get_path(), work_dir).str());
- }
// XXX Should use dllexport, but that has some other problems to solve
argv.push_back("--export-all-symbols");
throw invalid_argument("MsvcArchiver::create_target");
list<ObjectFile *> objs;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
objs.push_back(obj);
else
throw invalid_argument("MsvcArchiver::create_target");
argv.push_back("/OUT:"+relative(lib.get_path(), work_dir).str());
- const Target::Dependencies &deps = lib.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ for(Target *d: lib.get_dependencies())
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
argv.push_back(relative(obj->get_path(), work_dir).str());
return new ExternalTask(argv, work_dir);
system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"um");
string path;
- for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i)
+ for(const FS::Path &p: system_path)
{
- append(path, ";", i->str());
- builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i));
+ append(path, ";", p.str());
+ builder.get_logger().log("tools", format("Got %s system path: %s", tag, p));
}
setenv("INCLUDE", path);
else
argv.push_back("/w");
- for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i)
+ for(const FS::Path &p: binfo.local_incpath)
{
argv.push_back("/I");
- argv.push_back(i->str());
+ argv.push_back(p.str());
}
- for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
+ for(const FS::Path &p: binfo.incpath)
{
argv.push_back("/I");
- argv.push_back(i->str());
+ argv.push_back(p.str());
}
- for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+ for(const auto &kvp: binfo.defines)
{
argv.push_back("/D");
- if(i->second.empty())
- argv.push_back(i->first);
+ if(kvp.second.empty())
+ argv.push_back(kvp.first);
else
- argv.push_back(format("%s=%s", i->first, i->second));
+ argv.push_back(format("%s=%s", kvp.first, kvp.second));
}
if(binfo.debug)
throw invalid_argument("MsvcLinker::create_target");
list<ObjectFile *> objs;
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ for(Target *s: sources)
{
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
objs.push_back(obj);
else
throw invalid_argument("MsvcLinker::create_target");
system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"um"/arch_dir);
string path;
- for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i)
+ for(const FS::Path &p: system_path)
{
- append(path, ";", i->str());
- builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i));
+ append(path, ";", p.str());
+ builder.get_logger().log("tools", format("Got %s system path: %s", tag, p));
}
setenv("LIB", path);
BuildInfo binfo;
target.collect_build_info(binfo);
- /*for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
- argv.push_back("/LIBPATH:"+i->str());*/
+ /*for(const FS::Path &p: binfo.libpath)
+ argv.push_back("/LIBPATH:"+p.str());*/
if(binfo.strip)
argv.push_back("/INCREMENTAL:NO");
else
argv.push_back("/OUT:"+relative(bin.get_path(), work_dir).str());
- const Target::Dependencies &depends = target.get_dependencies();
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: target.get_dependencies())
{
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
- Target *tgt = (*i)->get_real_target();
+ FileTarget *file = dynamic_cast<FileTarget *>(d);
+ Target *tgt = d->get_real_target();
if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
argv.push_back(relative(obj->get_path(), work_dir).str());
-#include <algorithm>
+#include <msp/core/algorithm.h>
#include <msp/fs/utils.h>
#include "builder.h"
#include "component.h"
else
rel_src = FS::relative(src, pkg.get_source_directory());
string fn;
- for(FS::Path::Iterator i=rel_src.begin(); i!=rel_src.end(); ++i)
+ for(const string &c: rel_src)
{
if(!fn.empty())
fn += '_';
- if(*i!=".")
- fn += *i;
+ if(c!=".")
+ fn += c;
}
const Architecture &arch = comp.get_package().get_builder().get_current_arch();
return temp_dir/comp.get_name()/arch.create_filename<ObjectFile>(FS::basepart(fn));
void ObjectFile::find_dependencies()
{
- for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: depends)
{
- (*i)->prepare();
- find_dependencies(dynamic_cast<FileTarget *>(*i));
+ d->prepare();
+ find_dependencies(dynamic_cast<FileTarget *>(d));
}
}
/* The target has been displaced by installing it. Displace any
dependencies that come from the same package as well. */
const SourcePackage *tpkg = rtgt->get_package();
- for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
+ for(Target *d: tdeps)
{
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
+ FileTarget *file = dynamic_cast<FileTarget *>(d);
if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0)
{
const Component *tcomp = file->get_component();
deps_to_add.push_back(ddep);
else
{
- const Component::OverlayList &overlays = tcomp->get_overlays();
string last_dir = FS::basename(FS::dirname(displaced));
- for(Component::OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
- if(last_dir==*j)
- {
- displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
- if((ddep = builder.get_vfs().get_target(displaced)))
- deps_to_add.push_back(ddep);
- }
+ if(any_equals(tcomp->get_overlays(), last_dir))
+ {
+ displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
+ if((ddep = builder.get_vfs().get_target(displaced)))
+ deps_to_add.push_back(ddep);
+ }
}
}
else
- deps_to_add.push_back(*i);
+ deps_to_add.push_back(d);
}
}
- for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i)
- if(find(depends.begin(), depends.end(), *i)==depends.end())
+ for(Target *d: deps_to_add)
+ if(find(depends.begin(), depends.end(), d)==depends.end())
{
- add_dependency(**i);
- if((*i)->get_real_target()->is_buildable())
- (*i)->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
+ add_dependency(*d);
+ if(d->get_real_target()->is_buildable())
+ d->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
}
}
if(prepared)
return;
- for(Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
- (*i)->prepare();
+ for(Package *r: requires)
+ r->prepare();
do_prepare();
prepared = true;
#include <cstdlib>
+#include <msp/core/algorithm.h>
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
PackageManager::~PackageManager()
{
- for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
- delete i->second;
+ for(const auto &kvp: packages)
+ delete kvp.second;
}
void PackageManager::append_package_path(const FS::Path &p)
if(const char *pcp = getenv("PKG_CONFIG_PATH"))
{
vector<string> path = split(pcp, ':');
- bool found = false;
- for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
- found = (*i==pcdir.str());
- if(!found)
+ if(!any_equals(path, pcdir.str()))
{
path.push_back(pcdir.str());
setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
if(pkg_dirs.empty())
{
- for(SearchPath::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
+ for(const FS::Path &p: pkg_path)
{
- builder.get_logger().log("files", format("Traversing %s", *i));
- vector<string> files = list_files(*i);
+ builder.get_logger().log("files", format("Traversing %s", p));
unsigned count = 0;
- for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+ for(const string &f: list_files(p))
{
- FS::Path full = *i / *j;
+ FS::Path full = p/f;
if(FS::exists(full/"Build"))
{
pkg_dirs.push_back(full);
}
}
- builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, *i));
+ builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, p));
}
builder.get_logger().log("packagemgr", format("%d source packages found", pkg_dirs.size()));
}
bool msp = !name.compare(0, 3, "msp");
- for(SearchPath::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i)
+ for(const FS::Path &p: pkg_dirs)
{
- string base = FS::basename(*i);
+ string base = FS::basename(p);
unsigned dash = base.rfind('-');
if(!base.compare(0, dash, name))
- return *i;
+ return p;
else if(msp && !base.compare(0, dash, name, 3, string::npos))
- return *i;
+ return p;
}
return FS::Path();
if(binpkg_files.empty())
{
- for(list<FS::Path>::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i)
+ for(const FS::Path &p: binpkg_path)
{
- builder.get_logger().log("files", format("Traversing %s", *i));
- vector<string> files = list_filtered(*i, "\\.bpk$");
- for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
- binpkg_files.push_back(*i / *j);
- builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), *i));
+ builder.get_logger().log("files", format("Traversing %s", p));
+ vector<string> files = list_filtered(p, "\\.bpk$");
+ for(const string &f: files)
+ binpkg_files.push_back(p/f);
+ builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), p));
}
builder.get_logger().log("packagemgr", format("%d binary packages found", binpkg_files.size()));
}
- for(SearchPath::const_iterator i=binpkg_files.begin(); i!=binpkg_files.end(); ++i)
- {
- string base = FS::basepart(FS::basename(*i));
- if(base==name)
- return *i;
- }
+ auto i = find_if(binpkg_files, [&name](const FS::Path &p){ return FS::basepart(FS::basename(p))==name; });
+ if(i!=binpkg_files.end())
+ return *i;
return FS::Path();
}
void PackageManager::save_all_caches() const
{
- for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
- i->second->save_caches();
+ for(const auto &kvp: packages)
+ kvp.second->save_caches();
}
list<string> Pattern::apply_list(const list<Pattern> &patterns, const string &body)
{
list<string> result;
- for(list<Pattern>::const_iterator i=patterns.begin(); i!=patterns.end(); ++i)
- result.push_back(i->apply(body));
+ for(const Pattern &p: patterns)
+ result.push_back(p.apply(body));
return result;
}
IO::print(out, "Version: %s\n", spkg.get_version());
IO::print(out, "Requires:");
- const Package::Requirements &reqs = spkg.get_required_packages();
- for(Package::Requirements::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
- if((*i)->uses_pkgconfig())
- IO::print(out, " %s", (*i)->get_name());
+ for(const Package *r: spkg.get_required_packages())
+ if(r->uses_pkgconfig())
+ IO::print(out, " %s", r->get_name());
out.put('\n');
const BuildInfo &binfo = spkg.get_exported_build_info();
IO::print(out, "Libs:");
- for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
- IO::print(out, " -L%s", prefixify(*i, builder.get_prefix()));
- for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
- IO::print(out, " -l%s", *i);
+ for(const FS::Path &p: binfo.libpath)
+ IO::print(out, " -L%s", prefixify(p, builder.get_prefix()));
+ for(const string &l: binfo.libs)
+ IO::print(out, " -l%s", l);
if(binfo.threads)
out.write("-pthread");
out.put('\n');
IO::print(out, "Cflags:");
- for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
- IO::print(out, " -I%s", prefixify(*i, builder.get_prefix()));
- for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
- if(i->second.empty())
- IO::print(out, " -D%s", i->first);
+ for(const FS::Path &p: binfo.incpath)
+ IO::print(out, " -I%s", prefixify(p, builder.get_prefix()));
+ for(const auto &kvp: binfo.defines)
+ if(kvp.second.empty())
+ IO::print(out, " -D%s", kvp.first);
else
- IO::print(out, " -D%s=%s", i->first, i->second);
+ IO::print(out, " -D%s=%s", kvp.first, kvp.second);
out.put('\n');
status = Task::SUCCESS;
}
}
- for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
- (*i)->set_used_in_shared_library(true);
+ for(ObjectFile *o: objects)
+ o->set_used_in_shared_library(true);
}
string SharedLibrary::generate_filename(const Component &comp)
#include "tool.h"
using namespace std;
+using namespace Msp;
SourceArchiveComponent::SourceArchiveComponent(SourcePackage &p):
Component(p, p.get_name()+"-source")
list<Target *> files;
files.insert(files.begin(), &package.get_build_file());
- SourceList source_filenames = collect_source_files();
- for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ for(const FS::Path &s: collect_source_files())
{
- FileTarget *file = builder.get_vfs().get_target(*i);
+ FileTarget *file = builder.get_vfs().get_target(s);
if(!file)
- file = new File(builder, package, *i);
+ file = new File(builder, package, s);
files.push_back(file);
}
BuildGraph &build_graph = builder.get_build_graph();
- const BuildGraph::TargetMap &targets = build_graph.get_targets();
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->get_package()==&package && !i->second->is_buildable())
- if(find(files.begin(), files.end(), i->second)==files.end())
- files.push_back(i->second);
+ for(const auto &kvp: build_graph.get_targets())
+ if(kvp.second->get_package()==&package && !kvp.second->is_buildable())
+ if(find(files.begin(), files.end(), kvp.second)==files.end())
+ files.push_back(kvp.second);
const Toolchain &toolchain = builder.get_toolchain();
string archive_name = package.get_name();
}
Target *primary = 0;
- for(list<string>::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i)
+ for(const string &s: out_suffixes)
{
- Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true);
+ Tool *tool = builder.get_toolchain().get_tool_for_suffix(s, true);
if(tool)
{
- FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+*i);
+ FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+s);
Target *target = tool->create_source(*comp, fn);
target->set_tool(*this);
- for(list<Target *>::const_iterator j=sources.begin(); j!=sources.end(); ++j)
- target->add_dependency(**j);
+ for(Target *t: sources)
+ target->add_dependency(*t);
if(primary)
primary->add_side_effect(*target);
else
primary = target;
}
else
- throw runtime_error("No tool found for suffix "+*i);
+ throw runtime_error("No tool found for suffix "+s);
}
return primary;
args.push_back(executable->get_path().str());
args.insert(args.end(), arguments.begin(), arguments.end());
- const Target::Dependencies &deps = target.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(*i))
+ for(const Target *d: target.get_dependencies())
+ if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(d))
args.push_back(FS::relative(tmpl->get_path(), work_dir).str());
if(!out_argument.empty())
-#include <algorithm>
#include <cstdlib>
+#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
#include <msp/fs/utils.h>
#include <msp/io/print.h>
SourcePackage::~SourcePackage()
{
- for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
- delete *i;
+ for(Component *c: components)
+ delete c;
}
FS::Path SourcePackage::get_temp_directory() const
const Component &SourcePackage::get_component(const string &n) const
{
- for(ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i)
- if((*i)->get_name()==n)
- return **i;
+ auto i = find_if(components, [&n](const Component *c){ return c->get_name()==n; });
+ if(i!=components.end())
+ return **i;
throw key_error(n);
}
build_info.incpath.push_back((builder.get_prefix()/"include").str());
build_info.libpath.push_back((builder.get_prefix()/"lib").str());
- for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
+ for(const Feature &f: features)
{
- string ident = "WITH_"+toupper(i->name);
- string value = config.get_option("with_"+i->name).value;
+ string ident = "WITH_"+toupper(f.name);
+ string value = config.get_option("with_"+f.name).value;
- if(i->choices.empty())
+ if(f.choices.empty())
{
if(!lexical_cast<bool>(value))
continue;
}
build_info.defines[ident] = value;
- if(i->exported)
+ if(f.exported)
export_binfo.defines[ident] = value;
}
- for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
+ for(Component *c: components)
{
- (*i)->prepare();
- (*i)->create_build_info();
+ c->prepare();
+ c->create_build_info();
- (*i)->update_exported_build_info(export_binfo);
+ c->update_exported_build_info(export_binfo);
}
cache.load();
- for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
- (*i)->create_targets();
+ for(Component *c: components)
+ c->create_targets();
const Architecture &arch = builder.get_native_arch();
if(!export_binfo.libs.empty())
FileTarget(b, c.get_package(), c.get_package().get_output_directory()/generate_filename(c))
{
component = &c;
- for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
- add_dependency(**i);
+ for(ObjectFile *o: objs)
+ add_dependency(*o);
install_location = "lib";
nested_build_sig = true;
throw invalid_argument("Tar::create_target");
TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg);
- for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
- tarball->add_dependency(**i);
+ for(Target *s: sources)
+ tarball->add_dependency(*s);
tarball->set_tool(*this);
FS::Path basedir = FS::basepart(FS::basename(tarball.get_path()));
IO::File out(tarball.get_path().str(), IO::M_WRITE);
- const Target::Dependencies &deps = tarball.get_dependencies();
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+ for(Target *d: tarball.get_dependencies())
{
- FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+ FileTarget *ft = dynamic_cast<FileTarget *>(d);
if(!ft)
continue;
return 0;
bool self_ok = state!=BUILDING;
- for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: depends)
{
// Avoid infinite recursion if a target repends on its own side effect
- if(find(side_effects.begin(), side_effects.end(), *i)!=side_effects.end())
+ if(find(side_effects.begin(), side_effects.end(), d)!=side_effects.end())
continue;
- Target *tgt = (*i)->get_buildable_target();
+ Target *tgt = d->get_buildable_target();
if(tgt)
return tgt;
- else if((*i)->needs_rebuild())
+ else if(d->needs_rebuild())
self_ok = false;
}
void Target::set_tool(Tool &t)
{
tool = &t;
- for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
- (*i)->set_tool(t);
+ for(Target *s: side_effects)
+ s->set_tool(t);
}
void Target::collect_build_info(BuildInfo &binfo) const
broken |= (component && !component->get_problems().empty());
}
- for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+ for(Target *d: depends)
{
- (*i)->prepare();
- broken |= (*i)->is_broken();
+ d->prepare();
+ broken |= d->is_broken();
}
- for(Dependencies::iterator i=trans_depends.begin(); i!=trans_depends.end(); ++i)
- (*i)->prepare();
+ for(Target *d: trans_depends)
+ d->prepare();
check_rebuild();
if(broken)
else if(state==PREPARING)
state = UPTODATE;
- for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
- (*i)->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
+ for(Target *d: depends)
+ d->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
}
Task *Target::build()
state = BUILDING;
build(*task);
- for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
- (*i)->build(*task);
+ for(Target *s: side_effects)
+ s->build(*task);
return task;
}
if(success)
{
modified();
- for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
- (*i)->build_finished(success);
+ for(Target *s: side_effects)
+ s->build_finished(success);
signal_modified.emit();
}
}
void Task::prepare()
{
- for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
+ for(const FS::Path &f: files)
{
- if(FS::exists(*i))
+ if(FS::exists(f))
{
// If the file exists, the directory it's in must exist too
- FS::unlink(*i);
+ FS::unlink(f);
}
else
{
- FS::Path dir = FS::dirname(*i);
+ FS::Path dir = FS::dirname(f);
if(!FS::exists(dir))
FS::mkpath(dir, 0755);
}
+#include <algorithm>
#include <msp/core/maputils.h>
#include "tool.h"
#include "toolchain.h"
Toolchain::~Toolchain()
{
- for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i)
- delete i->second;
- for(ToolchainList::iterator i=chains.begin(); i!=chains.end(); ++i)
- delete *i;
+ for(const auto &kvp: tools)
+ delete kvp.second;
+ for(Toolchain *c: chains)
+ delete c;
}
void Toolchain::add_tool(Tool *tool)
{
if(tools.count(tag))
return true;
- for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
- if((*i)->has_tool(tag))
- return true;
- return false;
+ return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); });
}
Tool &Toolchain::get_tool(const string &tag) const
{
if(!tools.count(tag))
{
- for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
- if((*i)->has_tool(tag))
- return (*i)->get_tool(tag);
+ for(const Toolchain *c: chains)
+ if(c->has_tool(tag))
+ return c->get_tool(tag);
}
return *get_item(tools, tag);
Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const
{
- for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i)
- if(i->second->accepts_suffix(suffix, aux))
- return i->second;
+ for(const auto &kvp: tools)
+ if(kvp.second->accepts_suffix(suffix, aux))
+ return kvp.second;
- for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
- if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux))
+ for(const Toolchain *c: chains)
+ if(Tool *tool = c->get_tool_for_suffix(suffix, aux))
return tool;
return 0;
IO::print(out, "\t<ItemGroup Label=\"ProjectConfigurations\">\n");
vector<string> build_types = builder.get_build_types();
- const char *platforms[] = { "Win32", "x64", 0 };
- for(const char **i=platforms; *i; ++i)
- for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+ const char *platforms[] = { "Win32", "x64" };
+ for(const char *p: platforms)
+ for(const string &b: build_types)
{
- IO::print(out, "\t\t<ProjectConfiguration Include=\"%s|%s\">\n", *j, *i);
- IO::print(out, "\t\t\t<Configuration>%s</Configuration>\n", *j);
- IO::print(out, "\t\t\t<Platform>%s</Platform>\n", *i);
+ IO::print(out, "\t\t<ProjectConfiguration Include=\"%s|%s\">\n", b, p);
+ IO::print(out, "\t\t\t<Configuration>%s</Configuration>\n", b);
+ IO::print(out, "\t\t\t<Platform>%s</Platform>\n", p);
IO::print(out, "\t\t</ProjectConfiguration>\n");
}
IO::print(out, "\t</ItemGroup>\n");
IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n");
- const Target *world = builder.get_build_graph().get_target("world");
- const Target::Dependencies &world_deps = world->get_dependencies();
const Executable *exe = 0;
- for(Target::Dependencies::const_iterator i=world_deps.begin(); (!exe && i!=world_deps.end()); ++i)
- if((*i)->get_package()==&spkg)
- exe = dynamic_cast<const Executable *>(*i);
+ for(const Target *t: builder.get_build_graph().get_target("world")->get_dependencies())
+ if(t->get_package()==&spkg)
+ if((exe = dynamic_cast<const Executable *>(t)))
+ break;
const char *argv0 = Application::get_argv0();
const string &toolchain = builder.get_current_arch().get_toolchain();
- for(const char **i=platforms; *i; ++i)
- for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+ for(const char *p: platforms)
+ for(const string &b: build_types)
{
- string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, *i, toolchain, *j, builder.get_prefix());
- IO::print(out, "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='%s|%s'\" Label=\"Configuration\">\n", *j, *i);
+ string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, p, toolchain, b, builder.get_prefix());
+ IO::print(out, "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='%s|%s'\" Label=\"Configuration\">\n", b, p);
IO::print(out, "\t\t<ConfigurationType>MakeFile</ConfigurationType>\n");
IO::print(out, "\t\t<NMakeBuildCommandLine>%s</NMakeBuildCommandLine>\n", base_cmd);
IO::print(out, "\t\t<NMakeCleanCommandLine>%s -c</NMakeCleanCommandLine>\n", base_cmd);
IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n");
- const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
vector<const FileTarget *> sources;
vector<const FileTarget *> includes;
vector<const FileTarget *> others;
BuildInfo build_info;
- for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
- if(i->second->get_package()==&spkg)
+ for(const auto &kvp: builder.get_build_graph().get_targets())
+ if(kvp.second->get_package()==&spkg)
{
- if(i->second->is_buildable())
+ if(kvp.second->is_buildable())
{
BuildInfo tgt_binfo;
- i->second->collect_build_info(tgt_binfo);
+ kvp.second->collect_build_info(tgt_binfo);
build_info.update_from(tgt_binfo, BuildInfo::CHAINED);
}
- else if(const FileTarget *file = dynamic_cast<const FileTarget *>(i->second))
+ else if(const FileTarget *file = dynamic_cast<const FileTarget *>(kvp.second))
{
if(dynamic_cast<const CSourceFile *>(file))
{
{
IO::print(out, "\t<PropertyGroup>\n");
string path_str;
- for(BuildInfo::PathList::const_iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
- append(path_str, ";", i->str());
+ for(const FS::Path &p: build_info.incpath)
+ append(path_str, ";", p.str());
IO::print(out, "\t\t<NMakeIncludeSearchPath>%s</NMakeIncludeSearchPath>\n", path_str);
IO::print(out, "\t</PropertyGroup>\n");
}
IO::print(out, "\t<ItemGroup>\n");
- for(vector<const FileTarget *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
- IO::print(out, "\t\t<ClCompile Include=\"%s\" />\n", (*i)->get_path());
+ for(const FileTarget *s: sources)
+ IO::print(out, "\t\t<ClCompile Include=\"%s\" />\n", s->get_path());
IO::print(out, "\t</ItemGroup>\n");
IO::print(out, "\t<ItemGroup>\n");
- for(vector<const FileTarget *>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
- IO::print(out, "\t\t<ClInclude Include=\"%s\" />\n", (*i)->get_path());
+ for(const FileTarget *i: includes)
+ IO::print(out, "\t\t<ClInclude Include=\"%s\" />\n", i->get_path());
IO::print(out, "\t</ItemGroup>\n");
IO::print(out, "\t<ItemGroup>\n");
- for(vector<const FileTarget *>::const_iterator i=others.begin(); i!=others.end(); ++i)
- IO::print(out, "\t\t<None Include=\"%s\" />\n", (*i)->get_path());
+ for(const FileTarget *t: others)
+ IO::print(out, "\t\t<None Include=\"%s\" />\n", t->get_path());
IO::print(out, "\t</ItemGroup>\n");
IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n");
combined_path.insert(combined_path.end(), syspath.begin(), syspath.end());
}
- for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
+ for(const FS::Path &p: combined_path)
{
- FS::Path filename = *i/name;
+ FS::Path filename = p/name;
if(FileTarget *tgt = get_target(filename))
{
- builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, i->str(), tgt->get_type()));
+ builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, p.str(), tgt->get_type()));
return tgt;
}
else if(file_exists(filename))
{
- builder.get_logger().log("vfs", format("Header %s found in %s", name, i->str()));
+ builder.get_logger().log("vfs", format("Header %s found in %s", name, p.str()));
return dynamic_cast<FileTarget *>(tool->create_source(filename));
}
- builder.get_logger().log("vfs", format("Header %s not found in %s", name, i->str()));
+ builder.get_logger().log("vfs", format("Header %s not found in %s", name, p.str()));
}
return 0;
if(mode!=BuildInfo::FORCE_DYNAMIC)
static_names = Pattern::apply_list(arch.get_patterns<StaticLibrary>(), lib);
- for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
+ for(const FS::Path &p: combined_path)
{
const list<string> *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names);
- for(list<string>::const_iterator j=cur_names->begin(); j!=cur_names->end(); )
+ for(auto j=cur_names->begin(); j!=cur_names->end(); )
{
- FS::Path filename = *i / *j;
+ FS::Path filename = p / *j;
if(FileTarget *tgt = get_target(filename))
{
- builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type()));
+ builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, p.str(), tgt->get_type()));
return tgt;
}
else if(file_exists(filename))
{
- builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, i->str()));
+ builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, p.str()));
if(cur_names==&shared_names)
{
if(use_import_lib)
}
}
- builder.get_logger().log("vfs", format("Library %s not found in %s", lib, i->str()));
+ builder.get_logger().log("vfs", format("Library %s not found in %s", lib, p.str()));
}
return 0;
string env_path = Msp::getenv("PATH");
if(!env_path.empty())
{
- vector<string> parts = split(env_path, ':');
- for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
- path.push_back(*i);
+ for(const string &p: split(env_path, ':'))
+ path.push_back(p);
}
else
{
}
}
- for(SearchPath::const_iterator i=path.begin(); i!=path.end(); ++i)
+ for(const FS::Path &p: path)
{
- FS::Path filename = *i/name;
+ FS::Path filename = p/name;
if(FileTarget *tgt = get_target(filename))
{
- builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, *i, tgt->get_type()));
+ builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, p, tgt->get_type()));
return tgt;
}
else if(file_exists(filename))
{
- builder.get_logger().log("vfs", format("Binary %s found in %s", name, *i));
+ builder.get_logger().log("vfs", format("Binary %s found in %s", name, p));
return new Executable(builder, filename);
}
- builder.get_logger().log("vfs", format("Binary %s not found in %s", name, *i));
+ builder.get_logger().log("vfs", format("Binary %s not found in %s", name, p));
}
return 0;
+#include <msp/core/algorithm.h>
#include <msp/fs/path.h>
#include <msp/fs/utils.h>
#include "builder.h"
void VirtualTarget::check_rebuild()
{
// Virtual targets are only rebuilt if their dependencies need rebuilding.
- for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
- if((*i)->needs_rebuild())
- mark_rebuild((*i)->get_name()+" needs rebuilding");
+ auto i = find_if(depends, [](Target *d){ return d->needs_rebuild(); });
+ if(i!=depends.end())
+ mark_rebuild((*i)->get_name()+" needs rebuilding");
}
Task *VirtualTarget::build()
add_dependency(*project);
Package::Requirements reqs = package->get_required_packages();
- for(Package::Requirements::iterator i=reqs.begin(); i!=reqs.end(); ++i)
+ for(auto i=reqs.begin(); i!=reqs.end(); ++i)
if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(*i))
{
if(FileTarget *project = builder.get_vfs().get_target(spkg->get_source_directory()/(spkg->get_name()+".vcxproj")))
add_dependency(*project);
- const Package::Requirements &rreqs = spkg->get_required_packages();
- for(Package::Requirements::const_iterator j=rreqs.begin(); j!=rreqs.end(); ++j)
- if(find(reqs, *j)==reqs.end())
- reqs.push_back(*j);
+ for(Package *r: spkg->get_required_packages())
+ if(find(reqs, r)==reqs.end())
+ reqs.push_back(r);
}
}
void VsSolutionGenerator::Worker::main()
{
- Builder &builder = target.get_package()->get_builder();
+ const SourcePackage &spkg = *target.get_package();
+ Builder &builder = spkg.get_builder();
IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
- const Target::Dependencies &deps = target.get_dependencies();
vector<const VcxProjectFile *> projects;
- for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(*i))
+ for(const Target *t: target.get_dependencies())
+ if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
projects.push_back(project);
- for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
+ for(const VcxProjectFile *p: projects)
{
- const SourcePackage *pkg = (*i)->get_package();
+ const SourcePackage *pkg = p->get_package();
IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
- pkg->get_name(), (*i)->get_path(), (*i)->get_guid());
+ pkg->get_name(), p->get_path(), p->get_guid());
}
vector<string> build_types = builder.get_build_types();
- const char *platforms[] = { "x86", "x64", 0 };
+ const char *platforms[] = { "x86", "x64" };
IO::print(out, "Global\n");
IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
- for(vector<string>::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
- for(const char **j=platforms; *j; ++j)
- IO::print(out, "\t\t%s|%s = %s|%s\n", *i, *j, *i, *j);
+ for(const string &t: build_types)
+ for(const char *p: platforms)
+ IO::print(out, "\t\t%s|%s = %s|%s\n", t, p, t, p);
IO::print(out, "\tEndGlobalSection\n");
IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
- for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
- for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
- for(const char **k=platforms; *k; ++k)
+ for(const VcxProjectFile *p: projects)
+ for(const string &t: build_types)
+ for(const char *f: platforms)
{
- const char *project_platform = (!strcmp(*k, "x86") ? "Win32" : *k);
- IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
- if(i==projects.begin())
- IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
+ const char *project_platform = (!strcmp(f, "x86") ? "Win32" : f);
+ IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", p->get_guid(), t, f, t, project_platform);
+ if(p->get_package()==&spkg)
+ IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", p->get_guid(), t, f, t, project_platform);
}
IO::print(out, "\tEndGlobalSection\n");
IO::print(out, "EndGlobal\n");