Skip to content

Commit

Permalink
qmake|Builder: Building and deploying packages
Browse files Browse the repository at this point in the history
Added a new Python script for building a '.pack' package. Added
qmake macros for building and deploying packages.
  • Loading branch information
skyjake committed Aug 14, 2014
1 parent 85ab399 commit bebf791
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 39 deletions.
64 changes: 64 additions & 0 deletions doomsday/build/scripts/buildpackage.py
@@ -0,0 +1,64 @@
#!/usr/bin/env python2.7
#
# Command line utility for zipping a directory of files into a .pack.
# Checks that the required Info file is present.
#
# Usage:
# buildpackage (pack-dir) (output-dir)
#

import sys, os, os.path, zipfile

if len(sys.argv) < 2:
print "Usage: %s (pack-dir) (output-dir)" % sys.argv[0]
sys.exit(0)

# Check quiet flag.
class Package:
def __init__(self, sourcePath):
self.sourcePath = sourcePath

def build(self, outputPath):
outputName = os.path.join(outputPath, os.path.basename(self.sourcePath))
pack = zipfile.ZipFile(outputName, 'w', zipfile.ZIP_DEFLATED)
contents = []

# Index the contents of the folder recursively.
def descend(path):
for name in os.listdir(os.path.join(self.sourcePath, path)):
if name[0] == '.':
continue # Ignore these.

if len(path):
internalPath = os.path.join(path, name)
else:
internalPath = name
fullPath = os.path.join(self.sourcePath, internalPath)

if os.path.isfile(fullPath):
contents.append((fullPath, internalPath))
elif os.path.isdir(fullPath):
descend(internalPath)
descend('')

# Check for the required metadata file.
foundInfo = False
for full, internal in contents:
if internal.lower() == 'info':
foundInfo = True
break
if not foundInfo:
print "No 'Info' file found in \"%s\"!" % self.sourcePath
sys.exit(1)

# Write entries in alphabetical order.
for full, internal in sorted(contents):
pack.write(full, internal)

# Write it out.
print "Wrote %s (contains %i files)." % (outputName, len(pack.namelist()))
pack.close()

if __name__ == "__main__":
p = Package(sys.argv[1])
p.build(sys.argv[2])
10 changes: 0 additions & 10 deletions doomsday/build/scripts/packres.py
Expand Up @@ -76,16 +76,6 @@ def process_dir(path, dest_path):
p.add_files( [ ('net.dengine.base.pack', '') ] )
p.create('net.dengine.base.pack')

# net.dengine.stdlib.pack
p = Pack()
p.add_files( [ ('libcore/net.dengine.stdlib.pack', '') ] )
p.create('net.dengine.stdlib.pack')

# net.dengine.stdlib.gui.pack
p = Pack()
p.add_files( [ ('libgui/net.dengine.stdlib.gui.pack', '') ] )
p.create('net.dengine.stdlib.gui.pack')

# net.dengine.client.pack
p = Pack()
p.add_files( [ ('client/net.dengine.client.pack', '') ] )
Expand Down
5 changes: 4 additions & 1 deletion doomsday/config.pri
Expand Up @@ -50,7 +50,6 @@ DENG_INCLUDE_DIR = $$PWD/client/include
DENG_UNIX_INCLUDE_DIR = $$DENG_INCLUDE_DIR/unix
DENG_MAC_INCLUDE_DIR = $$DENG_INCLUDE_DIR/macx
DENG_WIN_INCLUDE_DIR = $$DENG_INCLUDE_DIR/windows
DENG_MODULES_DIR = $$PWD/libcore/modules

# Macros ---------------------------------------------------------------------

Expand Down Expand Up @@ -118,8 +117,12 @@ deng_sdk {
DENG_SDK_HEADER_DIR = $$DENG_SDK_DIR/include/de
DENG_SDK_LIB_DIR = $$DENG_SDK_DIR/lib
}
DENG_SDK_PACKS_DIR = $$DENG_SDK_DIR/packs
builtpacks.path = $$DENG_SDK_PACKS_DIR

echo(SDK header directory: $$DENG_SDK_HEADER_DIR)
echo(SDK library directory: $$DENG_SDK_LIB_DIR)
echo(SDK packages directory: $$DENG_SDK_PACKS_DIR)
}

win32: include(config_win32.pri)
Expand Down
62 changes: 37 additions & 25 deletions doomsday/doomsday_sdk.pri
Expand Up @@ -35,6 +35,10 @@ contains(DENG_CONFIG, gui): LIBS += -ldeng_gui
contains(DENG_CONFIG, appfw): LIBS += -ldeng_appfw
contains(DENG_CONFIG, shell): LIBS += -ldeng_shell

# Appropriate packages.
DENG_PACKAGES += net.dengine.stdlib
contains(DENG_CONFIG, gui): DENG_PACKAGES += net.dengine.stdlib.gui

defineTest(dengDynamicLinkPath) {
# 1: path to search dynamic libraries from
*-g++*|*-gcc*|*-clang* {
Expand All @@ -50,10 +54,13 @@ macx {
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
}

DENG_MODULES = $$DENG_SDK_DIR/modules/*.de

# Macros ---------------------------------------------------------------------

defineTest(dengRunPython2) {
win32: system(python $$1) # 2.7 still expected
else: system(/usr/bin/env python2.7 $$1)
}

defineTest(dengPostLink) {
isEmpty(QMAKE_POST_LINK) {
QMAKE_POST_LINK = $$1
Expand All @@ -63,22 +70,22 @@ defineTest(dengPostLink) {
export(QMAKE_POST_LINK)
}

defineTest(dengClear) {
# 1: file to remove
win32: system(del /q \"$$1\")
else: system(rm -f \"$$1\")
}
defineTest(dengPackage) {
# 1: path of a .pack source directory (without the ".pack")
# 2: target directory where the zipped .pack is written
dengRunPython2($$DENG_SDK_DIR/buildpackage.py \"$${1}.pack\" \"$$2\")

defineTest(dengPack) {
# 1: path of a .pack file
# 2: actual root directory
# 3: files to include, relative to the root
system(cd \"$$2\" && zip -r \"$$1\" $$3 -x \\*~)
# Automatically deploy the package.
appPackages.files += $$2/$${1}.pack
export(appPackages.files)
}

defineTest(dengPackModules) {
# 1: path of a .pack file
dengPack($$1, $$DENG_SDK_DIR, modules/*.de)
defineTest(dengSdkPackage) {
# 1: identifier of the package
exists($$DENG_SDK_DIR/packs/$${1}.pack) {
sdkPackages.files *= $$DENG_SDK_DIR/packs/$${1}.pack
export(sdkPackages.files)
}
}

defineReplace(dengFindLibDir) {
Expand Down Expand Up @@ -119,28 +126,32 @@ defineReplace(dengSdkLib) {
defineTest(dengDeploy) {
# 1: app name
# 2: install prefix
# 3: base pack file

for(i, DENG_PACKAGES): dengSdkPackage($$i)

prefix = $$2
INSTALLS += target basepack denglibs
basepack.files = $$3
INSTALLS += target denglibs appPackages sdkPackages

denglibs.files = $$dengSdkLib(deng_core)
contains(DENG_CONFIG, gui): denglibs.files += $$dengSdkLib(deng_gui)
contains(DENG_CONFIG, appfw): denglibs.files += $$dengSdkLib(deng_appfw)
contains(DENG_CONFIG, shell): denglibs.files += $$dengSdkLib(deng_shell)

win32 {
# todo
}
else:macx {
QMAKE_BUNDLE_DATA += $$INSTALLS
QMAKE_BUNDLE_DATA -= target
basepack.path = Contents/Resources
denglibs.path = Contents/Frameworks
appPackages.path = Contents/Resources
sdkPackages.path = Contents/Resources
denglibs.path = Contents/Frameworks
}
else {
target.path = $$prefix/bin
basepack.path = $$prefix/share/$${1}
denglibs.path = $$dengFindLibDir($$prefix)
target.path = $$prefix/bin
appPackages.path = $$prefix/share/$$1
sdkPackages.path = $$prefix/share/$$1
denglibs.path = $$dengFindLibDir($$prefix)
}

contains(DENG_CONFIG, symlink):unix {
Expand All @@ -163,8 +174,9 @@ defineTest(dengDeploy) {
export(INSTALLS)
export(target.path)
}
export(basepack.files)
export(basepack.path)
export(appPackages.path)
export(sdkPackages.files)
export(sdkPackages.path)
export(denglibs.files)
export(denglibs.path)
}
12 changes: 11 additions & 1 deletion doomsday/macros.pri
Expand Up @@ -70,6 +70,16 @@ defineTest(doPostLink) {
export(QMAKE_POST_LINK)
}

defineTest(buildPackage) {
# 1: path of a .pack source directory
# 2: target directory where the zipped .pack is written
runPython2($$PWD/../build/scripts/buildpackage.py \"$${1}.pack\" \"$$2\")

# Automatically deploy the package.
builtpacks.files += $$2/$${1}.pack
export(builtpacks.files)
}

defineTest(deployTarget) {
unix:!macx {
INSTALLS += target
Expand All @@ -94,7 +104,7 @@ defineTest(deployLibrary) {
export(target.path)
}
deng_sdk {
INSTALLS *= target
INSTALLS *= target builtpacks
target.path = $$DENG_SDK_LIB_DIR
export(target.path)
}
Expand Down
2 changes: 0 additions & 2 deletions doomsday/sdk.pro
Expand Up @@ -23,8 +23,6 @@ SUBDIRS = \
SUBDIRS += \
tests

#SUBDIRS += postbuild

OTHER_FILES += doomsday_sdk.pri

# Install the main .pri file of the SDK.
Expand Down

0 comments on commit bebf791

Please sign in to comment.