Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Apr 24, 2011
2 parents a5a5f6e + 8b138ca commit e8e1316
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 41 deletions.
6 changes: 0 additions & 6 deletions ROADMAP.md
@@ -1,9 +1,3 @@
0.2.0
---

- improve logging for ios
- ios plugins need to be identified in our old friend proj.pbxproj

0.3.0
---

Expand Down
1 change: 1 addition & 0 deletions generate-template/.gitignore
@@ -1,2 +1,3 @@
tmp/**/*
tmp/cache.lock
tmp/ios.log
9 changes: 9 additions & 0 deletions generate-template/bin/build/android
@@ -1,6 +1,15 @@
#! /bin/sh

# copy in any icons
./bin/build/android-copy-icons

# add any ./lib/plugins/* native and web code to android project
./bin/plugin/shotgun/android

# since we clobber www every time we need to copy in phonegap.js ...
cp ./bin/create/templates/android/phonegap-0.9.4.js ./tmp/android/assets/www/phonegap-0.9.4.js

# finally run the actual build
cd ./tmp/android && ant debug install

# FIXME launch app here with monkeyrunner
14 changes: 13 additions & 1 deletion generate-template/bin/build/ios
@@ -1,9 +1,21 @@
#! /bin/sh

# copy in the icons
./bin/build/ios-copy-icons

# copy ./lib/tmp/plugin/* into native and www in ./tmp
./bin/plugin/shotgun/ios

# update the xcode proj.pbxproj file
./bin/build/ios-add-plugins

# finally run the actual build
NAME=$(./bin/util/read-config name | sed 's/ //g')
PRJ="$NAME.xcodeproj"
APP="build/Release-iphonesimulator/$NAME.app"

cd ./tmp/ios
xcodebuild -project $PRJ -sdk iphonesimulator4.2

ios-sim launch $APP #--stderr ./tmp/ios.log
# kick up the simulator
ios-sim launch $APP --stderr ./../ios.log --stdout ./../ios.log &
172 changes: 172 additions & 0 deletions generate-template/bin/build/ios-add-plugins
@@ -0,0 +1,172 @@
#! /usr/bin/env ruby
#
# thank you @alunny for suffering this before I had to - @brianleroux
#
# a little module for munging pbxproj files
# with a stupid name
module PabstProj
# struct to contain all of the data for each file
if !defined?(PluginFile)
PluginFile = Class.new(Struct.new(:name, :type, :identifier, :fileref, :path))

class PluginFile
def group
case self.type
when :source
"Sources"
when :resource
"Resources"
end
end

def last_type
case File.extname(self.name)
when '.png'
'image.png'
when '.m'
'sourcecode.c.objc'
when '.h'
'sourcecode.c.h'
when '.xib'
'file.xib'
when '.plist'
'text.plist.xml'
else
'text'
end
end
end
end

XCODE_GUID_MATCH = /[0-9A-F]{24}/
DELIMITERS = {
:PBXBUILD_END => "/* End PBXBuildFile section */",
:PBXFILEREF_END => "/* End PBXFileReference section */",
:PBXGROUP_END => "\t\t\t);\n\t\t\tpath = Plugins;",
:PBXRESOURCES_END => "\t\t\t);\n\t\t\trunOnlyForDeploymentPostprocessing = 0;\n\t\t};\n/* End PBXResourcesBuildPhase",
:PBXSOURCES_END => "\t\t\t);\n\t\t\trunOnlyForDeploymentPostprocessing = 0;\n\t\t};\n/* End PBXSourcesBuildPhase"
}

attr_reader :guid_list, :source_files, :header_files, :resource_files


def add_plugins plugins_dir, pbxproj
read_all_guids pbxproj

parse_all_filenames plugins_dir

rewrite_project pbxproj
end

def read_all_guids pbxproj
@guid_list = File.read(pbxproj).scan(XCODE_GUID_MATCH).uniq
end

def parse_all_filenames plugins_dir
plugin_filepaths = Dir.glob("#{ plugins_dir }/**/*").select { |f| !File.directory? f }
plugin_files = []

plugin_filepaths.each do |filepath|
name = File.basename(filepath)
type = type_from_extn(File.extname(filepath))

plugin_files << PluginFile.new(name, type, new_guid, new_guid, filepath)
end

@source_files = plugin_files.select { |f| f.type == :source }
@header_files = plugin_files.select { |f| f.type == :header }
@resource_files = plugin_files.select { |f| f.type == :resource }
end

def new_guid
s4 = lambda { (100 + rand(899)).to_s }
new_one = lambda do
s4.call + s4.call + s4.call + s4.call + s4.call + s4.call + s4.call + s4.call
end
#new_one = UUIDTools::UUID.timestamp_create.to_s.gsub('-','').upcase[0,24]
guid_list.include?(new_one) ? new_guid : new_one.call
end

def type_from_extn extn
case extn
when ".m"
:source
when ".h"
:header
else
:resource
end
end

# make it work, then make it good
def rewrite_project pbxproj
project_data = File.read(pbxproj)

pbxbuildfile_files = @source_files + @resource_files
pbxfilereference_files = @source_files + @header_files + @resource_files
pbxgroup_files = @source_files + @header_files + @resource_files
pbxresources_files = @resource_files
pbxsources_files = @source_files

pbxbuildfile = pbxbuildfile_files.map { |f| pbxbuildfile_line(f) }
pbxfilereference = pbxfilereference_files.map { |f| pbxfilereference_line(f) }
pbxgroup = pbxgroup_files.map { |f| pbxgroup_line(f) }
pbxresources = pbxresources_files.map { |f| pbxresourcesbuild_line(f) }
pbxsources = pbxsources_files.map { |f| pbxsourcesbuildphase_line(f) }

pbxbuildfile.each do |file_line|
index = project_data.index(DELIMITERS[:PBXBUILD_END])
project_data.insert(index, file_line)
end

pbxfilereference.each do |file_line|
index = project_data.index(DELIMITERS[:PBXFILEREF_END])
project_data.insert(index, file_line)
end

pbxgroup.each do |file_line|
index = project_data.index(DELIMITERS[:PBXGROUP_END])
project_data.insert(index, file_line)
end

pbxresources.each do |file_line|
index = project_data.index(DELIMITERS[:PBXRESOURCES_END])
project_data.insert(index, file_line)
end

pbxsources.each do |file_line|
index = project_data.index(DELIMITERS[:PBXSOURCES_END])
project_data.insert(index, file_line)
end

open(pbxproj, 'w') { |f| f.puts(project_data) }
end

def pbxbuildfile_line f
"\t\t#{ f.identifier } /* #{ f.name } in #{ f.group } */ = {isa = PBXBuildFile; fileRef = #{ f.fileref } /* #{ f.name } */; };\n"
end

def pbxfilereference_line f
"\t\t#{ f.fileref } /* #{ f.name } */ = {isa = PBXFileReference; lastKnownFileType = #{ f.last_type }; name = #{ f.name }; path = #{ f.path }; sourceTree = SOURCE_ROOT; };\n"
end

def pbxgroup_line f
"\t\t\t\t#{ f.fileref } /* #{ f.name } */,\n"
end

def pbxresourcesbuild_line f
"\t\t\t\t#{ f.identifier } /* #{ f.name } in Resources */,\n"
end

def pbxsourcesbuildphase_line f
"\t\t\t\t#{ f.identifier } /* #{ f.name } in Sources */,\n"
end
end

if __FILE__ == $PROGRAM_NAME
name = `./bin/util/read-config name`.strip()
name = name.gsub(' ', '')
name = "./tmp/ios/#{ name }.xcodeproj/project.pbxproj"
include PabstProj
add_plugins './tmp/ios/Plugins', name
end
File renamed without changes.
2 changes: 1 addition & 1 deletion generate-template/bin/create/android
Expand Up @@ -28,4 +28,4 @@ find "$FULL" | xargs grep '__ACTIVITY__' -sl | xargs -L1 sed -i "" "s/__ACTIVITY
find "$FULL" | xargs grep '__ID__' -sl | xargs -L1 sed -i "" "s/__ID__/${PKG}/g"

# copy in intents
./bin/util/android-convert-config
./bin/create/android-convert-config
2 changes: 0 additions & 2 deletions generate-template/bin/debug/android
Expand Up @@ -3,6 +3,4 @@
rm -rf ./tmp/android/assets/www
cp -r ./www ./tmp/android/assets/www/

./bin/util/android-copy-icons
./bin/plugin/shotgun/android
./bin/build/android
5 changes: 2 additions & 3 deletions generate-template/bin/debug/ios
Expand Up @@ -3,6 +3,5 @@
rm -rf ./tmp/ios/www
cp -r ./www ./tmp/ios/www/

./bin/util/android-copy-icons
./bin/plugin/shotgun/ios
./bin/build/ios
# finally run the build
./bin/build/ios
3 changes: 2 additions & 1 deletion generate-template/bin/log/ios
@@ -1,4 +1,5 @@
#! /bin/sh

: > ./tmp/ios.log
rm ./tmp/ios.log
touch ./tmp/ios.log
tail -f ./tmp/ios.log
27 changes: 0 additions & 27 deletions generate-template/bin/util/ios-xcode-debug

This file was deleted.

0 comments on commit e8e1316

Please sign in to comment.