require "mspcore";
require "mspstrings";
require "mspdatafile";
- require "msppath";
+ require "mspfs";
require "sigc++-2.0";
program "builder"
#include <iomanip>
#include <iostream>
#include <sstream>
-#include <msp/path/path.h>
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include "analyzer.h"
#include "builder.h"
#include "install.h"
if(full_paths)
fn=tgt.get_name();
else
- fn=basename(tgt.get_name());
+ fn=FS::basename(tgt.get_name());
row.push_back(string(depth*2, ' ')+fn);
const Package *pkg=tgt.get_package();
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/utils.h>
#include "archive.h"
#include "builder.h"
#include "component.h"
if(dynamic_cast<ObjectFile *>(*i))
argv.push_back(relative((*i)->get_name(), work_dir).str());
- Path lpath=lib.get_name();
+ FS::Path lpath=lib.get_name();
if(!builder.get_dry_run())
- mkpath(lpath.subpath(0, lpath.size()-1), 0755);
+ FS::mkpath(FS::dirname(lpath), 0755);
announce(comp.get_package().get_name(), tool, relative(lpath, work_dir).str());
Sets the path where the package files were installed. This is only useful if
the package doesn't use pkg-config.
*/
-void BinaryPackage::set_path(const Msp::Path &p)
+void BinaryPackage::set_path(const Msp::FS::Path &p)
{
path=builder.get_cwd()/p;
}
};
BinaryPackage(Builder &, const std::string &);
- void set_path(const Msp::Path &);
+ void set_path(const Msp::FS::Path &);
bool get_need_path() const { return need_path; }
static BinaryPackage *from_pkgconfig(Builder &, const std::string &);
private:
bool need_path;
- Msp::Path path;
+ Msp::FS::Path path;
virtual void create_build_info();
};
#include <msp/core/except.h>
#include <msp/core/getopt.h>
#include <msp/datafile/parser.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/io/buffered.h>
#include <msp/io/except.h>
#include <msp/io/file.h>
-#include <msp/path/utils.h>
#include <msp/strings/formatter.h>
#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
bool full_paths=false;
unsigned max_depth=5;
StringList cmdline_warn;
+ string prfx;
GetOpt getopt;
getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG);
getopt.add_option( "full-paths", full_paths, GetOpt::NO_ARG);
//getopt.add_option( "makefile", create_makefile, GetOpt::NO_ARG);
getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG);
- getopt.add_option( "prefix", prefix, GetOpt::REQUIRED_ARG);
+ getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG);
getopt.add_option( "warnings", cmdline_warn, GetOpt::REQUIRED_ARG);
getopt(argc, argv);
if(!work_dir.empty())
chdir(work_dir.c_str());
- cwd=getcwd();
+ cwd=FS::getcwd();
Architecture &native_arch=archs.insert(ArchMap::value_type("native", Architecture(*this, "native"))).first->second;
native_arch.set_tool("CC", "gcc");
native_arch.set_tool("LXX", "g++");
native_arch.set_tool("AR", "ar");
- load_build_file((get_home_dir()/".builderrc").str());
+ load_build_file((FS::get_home_dir()/".builderrc").str());
- if(prefix.empty())
+ if(prfx.empty())
{
if(current_arch=="native")
- prefix=(get_home_dir()/"local").str();
+ prefix=(FS::get_home_dir()/"local").str();
else
- prefix=(get_home_dir()/"local"/current_arch).str();
+ prefix=(FS::get_home_dir()/"local"/current_arch).str();
}
+ else
+ prefix=prfx;
warnings.push_back("all");
warnings.push_back("extra");
argv.push_back(get_current_arch().get_tool("CXX"));
argv.push_back("--version");
cxx_ver=Regex("[0-9]\\.[0-9.]+").match(run_command(argv))[0].str;
- while(!cxx_ver.empty() && !exists(Path("/usr/include/c++")/cxx_ver))
+ while(!cxx_ver.empty() && !FS::is_dir(FS::Path("/usr/include/c++")/cxx_ver))
{
unsigned dot=cxx_ver.rfind('.');
if(dot==string::npos)
syspath.push_back("/usr/include");
else
syspath.push_back("/usr/"+get_architecture(current_arch).get_prefix()+"/include");
- syspath.push_back((Path("/usr/include/c++/")/cxx_ver/fn).str());
+ syspath.push_back((FS::Path("/usr/include/c++/")/cxx_ver/fn).str());
Target *tgt=0;
if(include[0]=='\"')
- tgt=get_header(Path(from)/fn);
+ tgt=get_header(FS::Path(from)/fn);
for(list<string>::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
tgt=get_header(cwd/ *j/fn);
for(list<string>::const_iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
- tgt=get_header(Path(*j)/fn);
+ tgt=get_header(FS::Path(*j)/fn);
includes.insert(TargetMap::value_type(id, tgt));
@return 0 on success, -1 if the file could not be opened
*/
-int Builder::load_build_file(const Path &fn)
+int Builder::load_build_file(const FS::Path &fn)
{
try
{
Check if a header exists, either as a target or a file. Either an existing
target or a new SystemHeader target will be returned.
*/
-Target *Builder::get_header(const Msp::Path &fn)
+Target *Builder::get_header(const Msp::FS::Path &fn)
{
Target *tgt=get_target(fn.str());
if(tgt) return tgt;
- if(exists(fn))
+ if(FS::is_reg(fn))
{
tgt=new SystemHeader(*this, fn.str());
return tgt;
return 0;
}
-Target *Builder::get_library(const string &lib, const Path &path, LibMode mode)
+Target *Builder::get_library(const string &lib, const FS::Path &path, LibMode mode)
{
// Populate a list of candidate filenames
StringList candidates;
else if(tgt)
return tgt;
}
- else if(exists(full))
+ else if(FS::is_reg(full))
{
tgt=new SystemLibrary(*this, full);
return tgt;
Application::RegApp<Builder> Builder::reg;
-Builder::Loader::Loader(Builder &b, const Path &s):
+Builder::Loader::Loader(Builder &b, const FS::Path &s):
bld(b),
src(s)
{
void Builder::Loader::profile(const string &n)
{
StringMap prf;
- load_sub<ProfileLoader>(prf);
+ ProfileLoader ldr(prf);
+ load_sub_with(ldr);
bld.profile_tmpl.insert(ProfileTemplateMap::value_type(n, prf));
}
#include <string>
#include <msp/core/application.h>
#include <msp/datafile/loader.h>
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
#include "architecture.h"
#include "config.h"
#include "misc.h"
const TargetMap &get_targets() const { return targets; }
Target *get_header(const std::string &, const std::string &, const StringList &);
Target *get_library(const std::string &, const StringList &, LibMode);
- const Msp::Path &get_cwd() const { return cwd; }
+ const Msp::FS::Path &get_cwd() const { return cwd; }
const Architecture &get_architecture(const std::string &) const;
const Architecture &get_current_arch() const;
- const std::string &get_prefix() const { return prefix; }
+ const Msp::FS::Path &get_prefix() const { return prefix; }
const StringList &get_warnings() const { return warnings; }
void apply_profile_template(Config &, const std::string &) const;
void add_target(Target *);
class Loader: public Msp::DataFile::Loader
{
public:
- Loader(Builder &, const Msp::Path &);
+ Loader(Builder &, const Msp::FS::Path &);
private:
- Builder &bld;
- Msp::Path src;
+ Builder &bld;
+ Msp::FS::Path src;
void architecture(const std::string &);
void binpkg(const std::string &);
StringList cmdline_targets;
StringMap cmdline_options;
- Msp::Path cwd;
+ Msp::FS::Path cwd;
PackageMap packages;
SourcePackage *main_pkg;
bool build_all;
bool create_makefile;
std::string current_arch;
- std::string prefix;
+ Msp::FS::Path prefix;
StringList warnings;
- int load_build_file(const Msp::Path &);
+ int load_build_file(const Msp::FS::Path &);
int create_targets();
- Target *get_header(const Msp::Path &);
- Target *get_library(const std::string &, const Msp::Path &, LibMode);
+ Target *get_header(const Msp::FS::Path &);
+ Target *get_library(const std::string &, const Msp::FS::Path &, LibMode);
void update_hash(std::string &, const std::string &);
int do_build();
int do_clean();
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/utils.h>
#include "builder.h"
#include "buildinfo.h"
#include "compile.h"
work_dir=comp.get_package().get_source();
const TargetList &deps=obj.get_depends();
- Path spath=deps.front()->get_name();
+ FS::Path spath=deps.front()->get_name();
- string ext=splitext(spath.str()).ext;
+ string ext=FS::extpart(spath.str());
const char *tool=0;
if(ext==".cpp" || ext==".cc")
tool="CXX";
for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
argv.push_back("-D"+*i);
- Path opath=obj.get_name();
+ FS::Path opath=obj.get_name();
argv.push_back("-o");
argv.push_back(relative(opath, work_dir).str());
argv.push_back(relative(spath, work_dir).str());
if(!builder.get_dry_run())
- mkpath(opath.subpath(0, opath.size()-1), 0755);
+ FS::mkpath(FS::dirname(opath), 0755);
announce(comp.get_package().get_name(), tool, relative(opath, work_dir).str());
#ifndef COMPILE_H_
#define COMPILE_H_
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
#include "externalaction.h"
class Component;
*/
#include <msp/core/except.h>
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/strings/lexicalcast.h>
#include "builder.h"
#include "component.h"
list<Target *> inst_tgts;
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
- string basename=(*i)[-1];
- string ext=splitext(basename).ext;
+ string ext=FS::extpart(FS::basename(*i));
if((ext==".cpp" || ext==".c") && build_exe)
{
SourceFile *src=new SourceFile(builder, this, i->str());
PathList files;
for(PathList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
{
- struct stat st=stat(*i);
- if(S_ISDIR(st.st_mode))
+ if(FS::is_dir(*i))
{
list<string> sfiles=list_files(*i);
for(list<string>::iterator j=sfiles.begin(); j!=sfiles.end(); ++j)
#include <string>
#include <msp/datafile/loader.h>
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
#include "buildinfo.h"
#include "misc.h"
#include "package.h"
#include <cstdlib>
#include <msp/core/except.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/io/except.h>
#include <msp/io/file.h>
#include <msp/io/print.h>
-#include <msp/path/utils.h>
#include <msp/time/utils.h>
#include "builder.h"
#include "config.h"
void Config::save() const
{
- Path fn=package.get_source()/".options.cache";
+ FS::Path fn=package.get_source()/".options.cache";
OptionMap::const_iterator i=options.find("profile");
if(i!=options.end())
void Config::load()
{
- Path fn=package.get_source()/".options.cache";
+ FS::Path fn=package.get_source()/".options.cache";
OptionMap::iterator i=options.find("profile");
if(i!=options.end())
IO::File inf(fn.str());
IO::Buffered in(inf);
- mtime=Time::TimeStamp::from_unixtime(stat(fn).st_mtime);
+ mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
DataFile::Parser parser(in, fn.str());
Loader loader(*this);
#include <map>
#include <string>
#include <msp/datafile/loader.h>
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
#include <msp/time/timestamp.h>
#include "misc.h"
#include <errno.h>
#include <fstream>
#include <iostream>
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include "builder.h"
#include "copy.h"
#include "package.h"
using namespace std;
using namespace Msp;
-Copy::Copy(Builder &b, const Package &pkg, const Path &s, const Path &d):
+Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
InternalAction(b),
src(s),
dest(d)
void Copy::Worker::main()
{
- mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
+ FS::mkpath(FS::dirname(copy.dest), 0755);
try
{
}
// Preserve file permissions
- struct stat st=stat(copy.src);
+ struct stat st=FS::stat(copy.src);
chmod(copy.dest.str().c_str(), st.st_mode&0777);
done=true;
#define COPY_H_
#include <msp/core/thread.h>
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
#include "internalaction.h"
class Package;
class Copy: public InternalAction
{
public:
- Copy(Builder &, const Package &, const Msp::Path &, const Msp::Path &);
+ Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &);
private:
/**
A worker thread that actually does the data transfer.
void main();
};
- Msp::Path src;
- Msp::Path dest;
+ Msp::FS::Path src;
+ Msp::FS::Path dest;
};
#endif
*/
#include <fstream>
-#include <msp/path/utils.h>
+#include <msp/fs/stat.h>
#include <msp/strings/utils.h>
#include "builder.h"
#include "dependencycache.h"
deps[parts[0]]=StringList(parts.begin()+1, parts.end());
}
- mtime=Time::TimeStamp::from_unixtime(stat(fn).st_mtime);
+ mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
}
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include <msp/strings/formatter.h>
#include "builder.h"
#include "component.h"
queue.push_back(&stlib->get_component());
}
else
- builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, basename(name)));
+ builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, FS::basename(name)));
}
}
#include <iostream>
#include <cstring>
#include <cstdlib>
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
#include "builder.h"
#include "externalaction.h"
argv_[j]=0;
if(!work_dir.empty())
- chdir(work_dir);
+ FS::chdir(work_dir);
execvp(argv_[0], argv_);
cout<<"Couldn't execute "<<argv.front()<<'\n';
exit(1);
int check();
protected:
StringList argv;
- Msp::Path work_dir;
+ Msp::FS::Path work_dir;
int pid;
int exit_code;
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include "builder.h"
#include "copy.h"
#include "executable.h"
{
Target *dep=depends.front();
if(dep->get_mtime()>mtime)
- mark_rebuild(basename(dep->get_name())+" has changed");
+ mark_rebuild(FS::basename(dep->get_name())+" has changed");
else if(dep->get_rebuild())
- mark_rebuild(basename(dep->get_name())+" needs rebuilding");
+ mark_rebuild(FS::basename(dep->get_name())+" needs rebuilding");
}
}
{
const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(tgt.get_package());
- Path base=spkg->get_builder().get_prefix();
+ FS::Path base=spkg->get_builder().get_prefix();
string tgtname=tgt.get_name().substr(tgt.get_name().rfind('/')+1);
string mid;
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/utils.h>
#include "builder.h"
#include "component.h"
#include "executable.h"
argv.push_back("-l"+syslib->get_libname());
}
- Path epath=exe.get_name();
+ FS::Path epath=exe.get_name();
if(!builder.get_dry_run())
- mkpath(epath.subpath(0, epath.size()-1), 0755);
+ FS::mkpath(FS::dirname(epath), 0755);
announce(comp.get_package().get_name(), tool, relative(epath, work_dir).str());
#include <list>
#include <map>
#include <string>
-#include <msp/path/path.h>
+#include <msp/fs/path.h>
enum LibMode
{
};
typedef std::list<std::string> StringList;
-typedef std::list<Msp::Path> PathList;
+typedef std::list<Msp::FS::Path> PathList;
typedef std::map<std::string, std::string> StringMap;
std::string run_command(const StringList &);
*/
#include <algorithm>
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include "builder.h"
#include "compile.h"
#include "component.h"
string ObjectFile::generate_target_name(const Component &comp, const string &src)
{
const SourcePackage &pkg=comp.get_package();
- return (pkg.get_temp_dir()/comp.get_name()/(splitext(basename(src)).base+".o")).str();
+ return (pkg.get_temp_dir()/comp.get_name()/(FS::basepart(FS::basename(src))+".o")).str();
}
#include <fstream>
#include <iostream>
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include "package.h"
#include "pkgconfig.h"
#include "pkgconfigaction.h"
/**
Creates a buildable package.
*/
-SourcePackage::SourcePackage(Builder &b, const string &n, const Path &s):
+SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &s):
Package(b, n),
source(s),
config(*this),
tar_files.push_back(source/"Build");
}
-Msp::Path SourcePackage::get_temp_dir() const
+Msp::FS::Path SourcePackage::get_temp_dir() const
{
return source/config.get_option("tempdir").value/builder.get_current_arch().get_name()/config.get_option("profile").value;
}
-Msp::Path SourcePackage::get_out_dir() const
+Msp::FS::Path SourcePackage::get_out_dir() const
{
return source/config.get_option("outdir").value;
}
unsigned flags=get_install_flags();
- build_info.incpath.push_back((Path(builder.get_prefix())/"include").str());
- build_info.libpath.push_back((Path(builder.get_prefix())/"lib").str());
+ build_info.incpath.push_back((builder.get_prefix()/"include").str());
+ build_info.libpath.push_back((builder.get_prefix()/"lib").str());
if(flags&INCLUDE)
- export_binfo.incpath.push_back((Path(builder.get_prefix())/"include").str());
+ export_binfo.incpath.push_back((builder.get_prefix()/"include").str());
if(flags&LIB)
- export_binfo.libpath.push_back((Path(builder.get_prefix())/"lib").str());
+ export_binfo.libpath.push_back((builder.get_prefix()/"lib").str());
string optimize=config.get_option("optimize").value;
if(lexical_cast<unsigned>(optimize))
void tar_file(const std::string &);
};
- SourcePackage(Builder &, const std::string &, const Msp::Path &);
+ SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
const std::string &get_name() const { return name; }
const std::string &get_version() const { return version; }
const std::string &get_description() const { return description; }
- const Msp::Path &get_source() const { return source; }
- Msp::Path get_temp_dir() const;
- Msp::Path get_out_dir() const;
+ const Msp::FS::Path &get_source() const { return source; }
+ Msp::FS::Path get_temp_dir() const;
+ Msp::FS::Path get_out_dir() const;
const ComponentList &get_components() const { return components; }
const Config &get_config() const { return config; }
const BuildInfo &get_build_info() const { return build_info; }
std::string version;
std::string description;
- Msp::Path source;
+ Msp::FS::Path source;
PackageList base_reqs;
FeatureList features;
BuildInfo build_info;
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/path.h>
+#include <msp/fs/utils.h>
#include "systemlibrary.h"
using namespace std;
SystemLibrary::SystemLibrary(Builder &b, const string &n):
Target(b, 0, n)
{
- libname=splitext(basename(n)).base;
+ libname=FS::basepart(FS::basename(n));
if(!libname.compare(0, 3, "lib"))
libname.erase(0, 3);
}
#include <iostream>
#include <cstring>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/io/file.h>
-#include <msp/path/utils.h>
#include "builder.h"
#include "sourcepackage.h"
#include "tar.h"
void Tar::Worker::main()
{
- const Path &pkg_src=tar.tarball.get_package()->get_source();
- Path basedir=splitext(basename(tar.tarball.get_name())).base;
+ const FS::Path &pkg_src=tar.tarball.get_package()->get_source();
+ FS::Path basedir=FS::basepart(FS::basename(tar.tarball.get_name()));
IO::File out(tar.tarball.get_name(), IO::M_WRITE);
const TargetList &deps=tar.tarball.get_depends();
memcpy(buf, rel_path.data(), rel_path.size());
- struct stat st=stat((*i)->get_name());
+ struct stat st=FS::stat((*i)->get_name());
store_number(buf+100, st.st_mode, 7);
store_number(buf+108, st.st_uid, 7);
store_number(buf+116, st.st_gid, 7);
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/time/utils.h>
#include "action.h"
#include "builder.h"
return 0;
}
- if(!builder.get_dry_run() && exists(name))
- unlink(name);
+ if(!builder.get_dry_run() && FS::exists(name))
+ FS::unlink(name);
Action *action=create_action();
if(action)
builder.add_target(this);
struct stat st;
- if(!stat(name, st))
+ if(!FS::stat(name, st))
mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
}
for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
{
if((*i)->get_mtime()>mtime)
- mark_rebuild(basename((*i)->get_name())+" has changed");
+ mark_rebuild(FS::basename((*i)->get_name())+" has changed");
else if((*i)->get_rebuild())
- mark_rebuild(basename((*i)->get_name())+" needs rebuilding");
+ mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding");
}
}
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
#include "sourcepackage.h"
#include "target.h"
#include "unlink.h"
Distributed under the LGPL
*/
-#include <msp/path/utils.h>
+#include <msp/fs/path.h>
+#include <msp/fs/utils.h>
#include "virtualtarget.h"
using namespace std;
+using namespace Msp;
/**
Virtual targets are only rebuilt if their dependencies need rebuilding.
{
for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
if((*i)->get_rebuild())
- mark_rebuild(Msp::basename((*i)->get_name())+" needs rebuilding");
+ mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding");
}
/**