Unverified Commit 59490e07 authored by Cole's avatar Cole Committed by GitHub
Browse files

Merge pull request #11 from chrisryancombs/cmake

Added scripts from svn repo
parents a1bef2fa aceb13f2
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!-- 

This stylesheet will be used to generate a Makefile for turning documentation inlined in the Documentation XML file
into an HTML page

Author
Deborah Lee Soltesz
12/04/2002

-->

<xsl:param name="dirParam"/>

<xsl:output indent="no" omit-xml-declaration="yes">
  <xsl:template match="/">
     <xsl:apply-templates select="documentation" />
  </xsl:template>
</xsl:output>

<!-- the following template contains very little whitespace to
     avoid adding spaces at the beginnings of the Makefile macro 
     lines:  trying to make this template more "readable" will
     likely break the system -->

<xsl:template name="document" match="documentation">

# Set up Xalan's command-line option names.
XALAN := XALAN_BIN_LOCATION
XALAN_VALIDATE_OPTION := -v
XALAN_OUTFILE_OPTION := -o
XALAN_PARAM_OPTION := -p
XALAN_INFILE_OPTION :=
XALAN_XSL_OPTION :=

docs:
<xsl:text>	</xsl:text>echo "          Constructing [<xsl:value-of select="$dirParam"/>]"
<xsl:for-each select="files/file"><xsl:if test="body"><xsl:choose>
<xsl:when test="@primary = 'true'"><xsl:text>	</xsl:text>$(XALAN)  $(XALAN_PARAM_OPTION) menuPath "'../../'" $(XALAN_PARAM_OPTION) filenameParam "'<xsl:value-of select="normalize-space(source/filename)"/>'" $(XALAN_OUTFILE_OPTION) <xsl:value-of select="normalize-space(source/filename)"/><xsl:text> $(XALAN_INFILE_OPTION) </xsl:text><xsl:value-of select="$dirParam"/>.xml $(XALAN_XSL_OPTION) ../../build/IsisPrimaryPageBuild.xsl</xsl:when>
<xsl:otherwise><xsl:text>	</xsl:text>$(XALAN) $(XALAN_PARAM_OPTION) menuPath "'../../'" $(XALAN_PARAM_OPTION) filenameParam "'<xsl:value-of select="normalize-space(source/filename)"/>'" $(XALAN_OUTFILE_OPTION) <xsl:value-of select="normalize-space(source/filename)"/><xsl:text> $(XALAN_INFILE_OPTION) </xsl:text><xsl:value-of select="$dirParam"/>.xml  $(XALAN_XSL_OPTION) ../../build/IsisSubPageBuild.xsl</xsl:otherwise>
</xsl:choose>
<xsl:text>&#xa;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
+645 −0

File added.

Preview size limit exceeded, changes collapsed.

+119 −0
Original line number Diff line number Diff line

''' This script will replace all "long" library paths such as
@rpath/a/long/path/libExample.dylib with shortened paths such as
@rpath/libExample.dylib. It does not change the rpaths themselves,
just the references to them.
'''

import os, sys, subprocess, stat

def fixOneFile(inputPath, resetRpath):
    '''Correct a single file'''

    # Get list of libraries loaded by this library
    cmd = ['otool', '-l', inputPath]
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    otoolOutput, err = p.communicate()

    #print otoolOutput

    # Search for abs paths to the USGS hard coded location
    needRpath  = False
    lines      = otoolOutput.split()
    numUpdates = 0
    for line in lines:

        # Keep track of whether the next change step is for an ID or a LOAD operation.
        if line == 'LC_ID_DYLIB':
            idLine = True
        if line == 'LC_LOAD_DYLIB':
            idLine = False

        # Only change lines containing @rpath
        if '@rpath' not in line:
            continue

        # Trim off just the library name and prepend @rpath
        #print line
        if 'framework' in line: # Need whole framework part
            posF = line.rfind('framework')
            pos  = line.rfind('/', 0, posF)
        else: # Simple case
            pos = line.rfind('/')
        end = line[pos:]

        #print 'CROPPED: ' + end
        #continue

        newPath = '@rpath' + end

        if newPath == line: # Skip already correct lines
            continue

        # Replace the line
        if idLine: # Handle LC_ID_DYLIB lines
            cmd = ' '.join(['install_name_tool', '-id', newPath, inputPath])
        else: # Handle LC_LOAD_DYLIB lines
            cmd = ' '.join(['install_name_tool', '-change', line, newPath, inputPath])
        #print cmd
        os.system(cmd)
        numUpdates += 1

    # TODO: Delete any existing rpaths to keep things clean!
    # If this option is set, reset the RPATH to look only in the local folder.
    if resetRpath:
        cmd = 'install_name_tool -add_rpath ./ ' + inputPath
        #print cmd
        os.system(cmd)
        numUpdates += 1

    return numUpdates

def main():
    '''Main program corrects all files in a folder'''

    # Check input arguments
    usage = 'python finalizeInstalledOsxRpaths.py folder [resetRpath]'
    if len(sys.argv) < 2:
        print usage
        return -1

    inputFolder= sys.argv[1]
    resetRpath = False
    if len(sys.argv) == 3:
        resetRpath = True
    if not os.path.exists(inputFolder):
        print 'Input folder '+inputFolder+' does not exist!'
        return -1

    # Fix all of the .dylib files in the given folder
    files = os.listdir(inputFolder)
    for f in files:

      fullPath = os.path.join(inputFolder, f)
 
      isBinary = (os.path.isfile(fullPath) and (stat.S_IXUSR & os.stat(fullPath)[stat.ST_MODE]))
      isLib    = ('.dylib' in f)
      isFrame  = 'framework' in f

      # Dig into framework folders to correct the rpaths in the underlying lib file
      if isFrame:
          name     = f.replace('.framework', '')
          path     = f+'/Versions/Current/'+name
          fullPath = os.path.join(inputFolder, path)
          isLib    = True
  
      if isBinary or isLib:
          #print fullPath
          numUpdates = fixOneFile(fullPath, resetRpath)
          print f + ' --> ' + str(numUpdates) + ' changes made.' 
          #raise Exception('DEBUG')

    

# Execute main() when called from command line
if __name__ == "__main__":
    sys.exit(main())


+109 −0
Original line number Diff line number Diff line

# TODO: Clean up this file!

import os, sys, subprocess

# Constants


libFolders = ['/Users/smcmich1/isis_cmake/opt/usgs/v006/3rdParty/lib', 
              '/Users/smcmich1/isis_cmake/opt/usgs/v006/ports/lib',
              '/Users/smcmich1/isis_cmake/opt/usgs/v006/ports/libexec']
#individualLibs = ['/Users/smcmich1/isis_cmake//opt/usgs/v006/ports/libexec/qt5/lib/QtCore.framework/Versions/5/QtCore']

qtLibs = ('QtXmlPatterns QtXml QtNetwork '+
                 'QtSql QtGui QtCore QtSvg '+
                 'QtTest QtWebKit QtOpenGL '+
                 'QtConcurrent QtDBus '+
                 'QtMultimedia QtMultimediaWidgets '+
                 'QtNfc QtPositioning QtPrintSupport '+
                 'QtQml QtQuick QtQuickParticles '+
                 'QtQuickTest QtQuickWidgets QtScript '+
                 'QtScriptTools QtSensors QtSerialPort '+
                 'QtWebKitWidgets QtWebSockets QtWidgets '+
                 'QtTest QtWebChannel QtWebEngine QtWebEngineCore QtWebEngineWidgets').split()
individualLibs = ['/Users/smcmich1/isis_cmake//opt/usgs/v006/ports/libexec/qt5/lib/'+x+'.framework/Versions/5/'+x for x in qtLibs]
print individualLibs

usgFolder = '/opt/usgs/v006/'

rpathFolder = '/Users/smcmich1/isis_cmake/'
ignoreFolder = '/Users/smcmich1/isis_cmake/'


# Process one file

def fixFile(fullPath, libName):
    '''Fix the paths of a single library file'''

    # Get list of libraries loaded by this library
    cmd = ['otool', '-l', fullPath]
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    otoolOutput, err = p.communicate()

    #print otoolOutput

    # Search for abs paths to the USGS hard coded location
    needRpath = False
    lines     = otoolOutput.split()
    for line in lines:

        # Some lines need to be skipped
        if (usgFolder not in line) or (ignoreFolder in line) or ('@rpath' in line):
            continue

        needRpath = True

        # Set up the command to fix this line
        if libName in line: # Hande LC_ID_DYLIB lines
            cmd = ' '.join(['install_name_tool', '-id', '@rpath'+line, fullPath])
        else: # Handle LC_LOAD_DYLIB lines
            cmd = ' '.join(['install_name_tool', '-change', line, '@rpath'+line, fullPath])
        print cmd
        os.system(cmd)

    # If any paths were changed, add the rpath.
    if needRpath:
        # Make sure this rpath is not there
        cmd = ' '.join(['install_name_tool', '-delete_rpath', '/opt/usgs/v006/ports/lib', fullPath])
        print cmd
        os.system(cmd)
        # Add the correct rpath
        cmd = ' '.join(['install_name_tool', '-add_rpath', rpathFolder, fullPath])
        print cmd
        os.system(cmd)
        print 'Fixed file ' + fullPath

# Main function

for folder in libFolders:

    libs = os.listdir(folder)
    for lib in libs:
    
        # Only modify .dylib files
        if 'dylib' not in lib:
            continue
        
        # Get the full path
        fullPath = os.path.join(folder, lib)
        #print lib
        
        fixFile(fullPath, lib)
 

for fullPath in individualLibs:

    ## Only modify .dylib files
    #if 'dylib' not in lib:
    #    continue

    # Get the full path
    libName = os.path.basename(fullPath)
    #print lib

    fixFile(fullPath, libName)

print 'Finished modifying files!'