X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flib%2Fcomponent.cpp;h=c12a5a8c604916a3777d8a783afe976b4e90177a;hb=17783446dddb1a60c5174031c97b13e4d1bc1f8e;hp=4fddcef79de59a9ca0ca6cf05e8a5b71ec565a79;hpb=c8e829c219c65ff8e93b6c7b66212ff0876441c5;p=builder.git diff --git a/source/lib/component.cpp b/source/lib/component.cpp index 4fddcef..c12a5a8 100644 --- a/source/lib/component.cpp +++ b/source/lib/component.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "builder.h" #include "component.h" #include "sourcepackage.h" @@ -13,16 +14,27 @@ using namespace Msp; void Component::prepare() { - for(Package *r: requires) + for(Package *r: required_pkgs) + { r->prepare(); + broken |= r->is_broken(); + } + + if(!problems.empty()) + broken = true; } void Component::create_build_info() { BuildInfo final_build_info; + string build_macro = toupper(name)+"_BUILD"; + for(char &c: build_macro) + if(!isalnum(static_cast(c))) + c = '_'; + final_build_info.defines[build_macro] = "1"; const Package::Requirements &pkg_reqs = package.get_required_packages(); - Package::Requirements direct_reqs = requires; + Package::Requirements direct_reqs = required_pkgs; direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end()); for(Package *r: direct_reqs) final_build_info.update_from(r->get_exported_build_info(), BuildInfo::DEPENDENCY); @@ -53,23 +65,33 @@ void Component::create_build_info() p = (package.get_source_directory()/p).str(); } +FS::Path Component::get_temp_directory() const +{ + return package.get_temp_directory()/name; +} + +string Component::flatten_source_path(const FS::Path &source) const +{ + FS::Path temp_dir = get_temp_directory(); + FS::Path rel_src; + if(FS::descendant_depth(source, temp_dir)>=0) + rel_src = FS::relative(source, temp_dir); + else + rel_src = FS::relative(source, package.get_source_directory()); + + string fn; + for(const string &c: rel_src) + if(c!=".") + append(fn, "_", c); + + return fn; +} + BuildInfo Component::get_build_info_for_path(const FS::Path &path) const { // XXX Cache these and check that the directories actually exist before adding them BuildInfo binfo = build_info; - FS::Path gen_dir = package.get_temp_directory()/"generated"; - if(FS::descendant_depth(path, gen_dir)>=0) - { - FS::Path subdir = FS::dirname(FS::relative(path, gen_dir)); - binfo.local_incpath.push_back(package.get_source_directory()/subdir); - } - else - { - FS::Path subdir = FS::dirname(FS::relative(path, package.get_source_directory())); - binfo.local_incpath.push_back(gen_dir/subdir); - } - if(!overlays.empty()) { FS::Path dir = FS::dirname(path); @@ -169,12 +191,15 @@ void Component::Loader::require(const string &n) { Package *req = obj.package.get_builder().get_package_manager().find_package(n); if(req) - obj.requires.push_back(req); + obj.required_pkgs.push_back(req); else obj.problems.push_back(format("Required package %s not found", n)); } void Component::Loader::source(const string &s) { - obj.sources.push_back((obj.package.get_source_directory()/s).str()); + FS::Path src_path = obj.package.get_source_directory()/s; + if(!FS::exists(src_path)) + throw IO::file_not_found(src_path.str()); + obj.sources.push_back(src_path); }