Commits

Anonymous committed b96dd23

Beginnings of a link farm for shared objects. Scary stuff...

Comments (0)

Files changed (2)

   echo "error: TOOLSHELF does not refer to a valid directory"
 else
   export PATH="$TOOLSHELF/.toolshelf/bin:$TOOLSHELF/.bin:$PATH"
+  export LD_LIBRARY_PATH="$TOOLSHELF/.lib:$LD_LIBRARY_PATH"
 
   # `toolshelf` itself can't change the shell's idea of the current working
   # directory, but a shell function can utilize `toolshelf` to do so.  Since
 
 TOOLSHELF = os.environ.get('TOOLSHELF')
 
-# TODO: there will eventually be multiple link farms (.lib, etc)
-LINK_FARM_DIR = os.path.join(TOOLSHELF, '.bin')
+BIN_LINK_FARM_DIR = os.path.join(TOOLSHELF, '.bin')
+LIB_LINK_FARM_DIR = os.path.join(TOOLSHELF, '.lib')
 
 # TODO: these should be regexes
 UNINTERESTING_EXECUTABLES = (
     'build-cygwin.sh', 'make-cygwin.sh', 'install-cygwin.sh',
     'build.pl', 'make.pl', 'install.pl', 'test.pl',
     'configure', 'config.status', 'config.sub', 'config.guess',
-    'missing', 'mkinstalldirs', 'install-sh', 'autogen.sh',
+    'missing', 'mkinstalldirs', 'install-sh', 'autogen.sh', 'ltmain.sh',
+    '.gitignore', '__init__.py', 'setup.py',
+    'Makefile', 'make-bindist.sh', 'index.html',
+    'run', 'runme', 'buildme', 'compile',
     # these executables are not considered "interesting" because if you happen
     # to dock a source which builds an executable by one of these names and
     # toolshelf puts it on the path, you may just have a *wee* problem when
     basename = os.path.basename(filename)
     if basename in UNINTERESTING_EXECUTABLES:
         return False
+    if basename.endswith('.so'):
+        return False
     return os.path.isfile(filename) and os.access(filename, os.X_OK)
 
 
+def is_shared_object(filename):
+    match = re.match('^.*?\.so$', filename)
+    return os.path.isfile(filename) and match and os.access(filename, os.X_OK)
+
+
 def run(*args, **kwargs):
     note("Running `%s`..." % ' '.join(args))
     subprocess.check_call(args, **kwargs)
 
     def create_link(self, filename):
         filename = os.path.abspath(filename)
-        linkname = os.path.basename(filename)
-        linkname = os.path.join(self.dirname, linkname)
+        linkname = os.path.join(self.dirname, os.path.basename(filename))
         # We do trample existing links
         if os.path.islink(linkname):
+            note("Trampling existing link %s" % linkname)
             os.unlink(linkname)
         symlink(filename, linkname)
 
                     return False
         return True
 
-    def linkable_executables(self):
+    def linkable_files(self, predicate):
         for root, dirs, files in os.walk(self.dir):
             if '.git' in dirs:
                 dirs.remove('.git')
                 continue
             for name in files:
                 filename = os.path.join(self.dir, root, name)
-                if is_executable(filename):
+                if predicate(filename):
                     note("    %s" % filename)
                     yield filename
 
 
 class Toolshelf(object):
     def __init__(self, options=DefaultOptions(), cookies=None,
-                       link_farm=LinkFarm(LINK_FARM_DIR), errors=None):
+                       bin_link_farm=LinkFarm(BIN_LINK_FARM_DIR),
+                       lib_link_farm=LinkFarm(LIB_LINK_FARM_DIR),
+                       errors=None):
         self.options = options
         if cookies is None:
             cookies = Cookies()
                 TOOLSHELF, '.toolshelf', 'local-cookies.catalog'
             ))
         self.cookies = cookies
-        self.link_farm = link_farm
+        self.bin_link_farm = bin_link_farm
+        self.lib_link_farm = lib_link_farm
         if errors is None:
             errors = {}
         self.errors = errors
         sources = self.make_sources_from_specs(specs)
         note("Adding the following executables to your link farm...")
         for source in sources:
-            self.link_farm.clean(prefix=source.dir)
-            for filename in source.linkable_executables():
-                self.link_farm.create_link(filename)
+            self.bin_link_farm.clean(prefix=source.dir)
+            for filename in source.linkable_files(is_executable):
+                self.bin_link_farm.create_link(filename)
+            self.lib_link_farm.clean(prefix=source.dir)
+            for filename in source.linkable_files(is_shared_object):
+                self.lib_link_farm.create_link(filename)
     
     def disable(self, args):
         specs = expand_docked_specs(args, default_all=True)
         sources = self.make_sources_from_specs(specs)
         for source in sources:
-            self.link_farm.clean(prefix=source.dir)
+            self.bin_link_farm.clean(prefix=source.dir)
+            self.lib_link_farm.clean(prefix=source.dir)
     
     def show(self, args):
         specs = expand_docked_specs(args, default_all=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.