2014年7月5日土曜日

Phingを使ってaws-adk-phpをビルドしてみた

■環境
CentOS release 5.10 (Final)
PHP 5.3.3
Pear 1.9.4 インストール方法
Composer インストール方法

■Phingインストール
pear channel-discover pear.phing.info
Adding Channel "pear.phing.info" succeeded
Discovery of channel "pear.phing.info" succeeded

pear install --alldeps phing/phing
Unknown remote channel: pear.phpunit.de
Unknown remote channel: pear.phpunit.de
WARNING: "pear/PEAR_PackageFileManager" is deprecated in favor of "pear/PEAR_PackageFileManager2"
Unknown remote channel: pear.pdepend.org
Unknown remote channel: pear.phpmd.org
Unknown remote channel: pear.phpunit.de
Unknown remote channel: pear.phpunit.de
Unknown remote channel: pear.phpdoc.org
Did not download optional dependencies: phing/phingdocs, pear/VersionControl_SVN, pear/VersionControl_Git, channel://pear.phpunit.de/PHPUnit, channel://pear.phpunit.de/PHP_CodeCoverage, pecl/Xdebug, pear/PEAR_PackageFileManager, pear/Services_Amazon_S3, channel://pear.pdepend.org/PHP_Depend, channel://pear.phpmd.org/PHP_PMD, channel://pear.phpunit.de/phpcpd, channel://pear.phpunit.de/phploc, channel://pear.phpdoc.org/phpDocumentor, pear/PHP_CodeSniffer, pear/Net_Growl, use --alldeps to download automatically
phing/phing can optionally use package "phing/phingdocs" (version >= 2.8.1)
phing/phing can optionally use package "pear/VersionControl_SVN" (version >= 0.4.0)
phing/phing can optionally use package "pear/VersionControl_Git" (version >= 0.4.3)
phing/phing can optionally use package "channel://pear.phpunit.de/PHPUnit" (version >= 3.6.0)
phing/phing can optionally use package "channel://pear.phpunit.de/PHP_CodeCoverage" (version >= 1.1.0)
phing/phing can optionally use package "pecl/Xdebug" (version >= 2.0.5)
phing/phing can optionally use package "pear/PEAR_PackageFileManager" (version >= 1.5.2)
phing/phing can optionally use package "pear/Services_Amazon_S3" (version >= 0.3.1)
phing/phing can optionally use package "channel://pear.pdepend.org/PHP_Depend" (version >= 0.10.0)
phing/phing can optionally use package "channel://pear.phpmd.org/PHP_PMD" (version >= 1.1.0)
phing/phing can optionally use package "channel://pear.phpunit.de/phpcpd" (version >= 1.3.3)
phing/phing can optionally use package "channel://pear.phpunit.de/phploc" (version >= 1.6.4)
phing/phing can optionally use package "channel://pear.phpdoc.org/phpDocumentor" (version >= 2.0.0b7)
phing/phing can optionally use package "pear/PHP_CodeSniffer" (version >= 1.5.0)
phing/phing can optionally use package "pear/Net_Growl" (version >= 2.6.0)
downloading phing-2.8.1.tgz ...
Starting to download phing-2.8.1.tgz (483,377 bytes)
.................................................................................................done: 483,377 bytes
install ok: channel://pear.phing.info/phing-2.8.1

pear list -c PEAR.PHING.INFO
INSTALLED PACKAGES, CHANNEL PEAR.PHING.INFO:
============================================
PACKAGE VERSION STATE
phing   2.8.1   stable

■aws-sdk-php のダウンロード
git clone https://github.com/aws/aws-sdk-php.git

■必要なライブラリのインストール(composer)
cd aws-sdk-php
※composer.js が存在することを確認します

composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/event-dispatcher (v2.5.0)
    Downloading: 100%

  - Installing guzzle/guzzle (v3.9.1)
    Loading from cache

  - Installing doctrine/cache (v1.3.0)
    Downloading: 100%

  - Installing psr/log (1.0.0)
    Downloading: 100%

  - Installing monolog/monolog (1.4.1)
    Downloading: 100%

  - Installing sebastian/version (1.0.3)
    Downloading: 100%

  - Installing sebastian/exporter (1.0.1)
    Downloading: 100%

  - Installing sebastian/environment (1.0.0)
    Downloading: 100%

  - Installing sebastian/diff (1.1.0)
    Downloading: 100%

  - Installing sebastian/comparator (1.0.0)
    Downloading: 100%

  - Installing symfony/yaml (v2.5.0)
    Downloading: 100%

  - Installing phpunit/php-text-template (1.2.0)
    Downloading: 100%

  - Installing phpunit/phpunit-mock-objects (2.1.5)
    Downloading: 100%

  - Installing phpunit/php-timer (1.0.5)
    Downloading: 100%

  - Installing phpunit/php-token-stream (1.2.2)
    Downloading: 100%

  - Installing phpunit/php-file-iterator (1.3.4)
    Downloading: 100%

  - Installing phpunit/php-code-coverage (2.0.9)
    Downloading: 100%

  - Installing phpunit/phpunit (4.1.3)
    Downloading: 100%

  - Installing symfony/class-loader (v2.5.0)
    Downloading: 100%

symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files

■aws-sdk-phpのビルド
cd aws-sdk-php
※build.xml が存在することを確認します

phing
※デフォルトだとUnitTestだけが実行されます
Buildfile: /var/tmp/aws-sdk-php/build.xml

aws-sdk-for-php > test-init:

     [copy] phpunit.xml.dist omitted, is up to date
     [copy] phpunit.functional.xml.dist omitted, is up to date
     [copy] test_services.json.dist omitted, is up to date

aws-sdk-for-php > test:

PHPUnit 4.1.3 by Sebastian Bergmann.

Configuration read from /var/tmp/aws-sdk-php/phpunit.xml

...SSS.......................................................F.  63 / 856 (  7%)
....................................................S.......... 126 / 856 ( 14%)
............................................................... 189 / 856 ( 22%)
............................................................... 252 / 856 ( 29%)
............................................................... 315 / 856 ( 36%)
............................................................... 378 / 856 ( 44%)
............................................................... 441 / 856 ( 51%)
............................................................... 504 / 856 ( 58%)
............................................................... 567 / 856 ( 66%)
............................................................... 630 / 856 ( 73%)
..................................PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to alloate 491520 bytes) in /var/tmp/aws-sdk-php/src/Aws/S3/Resources/s3-2006-03-01.php on line 1330

BUILD FINISHED

Total time: 3.9861 seconds
メモリが少ないと言われてテストが途中で失敗してしまいました
今回はスルーして先に進みます

phing build
※ライブラリとして配布できるpharファイルを作成します
Buildfile: /var/tmp/aws-sdk-php/build.xml

aws-sdk-for-php > phplint:


aws-sdk-for-php > clean:

   [delete] Directory /var/tmp/aws-sdk-php/build/artifacts does not exist or is not a directory.

aws-sdk-for-php > test-init:

     [copy] phpunit.xml.dist omitted, is up to date
     [copy] phpunit.functional.xml.dist omitted, is up to date
     [copy] test_services.json.dist omitted, is up to date

aws-sdk-for-php > prepare:

    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/logs

aws-sdk-for-php > test:

PHPUnit 4.1.3 by Sebastian Bergmann.

Configuration read from /var/tmp/aws-sdk-php/phpunit.xml

...SSS.......................................................F.  63 / 856 (  7%)
....................................................S.......... 126 / 856 ( 14%)
............................................................... 189 / 856 ( 22%)
............................................................... 252 / 856 ( 29%)
............................................................... 315 / 856 ( 36%)
............................................................... 378 / 856 ( 44%)
............................................................... 441 / 856 ( 51%)
............................................................... 504 / 856 ( 58%)
............................................................... 567 / 856 ( 66%)
............................................................... 630 / 856 ( 73%)
..................................PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 491520 bytes) in /var/tmp/aws-sdk-php/src/Aws/S3/Resources/s3-2006-03-01.php on line 1330

aws-sdk-for-php > create-staging:

    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging/Aws
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging/Guzzle
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging/Doctrine/Common/Cache
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging/Symfony
    [mkdir] Created dir: /var/tmp/aws-sdk-php/build/artifacts/staging/Monolog
     [copy] Copying 1 file to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 925 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 1 file to /var/tmp/aws-sdk-php/build/artifacts/staging/Aws
     [copy] Copying 1 file to /var/tmp/aws-sdk-php/build/artifacts/staging/Aws
     [copy] Copying 18 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 91 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 234 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 45 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 9 files to /var/tmp/aws-sdk-php/build/artifacts/staging
     [copy] Copying 17 files to /var/tmp/aws-sdk-php/build/artifacts/staging

aws-sdk-for-php > phar:

[pharpackage] Building package: /var/tmp/aws-sdk-php/build/aws.phar

aws-sdk-for-php > build:


BUILD FINISHED

Total time: 13.3099 seconds
先にテストが実行された後に phar ファイルが作成されます

SDKの改修をするのであれば
ソース改修 -> phing build -> phar 作成 -> テスト
といった流れで改修して行く感じかと思います

■作成したpharファイルの実行
cd aws-sdk-php/build
emacs pharTest.php
<?php
require './aws.phar';

use Aws\Sqs\SqsClient;

$client = SqsClient::factory(array(
  'key'    => 'your access key',
  'secret' => 'your secret access key',
  'region' => 'ap-northeast-1'
));
$result = $client->listQueues(array());
var_dump($result);
?>

php pharTest.php
でキューの東京リージョンにあるキューの一覧が取得できるかと思います

以上です
aws-sdk-php はオープンソースなのでバグがあったときはこれで修正してプルリクエストでも送ってあげるといいと思います
ちなみに「phing zip」として実行すると phar ファイルの代わりに配布可能な zip ファイルを作成してくれます

■参考サイト

0 件のコメント:

コメントを投稿