From 0edbdbaa43d40da250ab8b9b548ce764a7ae884e Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 27 Apr 2015 01:10:46 +0100 Subject: [PATCH] Add pakefile as replacement for makefile --- .gitignore | 2 +- composer.json | 3 +- pakefile.php | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 pakefile.php diff --git a/.gitignore b/.gitignore index 70c1a68..1305331 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ composer.phar composer.lock /vendor/* /tests/coverage/* - +/build/* diff --git a/composer.json b/composer.json index 62d1129..788aa99 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "phpunit/phpunit-selenium": "*", "codeclimate/php-test-reporter": "dev-master", "ext-curl": "*", - "ext-mbstring": "*" + "ext-mbstring": "*", + "indeyets/pake": "~1.99" }, "suggest": { "ext-curl": "Needed for HTTPS and HTTP 1.1 support, NTLM Auth etc...", diff --git a/pakefile.php b/pakefile.php new file mode 100644 index 0000000..2ae9e35 --- /dev/null +++ b/pakefile.php @@ -0,0 +1,189 @@ + 1) + self::$sourceBranch = $args[1]; + + pake_echo('---'.self::$libVersion.'---'); + } +} + +} + +namespace { + +use PhpXmlRpc\Builder; + +function run_default($task=null, $args=array(), $cliOpts=array()) +{ + echo "Syntax: pake {\$pake-options} \$task \$lib-version [\$git-tag]\n"; + echo "\n"; + echo " Run 'pake help' to list all pake options\n"; + echo " Run 'pake -T' to list all available tasks\n"; +} + +function run_getopts($task=null, $args=array(), $cliOpts=array()) +{ + Builder::getOpts($args, $cliOpts); +} + +/** + * Downloads source code in the build workspace directory, optionally checking out the given branch/tag + */ +function run_init($task=null, $args=array(), $cliOpts=array()) +{ + // download the current version into the workspace + $targetDir = Builder::workspaceDir(); + $targetBranch = 'php53'; + + // check if workspace exists and is not already set to the correct repo + if (is_dir($targetDir) && pakeGit::isRepository($targetDir)) { + $repo = new pakeGit($targetDir); + $remotes = $repo->remotes(); + if (trim($remotes['origin']['fetch']) != Builder::sourceRepo()) { + throw new Exception("Directory '$targetDir' exists and is not linked to correct git repo"); + } + + /// @todo should we not just fetch instead? + $repo->pull(); + } else { + pake_mkdirs(dirname($targetDir)); + $repo = pakeGit::clone_repository(Builder::sourceRepo(), Builder::workspaceDir()); + } + + $repo->checkout($targetBranch); +} + +/** + * Runs all the build steps. + * + * (does nothing by itself, as all the steps are managed via task dependencies) + */ +function run_build($task=null, $args=array(), $cliOpts=array()) +{ +} + +/** + * Generates documentation in all formats + */ +function run_doc($task=null, $args=array(), $cliOpts=array()) +{ + pake_echo('TBD...'); +} + +function run_clean_dist() +{ + pake_remove_dir(Builder::distDir()); + $finder = pakeFinder::type('file')->name(Builder::distFiles()); + pake_remove($finder, Builder::buildDir()); +} + +/** + * Creates the tarballs for a release + */ +function run_dist($task=null, $args=array(), $cliOpts=array()) +{ + // copy workspace dir into dist dir, without git + pake_mkdirs(Builder::distDir()); + $finder = pakeFinder::type('any')->ignore_version_control(); + pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir())); + + // remove unwanted files from dist dir + + // also: do we still need to run dos2unix? + + // create tarballs + chdir(dirname(Builder::distDir())); + foreach(Builder::distFiles() as $distFile) { + // php can not really create good zip files via phar: they are not compressed! + if (substr($distFile, -4) == '.zip') { + $cmd = 'zip'; + $extra = '-9 -r'; + pake_sh("$cmd $distFile $extra ".basename(Builder::distDir())); + } + else { + $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()).'/**'); + // see https://bugs.php.net/bug.php?id=58852 + $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile); + pakeArchive::createArchive($finder, '.', $pharFile); + rename($pharFile, $distFile); + } + } +} + +/** + * Cleans up the build directory + * @todo 'make clean' usually just removes the results of the build, distclean removes all but sources + */ +function run_clean($task=null, $args=array(), $cliOpts=array()) +{ + pake_remove_dir(Builder::buildDir()); +} + +// helper task: display help text +pake_task( 'default' ); +// internal task: parse cli options +pake_task('getopts'); +pake_task('init', 'getopts'); +pake_task('doc', 'getopts', 'init'); +pake_task('build', 'getopts', 'init', 'doc'); +pake_task('dist', 'getopts', 'init', 'build', 'clean-dist'); +pake_task('clean-dist', 'getopts'); +pake_task('clean', 'getopts'); + +} -- 2.43.0