]> git.tdb.fi Git - builder.git/commitdiff
Add a feature for overlay source directories
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Apr 2013 10:03:30 +0000 (13:03 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 24 Apr 2013 10:03:30 +0000 (13:03 +0300)
This allows separation of architecture- or feature-specific source files
in their own directories.

bootstrap.sh
source/component.cpp
source/component.h
source/installmap.cpp
source/objectfile.cpp

index 70d032399886d10d9bd983342a426e47866be271..5cb40121f4fae3a03d9dac81201259850390a538 100755 (executable)
@@ -61,7 +61,7 @@ for i in $REQUIRED; do
                else
                        ln -sf $path/source "$INCLUDEDIR/msp/$i"
                fi
-               sources="$sources `find $path/source -name '*.cpp'`"
+               sources="$sources `find $path/source \( -name windows -prune \) -o \( -name '*.cpp' -print \)`"
        fi
 done
 
@@ -72,6 +72,10 @@ if [ ! -z "$missing" ]; then
        exit 1
 fi
 
+for i in "$INCLUDEDIR/msp/"*/unix; do
+       CFLAGS="$CFLAGS -iquote $i -iquote ${i%/unix}"
+done
+
 echo "Compiling builder-stage1.  This may take several minutes."
 g++ $sources -o builder-stage1 $CFLAGS $LIBS
 echo "Using builder-stage1 to compile builder."
index 3b1f872ae92292529b845ab09e9b7b112763fa4f..566cf8896b3988553b9457be1996a455d252d064 100644 (file)
@@ -101,6 +101,32 @@ void Component::create_build_info()
        }
 }
 
+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;
+       if(!overlays.empty())
+       {
+               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;
+                       }
+
+               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);
+                       }
+       }
+       return binfo;
+}
+
 void Component::create_targets() const
 {
        Builder &builder = package.get_builder();
@@ -237,13 +263,32 @@ Component::SourceList Component::collect_source_files() const
                FS::Path path(*i);
                if(FS::is_dir(path))
                {
-                       package.get_builder().get_logger().log("files", format("Traversing %s", path));
-                       list<string> sfiles = list_files(path);
-                       for(list<string>::iterator j=sfiles.begin(); j!=sfiles.end(); ++j)
-                               files.push_back(path / *j);
+                       SourceList dirs;
+                       dirs.push_back(path);
+                       for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+                       {
+                               FS::Path opath = path / *j;
+                               if(FS::is_dir(opath))
+                                       dirs.push_back(opath);
+                       }
+                       for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j)
+                       {
+                               package.get_builder().get_logger().log("files", format("Traversing %s", *j));
+                               list<string> sfiles = list_files(*j);
+                               for(list<string>::iterator k=sfiles.begin(); k!=sfiles.end(); ++k)
+                                       files.push_back(*j / *k);
+                       }
                }
                else
+               {
                        files.push_back(path);
+                       for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+                       {
+                               FS::Path opath = FS::dirname(path)/ *j/FS::basename(path);
+                               if(FS::is_reg(opath))
+                                       files.push_back(opath);
+                       }
+               }
        }
 
        return files;
@@ -255,6 +300,7 @@ Component::Loader::Loader(Component &c):
 {
        add("if_arch",         &Loader::if_arch);
        add("if_feature",      &Loader::if_feature);
+       add("overlay",         &Loader::overlay);
        add("source",          &Loader::source);
        add("install",         &Component::install);
        add("install_map",     &Loader::install_map);
@@ -292,6 +338,11 @@ void Component::Loader::install_map()
        load_sub(obj.install_map, obj.package.get_source_directory());
 }
 
+void Component::Loader::overlay(const string &o)
+{
+       obj.overlays.push_back(o);
+}
+
 void Component::Loader::require(const string &n)
 {
        Package *req = obj.package.get_builder().get_package_manager().find_package(n);
index 09767d37437fa8aa4f38a241e2c37a54d13307b8..3a743d0c41987324ab7da79818cab037059984e4 100644 (file)
@@ -28,6 +28,7 @@ public:
                void if_arch(const std::string &);
                void if_feature(const std::string &);
                void install_map();
+               void overlay(const std::string &);
                void require(const std::string &);
                void source(const std::string &);
                void use(const std::string &);
@@ -44,6 +45,7 @@ public:
        };
 
        typedef std::list<Msp::FS::Path> SourceList;
+       typedef std::list<std::string> OverlayList;
        typedef std::list<const Component *> UseList;
 
 protected:
@@ -51,6 +53,7 @@ protected:
        Type type;
        std::string name;
        SourceList sources;
+       OverlayList overlays;
        bool install;
        BuildInfo build_info;
        Package::Requirements requires;
@@ -69,6 +72,8 @@ public:
        directories or individual files. */
        const SourceList &get_sources() const { return sources; }
 
+       const OverlayList &get_overlays() const { return overlays; }
+
 protected:
        /** Returns a list of all source files for the component. */
        SourceList collect_source_files() const;
@@ -89,6 +94,8 @@ public:
 
        const BuildInfo &get_build_info() const { return build_info; }
 
+       BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
+
        void create_targets() const;
 };
 
index 22d92b1586751d96943dfe73b675a6d75c112318..942b932b98c29babf1fd0d59eb090d53cb1cda30 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/fs/utils.h>
+#include "component.h"
 #include "filetarget.h"
 #include "installmap.h"
 
@@ -15,6 +16,17 @@ void InstallMap::add_mapping(const FS::Path &src, const FS::Path &inst)
 
 FS::Path InstallMap::get_install_location(const FileTarget &target) const
 {
+       const Component *comp = target.get_component();
+       unsigned overlay_depth = 0;
+       if(comp && !comp->get_overlays().empty())
+       {
+               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;
+       }
+
        const FS::Path &source = target.get_path();
        FS::Path install = target.get_install_location();
        for(list<Entry>::const_iterator i=entries.begin(); i!=entries.end(); ++i)
@@ -25,7 +37,7 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const
                        FS::Path install_base = FS::common_ancestor(install, i->install);
                        if(install_base.size()>1)
                        {
-                               install = i->install/FS::dirname(source).subpath(i->source.size());
+                               install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth);
                                break;
                        }
                }
index 97e52552b8d553ae3d360245a56bd15a440efc91..321b954d4e96c59bbbdb9ae845465853a6e7da54 100644 (file)
@@ -65,6 +65,19 @@ void ObjectFile::find_dependencies(FileTarget *tgt)
                                FS::Path displaced = tgt->get_path()/FS::relative(file->get_path(), rtgt->get_path());
                                if(Target *ddep = builder.get_vfs().get_target(displaced))
                                        deps_to_add.push_back(ddep);
+                               else
+                               {
+                                       const Component *tcomp = file->get_component();
+                                       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);
+                                               }
+                               }
                        }
                        else
                                deps_to_add.push_back(*i);