To arrange the contents of "Info.plist" file.

To generate two script bundles: KLayoutEditor.app & KLayoutViewer.app.

This refs #6.
This commit is contained in:
Kazunari Sekigawa 2017-12-31 21:22:32 +09:00
parent 65e9a1854a
commit 03222ee5c9
11 changed files with 288 additions and 17 deletions

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NOTE</key>
<string>This file was originally generated by Qt/QMake.</string>
<key>CFBundleGetInfoString</key>
<string>Created by Qt/QMake</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE}</string>
<key>CFBundleIconFile</key>
<string>${ICONFILE}</string>
<key>CFBundleIdentifier</key>
<string>de.klayout</string>
<key>CFBundleName</key>
<string>${BUNDLENAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>

View File

@ -0,0 +1,36 @@
#!/bin/bash
#-------------------------------------------------------------------------------------
# File: KLayoutEditor.sh
#
# Descriptions:
# This is to invoke "klayout" distributed as a binary package for Mac
# in "editor" mode.
#
# You may specify style and other options as you like by setting
# "opt_style" and "opt_others" variable in this script.
#-------------------------------------------------------------------------------------
#---------------------------------------------------------
# With "-n" option, multiple instances can be invoked
#---------------------------------------------------------
myKLayout="open -n -a /Applications/klayout.app --args "
#===================================================
# Pass command line parameters to klayout
# vvvvvvvvvv You may edit the block below vvvvvvvvvv
opt_mode="-e"
opt_style="-style=cleanlooks"
opt_others=""
# ^^^^^^^^^^ You may edit the block above ^^^^^^^^^^
#===================================================
options="$opt_mode $opt_style $opt_others"
targetfiles=$@
echo "### Starting KLayout in Editor mode..."
$myKLayout $options $targetfiles &
exit 0
#-------------------
# End of file
#-------------------

Binary file not shown.

View File

@ -0,0 +1,36 @@
#!/bin/bash
#-------------------------------------------------------------------------------------
# File: KLayoutViewer.sh
#
# Descriptions:
# This is to invoke "klayout" distributed as a binary package for Mac
# in "viewer" mode.
#
# You may specify style and other options as you like by setting
# "opt_style" and "opt_others" variable in this script.
#-------------------------------------------------------------------------------------
#---------------------------------------------------------
# With "-n" option, multiple instances can be invoked
#---------------------------------------------------------
myKLayout="open -n -a /Applications/klayout.app --args "
#===================================================
# Pass command line parameters to klayout
# vvvvvvvvvv You may edit the block below vvvvvvvvvv
opt_mode="-ne"
opt_style="-style=motif"
opt_others=""
# ^^^^^^^^^^ You may edit the block above ^^^^^^^^^^
#===================================================
options="$opt_mode $opt_style $opt_others"
targetfiles=$@
echo "### Starting KLayout in Viewer mode..."
$myKLayout $options $targetfiles &
exit 0
#-------------------
# End of file
#-------------------

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -40,6 +40,7 @@ def SetGlobals():
global DebugMode # True if debug mode build
global CheckComOnly # True if only for checking the command line parameters to "build.sh"
global Deployment # True if deploying the binaries for a package
global Version # KLayout's version
# auxiliary variables on platform
global System # 6-tuple from platform.uname()
global Node # - do -
@ -130,6 +131,7 @@ def SetGlobals():
DebugMode = False
CheckComOnly = False
Deployment = False
Version = GetKLayoutVersionFrom( "./version.sh" )
#------------------------------------------------------------------------------
## To get command line parameters
@ -451,9 +453,10 @@ def DeployBinariesForBundle():
global AbsMacBinDir
global AbsMacBuildDir
global AbsMacBuildLog
global Version
print("")
print( "##### Start deploying libraries and executables #####" )
print( "##### Started deploying libraries and executables for <klayout.app> #####" )
print( " [1] Checking the status of working directory ..." )
#-------------------------------------------------------------
# [1] Check the status of working directory
@ -594,21 +597,24 @@ def DeployBinariesForBundle():
os.chdir(ProjectDir)
sourceDir0 = "%s/klayout.app/Contents" % MacBinDir
sourceDir1 = sourceDir0 + "/MacOS"
sourceDir2 = "%s/etc" % ProjectDir
sourceDir3 = "%s/src/klayout_main" % ProjectDir
sourceDir4 = "%s" % MacBinDir
sourceDir2 = "%s/macbuild/Resources" % ProjectDir
sourceDir3 = "%s" % MacBinDir
shutil.copy2( sourceDir0 + "/Info.plist", targetDir0 )
shutil.copy2( sourceDir1 + "/klayout", targetDirM )
shutil.copy2( sourceDir2 + "/logo.png", targetDirR )
shutil.copy2( sourceDir3 + "/logo.ico", targetDirR )
tmpfileM = ProjectDir + "/macbuild/Resources/Info.plist.template"
keydicM = { 'exe': 'klayout', 'icon': 'klayout.icns', 'bname': 'klayout.main', 'ver': Version }
plistM = GenerateInfoPlist( keydicM, tmpfileM )
file = open( targetDir0 + "/Info.plist", "w" )
file.write(plistM)
file.close()
os.chmod( targetDir0 + "/Info.plist", 0644 )
os.chmod( targetDirM + "/klayout", 0755 )
os.chmod( targetDirR + "/logo.png", 0644 )
os.chmod( targetDirR + "/logo.ico", 0644 )
shutil.copy2( sourceDir1 + "/klayout", targetDirM )
shutil.copy2( sourceDir2 + "/klayout.icns", targetDirR )
buddies = glob.glob( sourceDir4 + "/strm*" )
os.chmod( targetDir0 + "/Info.plist", 0644 )
os.chmod( targetDirM + "/klayout", 0755 )
os.chmod( targetDirR + "/klayout.icns", 0644 )
buddies = glob.glob( sourceDir3 + "/strm*" )
for item in buddies:
shutil.copy2( item, targetDirB )
buddy = os.path.basename(item)
@ -665,12 +671,115 @@ def DeployBinariesForBundle():
os.chdir(ProjectDir)
return(1)
else:
msg = "### Deployed applications on OS X ###"
print( msg, file=sys.stderr )
print( "##### Finished deploying libraries and executables for <klayout.app> #####" )
print("")
os.chdir(ProjectDir)
return(0)
#------------------------------------------------------------------------------
## To deploy script bundles that invoke the main bundle (klayout.app) in
# editor mode or viewer mode
#
# @return 0 on success; non-zero on failure
#------------------------------------------------------------------------------
def DeployScriptBundles():
global ProjectDir
global MacPkgDir
global AbsMacPkgDir
print("")
print( "##### Started deploying files for <KLayoutEditor.app> and <KLayoutViewer.app> #####" )
print( " [1] Checking the status of working directory ..." )
#-------------------------------------------------------------
# [1] Check the status of working directory
#-------------------------------------------------------------
os.chdir(ProjectDir)
if not os.path.isdir(MacPkgDir):
print( "!!! Package directory <%s> does not present !!!" % MacPkgDir, file=sys.stderr )
return(1)
print( " [2] Creating a new empty directory <%s> for deployment ..." % (MacPkgDir + "/klayout.scripts") )
#-------------------------------------------------------------
# [2] Create a new empty directory for deploying binaries
#-------------------------------------------------------------
os.chdir(MacPkgDir)
scriptDir = "klayout.scripts"
if os.path.isfile(scriptDir):
os.remove(scriptDir)
if os.path.isdir(scriptDir):
shutil.rmtree(scriptDir)
os.mkdir(scriptDir)
print( " [3] Creating the standard directory structure for the script bundles ..." )
#-------------------------------------------------------------
# [3] Create the directory skeleton for the two script bundles.
#
# klayout.scripts/+
# +-- KLayoutEditor.app/+
# | +-- Contents/+
# | +-- Info.plist
# | +-- Resources/
# | +-- MacOS/+
# | +-- 'KLayoutEditor.sh'
# +-- KLayoutViewer.app/+
# +-- Contents/+
# +-- Info.plist
# +-- Resources/
# +-- MacOS/+
# +-- 'KLayoutViewer.sh'
#-------------------------------------------------------------
os.chdir(ProjectDir)
targetDir0E = "%s/%s/KLayoutEditor.app/Contents" % ( AbsMacPkgDir, scriptDir )
targetDir0V = "%s/%s/KLayoutViewer.app/Contents" % ( AbsMacPkgDir, scriptDir )
targetDirME = targetDir0E + "/MacOS"
targetDirMV = targetDir0V + "/MacOS"
targetDirRE = targetDir0E + "/Resources"
targetDirRV = targetDir0V + "/Resources"
os.makedirs(targetDirME)
os.makedirs(targetDirMV)
os.makedirs(targetDirRE)
os.makedirs(targetDirRV)
print( " [4] Copying script files and icon files ..." )
#-------------------------------------------------------------------------------
# [4] Copy different script files icon files
#-------------------------------------------------------------------------------
os.chdir(ProjectDir)
resourceDir = "macbuild/Resources"
shutil.copy2( resourceDir + "/KLayoutEditor.sh", targetDirME )
shutil.copy2( resourceDir + "/KLayoutViewer.sh", targetDirMV )
shutil.copy2( resourceDir + "/klayout-red.icns", targetDirRE )
shutil.copy2( resourceDir + "/klayout-blue.icns", targetDirRV )
os.chmod( targetDirME + "/KLayoutEditor.sh", 0755 )
os.chmod( targetDirMV + "/KLayoutViewer.sh", 0755 )
os.chmod( targetDirRE + "/klayout-red.icns", 0644 )
os.chmod( targetDirRV + "/klayout-blue.icns", 0644 )
tmpfileE = ProjectDir + "/macbuild/Resources/Info.plist.template"
keydicE = { 'exe': 'KLayoutEditor.sh', 'icon': 'klayout-red.icns', 'bname': 'klayout.editor', 'ver': Version }
plistE = GenerateInfoPlist( keydicE, tmpfileE )
fileE = open( targetDir0E + "/Info.plist", "w" )
fileE.write(plistE)
fileE.close()
tmpfileV = ProjectDir + "/macbuild/Resources/Info.plist.template"
keydicV = { 'exe': 'KLayoutViewer.sh', 'icon': 'klayout-blue.icns', 'bname': 'klayout.viewer', 'ver': Version }
plistV = GenerateInfoPlist( keydicV, tmpfileV )
fileV = open( targetDir0V + "/Info.plist", "w" )
fileV.write(plistV)
fileV.close()
print( "##### Finished deploying files for <KLayoutEditor.app> and <KLayoutViewer.app> #####" )
print("")
os.chdir(ProjectDir)
return(0)
#------------------------------------------------------------------------------
## The main function
#------------------------------------------------------------------------------
@ -684,8 +793,12 @@ def main():
else:
sys.exit(1)
else:
ret = DeployBinariesForBundle()
sys.exit(ret)
ret1 = DeployBinariesForBundle()
ret2 = DeployScriptBundles()
if not (ret1 == 0 and ret2 == 0):
sys.exit(1)
else:
sys.exit(0)
#===================================================================================
if __name__ == "__main__":

View File

@ -13,6 +13,8 @@
from __future__ import print_function # to use print() of Python 3 in Python >= 2.7
import sys
import os
import re
import string
import subprocess
#-------------------------------------------------------------------------------
@ -165,6 +167,62 @@ def SetChangeLibIdentificationName( executable, relativedir ):
# for-lib
return(0)
#------------------------------------------------------------------------------
## To get KLayout's version from a file like 'version.sh'
#
# @param[in] verfile version file from which version is retrieved
#
# @return version string
#------------------------------------------------------------------------------
def GetKLayoutVersionFrom( verfile='version.h' ):
version = "?.?.?"
try:
fd = open( verfile, "r" )
contents = fd.readlines()
fd.close()
except Exception as e:
return version
verReg = re.compile( u'(KLAYOUT_VERSION=\")([0-9A-Z_a-z\.]+)(\")' )
for line in contents:
m = verReg.match(line)
if m:
# print(m.group(0)) # KLAYOUT_VERSION="0.25"
# print(m.group(1)) # KLAYOUT_VERSION="
# print(m.group(2)) # 0.25
# print(m.group(3)) # "
version = m.group(2)
return version
return version
#------------------------------------------------------------------------------
## To generate the contents of "Info.plist" file from a template
#
# @param[in] keydic dictionary of four key words ['exe', 'icon', 'bname', 'ver']
# @param[in] templfile template file
#
# @return generated strings
#------------------------------------------------------------------------------
def GenerateInfoPlist( keydic, templfile ):
val_exe = keydic['exe']
val_icon = keydic['icon']
val_bname = keydic['bname']
val_ver = keydic['ver']
try:
fd = open( templfile, "r" )
template = fd.read()
fd.close()
except Exception as e:
return "???"
t = string.Template(template)
s = t.substitute( EXECUTABLE = val_exe,
ICONFILE = val_icon,
BUNDLENAME = val_bname,
VERSION = val_ver)
return s
#----------------
# End of File
#----------------