Skip to content

Commit

Permalink
Merge branch 'release/2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pegli committed Dec 12, 2014
2 parents a160338 + d864c80 commit 1c3f8a1
Show file tree
Hide file tree
Showing 14 changed files with 9,137 additions and 64 deletions.
Binary file not shown.
5 changes: 3 additions & 2 deletions mobile/android/manifest
Expand Up @@ -2,7 +2,8 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0
version: 2.1
architectures: armeabi armeabi-v7a x86
apiversion: 2
description: Keychain access module for iPhone
author: Paul Mietz Egli
Expand All @@ -15,4 +16,4 @@ name: keychain
moduleid: com.obscure.keychain
guid: eb0a9be8-02b5-43a2-a115-a220b293d202
platform: android
minsdk: 3.2.2.GA
minsdk: 3.5.0.Beta
186 changes: 128 additions & 58 deletions mobile/ios/build.py
Expand Up @@ -3,13 +3,13 @@
# Appcelerator Titanium Module Packager
#
#
import os, sys, glob, string
import os, subprocess, sys, glob, string
import zipfile
from datetime import date

cwd = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
os.chdir(cwd)
required_module_keys = ['name','version','moduleid','description','copyright','license','copyright','platform','minsdk']
required_module_keys = ['architectures', 'name','version','moduleid','description','copyright','license','copyright','platform','minsdk']
module_defaults = {
'description':'My module',
'author': 'Your Name',
Expand All @@ -18,6 +18,10 @@
}
module_license_default = "TODO: place your license here and we'll include it in the module distribution"

def find_sdk(config):
sdk = config['TITANIUM_SDK']
return os.path.expandvars(os.path.expanduser(sdk))

def replace_vars(config,token):
idx = token.find('$(')
while idx != -1:
Expand All @@ -28,8 +32,8 @@ def replace_vars(config,token):
token = token.replace('$(%s)' % key, config[key])
idx = token.find('$(')
return token


def read_ti_xcconfig():
contents = open(os.path.join(cwd,'titanium.xcconfig')).read()
config = {}
Expand All @@ -45,64 +49,83 @@ def read_ti_xcconfig():

def generate_doc(config):
docdir = os.path.join(cwd,'documentation')
if not os.path.exists(docdir):
docdir = os.path.join(cwd,'..','documentation')
if not os.path.exists(docdir):
print "Couldn't find documentation file at: %s" % docdir
return None
sdk = config['TITANIUM_SDK']
support_dir = os.path.join(sdk,'module','support')
sys.path.append(support_dir)
import markdown

try:
import markdown2 as markdown
except ImportError:
import markdown
documentation = []
for file in os.listdir(docdir):
if os.path.isdir(file) == False:
md = open(os.path.join(docdir,file)).read()
html = markdown.markdown(md)
documentation.append({file:html});
if file in ignoreFiles or os.path.isdir(os.path.join(docdir, file)):
continue
md = open(os.path.join(docdir,file)).read()
html = markdown.markdown(md)
documentation.append({file:html});
return documentation

def compile_js(manifest,config):
js_file = os.path.join(cwd,'assets','com.obscure.keychain.js')
js_file = os.path.join(cwd,'assets','com.foogle.js')
if not os.path.exists(js_file):
js_file = os.path.join(cwd,'..','assets','com.foogle.js')
if not os.path.exists(js_file): return

sdk = config['TITANIUM_SDK']
iphone_dir = os.path.join(sdk,'iphone')
sys.path.insert(0,iphone_dir)

from compiler import Compiler

path = os.path.basename(js_file)
metadata = Compiler.make_function_from_file(path,js_file)
method = metadata['method']
eq = path.replace('.','_')
method = ' return %s;' % method

f = os.path.join(cwd,'Classes','ComObscureKeychainModuleAssets.m')
c = open(f).read()
idx = c.find('return ')
before = c[0:idx]
after = """
}
try:
import json
except:
import simplejson as json

compiler = Compiler(cwd, manifest['moduleid'], manifest['name'], 'commonjs')
root_asset, module_assets = compiler.compile_module()

root_asset_content = """
%s
return filterDataInRange([NSData dataWithBytesNoCopy:data length:sizeof(data) freeWhenDone:NO], ranges[0]);
""" % root_asset

module_asset_content = """
%s
NSNumber *index = [map objectForKey:path];
if (index == nil) {
return nil;
}
return filterDataInRange([NSData dataWithBytesNoCopy:data length:sizeof(data) freeWhenDone:NO], ranges[index.integerValue]);
""" % module_assets

from tools import splice_code

assets_router = os.path.join(cwd,'Classes','ComFoogleModuleAssets.m')
splice_code(assets_router, 'asset', root_asset_content)
splice_code(assets_router, 'resolve_asset', module_asset_content)

# Generate the exports after crawling all of the available JS source
exports = open('metadata.json','w')
json.dump({'exports':compiler.exports }, exports)
exports.close()

@end
"""
newc = before + method + after

if newc!=c:
x = open(f,'w')
x.write(newc)
x.close()

def die(msg):
print msg
sys.exit(1)

def warn(msg):
print "[WARN] %s" % msg
print "[WARN] %s" % msg

def validate_license():
c = open(os.path.join(cwd,'LICENSE')).read()
if c.find(module_license_default)!=1:
warn('please update the LICENSE file with your license text before distributing')

license_file = os.path.join(cwd,'LICENSE')
if not os.path.exists(license_file):
license_file = os.path.join(cwd,'..','LICENSE')
if os.path.exists(license_file):
c = open(license_file).read()
if c.find(module_license_default)!=-1:
warn('please update the LICENSE file with your license text before distributing')

def validate_manifest():
path = os.path.join(cwd,'manifest')
f = open(path)
Expand All @@ -115,26 +138,28 @@ def validate_manifest():
key,value = line.split(':')
manifest[key.strip()]=value.strip()
for key in required_module_keys:
if not manifest.has_key(key): die("missing required manifest key '%s'" % key)
if not manifest.has_key(key): die("missing required manifest key '%s'" % key)
if manifest[key].strip() == '': die("manifest key '%s' missing required value" % key)
if module_defaults.has_key(key):
defvalue = module_defaults[key]
curvalue = manifest[key]
if curvalue==defvalue: warn("please update the manifest key: '%s' to a non-default value" % key)
return manifest,path

ignoreFiles = ['.DS_Store','.gitignore','libTitanium.a','titanium.jar','README','com.obscure.keychain.js']
ignoreFiles = ['.DS_Store','.gitignore','libTitanium.a','titanium.jar','README']
ignoreDirs = ['.DS_Store','.svn','.git','CVSROOT']

def zip_dir(zf,dir,basepath,ignore=[]):
def zip_dir(zf,dir,basepath,ignore=[],includeJSFiles=False):
for root, dirs, files in os.walk(dir):
for name in ignoreDirs:
if name in dirs:
dirs.remove(name) # don't visit ignored directories
dirs.remove(name) # don't visit ignored directories
for file in files:
if file in ignoreFiles: continue
e = os.path.splitext(file)
if len(e)==2 and e[1]=='.pyc':continue
from_ = os.path.join(root, file)
if len(e) == 2 and e[1] == '.pyc': continue
if not includeJSFiles and len(e) == 2 and e[1] == '.js': continue
from_ = os.path.join(root, file)
to_ = from_.replace(dir, basepath, 1)
zf.write(from_, to_)

Expand All @@ -146,6 +171,9 @@ def glob_libfiles():
return files

def build_module(manifest,config):
from tools import ensure_dev_path
ensure_dev_path()

rc = os.system("xcodebuild -sdk iphoneos -configuration Release")
if rc != 0:
die("xcodebuild failed")
Expand All @@ -157,9 +185,27 @@ def build_module(manifest,config):
libpaths = ''
for libfile in glob_libfiles():
libpaths+='%s ' % libfile

os.system("lipo %s -create -output build/lib%s.a" %(libpaths,moduleid))


def verify_build_arch(manifest, config):
binaryname = 'lib%s.a' % manifest['moduleid']
binarypath = os.path.join('build', binaryname)
manifestarch = set(manifest['architectures'].split(' '))

output = subprocess.check_output('lipo -info %s' % binarypath, shell=True)

builtarch = set(output.split(':')[-1].strip().split(' '))

if ('arm64' not in builtarch):
warn('built module is missing 64-bit support.')

if (manifestarch != builtarch):
warn('there is discrepancy between the architectures specified in module manifest and compiled binary.')
warn('architectures in manifest: %s' % ', '.join(manifestarch))
warn('compiled binary architectures: %s' % ', '.join(builtarch))
die('please update manifest to match module binary architectures.')

def package_module(manifest,mf,config):
name = manifest['name'].lower()
moduleid = manifest['moduleid'].lower()
Expand All @@ -177,20 +223,44 @@ def package_module(manifest,mf,config):
for file, html in doc.iteritems():
filename = string.replace(file,'.md','.html')
zf.writestr('%s/documentation/%s'%(modulepath,filename),html)
for dn in ('assets','example','platform'):
if os.path.exists(dn):
zip_dir(zf,dn,'%s/%s' % (modulepath,dn),['README'])
zf.write('LICENSE','%s/LICENSE' % modulepath)

p = os.path.join(cwd, 'assets')
if not os.path.exists(p):
p = os.path.join(cwd, '..', 'assets')
if os.path.exists(p):
zip_dir(zf,p,'%s/%s' % (modulepath,'assets'),['README'])

for dn in ('example','platform'):
p = os.path.join(cwd, dn)
if not os.path.exists(p):
p = os.path.join(cwd, '..', dn)
if os.path.exists(p):
zip_dir(zf,p,'%s/%s' % (modulepath,dn),['README'],True)

license_file = os.path.join(cwd,'LICENSE')
if not os.path.exists(license_file):
license_file = os.path.join(cwd,'..','LICENSE')
if os.path.exists(license_file):
zf.write(license_file,'%s/LICENSE' % modulepath)

zf.write('module.xcconfig','%s/module.xcconfig' % modulepath)
exports_file = 'metadata.json'
if os.path.exists(exports_file):
zf.write(exports_file, '%s/%s' % (modulepath, exports_file))
zf.close()


if __name__ == '__main__':
manifest,mf = validate_manifest()
validate_license()
config = read_ti_xcconfig()

sdk = find_sdk(config)
sys.path.insert(0,os.path.join(sdk,'iphone'))
sys.path.append(os.path.join(sdk, "common"))

compile_js(manifest,config)
build_module(manifest,config)
verify_build_arch(manifest, config)
package_module(manifest,mf,config)
sys.exit(0)

Binary file removed mobile/ios/dist/com.obscure.keychain-iphone-2.0.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion mobile/ios/keychain.xcodeproj/project.pbxproj
Expand Up @@ -167,7 +167,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0610;
};
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "keychain" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -272,6 +272,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.2;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
5 changes: 3 additions & 2 deletions mobile/ios/manifest
@@ -1,4 +1,5 @@
version: 2.0
version: 2.1
architectures: armv7 arm64 i386 x86_64
description: Keychain access module for iPhone
author: Paul Mietz Egli
license: Apache 2.0
Expand All @@ -10,4 +11,4 @@ name: keychain
moduleid: com.obscure.keychain
guid: acf8434d-5290-4b73-8f39-e4cd7349860a
platform: iphone
minsdk: 3.2.2.GA
minsdk: 3.5.0.Beta
2 changes: 1 addition & 1 deletion mobile/ios/titanium.xcconfig
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 3.2.3.GA
TITANIUM_SDK_VERSION = 3.5.0.Beta


//
Expand Down
17 changes: 17 additions & 0 deletions mobile/noarch/testapp/Resources/001_module.js
@@ -0,0 +1,17 @@
require('ti-mocha');

var should = require('should');

module.exports = function() {
describe('module', function() {
var module = require('com.obscure.keychain');

it('must exist', function() {
should.exist(module);
});

it('must have a createKeychainItem method', function() {
should(module.createKeychainItem).be.a.Function;
});
});
};

0 comments on commit 1c3f8a1

Please sign in to comment.