Skip to content

Commit

Permalink
Merge pull request Macadamian#79 from alexandergalstyan/genBarDescBranch
Browse files Browse the repository at this point in the history
TIMOB-9164: Blackberry: [Studio integration] regenerate the bar-descriptor file at packaging time
  • Loading branch information
alexandergalstyan committed Jun 22, 2012
2 parents 95bdf32 + 0915850 commit 691d062
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 43 deletions.
2 changes: 1 addition & 1 deletion support/android/compiler.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from xml.sax.saxutils import escape
from sgmllib import SGMLParser
from csspacker import CSSPacker
from deltafy import Deltafy
import bindings

ignoreFiles = ['.gitignore', '.cvsignore', '.DS_Store']
Expand All @@ -21,6 +20,7 @@
sys.path.append(os.path.abspath(os.path.join(template_dir, "..", "common")))

import simplejson
from deltafy import Deltafy

# class for extracting javascripts
class ScriptProcessor(SGMLParser):
Expand Down
87 changes: 50 additions & 37 deletions support/blackberry/blackberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ def __init__(self, name, appid, bbndk):
self.id = appid
self.ndk = bbndk

# TODO MAC: the bar-descriptor likely needs to be regenerated at
# build time to capture changes to tiapp.xml
# Configuration for the bar-descriptor.xml file
self.configDescriptor = {
'id':self.id,
'appname':self.name,
'platformversion':self.ndk.version,
'description':None,
'version':'1.0',
'author':'Appcelerator Titanium Mobile', # TODO MAC: Find out how validate the author
'category':'core.games', # TODO MAC: Find out how validate the category
'icon':'assets/appicon.png',
'splashscreen':'assets/default.png'
}

# Configuration for the project file
self.configProject = {
'appname':self.name,
'buildlocation':None # TODO MAC: Find out how specify the build location
}

def create(self, dir):
project_dir = os.path.join(dir, self.name)
# Creates directory named as project name.
Expand Down Expand Up @@ -80,14 +59,33 @@ def create(self, dir):
print >> sys.stderr, e
sys.exit(1)

# Configuration for the bar-descriptor.xml file
configDescriptor = {
'id':self.id,
'appname':self.name,
'platformversion':self.ndk.version,
'description':'not specified',
'version':'1.0',
'author':'not specified',
'category':'core.games', # TODO MAC: Find out how validate the category
'icon':'assets/appicon.png',
'splashscreen':'assets/default.png'
}

# Configuration for the project file
configProject = {
'appname':self.name,
'buildlocation':None # TODO MAC: Find out how specify the build location
}

# add replaced templates: bar-descriptor.xml, .project files
templates = os.path.join(template_dir,'templates')
# copy bar-descriptor.xml
shutil.copy2(os.path.join(templates,'bar-descriptor.xml'), build_dir)
_renderTemplate(os.path.join(build_dir,'bar-descriptor.xml'), self.configDescriptor)
renderTemplate(os.path.join(build_dir,'bar-descriptor.xml'), configDescriptor)
# copy project file
shutil.copy2(os.path.join(templates,'project'), os.path.join(build_dir, '.project'))
_renderTemplate(os.path.join(build_dir,'.project'), self.configProject)
renderTemplate(os.path.join(build_dir,'.project'), configProject)

# import project into workspace so it can be built with mkbuild
self.ndk.importProject(build_dir)
Expand All @@ -98,18 +96,15 @@ def create(self, dir):
#if not os.path.exists(blackberry_resources_dir):
# os.makedirs(blackberry_resources_dir)

def _renderTemplate(template, config):
tmpl = _loadTemplate(template)
f = None
try:
f = open(template, "w")
f.write(tmpl.render(config = config))
except Exception, e:
print >>sys.stderr, e
sys.exit(1)
finally:
if f != None:
f.close
@staticmethod
def renderTemplate(template, config):
tmpl = _loadTemplate(template)
try:
with open(template, 'w') as f:
f.write(tmpl.render(config = config))
except Exception, e:
print >>sys.stderr, e
sys.exit(1)

def _loadTemplate(template):
return Template(filename=template, output_encoding='utf-8', encoding_errors='replace')
Expand Down Expand Up @@ -153,12 +148,30 @@ def __runUnitTests():
bbndk = BlackberryNDK(ndk)
bb = Blackberry('TemplateTest', 'com.macadamian.template', bbndk)

configDescriptor = {
'id':bb.id,
'appname':bb.name,
'platformversion':bb.ndk.version,
'description':'not specified',
'version':'1.0',
'author':'not specified',
'category':'core.games', # TODO MAC: Find out how validate the category
'icon':'assets/appicon.png',
'splashscreen':'assets/default.png'
}

# Configuration for the project file
configProject = {
'appname':bb.name,
'buildlocation':None # TODO MAC: Find out how specify the build location
}

with UnitTest('Test template replacing on bar-descriptor.xml file..'):
passed =__runTemplatingDescriptorTest(bb.configDescriptor)
passed =__runTemplatingDescriptorTest(configDescriptor)
assert passed

with UnitTest('Test template replacing on .project file..'):
passed = __runTemplatingProjectTest(bb.configProject)
passed = __runTemplatingProjectTest(configProject)
assert passed

print '\nFinished Running Unit Tests'
Expand Down
44 changes: 39 additions & 5 deletions support/blackberry/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# General builder script for staging, packaging, deploying,
# and debugging Titanium Mobile applications on Blackberry
#
import os, sys
import os, sys, shutil
from optparse import OptionParser

template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
Expand All @@ -20,6 +20,8 @@
from tilogger import TiLogger
from tiapp import TiAppXML
from blackberryndk import BlackberryNDK
from blackberry import Blackberry
from deltafy import Deltafy

class Builder(object):
type2variantCpu = {'simulator' : ('o-g', 'x86'),
Expand All @@ -31,17 +33,22 @@ def __init__(self, project_dir, type, ndk, useLogFile = False):
self.type = type
(self.variant, self.cpu) = Builder.type2variantCpu[type]
self.ndk = ndk
project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml')
self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml')
self.tiappxml = TiAppXML(self.project_tiappxml)
self.name = self.tiappxml.properties['name']
self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry', self.name)
self.project_deltafy = Deltafy(self.top_dir)

if useLogFile:
tiappxml = TiAppXML(project_tiappxml)
self.tiappxml = TiAppXML(self.project_tiappxml)
else:
# hide property output
with open(os.devnull, 'w') as nul:
oldStdout = sys.stdout
sys.stdout = nul
tiappxml = TiAppXML(project_tiappxml)
self.tiappxml = TiAppXML(self.project_tiappxml)
sys.stdout = oldStdout
self.name = tiappxml.properties['name']
self.name = self.tiappxml.properties['name']
self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry', self.name)

def getPackage(self):
Expand All @@ -55,13 +62,40 @@ def run(self, ipAddress, password = None, debugToken = None):
return retCode
info('Running')

# Check if tiapp.xml changed since last run
tiapp_delta = self.project_deltafy.scan_single_file(self.project_tiappxml)
tiapp_changed = tiapp_delta is not None

if (tiapp_changed):
# regenerate bar-descriptor.xml
# TODO MAC: Add blackberry specific properties. Needs update in tiapp.py script
templates = os.path.join(template_dir,'templates')
shutil.copy2(os.path.join(templates,'bar-descriptor.xml'), self.buildDir)
newConfig = {
'id':self.tiappxml.properties['id'],
'appname':self.tiappxml.properties['name'],
'platformversion':self.ndk.version,
'description':(self.tiappxml.properties['description'] or 'not specified'),
'version':(self.tiappxml.properties['version'] or '1.0'),
'author':(self.tiappxml.properties['publisher'] or 'not specified'),
'category':'core.games',
'icon':'assets/%s' %(self.tiappxml.properties['icon'] or 'appicon.png'),
'splashscreen':'assets/default.png'
}
try:
Blackberry.renderTemplate(os.path.join(self.buildDir,'bar-descriptor.xml'), newConfig)
except Exception, e:
print >>sys.stderr, e
sys.exit(1)

# Change current directory to do relative operations
os.chdir("%s" % self.buildDir)
barPath = self.getPackage()
savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name)
retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken)
if retCode != 0:
return retCode

retCode = self.ndk.deploy(ipAddress, barPath, password)
return retCode

Expand Down
File renamed without changes.

0 comments on commit 691d062

Please sign in to comment.