summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--psysh-bin-autoload.patch119
-rw-r--r--psysh.spec223
2 files changed, 342 insertions, 0 deletions
diff --git a/psysh-bin-autoload.patch b/psysh-bin-autoload.patch
new file mode 100644
index 0000000..a9e670a
--- /dev/null
+++ b/psysh-bin-autoload.patch
@@ -0,0 +1,119 @@
+diff --git a/bin/psysh b/bin/psysh
+index 4fbd223..ef7b940 100755
+--- a/bin/psysh
++++ b/bin/psysh
+@@ -10,91 +10,7 @@
+ * file that was distributed with this source code.
+ */
+
+-// Try to find an autoloader for a local psysh version.
+-// We'll wrap this whole mess in a Closure so it doesn't leak any globals.
+-call_user_func(function () {
+- $cwd = null;
+-
+- // Find the cwd arg (if present)
+- $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
+- foreach ($argv as $i => $arg) {
+- if ($arg === '--cwd') {
+- if ($i >= count($argv) - 1) {
+- echo 'Missing --cwd argument.' . PHP_EOL;
+- exit(1);
+- }
+- $cwd = $argv[$i + 1];
+- break;
+- }
+-
+- if (preg_match('/^--cwd=/', $arg)) {
+- $cwd = substr($arg, 6);
+- break;
+- }
+- }
+-
+- // Or fall back to the actual cwd
+- if (!isset($cwd)) {
+- $cwd = getcwd();
+- }
+-
+- $cwd = str_replace('\\', '/', $cwd);
+-
+- $chunks = explode('/', $cwd);
+- while (!empty($chunks)) {
+- $path = implode('/', $chunks);
+-
+- // Find composer.json
+- if (is_file($path . '/composer.json')) {
+- if ($cfg = json_decode(file_get_contents($path . '/composer.json'), true)) {
+- if (isset($cfg['name']) && $cfg['name'] === 'psy/psysh') {
+- // We're inside the psysh project. Let's use the local
+- // Composer autoload.
+- if (is_file($path . '/vendor/autoload.php')) {
+- require $path . '/vendor/autoload.php';
+- }
+-
+- return;
+- }
+- }
+- }
+-
+- // Or a composer.lock
+- if (is_file($path . '/composer.lock')) {
+- if ($cfg = json_decode(file_get_contents($path . '/composer.lock'), true)) {
+- foreach (array_merge($cfg['packages'], $cfg['packages-dev']) as $pkg) {
+- if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
+- // We're inside a project which requires psysh. We'll
+- // use the local Composer autoload.
+- if (is_file($path . '/vendor/autoload.php')) {
+- require $path . '/vendor/autoload.php';
+- }
+-
+- return;
+- }
+- }
+- }
+- }
+-
+- array_pop($chunks);
+- }
+-});
+-
+-// We didn't find an autoloader for a local version, so use the autoloader that
+-// came with this script.
+-if (!class_exists('Psy\Shell')) {
+-/* <<< */
+- if (is_file(__DIR__ . '/../vendor/autoload.php')) {
+- require __DIR__ . '/../vendor/autoload.php';
+- } elseif (is_file(__DIR__ . '/../../../autoload.php')) {
+- require __DIR__ . '/../../../autoload.php';
+- } else {
+- echo 'PsySH dependencies not found, be sure to run `composer install`.' . PHP_EOL;
+- echo 'See https://getcomposer.org to get Composer.' . PHP_EOL;
+- exit(1);
+- }
+-/* >>> */
+-}
++require_once '__PHPDIR__/Psy/autoload.php';
+
+ // If the psysh binary was included directly, assume they just wanted an
+ // autoloader and bail early.
+@@ -115,21 +31,5 @@ if (Psy\Shell::isIncluded($trace)) {
+ // Clean up after ourselves.
+ unset($trace);
+
+-// If the local version is too old, we can't do this
+-if (!function_exists('Psy\bin')) {
+- $argv = $_SERVER['argv'];
+- $first = array_shift($argv);
+- if (preg_match('/php(\.exe)?$/', $first)) {
+- array_shift($argv);
+- }
+- array_unshift($argv, 'vendor/bin/psysh');
+-
+- echo 'A local PsySH dependency was found, but it cannot be loaded. Please update to' . PHP_EOL;
+- echo 'the latest version, or run the local copy directly, e.g.:' . PHP_EOL;
+- echo PHP_EOL;
+- echo ' ' . implode(' ', $argv) . PHP_EOL;
+- exit(1);
+-}
+-
+ // And go!
+ call_user_func(Psy\bin());
diff --git a/psysh.spec b/psysh.spec
new file mode 100644
index 0000000..6b57b3c
--- /dev/null
+++ b/psysh.spec
@@ -0,0 +1,223 @@
+#
+# Fedora spec file for psysh
+#
+# Copyright (c) 2016 Shawn Iwinski <shawn@iwin.ski>
+#
+# License: MIT
+# http://opensource.org/licenses/MIT
+#
+# Please preserve changelog entries
+#
+
+%global github_owner bobthecow
+%global github_name psysh
+%global github_version 0.7.2
+%global github_commit e64e10b20f8d229cac76399e1f3edddb57a0f280
+
+%global composer_vendor psy
+%global composer_project psysh
+
+# "php": ">=5.3.9"
+%global php_min_ver 5.3.9
+# "dnoegel/php-xdg-base-dir": "0.1"
+%global php_xdg_base_dir_min_ver 0.1
+%global php_xdg_base_dir_max_ver 0.2
+# "jakub-onderka/php-console-highlighter": "0.3.*"
+%global php_console_highlighter_min_ver 0.3.0
+%global php_console_highlighter_max_ver 0.4.0
+# "nikic/php-parser": "^1.2.1|~2.0"
+# NOTE: Min version not 1.2.1 to force 2.x so 1.x is not
+# a dependency so it could possibly be retired
+%global php_parser_min_ver 2.0
+%global php_parser_max_ver 3.0
+# "symfony/console": "~2.3.10|^2.4.2|~3.0"
+# "symfony/finder": "~2.1|~3.0"
+# "symfony/var-dumper": "~2.7|~3.0"
+# NOTE: Min version not 2.7.0 because autoloader required
+%global symfony_min_ver 2.7.1
+%global symfony_max_ver 3.0
+
+# Build using "--without tests" to disable tests
+%global with_tests 0%{!?_without_tests:1}
+
+%{!?phpdir: %global phpdir %{_datadir}/php}
+
+Name: psysh
+Version: %{github_version}
+Release: 2%{?github_release}%{?dist}
+Summary: A runtime developer console, interactive debugger and REPL for PHP
+
+Group: Development/Libraries
+License: MIT
+URL: http://psysh.org
+Source0: https://github.com/%{github_owner}/%{github_name}/archive/%{github_commit}/%{name}-%{github_version}-%{github_commit}.tar.gz
+
+# Update bin script to use generated autoloader
+Patch0: %{name}-bin-autoload.patch
+
+BuildArch: noarch
+# Tests
+%if %{with_tests}
+BuildRequires: php-cli
+## composer.json
+BuildRequires: php(language) >= %{php_min_ver}
+BuildRequires: php-composer(phpunit/phpunit)
+BuildRequires: php-composer(dnoegel/php-xdg-base-dir) >= %{php_xdg_base_dir_min_ver}
+BuildRequires: php-composer(jakub-onderka/php-console-highlighter) >= %{php_console_highlighter_min_ver}
+BuildRequires: php-composer(nikic/php-parser) >= %{php_parser_min_ver}
+BuildRequires: php-composer(symfony/console) >= %{symfony_min_ver}
+BuildRequires: php-composer(symfony/finder) >= %{symfony_min_ver}
+BuildRequires: php-composer(symfony/var-dumper) >= %{symfony_min_ver}
+## composer.json: optional
+BuildRequires: php-pcntl
+BuildRequires: php-pdo_sqlite
+BuildRequires: php-posix
+BuildRequires: php-readline
+## phpcompatinfo (computed from version 0.7.2)
+BuildRequires: php-ctype
+BuildRequires: php-date
+BuildRequires: php-dom
+BuildRequires: php-json
+BuildRequires: php-pcre
+BuildRequires: php-pdo
+BuildRequires: php-reflection
+BuildRequires: php-spl
+BuildRequires: php-tokenizer
+## Autoloader
+BuildRequires: php-composer(symfony/class-loader)
+%endif
+
+Requires: php-cli
+# composer.json
+Requires: php(language) >= %{php_min_ver}
+Requires: php-composer(dnoegel/php-xdg-base-dir) < %{php_xdg_base_dir_max_ver}
+Requires: php-composer(dnoegel/php-xdg-base-dir) >= %{php_xdg_base_dir_min_ver}
+Requires: php-composer(jakub-onderka/php-console-highlighter) < %{php_console_highlighter_max_ver}
+Requires: php-composer(jakub-onderka/php-console-highlighter) >= %{php_console_highlighter_min_ver}
+Requires: php-composer(nikic/php-parser) < %{php_parser_max_ver}
+Requires: php-composer(nikic/php-parser) >= %{php_parser_min_ver}
+Requires: php-composer(symfony/console) < %{symfony_max_ver}
+Requires: php-composer(symfony/console) >= %{symfony_min_ver}
+Requires: php-composer(symfony/var-dumper) < %{symfony_max_ver}
+Requires: php-composer(symfony/var-dumper) >= %{symfony_min_ver}
+# composer.json: optional
+Requires: php-pcntl
+Requires: php-pdo_sqlite
+Requires: php-posix
+Requires: php-readline
+# phpcompatinfo (computed from version 0.7.2)
+Requires: php-ctype
+Requires: php-date
+Requires: php-json
+Requires: php-pcre
+Requires: php-pdo
+Requires: php-reflection
+Requires: php-spl
+Requires: php-tokenizer
+# Autoloader
+Requires: php-composer(symfony/class-loader)
+
+# Standard "php-{COMPOSER_VENDOR}-{COMPOSER_PROJECT}" naming
+Provides: php-%{composer_vendor}-%{composer_project} = %{version}-%{release}
+# Composer
+Provides: php-composer(%{composer_vendor}/%{composer_project}) = %{version}
+
+%description
+%{summary}.
+
+
+%prep
+%setup -qn %{github_name}-%{github_commit}
+
+: Update bin script to use generated autoloader
+%patch0 -p1
+sed 's#__PHPDIR__#%{phpdir}#' -i bin/psysh
+
+: Remove upstream autoloader class and test
+rm -f src/Psy/Autoloader.php test/Psy/Test/AutoloaderTest.php
+
+
+%build
+: Create autoloader
+cat <<'AUTOLOAD' | tee src/Psy/autoload.php
+<?php
+/**
+ * Autoloader for %{name} and its' dependencies
+ * (created by %{name}-%{version}-%{release}).
+ */
+
+if (!isset($fedoraClassLoader) || !($fedoraClassLoader instanceof \Symfony\Component\ClassLoader\ClassLoader)) {
+ if (!class_exists('Symfony\\Component\\ClassLoader\\ClassLoader', false)) {
+ require_once '%{phpdir}/Symfony/Component/ClassLoader/ClassLoader.php';
+ }
+
+ $fedoraClassLoader = new \Symfony\Component\ClassLoader\ClassLoader();
+ $fedoraClassLoader->register();
+}
+
+$fedoraClassLoader->addPrefix('Psy\\', dirname(__DIR__));
+
+require_once __DIR__.'/functions.php';
+
+// Required dependencies
+require_once '%{phpdir}/JakubOnderka/PhpConsoleHighlighter/autoload.php';
+require_once '%{phpdir}/PhpParser2/autoload.php';
+require_once '%{phpdir}/Symfony/Component/Console/autoload.php';
+require_once '%{phpdir}/Symfony/Component/VarDumper/autoload.php';
+require_once '%{phpdir}/XdgBaseDir/autoload.php';
+
+return $fedoraClassLoader;
+AUTOLOAD
+
+
+%install
+: Library
+mkdir -p %{buildroot}%{phpdir}
+cp -rp src/* %{buildroot}%{phpdir}/
+
+: Bin
+mkdir -p %{buildroot}%{_bindir}
+install -pm 0755 bin/psysh %{buildroot}%{_bindir}/
+
+
+%check
+%if %{with_tests}
+: Create tests bootstrap
+cat <<'BOOTSTRAP' | tee bootstrap.php
+<?php
+$fedoraClassLoader =
+ require '%{buildroot}%{phpdir}/Psy/autoload.php';
+$fedoraClassLoader->addPrefix('Psy\\Test\\', __DIR__.'/test');
+BOOTSTRAP
+
+: Skip tests known to fail
+sed '/exit\(\).*die;/d' -i test/Psy/Test/CodeCleaner/ImplicitReturnPassTest.php
+sed '/foo.*return/d' -i test/Psy/Test/CodeCleanerTest.php
+
+: Skip tests known to fail in a mock env
+sed 's/function testFormat/function SKIP_testFormat/' \
+ -i test/Psy/Test/Formatter/CodeFormatterTest.php
+sed 's/function testWriteReturnValue/function SKIP_testWriteReturnValue/' \
+ -i test/Psy/Test/ShellTest.php
+
+%{_bindir}/phpunit --verbose --bootstrap bootstrap.php
+%else
+: Tests skipped
+%endif
+
+
+%files
+%{!?_licensedir:%global license %%doc}
+%license LICENSE
+%doc *.md
+%doc composer.json
+%{phpdir}/Psy
+%{_bindir}/psysh
+
+
+%changelog
+* Wed Jul 20 2016 Shawn Iwinski <shawn@iwin.ski> - 0.7.2-2
+- Add explicit php-cli dependency (bin script uses "#!/usr/bin/env php")
+
+* Fri Jul 15 2016 Shawn Iwinski <shawn@iwin.ski> - 0.7.2-1
+- Initial package