From: Mikko Rasa Date: Wed, 28 Dec 2022 13:39:12 +0000 (+0200) Subject: Convert builtin tools into a plugin X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d3e9e3db18a9fb6024fced0fe506752763c91c7f;p=builder.git Convert builtin tools into a plugin --- diff --git a/.gitignore b/.gitignore index 6bfc7f6..dc00fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,12 +2,12 @@ /builder /builder.pc /builder-stage1 +/builtintools.dlm /clangtools.dlm /gnutools.dlm /libbuilder.a /libbuilder.so /libandroidtools.a -/libbuiltintools.a /libdatatools.a /msvctools.dlm /temp diff --git a/Build b/Build index 794c3f3..2cf1583 100644 --- a/Build +++ b/Build @@ -13,12 +13,6 @@ package "builder" standard CXX "c++11"; }; - library "builtintools" - { - source "plugins/builtin"; - default false; - }; - library "androidtools" { source "plugins/android"; @@ -34,7 +28,6 @@ package "builder" library "libbuilder" { source "source/lib"; - use "builtintools"; use "androidtools"; use "datatools"; build_info @@ -63,6 +56,12 @@ package "builder" install true; }; + module "builtintools" + { + source "plugins/builtin"; + install true; + }; + module "gnutools" { source "plugins/gnu"; diff --git a/plugins/base/baseplugin.cpp b/plugins/base/baseplugin.cpp new file mode 100644 index 0000000..3646d10 --- /dev/null +++ b/plugins/base/baseplugin.cpp @@ -0,0 +1,39 @@ +#include +#include +#include "builtinplugin.h" +#include "builtintools.h" +#include "compilecommandsjson.h" +#include "pkgconfigfile.h" +#include "vcxprojectfile.h" +#include "vssolutionfile.h" + +void BuiltinPlugin::add_tools(Toolchain &toolchain, const Architecture &) const +{ + toolchain.add_toolchain(new BuiltinTools(builder)); +} + +void BuiltinPlugin::create_targets(SourcePackage &spkg) const +{ + const Architecture &native_arch = builder.get_native_arch(); + + if(!spkg.get_exported_build_info().libs.empty() && native_arch.get_system()=="linux") + { + PkgConfigFile *pc = new PkgConfigFile(builder, spkg); + builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc)); + } + + if(native_arch.get_system()=="windows") + { + new VcxProjectFile(builder, spkg); + new VsSolutionFile(builder, spkg); + } + + new CompileCommandsJson(builder, spkg); +} + + +extern "C" +Plugin *create_plugin(Builder &builder) +{ + return new BuiltinPlugin(builder); +} diff --git a/plugins/base/baseplugin.h b/plugins/base/baseplugin.h new file mode 100644 index 0000000..afe48af --- /dev/null +++ b/plugins/base/baseplugin.h @@ -0,0 +1,15 @@ +#ifndef BUILTINPLUGIN_H_ +#define BUILTINPLUGIN_H_ + +#include + +class BuiltinPlugin: public Plugin +{ +public: + BuiltinPlugin(Builder &b): Plugin(b) { } + + void add_tools(Toolchain &, const Architecture &) const override; + void create_targets(SourcePackage &) const override; +}; + +#endif diff --git a/plugins/base/basetools.cpp b/plugins/base/basetools.cpp new file mode 100644 index 0000000..c2c11e6 --- /dev/null +++ b/plugins/base/basetools.cpp @@ -0,0 +1,17 @@ +#include "builtintools.h" +#include "copy.h" +#include "compilecommandsgenerator.h" +#include "pkgconfiggenerator.h" +#include "tar.h" +#include "vcxprojectgenerator.h" +#include "vssolutiongenerator.h" + +BuiltinTools::BuiltinTools(Builder &builder) +{ + add_tool(new Copy(builder)); + add_tool(new Tar(builder)); + add_tool(new PkgConfigGenerator(builder)); + add_tool(new VcxProjectGenerator(builder)); + add_tool(new VsSolutionGenerator(builder)); + add_tool(new CompileCommandsGenerator(builder)); +} diff --git a/plugins/base/basetools.h b/plugins/base/basetools.h new file mode 100644 index 0000000..4771e83 --- /dev/null +++ b/plugins/base/basetools.h @@ -0,0 +1,14 @@ +#ifndef BUILTINTOOLS_H_ +#define BUILTINTOOLS_H_ + +#include + +class Builder; + +class BuiltinTools: public Toolchain +{ +public: + BuiltinTools(Builder &); +}; + +#endif diff --git a/plugins/base/compilecommandsgenerator.cpp b/plugins/base/compilecommandsgenerator.cpp new file mode 100644 index 0000000..61e11db --- /dev/null +++ b/plugins/base/compilecommandsgenerator.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include "compilecommandsgenerator.h" +#include "compilecommandsjson.h" + +using namespace std; +using namespace Msp; + +CompileCommandsGenerator::CompileCommandsGenerator(Builder &b): + Tool(b, "CCJG") +{ + set_run_internal(_run); +} + +Target *CompileCommandsGenerator::create_target(const vector &, const string &) +{ + throw logic_error("Not implemented"); +} + +bool CompileCommandsGenerator::_run(const CompileCommandsJson &cmds) +{ + Builder &builder = cmds.get_package()->get_builder(); + const SourcePackage &spkg = *cmds.get_package(); + string work_dir = c_escape(spkg.get_source_directory().str()); + + IO::BufferedFile out(cmds.get_path().str(), IO::M_WRITE); + IO::print(out, "["); + + bool first = true; + 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(kvp.second)) + { + FS::Path src_path = obj->get_source().get_path(); + Task *task = kvp.second->build(); + if(!first) + out.put(','); + IO::print(out, "\n\t{\n"); + IO::print(out, "\t\t\"file\": \"%s\"\n", src_path); + IO::print(out, "\t\t\"command\": \"%s\"\n", c_escape(task->get_command())); + IO::print(out, "\t\t\"directory\": \"%s\"\n", work_dir); + IO::print(out, "\t}"); + delete task; + first = false; + } + + IO::print(out, "\n]\n"); + + return true; +} diff --git a/plugins/base/compilecommandsgenerator.h b/plugins/base/compilecommandsgenerator.h new file mode 100644 index 0000000..ec4a501 --- /dev/null +++ b/plugins/base/compilecommandsgenerator.h @@ -0,0 +1,19 @@ +#ifndef COMPILECOMMANDSGENERATOR_H_ +#define COMPILECOMMANDSGENERATOR_H_ + +#include + +class CompileCommandsJson; + +class CompileCommandsGenerator: public Tool +{ +public: + CompileCommandsGenerator(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const CompileCommandsJson &); +}; + +#endif diff --git a/plugins/base/compilecommandsjson.cpp b/plugins/base/compilecommandsjson.cpp new file mode 100644 index 0000000..d4adc14 --- /dev/null +++ b/plugins/base/compilecommandsjson.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include "compilecommandsjson.h" + +CompileCommandsJson::CompileCommandsJson(Builder &b, const SourcePackage &p): + FileTarget(b, p, p.get_source_directory()/("compile_commands.json")) +{ + tool = &builder.get_toolchain().get_tool("CCJG"); +} + +void CompileCommandsJson::find_dependencies() +{ + for(const auto &kvp: builder.get_build_graph().get_targets()) + if(kvp.second->is_buildable() && kvp.second->get_package()==package && dynamic_cast(kvp.second)) + kvp.second->prepare(); +} diff --git a/plugins/base/compilecommandsjson.h b/plugins/base/compilecommandsjson.h new file mode 100644 index 0000000..be9c448 --- /dev/null +++ b/plugins/base/compilecommandsjson.h @@ -0,0 +1,20 @@ +#ifndef COMPILECOMMANDSJSON_H_ +#define COMPILECOMMANDSJSON_H_ + +#include +#include + +class CompileCommandsJson: public FileTarget +{ +private: + +public: + CompileCommandsJson(Builder &, const SourcePackage &); + + const char *get_type() const override { return "CompileCommandsJson"; } + +protected: + void find_dependencies() override; +}; + +#endif diff --git a/plugins/base/copy.cpp b/plugins/base/copy.cpp new file mode 100644 index 0000000..0633ff9 --- /dev/null +++ b/plugins/base/copy.cpp @@ -0,0 +1,73 @@ +#ifndef _WIN32 +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include "copy.h" + +using namespace std; +using namespace Msp; + +Copy::Copy(Builder &b): + Tool(b, "CP") +{ + set_run_internal(_run); +} + +Target *Copy::create_target(const vector &sources, const string &arg) +{ + FileTarget &file_tgt = dynamic_cast(*sources.front()); + InstalledFile *inst = new InstalledFile(builder, *file_tgt.get_package(), file_tgt, arg); + inst->set_tool(*this); + return inst; +} + +bool Copy::_run(const InstalledFile &install) +{ + const FileTarget &source = install.get_source(); + const FS::Path &src_path = source.get_path(); + const FS::Path &dst_path = install.get_path(); + + try + { + IO::File in(src_path.str()); + IO::File out(dst_path.str(), IO::M_WRITE); + + // Actual transfer loop + char buf[16384]; + while(!in.eof()) + { + unsigned len = in.read(buf, sizeof(buf)); + out.write(buf, len); + } + } + catch(const exception &e) + { + IO::print(IO::cerr, "%s\n", e.what()); + return false; + } + +#ifndef _WIN32 + // Preserve file permissions + struct stat st; + if(stat(src_path.str().c_str(), &st)==0) + chmod(dst_path.str().c_str(), st.st_mode&0777); + + const FS::Path &link = install.get_symlink(); + if(!link.empty()) + { + FS::Path relpath = FS::relative(dst_path, FS::dirname(link)); + if(FS::exists(link)) + FS::unlink(link); + symlink(relpath.str().c_str(), link.str().c_str()); + } +#endif + + return true; +} diff --git a/plugins/base/copy.h b/plugins/base/copy.h new file mode 100644 index 0000000..f6f01fb --- /dev/null +++ b/plugins/base/copy.h @@ -0,0 +1,22 @@ +#ifndef COPY_H_ +#define COPY_H_ + +#include + +class InstalledFile; + +/** +Copies a file to another place. Used by the InstalledFile target. +*/ +class Copy: public Tool +{ +public: + Copy(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const InstalledFile &); +}; + +#endif diff --git a/plugins/base/pkgconfigfile.cpp b/plugins/base/pkgconfigfile.cpp new file mode 100644 index 0000000..70ab59d --- /dev/null +++ b/plugins/base/pkgconfigfile.cpp @@ -0,0 +1,11 @@ +#include +#include +#include "pkgconfigfile.h" + +PkgConfigFile::PkgConfigFile(Builder &b, const SourcePackage &p): + FileTarget(b, p, p.get_source_directory()/(p.get_name()+".pc")) +{ + tool = &builder.get_toolchain().get_tool("PCG"); + + install_location = "lib/pkgconfig"; +} diff --git a/plugins/base/pkgconfigfile.h b/plugins/base/pkgconfigfile.h new file mode 100644 index 0000000..23027e4 --- /dev/null +++ b/plugins/base/pkgconfigfile.h @@ -0,0 +1,18 @@ +#ifndef PKGCONFIGFILE_H_ +#define PKGCONFIGFILE_H_ + +#include +#include + +/** +Creates a .pc file to enable other packages fetch build options with pkg-config. +*/ +class PkgConfigFile: public FileTarget +{ +public: + PkgConfigFile(Builder &, const SourcePackage &); + + const char *get_type() const override { return "PkgConfigFile"; } +}; + +#endif diff --git a/plugins/base/pkgconfiggenerator.cpp b/plugins/base/pkgconfiggenerator.cpp new file mode 100644 index 0000000..76ed7d9 --- /dev/null +++ b/plugins/base/pkgconfiggenerator.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include "pkgconfigfile.h" +#include "pkgconfiggenerator.h" + +using namespace std; +using namespace Msp; + +PkgConfigGenerator::PkgConfigGenerator(Builder &b): + Tool(b, "PCG") +{ + set_run_internal(_run); +} + +Target *PkgConfigGenerator::create_target(const vector &, const string &) +{ + throw logic_error("Not implemented"); +} + +bool PkgConfigGenerator::_run(const PkgConfigFile &pkgc) +{ + Builder &builder = pkgc.get_package()->get_builder(); + const SourcePackage &spkg = *pkgc.get_package(); + + IO::BufferedFile out(pkgc.get_path().str(), IO::M_WRITE); + IO::print(out, "prefix=%s\n", builder.get_prefix().str()); + IO::print(out, "source=%s\n\n", spkg.get_source_directory()); + + IO::print(out, "Name: %s\n", spkg.get_label()); + IO::print(out, "Description: %s\n", spkg.get_description()); + IO::print(out, "Version: %s\n", spkg.get_version()); + + IO::print(out, "Requires:"); + 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(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(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", kvp.first, kvp.second); + out.put('\n'); + + return true; +} + +string PkgConfigGenerator::prefixify(const FS::Path &path, const FS::Path &prefix) +{ + if(FS::descendant_depth(path, prefix)>=0) + { + FS::Path rel_path = FS::relative(path, prefix); + return "${prefix}"+rel_path.str().substr(1); + } + else + return path.str(); +} diff --git a/plugins/base/pkgconfiggenerator.h b/plugins/base/pkgconfiggenerator.h new file mode 100644 index 0000000..2a0e0b1 --- /dev/null +++ b/plugins/base/pkgconfiggenerator.h @@ -0,0 +1,20 @@ +#ifndef PKGCONFIGGENERATOR_H_ +#define PKGCONFIGGENERATOR_H_ + +#include + +class PkgConfigFile; + +class PkgConfigGenerator: public Tool +{ +public: + PkgConfigGenerator(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const PkgConfigFile &); + static std::string prefixify(const Msp::FS::Path &, const Msp::FS::Path &); +}; + +#endif diff --git a/plugins/base/tar.cpp b/plugins/base/tar.cpp new file mode 100644 index 0000000..4bac32a --- /dev/null +++ b/plugins/base/tar.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include +#include "tar.h" +#include "tarball.h" + +using namespace std; +using namespace Msp; + +Tar::Tar(Builder &b): + Tool(b, "TAR") +{ + processing_unit = COMPONENT; + set_run_internal(&_run); +} + +Target *Tar::create_target(const vector &sources, const string &arg) +{ + if(sources.empty() || !sources.front()->get_package()) + throw invalid_argument("Tar::create_target"); + + TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg); + for(Target *s: sources) + tarball->add_dependency(*s); + + tarball->set_tool(*this); + + return tarball; +} + +bool Tar::_run(const TarBall &tarball) +{ + const FS::Path &pkg_src = tarball.get_package()->get_source_directory(); + FS::Path basedir = FS::basepart(FS::basename(tarball.get_path())); + + IO::File out(tarball.get_path().str(), IO::M_WRITE); + for(Target *d: tarball.get_dependencies()) + { + FileTarget *ft = dynamic_cast(d); + if(!ft) + continue; + + char buf[4096]; + memset(buf, 0, 512); + + string rel_path = (basedir/relative(ft->get_path(), pkg_src)).str(); + if(rel_path.size()>99) + { + IO::print("Can't store %s in tar archive - too long name\n", rel_path); + return false; + } + + memcpy(buf, rel_path.data(), rel_path.size()); + + FS::Stat st = FS::stat(ft->get_path()); + store_number(buf+100, 0666, 7); + store_number(buf+108, 0, 7); + store_number(buf+116, 0, 7); + store_number(buf+124, st.get_size(), 11); + store_number(buf+136, st.get_modify_time().to_unixtime(), 11); + buf[156] = '0'; + + memset(buf+148, ' ', 8); + unsigned chk = 0; + for(unsigned j=0; j<512; ++j) + chk += static_cast(buf[j]); + store_number(buf+148, chk, 7); + buf[155] = 0; + + out.write(buf, 512); + IO::File in(ft->get_path().str()); + for(unsigned j=0; j + +class TarBall; + +class Tar: public Tool +{ +public: + Tar(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const TarBall &); + static void store_number(char *, unsigned, unsigned); +}; + +#endif diff --git a/plugins/base/tarball.cpp b/plugins/base/tarball.cpp new file mode 100644 index 0000000..0b2d481 --- /dev/null +++ b/plugins/base/tarball.cpp @@ -0,0 +1,14 @@ +#include +#include "tar.h" +#include "tarball.h" + +using namespace std; + +TarBall::TarBall(Builder &b, const SourcePackage &p, const string &n): + FileTarget(b, p, p.get_source_directory()/(n+".tar")) +{ } + +const SourcePackage *TarBall::get_package() const +{ + return static_cast(package); +} diff --git a/plugins/base/tarball.h b/plugins/base/tarball.h new file mode 100644 index 0000000..f63840e --- /dev/null +++ b/plugins/base/tarball.h @@ -0,0 +1,15 @@ +#ifndef TARBALL_H_ +#define TARBALL_H_ + +#include + +class TarBall: public FileTarget +{ +public: + TarBall(Builder &, const SourcePackage &, const std::string &); + + const char *get_type() const override { return "TarBall"; } + const SourcePackage *get_package() const; +}; + +#endif diff --git a/plugins/base/vcxprojectfile.cpp b/plugins/base/vcxprojectfile.cpp new file mode 100644 index 0000000..3ec7da1 --- /dev/null +++ b/plugins/base/vcxprojectfile.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include "vcxprojectfile.h" + +using namespace Msp; + +VcxProjectFile::VcxProjectFile(Builder &b, const SourcePackage &p): + FileTarget(b, p, p.get_source_directory()/(p.get_name()+".vcxproj")) +{ + tool = &builder.get_toolchain().get_tool("VCXG"); + + char digest[16]; + Crypto::MD5(package->get_name()).get_digest(digest, sizeof(digest)); + digest[6] = 3; + digest[8] = (digest[6]&0x3F)|0x80; + for(unsigned j=0; j(digest[j])); + } +} diff --git a/plugins/base/vcxprojectfile.h b/plugins/base/vcxprojectfile.h new file mode 100644 index 0000000..1f85d0e --- /dev/null +++ b/plugins/base/vcxprojectfile.h @@ -0,0 +1,19 @@ +#ifndef VCXPROJECTFILE_H_ +#define VCXPROJECTFILE_H_ + +#include + +class VcxProjectFile: public FileTarget +{ +private: + std::string guid; + +public: + VcxProjectFile(Builder &, const SourcePackage &); + + const char *get_type() const override { return "VcxProjectFile"; } + + const std::string &get_guid() const { return guid; } +}; + +#endif diff --git a/plugins/base/vcxprojectgenerator.cpp b/plugins/base/vcxprojectgenerator.cpp new file mode 100644 index 0000000..7cb9faf --- /dev/null +++ b/plugins/base/vcxprojectgenerator.cpp @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "vcxprojectfile.h" +#include "vcxprojectgenerator.h" + +using namespace std; +using namespace Msp; + +VcxProjectGenerator::VcxProjectGenerator(Builder &b): + Tool(b, "VCXG") +{ + set_run_internal(_run); +} + +Target *VcxProjectGenerator::create_target(const vector &, const string &) +{ + throw logic_error("Not implemented"); +} + +bool VcxProjectGenerator::_run(const VcxProjectFile &project) +{ + const SourcePackage &spkg = *project.get_package(); + Builder &builder = spkg.get_builder(); + + IO::BufferedFile out(project.get_path().str(), IO::M_WRITE); + IO::print(out, "\n"); + + IO::print(out, "\t\n"); + vector build_types = builder.get_build_types(); + const char *platforms[] = { "Win32", "x64" }; + for(const char *p: platforms) + for(const string &b: build_types) + { + IO::print(out, "\t\t\n", b, p); + IO::print(out, "\t\t\t%s\n", b); + IO::print(out, "\t\t\t%s\n", p); + IO::print(out, "\t\t\n"); + } + IO::print(out, "\t\n"); + + IO::print(out, "\t\n"); + IO::print(out, "\t\t15.0\n"); + IO::print(out, "\t\tMakeFileProj\n"); + IO::print(out, "\t\t{%s}\n", project.get_guid()); + IO::print(out, "\t\n"); + + IO::print(out, "\t\n"); + + const Executable *exe = 0; + for(const Target *t: builder.get_build_graph().get_target("world")->get_dependencies()) + if(t->get_package()==&spkg) + if((exe = dynamic_cast(t))) + break; + + const char *argv0 = Application::get_argv0(); + const string &toolchain = builder.get_current_arch().get_toolchain(); + 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, p, toolchain, b, builder.get_prefix()); + IO::print(out, "\t\n", b, p); + IO::print(out, "\t\tMakeFile\n"); + IO::print(out, "\t\t%s\n", base_cmd); + IO::print(out, "\t\t%s -c\n", base_cmd); + IO::print(out, "\t\t%s -B\n", base_cmd); + if(exe) + IO::print(out, "\t\t%s\n", exe->get_path()); + IO::print(out, "\t\n"); + } + + IO::print(out, "\t\n"); + + vector sources; + vector includes; + vector others; + BuildInfo build_info; + for(const auto &kvp: builder.get_build_graph().get_targets()) + if(kvp.second->get_package()==&spkg) + { + if(kvp.second->is_buildable()) + { + BuildInfo tgt_binfo; + kvp.second->collect_build_info(tgt_binfo); + build_info.update_from(tgt_binfo, BuildInfo::CHAINED); + } + else if(const FileTarget *file = dynamic_cast(kvp.second)) + { + if(dynamic_cast(file)) + { + string ext = tolower(FS::extpart(FS::basename(file->get_path()))); + if(ext==".h" || ext==".hpp") + includes.push_back(file); + else + sources.push_back(file); + } + else + others.push_back(file); + } + } + + if(!build_info.incpath.empty()) + { + IO::print(out, "\t\n"); + string path_str; + for(const FS::Path &p: build_info.incpath) + append(path_str, ";", p.str()); + IO::print(out, "\t\t%s\n", path_str); + IO::print(out, "\t\n"); + } + + IO::print(out, "\t\n"); + for(const FileTarget *s: sources) + IO::print(out, "\t\t\n", s->get_path()); + IO::print(out, "\t\n"); + + IO::print(out, "\t\n"); + for(const FileTarget *i: includes) + IO::print(out, "\t\t\n", i->get_path()); + IO::print(out, "\t\n"); + + IO::print(out, "\t\n"); + for(const FileTarget *t: others) + IO::print(out, "\t\t\n", t->get_path()); + IO::print(out, "\t\n"); + + IO::print(out, "\t\n"); + IO::print(out, "\n"); + + return true; +} diff --git a/plugins/base/vcxprojectgenerator.h b/plugins/base/vcxprojectgenerator.h new file mode 100644 index 0000000..ce96a54 --- /dev/null +++ b/plugins/base/vcxprojectgenerator.h @@ -0,0 +1,19 @@ +#ifndef VCXPROJECTGENERATOR_H_ +#define VCXPROJECTGENERATOR_H_ + +#include + +class VcxProjectFile; + +class VcxProjectGenerator: public Tool +{ +public: + VcxProjectGenerator(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const VcxProjectFile &); +}; + +#endif diff --git a/plugins/base/vssolutionfile.cpp b/plugins/base/vssolutionfile.cpp new file mode 100644 index 0000000..38908df --- /dev/null +++ b/plugins/base/vssolutionfile.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include "vssolutionfile.h" + +using namespace std; +using namespace Msp; + +VsSolutionFile::VsSolutionFile(Builder &b, const SourcePackage &p): + FileTarget(b, p, p.get_source_directory()/(p.get_name()+".sln")) +{ + tool = &builder.get_toolchain().get_tool("VSSG"); +} + +void VsSolutionFile::find_dependencies() +{ + find_dependencies(*package); +} + +void VsSolutionFile::find_dependencies(const SourcePackage &spkg) +{ + if(FileTarget *project = builder.get_vfs().get_target(spkg.get_source_directory()/(spkg.get_name()+".vcxproj"))) + if(!any_equals(depends, static_cast(project))) + { + add_dependency(*project); + + for(const Package *r: spkg.get_required_packages()) + if(const SourcePackage *s = dynamic_cast(r)) + find_dependencies(*s); + } +} diff --git a/plugins/base/vssolutionfile.h b/plugins/base/vssolutionfile.h new file mode 100644 index 0000000..2c1e602 --- /dev/null +++ b/plugins/base/vssolutionfile.h @@ -0,0 +1,17 @@ +#ifndef VSSOLUTIONFILE_H_ +#define VSSOLUTIONFILE_H_ + +#include + +class VsSolutionFile: public FileTarget +{ +public: + VsSolutionFile(Builder &, const SourcePackage &); + + const char *get_type() const override { return "VsSolutionFile"; } +protected: + void find_dependencies() override; + void find_dependencies(const SourcePackage &); +}; + +#endif diff --git a/plugins/base/vssolutiongenerator.cpp b/plugins/base/vssolutiongenerator.cpp new file mode 100644 index 0000000..60602e1 --- /dev/null +++ b/plugins/base/vssolutiongenerator.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include "vcxprojectfile.h" +#include "vssolutionfile.h" +#include "vssolutiongenerator.h" + +using namespace std; +using namespace Msp; + +VsSolutionGenerator::VsSolutionGenerator(Builder &b): + Tool(b, "VSSG") +{ + set_run_internal(_run); +} + +Target *VsSolutionGenerator::create_target(const vector &, const string &) +{ + throw logic_error("Not implemented"); +} + +bool VsSolutionGenerator::_run(const VsSolutionFile &solution) +{ + const SourcePackage &spkg = *solution.get_package(); + Builder &builder = spkg.get_builder(); + + IO::BufferedFile out(solution.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"); + + vector projects; + for(const Target *t: solution.get_dependencies()) + if(const VcxProjectFile *project = dynamic_cast(t)) + projects.push_back(project); + + for(const VcxProjectFile *p: projects) + { + const SourcePackage *pkg = p->get_package(); + IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n", + pkg->get_name(), p->get_path(), p->get_guid()); + } + + vector build_types = builder.get_build_types(); + const char *platforms[] = { "x86", "x64" }; + + IO::print(out, "Global\n"); + IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n"); + 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(const VcxProjectFile *p: projects) + for(const string &t: build_types) + for(const char *f: platforms) + { + 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"); + + return true; +} diff --git a/plugins/base/vssolutiongenerator.h b/plugins/base/vssolutiongenerator.h new file mode 100644 index 0000000..c98fcb2 --- /dev/null +++ b/plugins/base/vssolutiongenerator.h @@ -0,0 +1,19 @@ +#ifndef VSSOLUTIONGENERATOR_H_ +#define VSSOLUTIONGENERATOR_H_ + +#include + +class VsSolutionFile; + +class VsSolutionGenerator: public Tool +{ +public: + VsSolutionGenerator(Builder &); + + Target *create_target(const std::vector &, const std::string &) override; + +private: + static bool _run(const VsSolutionFile &); +}; + +#endif diff --git a/plugins/builtin/builtintools.cpp b/plugins/builtin/builtintools.cpp deleted file mode 100644 index c2c11e6..0000000 --- a/plugins/builtin/builtintools.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "builtintools.h" -#include "copy.h" -#include "compilecommandsgenerator.h" -#include "pkgconfiggenerator.h" -#include "tar.h" -#include "vcxprojectgenerator.h" -#include "vssolutiongenerator.h" - -BuiltinTools::BuiltinTools(Builder &builder) -{ - add_tool(new Copy(builder)); - add_tool(new Tar(builder)); - add_tool(new PkgConfigGenerator(builder)); - add_tool(new VcxProjectGenerator(builder)); - add_tool(new VsSolutionGenerator(builder)); - add_tool(new CompileCommandsGenerator(builder)); -} diff --git a/plugins/builtin/builtintools.h b/plugins/builtin/builtintools.h deleted file mode 100644 index 4771e83..0000000 --- a/plugins/builtin/builtintools.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef BUILTINTOOLS_H_ -#define BUILTINTOOLS_H_ - -#include - -class Builder; - -class BuiltinTools: public Toolchain -{ -public: - BuiltinTools(Builder &); -}; - -#endif diff --git a/plugins/builtin/compilecommandsgenerator.cpp b/plugins/builtin/compilecommandsgenerator.cpp deleted file mode 100644 index 61e11db..0000000 --- a/plugins/builtin/compilecommandsgenerator.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "compilecommandsgenerator.h" -#include "compilecommandsjson.h" - -using namespace std; -using namespace Msp; - -CompileCommandsGenerator::CompileCommandsGenerator(Builder &b): - Tool(b, "CCJG") -{ - set_run_internal(_run); -} - -Target *CompileCommandsGenerator::create_target(const vector &, const string &) -{ - throw logic_error("Not implemented"); -} - -bool CompileCommandsGenerator::_run(const CompileCommandsJson &cmds) -{ - Builder &builder = cmds.get_package()->get_builder(); - const SourcePackage &spkg = *cmds.get_package(); - string work_dir = c_escape(spkg.get_source_directory().str()); - - IO::BufferedFile out(cmds.get_path().str(), IO::M_WRITE); - IO::print(out, "["); - - bool first = true; - 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(kvp.second)) - { - FS::Path src_path = obj->get_source().get_path(); - Task *task = kvp.second->build(); - if(!first) - out.put(','); - IO::print(out, "\n\t{\n"); - IO::print(out, "\t\t\"file\": \"%s\"\n", src_path); - IO::print(out, "\t\t\"command\": \"%s\"\n", c_escape(task->get_command())); - IO::print(out, "\t\t\"directory\": \"%s\"\n", work_dir); - IO::print(out, "\t}"); - delete task; - first = false; - } - - IO::print(out, "\n]\n"); - - return true; -} diff --git a/plugins/builtin/compilecommandsgenerator.h b/plugins/builtin/compilecommandsgenerator.h deleted file mode 100644 index ec4a501..0000000 --- a/plugins/builtin/compilecommandsgenerator.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef COMPILECOMMANDSGENERATOR_H_ -#define COMPILECOMMANDSGENERATOR_H_ - -#include - -class CompileCommandsJson; - -class CompileCommandsGenerator: public Tool -{ -public: - CompileCommandsGenerator(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const CompileCommandsJson &); -}; - -#endif diff --git a/plugins/builtin/compilecommandsjson.cpp b/plugins/builtin/compilecommandsjson.cpp deleted file mode 100644 index d4adc14..0000000 --- a/plugins/builtin/compilecommandsjson.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include "compilecommandsjson.h" - -CompileCommandsJson::CompileCommandsJson(Builder &b, const SourcePackage &p): - FileTarget(b, p, p.get_source_directory()/("compile_commands.json")) -{ - tool = &builder.get_toolchain().get_tool("CCJG"); -} - -void CompileCommandsJson::find_dependencies() -{ - for(const auto &kvp: builder.get_build_graph().get_targets()) - if(kvp.second->is_buildable() && kvp.second->get_package()==package && dynamic_cast(kvp.second)) - kvp.second->prepare(); -} diff --git a/plugins/builtin/compilecommandsjson.h b/plugins/builtin/compilecommandsjson.h deleted file mode 100644 index be9c448..0000000 --- a/plugins/builtin/compilecommandsjson.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef COMPILECOMMANDSJSON_H_ -#define COMPILECOMMANDSJSON_H_ - -#include -#include - -class CompileCommandsJson: public FileTarget -{ -private: - -public: - CompileCommandsJson(Builder &, const SourcePackage &); - - const char *get_type() const override { return "CompileCommandsJson"; } - -protected: - void find_dependencies() override; -}; - -#endif diff --git a/plugins/builtin/copy.cpp b/plugins/builtin/copy.cpp deleted file mode 100644 index 0633ff9..0000000 --- a/plugins/builtin/copy.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _WIN32 -#include -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include "copy.h" - -using namespace std; -using namespace Msp; - -Copy::Copy(Builder &b): - Tool(b, "CP") -{ - set_run_internal(_run); -} - -Target *Copy::create_target(const vector &sources, const string &arg) -{ - FileTarget &file_tgt = dynamic_cast(*sources.front()); - InstalledFile *inst = new InstalledFile(builder, *file_tgt.get_package(), file_tgt, arg); - inst->set_tool(*this); - return inst; -} - -bool Copy::_run(const InstalledFile &install) -{ - const FileTarget &source = install.get_source(); - const FS::Path &src_path = source.get_path(); - const FS::Path &dst_path = install.get_path(); - - try - { - IO::File in(src_path.str()); - IO::File out(dst_path.str(), IO::M_WRITE); - - // Actual transfer loop - char buf[16384]; - while(!in.eof()) - { - unsigned len = in.read(buf, sizeof(buf)); - out.write(buf, len); - } - } - catch(const exception &e) - { - IO::print(IO::cerr, "%s\n", e.what()); - return false; - } - -#ifndef _WIN32 - // Preserve file permissions - struct stat st; - if(stat(src_path.str().c_str(), &st)==0) - chmod(dst_path.str().c_str(), st.st_mode&0777); - - const FS::Path &link = install.get_symlink(); - if(!link.empty()) - { - FS::Path relpath = FS::relative(dst_path, FS::dirname(link)); - if(FS::exists(link)) - FS::unlink(link); - symlink(relpath.str().c_str(), link.str().c_str()); - } -#endif - - return true; -} diff --git a/plugins/builtin/copy.h b/plugins/builtin/copy.h deleted file mode 100644 index f6f01fb..0000000 --- a/plugins/builtin/copy.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef COPY_H_ -#define COPY_H_ - -#include - -class InstalledFile; - -/** -Copies a file to another place. Used by the InstalledFile target. -*/ -class Copy: public Tool -{ -public: - Copy(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const InstalledFile &); -}; - -#endif diff --git a/plugins/builtin/pkgconfigfile.cpp b/plugins/builtin/pkgconfigfile.cpp deleted file mode 100644 index 70ab59d..0000000 --- a/plugins/builtin/pkgconfigfile.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "pkgconfigfile.h" - -PkgConfigFile::PkgConfigFile(Builder &b, const SourcePackage &p): - FileTarget(b, p, p.get_source_directory()/(p.get_name()+".pc")) -{ - tool = &builder.get_toolchain().get_tool("PCG"); - - install_location = "lib/pkgconfig"; -} diff --git a/plugins/builtin/pkgconfigfile.h b/plugins/builtin/pkgconfigfile.h deleted file mode 100644 index 23027e4..0000000 --- a/plugins/builtin/pkgconfigfile.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PKGCONFIGFILE_H_ -#define PKGCONFIGFILE_H_ - -#include -#include - -/** -Creates a .pc file to enable other packages fetch build options with pkg-config. -*/ -class PkgConfigFile: public FileTarget -{ -public: - PkgConfigFile(Builder &, const SourcePackage &); - - const char *get_type() const override { return "PkgConfigFile"; } -}; - -#endif diff --git a/plugins/builtin/pkgconfiggenerator.cpp b/plugins/builtin/pkgconfiggenerator.cpp deleted file mode 100644 index 76ed7d9..0000000 --- a/plugins/builtin/pkgconfiggenerator.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include "pkgconfigfile.h" -#include "pkgconfiggenerator.h" - -using namespace std; -using namespace Msp; - -PkgConfigGenerator::PkgConfigGenerator(Builder &b): - Tool(b, "PCG") -{ - set_run_internal(_run); -} - -Target *PkgConfigGenerator::create_target(const vector &, const string &) -{ - throw logic_error("Not implemented"); -} - -bool PkgConfigGenerator::_run(const PkgConfigFile &pkgc) -{ - Builder &builder = pkgc.get_package()->get_builder(); - const SourcePackage &spkg = *pkgc.get_package(); - - IO::BufferedFile out(pkgc.get_path().str(), IO::M_WRITE); - IO::print(out, "prefix=%s\n", builder.get_prefix().str()); - IO::print(out, "source=%s\n\n", spkg.get_source_directory()); - - IO::print(out, "Name: %s\n", spkg.get_label()); - IO::print(out, "Description: %s\n", spkg.get_description()); - IO::print(out, "Version: %s\n", spkg.get_version()); - - IO::print(out, "Requires:"); - 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(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(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", kvp.first, kvp.second); - out.put('\n'); - - return true; -} - -string PkgConfigGenerator::prefixify(const FS::Path &path, const FS::Path &prefix) -{ - if(FS::descendant_depth(path, prefix)>=0) - { - FS::Path rel_path = FS::relative(path, prefix); - return "${prefix}"+rel_path.str().substr(1); - } - else - return path.str(); -} diff --git a/plugins/builtin/pkgconfiggenerator.h b/plugins/builtin/pkgconfiggenerator.h deleted file mode 100644 index 2a0e0b1..0000000 --- a/plugins/builtin/pkgconfiggenerator.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef PKGCONFIGGENERATOR_H_ -#define PKGCONFIGGENERATOR_H_ - -#include - -class PkgConfigFile; - -class PkgConfigGenerator: public Tool -{ -public: - PkgConfigGenerator(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const PkgConfigFile &); - static std::string prefixify(const Msp::FS::Path &, const Msp::FS::Path &); -}; - -#endif diff --git a/plugins/builtin/tar.cpp b/plugins/builtin/tar.cpp deleted file mode 100644 index 4bac32a..0000000 --- a/plugins/builtin/tar.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "tar.h" -#include "tarball.h" - -using namespace std; -using namespace Msp; - -Tar::Tar(Builder &b): - Tool(b, "TAR") -{ - processing_unit = COMPONENT; - set_run_internal(&_run); -} - -Target *Tar::create_target(const vector &sources, const string &arg) -{ - if(sources.empty() || !sources.front()->get_package()) - throw invalid_argument("Tar::create_target"); - - TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg); - for(Target *s: sources) - tarball->add_dependency(*s); - - tarball->set_tool(*this); - - return tarball; -} - -bool Tar::_run(const TarBall &tarball) -{ - const FS::Path &pkg_src = tarball.get_package()->get_source_directory(); - FS::Path basedir = FS::basepart(FS::basename(tarball.get_path())); - - IO::File out(tarball.get_path().str(), IO::M_WRITE); - for(Target *d: tarball.get_dependencies()) - { - FileTarget *ft = dynamic_cast(d); - if(!ft) - continue; - - char buf[4096]; - memset(buf, 0, 512); - - string rel_path = (basedir/relative(ft->get_path(), pkg_src)).str(); - if(rel_path.size()>99) - { - IO::print("Can't store %s in tar archive - too long name\n", rel_path); - return false; - } - - memcpy(buf, rel_path.data(), rel_path.size()); - - FS::Stat st = FS::stat(ft->get_path()); - store_number(buf+100, 0666, 7); - store_number(buf+108, 0, 7); - store_number(buf+116, 0, 7); - store_number(buf+124, st.get_size(), 11); - store_number(buf+136, st.get_modify_time().to_unixtime(), 11); - buf[156] = '0'; - - memset(buf+148, ' ', 8); - unsigned chk = 0; - for(unsigned j=0; j<512; ++j) - chk += static_cast(buf[j]); - store_number(buf+148, chk, 7); - buf[155] = 0; - - out.write(buf, 512); - IO::File in(ft->get_path().str()); - for(unsigned j=0; j - -class TarBall; - -class Tar: public Tool -{ -public: - Tar(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const TarBall &); - static void store_number(char *, unsigned, unsigned); -}; - -#endif diff --git a/plugins/builtin/tarball.cpp b/plugins/builtin/tarball.cpp deleted file mode 100644 index 0b2d481..0000000 --- a/plugins/builtin/tarball.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "tar.h" -#include "tarball.h" - -using namespace std; - -TarBall::TarBall(Builder &b, const SourcePackage &p, const string &n): - FileTarget(b, p, p.get_source_directory()/(n+".tar")) -{ } - -const SourcePackage *TarBall::get_package() const -{ - return static_cast(package); -} diff --git a/plugins/builtin/tarball.h b/plugins/builtin/tarball.h deleted file mode 100644 index f63840e..0000000 --- a/plugins/builtin/tarball.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef TARBALL_H_ -#define TARBALL_H_ - -#include - -class TarBall: public FileTarget -{ -public: - TarBall(Builder &, const SourcePackage &, const std::string &); - - const char *get_type() const override { return "TarBall"; } - const SourcePackage *get_package() const; -}; - -#endif diff --git a/plugins/builtin/vcxprojectfile.cpp b/plugins/builtin/vcxprojectfile.cpp deleted file mode 100644 index 3ec7da1..0000000 --- a/plugins/builtin/vcxprojectfile.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include -#include "vcxprojectfile.h" - -using namespace Msp; - -VcxProjectFile::VcxProjectFile(Builder &b, const SourcePackage &p): - FileTarget(b, p, p.get_source_directory()/(p.get_name()+".vcxproj")) -{ - tool = &builder.get_toolchain().get_tool("VCXG"); - - char digest[16]; - Crypto::MD5(package->get_name()).get_digest(digest, sizeof(digest)); - digest[6] = 3; - digest[8] = (digest[6]&0x3F)|0x80; - for(unsigned j=0; j(digest[j])); - } -} diff --git a/plugins/builtin/vcxprojectfile.h b/plugins/builtin/vcxprojectfile.h deleted file mode 100644 index 1f85d0e..0000000 --- a/plugins/builtin/vcxprojectfile.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VCXPROJECTFILE_H_ -#define VCXPROJECTFILE_H_ - -#include - -class VcxProjectFile: public FileTarget -{ -private: - std::string guid; - -public: - VcxProjectFile(Builder &, const SourcePackage &); - - const char *get_type() const override { return "VcxProjectFile"; } - - const std::string &get_guid() const { return guid; } -}; - -#endif diff --git a/plugins/builtin/vcxprojectgenerator.cpp b/plugins/builtin/vcxprojectgenerator.cpp deleted file mode 100644 index 7cb9faf..0000000 --- a/plugins/builtin/vcxprojectgenerator.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "vcxprojectfile.h" -#include "vcxprojectgenerator.h" - -using namespace std; -using namespace Msp; - -VcxProjectGenerator::VcxProjectGenerator(Builder &b): - Tool(b, "VCXG") -{ - set_run_internal(_run); -} - -Target *VcxProjectGenerator::create_target(const vector &, const string &) -{ - throw logic_error("Not implemented"); -} - -bool VcxProjectGenerator::_run(const VcxProjectFile &project) -{ - const SourcePackage &spkg = *project.get_package(); - Builder &builder = spkg.get_builder(); - - IO::BufferedFile out(project.get_path().str(), IO::M_WRITE); - IO::print(out, "\n"); - - IO::print(out, "\t\n"); - vector build_types = builder.get_build_types(); - const char *platforms[] = { "Win32", "x64" }; - for(const char *p: platforms) - for(const string &b: build_types) - { - IO::print(out, "\t\t\n", b, p); - IO::print(out, "\t\t\t%s\n", b); - IO::print(out, "\t\t\t%s\n", p); - IO::print(out, "\t\t\n"); - } - IO::print(out, "\t\n"); - - IO::print(out, "\t\n"); - IO::print(out, "\t\t15.0\n"); - IO::print(out, "\t\tMakeFileProj\n"); - IO::print(out, "\t\t{%s}\n", project.get_guid()); - IO::print(out, "\t\n"); - - IO::print(out, "\t\n"); - - const Executable *exe = 0; - for(const Target *t: builder.get_build_graph().get_target("world")->get_dependencies()) - if(t->get_package()==&spkg) - if((exe = dynamic_cast(t))) - break; - - const char *argv0 = Application::get_argv0(); - const string &toolchain = builder.get_current_arch().get_toolchain(); - 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, p, toolchain, b, builder.get_prefix()); - IO::print(out, "\t\n", b, p); - IO::print(out, "\t\tMakeFile\n"); - IO::print(out, "\t\t%s\n", base_cmd); - IO::print(out, "\t\t%s -c\n", base_cmd); - IO::print(out, "\t\t%s -B\n", base_cmd); - if(exe) - IO::print(out, "\t\t%s\n", exe->get_path()); - IO::print(out, "\t\n"); - } - - IO::print(out, "\t\n"); - - vector sources; - vector includes; - vector others; - BuildInfo build_info; - for(const auto &kvp: builder.get_build_graph().get_targets()) - if(kvp.second->get_package()==&spkg) - { - if(kvp.second->is_buildable()) - { - BuildInfo tgt_binfo; - kvp.second->collect_build_info(tgt_binfo); - build_info.update_from(tgt_binfo, BuildInfo::CHAINED); - } - else if(const FileTarget *file = dynamic_cast(kvp.second)) - { - if(dynamic_cast(file)) - { - string ext = tolower(FS::extpart(FS::basename(file->get_path()))); - if(ext==".h" || ext==".hpp") - includes.push_back(file); - else - sources.push_back(file); - } - else - others.push_back(file); - } - } - - if(!build_info.incpath.empty()) - { - IO::print(out, "\t\n"); - string path_str; - for(const FS::Path &p: build_info.incpath) - append(path_str, ";", p.str()); - IO::print(out, "\t\t%s\n", path_str); - IO::print(out, "\t\n"); - } - - IO::print(out, "\t\n"); - for(const FileTarget *s: sources) - IO::print(out, "\t\t\n", s->get_path()); - IO::print(out, "\t\n"); - - IO::print(out, "\t\n"); - for(const FileTarget *i: includes) - IO::print(out, "\t\t\n", i->get_path()); - IO::print(out, "\t\n"); - - IO::print(out, "\t\n"); - for(const FileTarget *t: others) - IO::print(out, "\t\t\n", t->get_path()); - IO::print(out, "\t\n"); - - IO::print(out, "\t\n"); - IO::print(out, "\n"); - - return true; -} diff --git a/plugins/builtin/vcxprojectgenerator.h b/plugins/builtin/vcxprojectgenerator.h deleted file mode 100644 index ce96a54..0000000 --- a/plugins/builtin/vcxprojectgenerator.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VCXPROJECTGENERATOR_H_ -#define VCXPROJECTGENERATOR_H_ - -#include - -class VcxProjectFile; - -class VcxProjectGenerator: public Tool -{ -public: - VcxProjectGenerator(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const VcxProjectFile &); -}; - -#endif diff --git a/plugins/builtin/vssolutionfile.cpp b/plugins/builtin/vssolutionfile.cpp deleted file mode 100644 index 38908df..0000000 --- a/plugins/builtin/vssolutionfile.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include "vssolutionfile.h" - -using namespace std; -using namespace Msp; - -VsSolutionFile::VsSolutionFile(Builder &b, const SourcePackage &p): - FileTarget(b, p, p.get_source_directory()/(p.get_name()+".sln")) -{ - tool = &builder.get_toolchain().get_tool("VSSG"); -} - -void VsSolutionFile::find_dependencies() -{ - find_dependencies(*package); -} - -void VsSolutionFile::find_dependencies(const SourcePackage &spkg) -{ - if(FileTarget *project = builder.get_vfs().get_target(spkg.get_source_directory()/(spkg.get_name()+".vcxproj"))) - if(!any_equals(depends, static_cast(project))) - { - add_dependency(*project); - - for(const Package *r: spkg.get_required_packages()) - if(const SourcePackage *s = dynamic_cast(r)) - find_dependencies(*s); - } -} diff --git a/plugins/builtin/vssolutionfile.h b/plugins/builtin/vssolutionfile.h deleted file mode 100644 index 2c1e602..0000000 --- a/plugins/builtin/vssolutionfile.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef VSSOLUTIONFILE_H_ -#define VSSOLUTIONFILE_H_ - -#include - -class VsSolutionFile: public FileTarget -{ -public: - VsSolutionFile(Builder &, const SourcePackage &); - - const char *get_type() const override { return "VsSolutionFile"; } -protected: - void find_dependencies() override; - void find_dependencies(const SourcePackage &); -}; - -#endif diff --git a/plugins/builtin/vssolutiongenerator.cpp b/plugins/builtin/vssolutiongenerator.cpp deleted file mode 100644 index 60602e1..0000000 --- a/plugins/builtin/vssolutiongenerator.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include -#include -#include "vcxprojectfile.h" -#include "vssolutionfile.h" -#include "vssolutiongenerator.h" - -using namespace std; -using namespace Msp; - -VsSolutionGenerator::VsSolutionGenerator(Builder &b): - Tool(b, "VSSG") -{ - set_run_internal(_run); -} - -Target *VsSolutionGenerator::create_target(const vector &, const string &) -{ - throw logic_error("Not implemented"); -} - -bool VsSolutionGenerator::_run(const VsSolutionFile &solution) -{ - const SourcePackage &spkg = *solution.get_package(); - Builder &builder = spkg.get_builder(); - - IO::BufferedFile out(solution.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"); - - vector projects; - for(const Target *t: solution.get_dependencies()) - if(const VcxProjectFile *project = dynamic_cast(t)) - projects.push_back(project); - - for(const VcxProjectFile *p: projects) - { - const SourcePackage *pkg = p->get_package(); - IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n", - pkg->get_name(), p->get_path(), p->get_guid()); - } - - vector build_types = builder.get_build_types(); - const char *platforms[] = { "x86", "x64" }; - - IO::print(out, "Global\n"); - IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n"); - 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(const VcxProjectFile *p: projects) - for(const string &t: build_types) - for(const char *f: platforms) - { - 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"); - - return true; -} diff --git a/plugins/builtin/vssolutiongenerator.h b/plugins/builtin/vssolutiongenerator.h deleted file mode 100644 index c98fcb2..0000000 --- a/plugins/builtin/vssolutiongenerator.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VSSOLUTIONGENERATOR_H_ -#define VSSOLUTIONGENERATOR_H_ - -#include - -class VsSolutionFile; - -class VsSolutionGenerator: public Tool -{ -public: - VsSolutionGenerator(Builder &); - - Target *create_target(const std::vector &, const std::string &) override; - -private: - static bool _run(const VsSolutionFile &); -}; - -#endif diff --git a/source/lib/builder.cpp b/source/lib/builder.cpp index 77d0872..53b9efb 100644 --- a/source/lib/builder.cpp +++ b/source/lib/builder.cpp @@ -15,7 +15,6 @@ #include "android/androidtools.h" #include "binarypackage.h" #include "builder.h" -#include "builtin/builtintools.h" #include "datafile/datatool.h" #include "installedfile.h" #include "package.h" @@ -145,7 +144,6 @@ void Builder::add_default_tools() { if(current_arch->get_system()=="android") toolchain.add_toolchain(new AndroidTools(*this, *current_arch)); - toolchain.add_toolchain(new BuiltinTools(*this)); toolchain.add_tool(new DataTool(*this)); for(const LoadedPlugin &p: plugins) p.plugin->add_tools(toolchain, *current_arch); diff --git a/source/lib/sourcepackage.cpp b/source/lib/sourcepackage.cpp index 014bd83..dfbf16e 100644 --- a/source/lib/sourcepackage.cpp +++ b/source/lib/sourcepackage.cpp @@ -9,18 +9,14 @@ #include "binarycomponent.h" #include "binarypackage.h" #include "builder.h" -#include "builtin/compilecommandsjson.h" #include "datafile/datapackcomponent.h" #include "file.h" #include "installcomponent.h" -#include "builtin/pkgconfigfile.h" #include "plugin.h" #include "sourcearchivecomponent.h" #include "sourcegenerator.h" #include "sourcepackage.h" #include "tool.h" -#include "builtin/vcxprojectfile.h" -#include "builtin/vssolutionfile.h" using namespace std; using namespace Msp; @@ -136,29 +132,14 @@ void SourcePackage::do_prepare() for(Component *c: components) c->create_targets(); - const Architecture &arch = builder.get_native_arch(); if(!export_binfo.libs.empty()) { export_binfo.incpath.push_back((builder.get_prefix()/"include").str()); export_binfo.libpath.push_back((builder.get_prefix()/"lib").str()); - - if(arch.get_system()=="linux") - { - PkgConfigFile *pc = new PkgConfigFile(builder, *this); - builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc)); - } } export_binfo.standards = build_info.standards; - if(arch.get_system()=="windows") - { - new VcxProjectFile(builder, *this); - new VsSolutionFile(builder, *this); - } - - new CompileCommandsJson(builder, *this); - builder.call_plugins([this](const Plugin &p){ p.create_targets(*this); }); }