Page MenuHomeDevCentral

D2526.diff
No OneTemporary

D2526.diff

diff --git a/.arcconfig b/.arcconfig
new file mode 100644
--- /dev/null
+++ b/.arcconfig
@@ -0,0 +1,7 @@
+{
+ "phabricator.uri": "https://devcentral.nasqueron.org/",
+ "repository.callsign": "PHPWRAP",
+ "load": [
+ "shellcheck-linter"
+ ]
+}
diff --git a/.arclint b/.arclint
new file mode 100644
--- /dev/null
+++ b/.arclint
@@ -0,0 +1,24 @@
+{
+ "linters": {
+ "chmod": {
+ "type": "chmod"
+ },
+ "shell": {
+ "type": "shellcheck",
+ "include": [
+ "(\\.sh$)"
+ ]
+ },
+ "filename": {
+ "type": "filename"
+ },
+ "json": {
+ "type": "json",
+ "include": [
+ "(^\\.arcconfig$)",
+ "(^\\.arclint$)",
+ "(\\.json$)"
+ ]
+ }
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/Makefile b/Makefile
new file mode 100644
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,40 @@
+COMMANDS=phan phpcs phpcbf phpunit psysh phpmd phpstan psalm
+PREFIX=/usr/local
+
+SED=sed
+INSTALL_SCRIPT=install -m0755
+
+# Expand commands into specific targets
+# GNU Makefile compatible only
+
+BIN_COMMANDS:=$(COMMANDS:%=$(PREFIX)/bin/%)
+WRAP_COMMANDS:=$(COMMANDS:%=build/%)
+
+# Main targets
+
+all: wrappers
+
+install: $(PREFIX)/bin/run-php-script ${BIN_COMMANDS}
+
+# Build targets
+
+wrappers: build $(WRAP_COMMANDS)
+
+build:
+ mkdir -p build
+
+$(WRAP_COMMANDS):
+ ${SED} s/%%COMMAND%%/${@:build/%=%}/g src/command.template > $@
+
+# Install targets
+
+$(PREFIX)/bin/run-php-script:
+ ${INSTALL_SCRIPT} bin/run-php-script.sh $(PREFIX)/bin/run-php-script
+
+$(BIN_COMMANDS):
+ ${INSTALL_SCRIPT} ${@:$(PREFIX)/bin/%=build/%} $@
+
+# Clean targets
+
+clean:
+ rm -rf build/
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+# run-php-script
+
+Quality and development PHP tools like PHPUnit, phpcs or phan are typically installed through Composer packages. As such, several software can use several versions of those tools.
+
+Generally, some of those tools are also installed globally to be able to run them everywhere.
+
+Meanwhile, programs calling linters like Arcanist have some trouble to find executables.
+
+Finally, programs like PHPUnit are distributed in phar format with .phar extension and can so be installed as phpunit or phpunit.phar on the system.
+
+This wrapper package addresses two issues:
+
+ 1. Give priority to Composer version, located in vendor/bin
+ 2. Find tools executables in /opt, for example /opt/phpunit.phar /opt/phpunit
+
+## Build wrappers
+This package provides a Makefile to generate those wrappers:
+```
+$ make
+```
+On BSD systems, you need to explicitlely require GNU make:
+```
+$ gmake
+```
+Wrappers are then located in the `builds/` folder.
+
+## Install wrappers
+You can customize the target path in Makefile editing the PREFIX variable, then:
+
+```
+$ sudo make install
+```
diff --git a/bin/run-php-script.sh b/bin/run-php-script.sh
new file mode 100755
--- /dev/null
+++ b/bin/run-php-script.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+COMMAND=$1
+shift
+
+if [ -f "vendor/bin/$COMMAND" ]; then
+ echo "Switching to Composer $COMMAND:"
+ SCRIPT="vendor/bin/$COMMAND"
+elif [ -f "/opt/$COMMAND.phar" ]; then
+ SCRIPT="/opt/$COMMAND.phar"
+elif [ -f "/opt/$COMMAND" ]; then
+ SCRIPT="/opt/$COMMAND"
+else
+ echo "No $COMMAND has been found."
+ exit 1
+fi
+
+php "$SCRIPT" "$@"
diff --git a/src/command.template b/src/command.template
new file mode 100755
--- /dev/null
+++ b/src/command.template
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+run-php-script %%COMMAND%% "$@"

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 18:47 (11 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2316041
Default Alt Text
D2526.diff (3 KB)

Event Timeline