Prepare Python scripts for building for Mac OSX.

This refs #4 and #6.
This commit is contained in:
Kazunari Sekigawa 2017-12-28 23:02:01 +09:00
parent 978ac4786e
commit 6e86ac77d3
2 changed files with 121 additions and 55 deletions

View File

@ -451,6 +451,9 @@ def DeployBinariesForBundle():
global AbsMacBuildDir global AbsMacBuildDir
global AbsMacBuildLog global AbsMacBuildLog
print("")
print( "##### Start deploying libraries and executables #####" )
print( "[1] Checking the status of working directory ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [1] Check the status of working directory # [1] Check the status of working directory
#------------------------------------------------------------- #-------------------------------------------------------------
@ -467,6 +470,8 @@ def DeployBinariesForBundle():
print( "!!! Binary directory <%s> does not present !!!" % MacBinDir, file=sys.stderr ) print( "!!! Binary directory <%s> does not present !!!" % MacBinDir, file=sys.stderr )
return(1) return(1)
print( "[2] Creating a new empty directory for deployment ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [2] Create a new empty directory for deploying binaries # [2] Create a new empty directory for deploying binaries
#------------------------------------------------------------- #-------------------------------------------------------------
@ -477,42 +482,46 @@ def DeployBinariesForBundle():
shutil.rmtree(MacPkgDir) shutil.rmtree(MacPkgDir)
os.mkdir(MacPkgDir) os.mkdir(MacPkgDir)
print( "[3] Creating the standard directory structure for a bundle ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [3] Create the directory skeleton for "klayout.app" bundle # [3] Create the directory skeleton for "klayout.app" bundle
# and command line buddy tools such as "strm2cif" # and command line buddy tools such as "strm2cif".
# that should look like... # They should be stored in a directory structure like...
# #
# klayout.app/+ # klayout.app/+
# +-- Contents/+ # +-- Contents/+
# +-- Info.plist # +-- Info.plist
# +-- MacOS/+
# +-- 'klayout'
# +-- PkgInfo # +-- PkgInfo
# +-- Resources/ # +-- Resources/
# +-- Frameworks/ # +-- Frameworks/
# +-- buddy_tool/+ # +-- MacOS/+
# +-- 'strm2cif' # | +-- 'klayout'
# +-- 'strm2dxf' # +-- Buddy/+
# : # +-- 'strm2cif'
# +-- 'strmxor' # +-- 'strm2dxf'
# :
# +-- 'strmxor'
#------------------------------------------------------------- #-------------------------------------------------------------
targetDir0 = "%s/klayout.app/Contents/" % AbsMacPkgDir targetDir0 = "%s/klayout.app/Contents" % AbsMacPkgDir
targetDir1 = targetDir0 + "MacOS/" targetDirR = targetDir0 + "/Resources"
targetDir2 = targetDir0 + "Resources/" targetDirF = targetDir0 + "/Frameworks"
targetDir3 = targetDir0 + "Frameworks/" targetDirM = targetDir0 + "/MacOS"
targetDir4 = targetDir0 + "buddy_tool/" targetDirB = targetDir0 + "/Buddy"
os.makedirs(targetDir1) os.makedirs(targetDirR)
os.makedirs(targetDir2) os.makedirs(targetDirF)
os.makedirs(targetDir3) os.makedirs(targetDirM)
os.makedirs(targetDir4) os.makedirs(targetDirB)
print( "[4] Copying KLayout's dynamic link libraries to 'Frameworks' ..." )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# [4] Copy KLayout's dynamic link libraries to "Frameworks/" and create # [4] Copy KLayout's dynamic link libraries to "Frameworks/" and create
# the library dependency dictionary. # the library dependency dictionary.
# <<< Do this job in "Frameworks/" >>> # <<< Do this job in "Frameworks/" >>>
# #
# Note: # Note:
# A dynamic link library is built as below: # KLayout's dynamic link library is built as below:
# (1) libklayout_lay.0.25.0.dylib # (1) libklayout_lay.0.25.0.dylib
# (2) libklayout_lay.0.25.dylib -> libklayout_lay.0.25.0.dylib # (2) libklayout_lay.0.25.dylib -> libklayout_lay.0.25.0.dylib
# (3) libklayout_lay.0.dylib -> libklayout_lay.0.25.0.dylib # (3) libklayout_lay.0.dylib -> libklayout_lay.0.25.0.dylib
@ -537,7 +546,7 @@ def DeployBinariesForBundle():
# libklayout_db.0.dylib (compatibility version 0.25.0, current version 0.25.0) # libklayout_db.0.dylib (compatibility version 0.25.0, current version 0.25.0)
# : # :
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
os.chdir( targetDir3 ) os.chdir( targetDirF )
dynamicLinkLibs = glob.glob( AbsMacBinDir + "/*.dylib" ) dynamicLinkLibs = glob.glob( AbsMacBinDir + "/*.dylib" )
depDicOrdinary = {} # inter-library dependency dictionary depDicOrdinary = {} # inter-library dependency dictionary
for item in dynamicLinkLibs: for item in dynamicLinkLibs:
@ -563,16 +572,22 @@ def DeployBinariesForBundle():
quit() quit()
''' '''
print( "[5] Setting and changing the identification names among KLayout's libraries ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [5] Set the identification names for KLayout's libraries # [5] Set the identification names for KLayout's libraries
# and make the library aware of the locations of libraries # and make the library aware of the locations of libraries
# on which it depends; that is, inter-library dependency # on which it depends; that is, inter-library dependency
#------------------------------------------------------------- #-------------------------------------------------------------
ret = SetChangeIdentificationNameOfDyLib( depDicOrdinary )
if not ret == 0:
msg = "!!! Failed to set and change to new identification names !!!"
print(msg)
return(1)
print( "[6] Copying built executables and resource files ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [6] Copy known some files in source directories to # [6] Copy some known files in source directories to
# relevant target directories # relevant target directories
#------------------------------------------------------------- #-------------------------------------------------------------
os.chdir(ProjectDir) os.chdir(ProjectDir)
@ -583,21 +598,23 @@ def DeployBinariesForBundle():
sourceDir4 = "%s" % MacBinDir sourceDir4 = "%s" % MacBinDir
shutil.copy2( sourceDir0 + "/Info.plist", targetDir0 ) shutil.copy2( sourceDir0 + "/Info.plist", targetDir0 )
shutil.copy2( sourceDir1 + "/klayout", targetDir1 ) shutil.copy2( sourceDir1 + "/klayout", targetDirM )
shutil.copy2( sourceDir2 + "/logo.png", targetDir2 ) shutil.copy2( sourceDir2 + "/logo.png", targetDirR )
shutil.copy2( sourceDir3 + "/logo.ico", targetDir2 ) shutil.copy2( sourceDir3 + "/logo.ico", targetDirR )
os.chmod( targetDir0 + "/Info.plist", 0644 ) os.chmod( targetDir0 + "/Info.plist", 0644 )
os.chmod( targetDir1 + "/klayout", 0755 ) os.chmod( targetDirM + "/klayout", 0755 )
os.chmod( targetDir2 + "/logo.png", 0644 ) os.chmod( targetDirR + "/logo.png", 0644 )
os.chmod( targetDir2 + "/logo.ico", 0644 ) os.chmod( targetDirR + "/logo.ico", 0644 )
buddies = glob.glob( sourceDir4 + "/strm*" ) buddies = glob.glob( sourceDir4 + "/strm*" )
for item in buddies: for item in buddies:
shutil.copy2( item, targetDir4 ) shutil.copy2( item, targetDirB )
buddy = os.path.basename(item) buddy = os.path.basename(item)
os.chmod( targetDir4 + buddy, 0755 ) os.chmod( targetDirB + "/" + buddy, 0755 )
print( "[7] Setting and changing the identification names of KLayout's libraries in each executable ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [7] Set and change the library identification name(s) of # [7] Set and change the library identification name(s) of
# different executables # different executables
@ -608,40 +625,48 @@ def DeployBinariesForBundle():
ret = SetChangeLibIdentificationName( klayoutexec, "../Frameworks" ) ret = SetChangeLibIdentificationName( klayoutexec, "../Frameworks" )
if not ret == 0: if not ret == 0:
os.chdir(ProjectDir) os.chdir(ProjectDir)
print( "!!! Failed to set/change library identification name for <%s> !!!" % klayoutexec, \ msg = "!!! Failed to set/change library identification name for <%s> !!!"
file=sys.stderr ) print( msg % klayoutexec, file=sys.stderr )
return(1) return(1)
buddies = glob.glob( "klayout.app/Contents/buddy_tool/strm*" ) buddies = glob.glob( "klayout.app/Contents/Buddy/strm*" )
macdepQtOpt = ""
for buddy in buddies: for buddy in buddies:
macdepQtOpt += "-executable=%s " % buddy
ret = SetChangeLibIdentificationName( buddy, "../Frameworks" ) ret = SetChangeLibIdentificationName( buddy, "../Frameworks" )
if not ret == 0: if not ret == 0:
os.chdir(ProjectDir) os.chdir(ProjectDir)
print( "!!! Failed to set/change library identification name for <%s> !!!" % buddy, \ msg = "!!! Failed to set/change library identification name for <%s> !!!"
file=sys.stderr ) print( msg % buddy, file=sys.stderr )
return(1) return(1)
print( "[8] Finally, deploying Qt's frameworks ..." )
#------------------------------------------------------------- #-------------------------------------------------------------
# [8] Deploying Applications on OS X including Qt frameworks # [8] Deploy Qt frameworks
#------------------------------------------------------------- #-------------------------------------------------------------
if ModuleQt == 'Qt4MacPorts': if ModuleQt == 'Qt4MacPorts':
deploytool = Qt4MacPorts['deploy'] deploytool = Qt4MacPorts['deploy']
app_bundle = "klayout.app" app_bundle = "klayout.app"
options = "-libpath=klayout.app/Contents/Frameworks" options = macdepQtOpt
elif ModuleQt == 'Qt5MacPorts': elif ModuleQt == 'Qt5MacPorts':
deploytool = Qt5MacPorts['deploy'] deploytool = Qt5MacPorts['deploy']
app_bundle = "klayout.app" app_bundle = "klayout.app"
options = "-libpath=klayout.app/Contents/Frameworks" options = macdepQtOpt
os.chdir(ProjectDir) os.chdir(ProjectDir)
os.chdir(MacPkgDir) os.chdir(MacPkgDir)
command = "%s %s %s" % ( deploytool, app_bundle, options ) command = "%s %s %s" % ( deploytool, app_bundle, options )
if subprocess.call( command, shell=True ) != 0: if subprocess.call( command, shell=True ) != 0:
print( "!!! Failed to deploy applications on OSX !!!", file=sys.stderr ) msg = "!!! Failed to deploy applications on OSX !!!"
print( msg, file=sys.stderr )
print("")
os.chdir(ProjectDir) os.chdir(ProjectDir)
return(1) return(1)
else: else:
print( "### Deployed applications on OS X ###", file=sys.stderr ) msg = "### Deployed applications on OS X ###"
print( msg, file=sys.stderr )
print("")
os.chdir(ProjectDir) os.chdir(ProjectDir)
return(0) return(0)

View File

@ -28,7 +28,7 @@ from build4mac_env import *
# #
# @param[in] depstr strings that tell dependency such as: # @param[in] depstr strings that tell dependency such as:
# #
# libklayout_edt.0.25.0.dylib: <=== key # libklayout_edt.0.dylib:
# libklayout_edt.0.dylib (compatibility version 0.25.0, current version 0.25.0) # libklayout_edt.0.dylib (compatibility version 0.25.0, current version 0.25.0)
# libklayout_tl.0.dylib (compatibility version 0.25.0, current version 0.25.0) # libklayout_tl.0.dylib (compatibility version 0.25.0, current version 0.25.0)
# libklayout_gsi.0.dylib (compatibility version 0.25.0, current version 0.25.0) # libklayout_gsi.0.dylib (compatibility version 0.25.0, current version 0.25.0)
@ -64,6 +64,45 @@ def PrintLibraryDependencyDictionary( depdic, namedic ):
for item in supporters: for item in supporters:
print( " %s" % item ) print( " %s" % item )
#------------------------------------------------------------------------------
## To set and change identification name of dylib
#
# @param[in] libdic inter-library dependency dictionary
#
# @return 0 on success; non-zero on failure
#------------------------------------------------------------------------------
def SetChangeIdentificationNameOfDyLib( libdic ):
cmdNameId = XcodeToolChain['nameID']
cmdNameChg = XcodeToolChain['nameCH']
dependentLibs = libdic.keys()
for lib in dependentLibs:
#-----------------------------------------------------------
# [1] Set the identification name of each dependent library
#-----------------------------------------------------------
nameOld = "%s" % lib
nameNew = "@executable_path/../Frameworks/%s" % lib
command = "%s %s %s" % ( cmdNameId, nameNew, nameOld )
if subprocess.call( command, shell=True ) != 0:
msg = "!!! Failed to set the new identification name to <%s> !!!"
print( msg % lib, file=sys.stderr )
return(1)
#-------------------------------------------------------------------------
# [2] Make the library aware of the new identifications of all supporters
#-------------------------------------------------------------------------
supporters = libdic[lib]
for sup in supporters:
nameOld = "%s" % sup
nameNew = "@executable_path/../Frameworks/%s" % sup
command = "%s %s %s %s" % ( cmdNameChg, nameOld, nameNew, lib )
if subprocess.call( command, shell=True ) != 0:
msg = "!!! Failed to make the library aware of the new identification name <%s> of supporter <%s> !!!"
print( msg % (nameNew, sup), file=sys.stderr )
return(1)
# for-lib
return(0)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
## To set the identification names of KLayout's libraries to an executable ## To set the identification names of KLayout's libraries to an executable
# and make the application aware of the library locations # and make the application aware of the library locations
@ -77,16 +116,16 @@ def PrintLibraryDependencyDictionary( depdic, namedic ):
# klayout.app/+ # klayout.app/+
# +-- Contents/+ # +-- Contents/+
# +-- Info.plist # +-- Info.plist
# +-- MacOS/+
# +-- 'klayout'
# +-- PkgInfo # +-- PkgInfo
# +-- Resources/ # +-- Resources/
# +-- Frameworks/ # +-- Frameworks/
# +-- buddy_tool/+ # +-- MacOS/+
# +-- 'strm2cif' # | +-- 'klayout'
# +-- 'strm2dxf' # +-- Buddy/+
# : # +-- 'strm2cif'
# +-- 'strmxor' # +-- 'strm2dxf'
# :
# +-- 'strmxor'
# #
# @return 0 on success; non-zero on failure # @return 0 on success; non-zero on failure
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -98,28 +137,30 @@ def SetChangeLibIdentificationName( executable, relativedir ):
exedepdic = DecomposeLibraryDependency( executable + ":\n" + otoolOut ) exedepdic = DecomposeLibraryDependency( executable + ":\n" + otoolOut )
keys = exedepdic.keys() keys = exedepdic.keys()
deplibs = exedepdic[ keys[0] ] deplibs = exedepdic[ keys[0] ]
for lib in deplibs: for lib in deplibs:
#----------------------------------------------------------- #-----------------------------------------------------------
# (A) Set the identification names for the library # [1] Set the identification names for the library
#----------------------------------------------------------- #-----------------------------------------------------------
nameOld = "klayout.app/Contents/Frameworks/%s" % lib nameOld = "klayout.app/Contents/Frameworks/%s" % lib
nameNew = "@executable_path/%s/%s" % ( relativedir, lib ) nameNew = "@executable_path/%s/%s" % ( relativedir, lib )
command = "%s %s %s" % ( cmdNameId, nameNew, nameOld ) command = "%s %s %s" % ( cmdNameId, nameNew, nameOld )
if subprocess.call( command, shell=True ) != 0: if subprocess.call( command, shell=True ) != 0:
print( "!!! Failed to set the new identification name to <%s> !!!" % lib, \ msg = "!!! Failed to set the new identification name to <%s> !!!"
file=sys.stderr ) print( msg % lib, file=sys.stderr )
return(1) return(1)
#----------------------------------------------------------- #-----------------------------------------------------------
# (B) Make the application aware of the new identification # [2] Make the application aware of the new identification
#----------------------------------------------------------- #-----------------------------------------------------------
nameOld = "%s" % lib nameOld = "%s" % lib
nameNew = "@executable_path/%s/%s" % ( relativedir, lib ) nameNew = "@executable_path/%s/%s" % ( relativedir, lib )
command = "%s %s %s %s" % ( cmdNameChg, nameOld, nameNew, executable ) command = "%s %s %s %s" % ( cmdNameChg, nameOld, nameNew, executable )
if subprocess.call( command, shell=True ) != 0: if subprocess.call( command, shell=True ) != 0:
print( "!!! Failed to make the application aware of the new identification name <%s> !!!" % nameNew, \ msg = "!!! Failed to make the application aware of the new identification name <%s> !!!"
file=sys.stderr ) print( msg % nameNew, file=sys.stderr )
return(1) return(1)
# for-lib
return(0) return(0)
#---------------- #----------------