Skip to content

Commit abbbe22

Browse files
authoredMay 29, 2023
Phar build fix (phpactor#2281)
* Introduce docker env for development * Ignore .phpbench * Do not use realpath (doesn't work with PHAR) * Failing test for phar uri * Make filepath compatible with phar * Refacvtor text document uri to ot use parse_uri * Support "untitled" - NEED TO TEST THIS IN REAL LIFE * Failing test for phar scheme * Fix PHar * Install no-dev before building phar * Refactor filepath to use TextDocumentUri internally * Include vendor * Fix URI handling * Fix Untitled * Do not include vendor * Fix CS * Fix and remove * Fix SplFileInfo * Set memory limit and inotify-tools * Set columns and XDG home * Build Phar in regular CI * Use docker for docs * Add php.ini * no 1000 * Stop * Foo * u1001 * Do not map user * Include zip ext * Rename test * Makefile use docker * Use `phpactor` as folder for the sake of vimdoc * Up * Composer * Debug * Update * Debug * Up * No generate with compose
1 parent 2358b75 commit abbbe22

File tree

16 files changed

+163
-119
lines changed

16 files changed

+163
-119
lines changed
 

‎.github/build-phar.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -e
44

5+
composer install --no-dev
56
mkdir -p build
67
cd build
78

‎.github/workflows/ci.yml

+38-29
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,44 @@ env:
1212
TZ: "Europe/Paris"
1313

1414
jobs:
15+
phar:
16+
name: Compile Phar
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set PHP 8.1
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: '8.1'
28+
29+
-
30+
name: "Composer install"
31+
uses: "ramsey/composer-install@v2"
32+
with:
33+
composer-options: "--no-scripts --no-dev"
34+
35+
- name: Compile phpactor.phar
36+
run: .github/build-phar.sh
37+
38+
- name: Check existence of compiled .phar
39+
run: test -e build/phpactor.phar && exit 0 || exit 10
40+
- name: Execute Phar
41+
run: ./build/phpactor.phar
42+
43+
#- name: "Attach signature to Release"
44+
# uses: actions/upload-release-asset@v1
45+
# env:
46+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
# with:
48+
# upload_url: ${{ github.event.release.upload_url }}
49+
# asset_path: ./build/phpactor.phar.asc
50+
# asset_name: phpactor.phar.asc
51+
# asset_content_type: application/pgp-signature
52+
1553
vim-tests:
1654
name: "VIM Tests (${{ matrix.php-version }})"
1755

@@ -216,39 +254,10 @@ jobs:
216254
name: "Lint Docs (${{ matrix.php-version }})"
217255

218256
runs-on: "ubuntu-latest"
219-
220-
strategy:
221-
matrix:
222-
php-version:
223-
- '8.0'
224-
225257
steps:
226258
-
227259
name: "Checkout code"
228260
uses: "actions/checkout@v2"
229-
-
230-
name: "Install PHP"
231-
uses: "shivammathur/setup-php@v2"
232-
with:
233-
coverage: "none"
234-
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
235-
php-version: "${{ matrix.php-version }}"
236-
tools: composer:v2
237-
238-
-
239-
name: "Composer install"
240-
uses: "ramsey/composer-install@v1"
241-
with:
242-
composer-options: "--no-scripts"
243-
-
244-
name: Install Doc Dependencies
245-
run: |
246-
wget https://github.com/google/vimdoc/releases/download/v0.6.0/vimdoc_0.6.0-1_all.deb
247-
sudo dpkg -i vimdoc_0.6.0-1_all.deb
248-
sudo pip3 install -r requirements.txt
249-
composer install --optimize-autoloader --classmap-authoritative
250-
251261
-
252262
name: "Make Docs"
253263
run: "make docs"
254-

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/extensions
22
/phpactor.schema.json
33
/lib/Extension/WorseReflection/stubs
4+
/.phpbench
45

56
# Composer
67
/vendor

‎Makefile

+9-16
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ BUILDDIR = build
1414
build:
1515
mkdir build
1616

17-
build/vimdoc:
18-
git clone https://github.com/google/vimdoc build/vimdoc
17+
composer:
18+
composer install --no-scripts --optimize-autoloader --classmap-authoritative
1919

20-
build/vimdoc/build: build/vimdoc
21-
cd build/vimdoc; python3 setup.py config
22-
cd build/vimdoc; python3 setup.py build
23-
24-
build/bin/vimdoc: build/vimdoc/build
25-
cd build/vimdoc; python3 setup.py install --user
26-
27-
vimdoc: build/bin/vimdoc
28-
vimdoc .
20+
vimdoc:
21+
docker compose run php vimdoc .
2922

3023
configreference:
3124
./bin/phpactor development:generate-documentation extension > doc/reference/configuration.rst
@@ -34,18 +27,18 @@ configreference:
3427

3528
# Put it first so that "make" without argument is like "make help".
3629
help:
37-
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
30+
docker compose run php $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
3831

3932
sphinxwatch:
40-
@$(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
33+
docker compose run php $(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4134

4235
sphinx:
43-
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
36+
docker compose run php $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4437

4538
sphinxlatex:
46-
@$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
39+
docker compose run php $(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4740

48-
docs: configreference sphinx vimdoc
41+
docs: composer configreference vimdoc sphinx
4942

5043
clean:
5144
rm -Rf build

‎doc/reference/configuration.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ FilePathResolverExtension
890890
"""""""""""""""""""""""""""""""""""
891891

892892

893-
**Default**: ``"\/home\/mamazu\/packages\/phpactor\/phpactor"``
893+
**Default**: ``"\/phpactor"``
894894

895895

896896
.. _param_file_path_resolver.app_name:

‎docker-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
php:
3+
build:
4+
dockerfile: ./docker/Dockerfile
5+
context: ./
6+
command: sleep infinity
7+
environment:
8+
XDG_CACHE_HOME: /phpactor/build/.cache
9+
COLUMNS: 100
10+
volumes:
11+
- ./:/phpactor:delegated

‎docker/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM php:8.1-cli
2+
RUN apt-get update && apt-get install -y python3-pip wget git inotify-tools libzip-dev
3+
RUN echo "$(curl -sS https://composer.github.io/installer.sig) -" > composer-setup.php.sig \
4+
&& curl -sS https://getcomposer.org/installer | tee composer-setup.php | sha384sum -c composer-setup.php.sig \
5+
&& php composer-setup.php && rm composer-setup.php* \
6+
&& chmod +x composer.phar && mv composer.phar /usr/bin/composer
7+
RUN docker-php-ext-install pcntl zip
8+
RUN wget https://github.com/google/vimdoc/releases/download/v0.7.1/vimdoc_0.7.1-1_all.deb && \
9+
dpkg -i vimdoc_0.7.1-1_all.deb
10+
COPY requirements.txt ./
11+
COPY docker/php.ini /usr/local/etc/php/conf.d/
12+
RUN pip3 install -r requirements.txt
13+
RUN git config --global init.defaultBranch master
14+
WORKDIR /phpactor

‎docker/php.ini

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
memory_limit = -1

‎lib/Filesystem/Adapter/Simple/SimpleFileListProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function fileList(): FileList
2020
{
2121
return FileList::fromIterator(
2222
$this->createFileIterator(
23-
(string) $this->path
23+
$this->path->uriAsString()
2424
)
2525
);
2626
}
2727

2828
private function createFileIterator(string $path): Iterator
2929
{
30-
$path = $path ? $this->path->makeAbsoluteFromString($path) : $this->path->path();
30+
$path = $path ? $this->path->makeAbsoluteFromString($path)->uriAsString() : $this->path->uriAsString();
3131
$flags =
3232
FilesystemIterator::KEY_AS_PATHNAME |
3333
FilesystemIterator::CURRENT_AS_FILEINFO |

‎lib/Filesystem/Domain/FilePath.php

+19-39
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,31 @@
22

33
namespace Phpactor\Filesystem\Domain;
44

5+
use Phpactor\TextDocument\TextDocumentUri;
56
use RuntimeException;
67
use SplFileInfo;
7-
use InvalidArgumentException;
88
use Symfony\Component\Filesystem\Path;
99

1010
final class FilePath
1111
{
12-
private function __construct(private string $path)
12+
private function __construct(private TextDocumentUri $uri)
1313
{
14-
if (false === Path::isAbsolute($path)) {
15-
throw new InvalidArgumentException(sprintf(
16-
'File path must be absolute, but "%s" given',
17-
$path
18-
));
19-
}
2014
}
2115

2216
public function __toString(): string
2317
{
24-
return $this->path;
18+
return $this->uri->path();
2519
}
2620

27-
public static function fromString(string $string): FilePath
21+
public function uriAsString(): string
2822
{
29-
$url = parse_url($string);
30-
31-
if (false === $url) {
32-
throw new RuntimeException(sprintf('Cannot guess path from "%s"', $string));
33-
}
34-
35-
$url += ['scheme' => null, 'path' => null];
36-
37-
['scheme' => $scheme, 'path' => $path] = $url;
38-
39-
if (null === $path) {
40-
throw new RuntimeException(sprintf('No path info from URI "%s"', $string));
41-
}
42-
43-
if (null !== $scheme && 'file' !== $scheme) {
44-
throw new RuntimeException(sprintf('Unsupported scheme "%s" for path "%s"', $scheme, $string));
45-
}
23+
return $this->uri->__toString();
24+
}
4625

47-
return new self((string)$path);
26+
public static function fromString(string $string): FilePath
27+
{
28+
$textDocumentUri = TextDocumentUri::fromString($string);
29+
return new self($textDocumentUri);
4830
}
4931

5032
public static function fromParts(array $parts): FilePath
@@ -54,12 +36,12 @@ public static function fromParts(array $parts): FilePath
5436
$path = '/'.$path;
5537
}
5638

57-
return new self($path);
39+
return self::fromString($path);
5840
}
5941

6042
public static function fromSplFileInfo(SplFileInfo $fileInfo): FilePath
6143
{
62-
return new self((string) $fileInfo);
44+
return self::fromString((string) $fileInfo);
6345
}
6446

6547
public static function fromUnknown($path): FilePath
@@ -88,12 +70,15 @@ public static function fromUnknown($path): FilePath
8870

8971
public function isDirectory(): bool
9072
{
91-
return is_dir($this->path);
73+
return is_dir($this->uri->path());
9274
}
9375

76+
/**
77+
* This will lose the scheme
78+
*/
9479
public function asSplFileInfo(): SplFileInfo
9580
{
96-
return new SplFileInfo($this->path());
81+
return new SplFileInfo($this->uri->path());
9782
}
9883

9984
public function makeAbsoluteFromString(string $path): FilePath
@@ -117,12 +102,7 @@ public function makeAbsoluteFromString(string $path): FilePath
117102

118103
public function extension(): string
119104
{
120-
return Path::getExtension($this->path);
121-
}
122-
123-
public function concatPath(FilePath $path): FilePath
124-
{
125-
return new self(Path::join($this->path(), (string) $path));
105+
return Path::getExtension($this->uri->path());
126106
}
127107

128108
public function isWithin(FilePath $path): bool
@@ -146,6 +126,6 @@ public function isNamed(string $name): bool
146126

147127
public function path(): string
148128
{
149-
return $this->path;
129+
return $this->uri->path();
150130
}
151131
}

‎lib/Filesystem/Tests/Unit/Domain/FilePathTest.php

+21-10
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Phpactor\Filesystem\Domain\FilePath;
7+
use Phpactor\TextDocument\Exception\InvalidUriException;
78
use RuntimeException;
89
use SplFileInfo;
910
use stdClass;
10-
use InvalidArgumentException;
1111

1212
class FilePathTest extends TestCase
1313
{
@@ -16,8 +16,8 @@ class FilePathTest extends TestCase
1616
*/
1717
public function testNotAbsolute(): void
1818
{
19-
$this->expectException(InvalidArgumentException::class);
20-
$this->expectExceptionMessage('File path must be absolute, but "foobar" given');
19+
$this->expectException(InvalidUriException::class);
20+
$this->expectExceptionMessage('must be absolute');
2121
FilePath::fromString('foobar');
2222
}
2323

@@ -54,6 +54,11 @@ public function provideUnknown()
5454
'/foo.php',
5555
];
5656

57+
yield 'PHAR string' => [
58+
'phar:///foo.php',
59+
'/foo.php',
60+
];
61+
5762
yield 'array' => [
5863
[ 'one', 'two' ],
5964
'/one/two'
@@ -63,6 +68,10 @@ public function provideUnknown()
6368
new SplFileInfo(__FILE__),
6469
__FILE__
6570
];
71+
yield 'SplFileInfo with scheme' => [
72+
new SplFileInfo('file://' . __FILE__),
73+
__FILE__
74+
];
6675
}
6776

6877
/**
@@ -84,17 +93,12 @@ public function provideUnsupportedInput()
8493

8594
yield 'unsupported scheme' => [
8695
'ftp://host/foo.php',
87-
'Unsupported scheme "ftp" for path "ftp://host/foo.php"',
88-
];
89-
90-
yield 'malformed string' => [
91-
'bar:///foo.php',
92-
'Cannot guess path from "bar:///foo.php"',
96+
'are supported', // only X schemes are supported
9397
];
9498

9599
yield 'URI without a path' => [
96100
'http://.?x=1&n',
97-
'No path info from URI "http://.?x=1&n"',
101+
'are supported', // only X schemes are supported
98102
];
99103
}
100104

@@ -172,4 +176,11 @@ public function testIsNamed(): void
172176
$this->assertTrue($path2->isNamed('foobar'));
173177
$this->assertFalse($path3->isNamed('foobar'));
174178
}
179+
180+
public function testAsSplFileInfo(): void
181+
{
182+
$path1 = FilePath::fromUnknown(new SplFileInfo('file://' . __FILE__));
183+
self::assertEquals(__FILE__, $path1->__toString());
184+
self::assertEquals(__FILE__, $path1->asSplFileInfo()->__toString());
185+
}
175186
}

0 commit comments

Comments
 (0)