LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: Adam Jacob Muller Date: Sun Nov 4 16:18:47 2007 Subject: Re: make-bundle.diff
Index: make-bundle
===================================================================
RCS file: /repository/php-objc/utils/make-bundle,v
retrieving revision 1.1
diff -u -r1.1 make-bundle
--- make-bundle 4 Nov 2007 17:02:17 -0000 1.1
+++ make-bundle 4 Nov 2007 22:22:08 -0000
@@ -11,30 +11,36 @@
);
$props = array();
-array_shift($argv);
-
-if (!count($argv)) {
- usage(null);
-}
-
-while (count($argv)) {
- $arg = array_shift($argv);
- if ($arg[0] != '-') {
- usage("args must start with a -\n");
- }
- $arg = substr($arg, 1);
- if (!count($argv)) {
- usage("args must all have a value\n");
- }
- $val = array_shift($argv);
-
- $props[$arg][] = $val;
+$bool=array("symlink","overwrite");
+$single=array("target-dir","name","main","nib","version","url","icon","php-config","dmg");
+$array=array("resources");
+
+if ($_SERVER['argc']==1) {
+ usage();
+} else {
+ for($i=1;$i<$_SERVER['argc'];) {
+ if ($_SERVER['argv'][$i][0]!="-") {
+ usage(sprintf("args must start with a - (%s)\n",$_SERVER['argv'][$i]));
+ } else {
+ $name=substr($_SERVER['argv'][$i],1);
+ if (in_array($name,$bool)) {
+ $props[$name]=true;
+ } elseif (in_array($name,$single)) {
+ $props[$name]=$_SERVER['argv'][++$i];
+ } elseif (in_array($name,$array)) {
+ $props[$name][]=$_SERVER['argv'][++$i];
+ } else {
+ usage(sprintf("argument %s unrecognized\n",$name));
+ }
+ $i++;
+ }
+ }
}
function get_arg($name, $required = false) {
global $props, $defaults;
- if (isset($props[$name][0])) {
- return $props[$name][0];
+ if (isset($props[$name])) {
+ return $props[$name];
}
if ($required && !isset($defaults[$name])) {
usage("Required argument $name was not specified\n");
@@ -43,14 +49,18 @@
}
function get_arg_array($name) {
- global $props, $defaults;
- if (isset($props[$name])) {
- return $props[$name];
- }
- return $defaults[$name];
+ global $props, $defaults;
+ if (isset($props[$name])) {
+ return $props[$name];
+ } elseif (isset($defaults[$name])) {
+ return $defaults[$name];
+ } else {
+ return false;
+ }
}
-function usage($msg) {
+
+function usage($msg=false) {
if (strlen($msg)) {
echo "Error: $msg";
}
@@ -63,20 +73,21 @@
echo " -nib MainMenu Main nib file for the app\n";
echo " -version 1.0.0 Application version, must include major.minor.patch\n";
echo " otherwise the bundle will not function\n";
- echo " -url 'http://my.blog.url.example.com' Your URL, should be unique to you.\n";
+ echo " -url 'http://example.com' Your URL, should be unique to you.\n";
echo " -icon icon.icns Name of icon to use for the bundle.\n";
echo " You must also use -resources to import it into the bundle\n";
echo " -php-config php-config Path to php-config script. The PHP install described by\n";
echo " this script will be imported into your bundle\n";
- echo " -copy-mode symlink Use symlinks instead of copying. Use for testing locally only.\n";
+ echo " -symlink Use symlinks instead of copying. Use for testing locally only.\n";
echo " -dmg filename.dmg Also bake it into a .dmg file\n";
+ echo " -overwrite Overwrite target-dir/name.app and/or dmg\n";
echo "\n";
exit(1);
}
$target_dir = get_arg("target-dir", true);
if (!is_dir($target_dir)) {
- usage("target-dir must be a directory that already exists\n");
+ usage("target-dir must be a directory that already exists\n");
}
$name = get_arg('name', true);
@@ -88,6 +99,9 @@
$ident = "$url $name";
$target_dir .= "/$name.app";
+if (is_dir($target_dir)&&(get_arg("overwrite"))) {
+ system(sprintf("/bin/rm -rf %s",$target_dir));
+}
mkdir($target_dir) or die("failed to create $target_dir\n");
mkdir("$target_dir/Contents");
mkdir("$target_dir/Contents/Resources");
@@ -174,13 +188,17 @@
@chmod("$target_dir/Contents/MacOS/php", 0755);
chmod("$target_dir/Contents/MacOS/boot", 0755);
-foreach (get_arg_array('resources') as $res) {
- copy_or_link($res, "$target_dir/Contents/Resources");
+if (($resources=get_arg_array('resources'))===false) {
+ printf("Warning: not copying any resources, this probably isn't what you want\n");
+} else {
+ foreach ($resources as $res) {
+ copy_or_link($res, "$target_dir/Contents/Resources");
+ }
}
function copy_or_link($source, $dest)
{
- if (get_arg('copy-mode') == 'symlink') {
+ if (get_arg('symlink')) {
# echo "$dest link-to $source\n";
$source = realpath($source);
system("ln -sf '$source' '$dest'");
@@ -238,5 +256,8 @@
$dmg = get_arg('dmg');
if (strlen($dmg)) {
- system("hdiutil create -srcfolder '$target_dir' -format UDZO -volname '$name' '$dmg'");
+ if (file_exists($dmg)&&get_arg("overwrite")) {
+ unlink($dmg);
+ }
+ system("hdiutil create -srcfolder '$target_dir' -format UDZO -volname '$name' '$dmg'");
}
also: http://adam.gs/make-bundle.diff
-Adam
On Nov 4, 2007, at 5:52 PM, Wez Furlong wrote:
> The diff went AWOL; the mailing list strips non text attachments, so
> try saving it as .txt and attaching it.
>
> --Wez.
>
>
> On Nov 4, 2007, at 5:25 PM, Adam Jacob Muller wrote:
>
>> Summary:
>> re-wrote argument parsing code so it can handle single args (-
>> symlink for example)
>> cleaned up usage() a bit
>> added -overwrite that will rm -rf $target_dir and unlink() $dmg
>> added: Warning: not copying any resources, this probably isn't
>> what you want
>>
>> Comments please :)
>>
>>
>>
>>
>> --
>> PHP Objective-C Bridge Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
| Navigate in group php.objc at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |