cvs: php-objc /utils make-bundle

From: Date: Sun, 04 Nov 2007 23:54:48 +0000
Subject: cvs: php-objc /utils make-bundle
Groups: php.objc 
Request: Send a blank email to php-objc+get-15@lists.php.net to get a copy of this message
wez Sun Nov 4 23:54:48 2007 UTC Modified files: /php-objc/utils make-bundle Log: Modified patch from Adam Jacob Muller to fixup some strictness issues and argument handling. http://cvs.php.net/viewvc.cgi/php-objc/utils/make-bundle?r1=1.1&r2=1.2&diff_format=u Index: php-objc/utils/make-bundle diff -u php-objc/utils/make-bundle:1.1 php-objc/utils/make-bundle:1.2 --- php-objc/utils/make-bundle:1.1 Sun Nov 4 17:02:17 2007 +++ php-objc/utils/make-bundle Sun Nov 4 23:54:47 2007 @@ -11,30 +11,51 @@ ); $props = array(); -array_shift($argv); - -if (!count($argv)) { - usage(null); -} +$bool = array( + "symlink", + "overwrite" +); +$single = array( + "target-dir", + "name", + "main", + "nib", + "version", + "url", + "icon", + "php-config", + "dmg" +); +$array = array( + "resources" +); -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"); +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++; + } } - $val = array_shift($argv); - - $props[$arg][] = $val; } 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"); @@ -46,11 +67,15 @@ global $props, $defaults; if (isset($props[$name])) { return $props[$name]; + } elseif (isset($defaults[$name])) { + return $defaults[$name]; + } else { + return false; } - return $defaults[$name]; } -function usage($msg) { + +function usage($msg=false) { if (strlen($msg)) { echo "Error: $msg"; } @@ -63,13 +88,14 @@ 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); } @@ -88,6 +114,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"); @@ -102,8 +131,8 @@ file_put_contents("$target_dir/Contents/Info.plist", <<<XML <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC - "-//Apple Computer//DTD PLIST 1.0//EN" - "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + "-//Apple Computer//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> @@ -174,13 +203,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 +271,8 @@ $dmg = get_arg('dmg'); if (strlen($dmg)) { + if (get_arg("overwrite") && file_exists($dmg)) { + unlink($dmg); + } system("hdiutil create -srcfolder '$target_dir' -format UDZO -volname '$name' '$dmg'"); }

« previous php.objc (#15) next »