Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 6b2d41e

Browse files
authored
Merge pull request #3 from mcuadros/master
Normalizator and SDK update
2 parents 81fe8e5 + ef4b3e1 commit 6b2d41e

29 files changed

+13584
-345
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.composer
12
.sdk
2-
build
3+
build

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ services:
77
- docker
88

99
before_script:
10-
- go get -v github.com/bblfsh/sdk/...
10+
- go get -v gopkg.in/bblfsh/sdk.v1/...
1111
- bblfsh-sdk prepare-build .
1212
- go get -v -t ./...
1313

1414
script:
15-
- make test
15+
- make test integration-test
1616

1717
after_success:
18-
- make push
18+
- make push

Dockerfile.build.tpl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
# Dockerfile.build represents the build environment of the driver, used during
2-
# the development phase to test and in CI to build and test.
3-
4-
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
5-
# meet the requirements you can switch the from to the latest stable slim
6-
# version of Debian (eg.: `debian:jessie-slim`).
71
FROM alpine:3.5
82

9-
# To avoid files written in the volume by root or foreign users, we create a
10-
# container local user with the same UID of the user executing the build.
11-
# The following commands are defined to use in busybox based distributions,
12-
# if you are using a standard distributions, replace the `adduser` command with:
13-
# `useradd --uid ${BUILD_UID} --home /opt/driver ${BUILD_USER}`
143
RUN mkdir -p /opt/driver/src && \
154
adduser ${BUILD_USER} -u ${BUILD_UID} -D -h /opt/driver/src
165

6+
# PHP installation from: http://php-alpine.codecasts.rocks/
7+
ADD https://php.codecasts.rocks/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub
8+
RUN echo "http://php.codecasts.rocks/v3.5/php-7.1" >> /etc/apk/repositories
9+
RUN apk add --no-cache make git ca-certificates \
10+
php7=${RUNTIME_NATIVE_VERSION} \
11+
php7-openssl php7-zlib php7-mbstring php7-json php7-phar php7-ctype \
12+
php7-xml php7-xdebug php7-dom
13+
14+
RUN ln -s /usr/bin/php7 /usr/bin/php
1715

18-
# As minimal build tools you need: make, curl and git, install using the same
19-
# command the specific tools required to build the driver.
20-
RUN apk add --no-cache make git curl ca-certificates
2116

17+
# PHP composer installation
18+
ADD https://getcomposer.org/installer /tmp/composer-setup.php
19+
RUN php /tmp/composer-setup.php --install-dir=/bin/
2220

23-
# The volume with the full source code is mounted at `/opt/driver/src` so, we
24-
# set the workdir to this path.
25-
WORKDIR /opt/driver/src
21+
WORKDIR /opt/driver/src

Dockerfile.tpl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
# Dockerfile represents the container being use to run the driver, should be
2-
# small as possible containing strictly only the tools required to run the
3-
# driver.
1+
FROM bblfsh/php-driver-build
42

5-
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
6-
# meet the requirements you can switch the from to the latest stable slim
7-
# version of Debian (eg.: `debian:jessie-slim`). If the excution environment
8-
# is equals to the build environment the build image can be use as FROM:
9-
# bblfsh/<language>-driver-build
10-
FROM alpine:3.5
11-
12-
CMD /opt/driver/bin/driver
3+
ADD build /opt/driver
4+
ENTRYPOINT ["/opt/driver/bin/driver"]

Makefile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
build-native-internal:
2-
echo "build-native-internal > not implemented"
1+
-include .sdk/Makefile
2+
3+
$(if $(filter true,$(sdkloaded)),,$(error You must install bblfsh-sdk))
34

45
test-native-internal:
5-
echo "test-native-internal > not implemented"
6+
cd native && \
7+
composer.phar install && \
8+
./vendor/bin/phpunit tests/
69

7-
test-native:
8-
cd native; \
9-
echo "test-native > not implemented"
10+
build-native-internal:
11+
cp -rf native $(BUILD_PATH)/src
12+
cd $(BUILD_PATH)/src && composer.phar install
1013

11-
build-native:
12-
cd native; \
13-
echo "build-native > not implemented"
14-
echo -e "#!/bin/bash\necho 'not implemented'" > $(BUILD_PATH)/native
15-
chmod +x $(BUILD_PATH)/native
14+
rm $(BUILD_PATH)/bin/native || true
15+
ln -s /opt/driver/src/ast $(BUILD_PATH)/bin/native
1616

17-
include .sdk/Makefile

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
# php-driver ![Driver Status](https://img.shields.io/badge/status-pre--alpha-d6ae86.svg) [![Build Status](https://travis-ci.org/bblfsh/php-driver.svg?branch=master)](https://travis-ci.org/bblfsh/php-driver) ![Native Version](https://img.shields.io/badge/php%20version-7.1-aa93ea.svg) ![Go Version](https://img.shields.io/badge/go%20version-1.8-63afbf.svg)
1+
# php-driver ![Driver Status](https://img.shields.io/badge/status-alpha-db975c.svg) [![Build Status](https://travis-ci.org/bblfsh/php-driver.svg?branch=master)](https://travis-ci.org/bblfsh/php-driver) ![Native Version](https://img.shields.io/badge/php%20version-7.1.7--r0-aa93ea.svg) ![Go Version](https://img.shields.io/badge/go%20version-1.8-63afbf.svg)
22

3-
php driver for [babelfish](https://github.com/bblfsh/server).
3+
php driver for [babelfish](https://github.com/bblfsh/bblfshd).
44

55

66
Development Environment
77
-----------------------
88

99
Requirements:
1010
- `docker`
11-
- [`bblfsh-sdk`](https://github.com/bblfsh/sdk) _(go get -u github.com/bblfsh/sdk/...)_
11+
- [`bblfsh-sdk`](https://github.com/bblfsh/sdk) _(go get -u gopkg.in/bblfsh/sdk.v1/...)_
12+
- UAST converter dependencies _(go get -t -v ./...)_
1213

1314
To initialize the build system execute: `bblfsh-sdk prepare-build`, at the root of the project. This will install the SDK at `.sdk` for this driver.
1415

1516
To execute the tests just execute `make test`, this will execute the test over the native and the go components of the driver. Use `make test-native` to run the test only over the native component or `make test-driver` to run the test just over the go component.
1617

17-
The build is done executing `make build`. To evaluate the result, a docker container, execute:
18-
`docker run -it bblfsh/php-driver:dev-<commit[:6]>`
18+
The build is done executing `make build`. To evaluate the result using a docker container, execute:
19+
`docker run -it bblfsh/php-driver:dev-<commit[:7]>-dirty`
1920

2021

2122
License

driver/main.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
4+
"github.com/bblfsh/php-driver/driver/normalizer"
65

7-
"github.com/bblfsh/sdk"
8-
9-
_ "github.com/bblfsh/php-driver/driver/normalizer"
6+
"gopkg.in/bblfsh/sdk.v1/sdk/driver"
107
)
118

12-
var version string
13-
var build string
14-
159
func main() {
16-
fmt.Printf("version: %s\nbuild: %s\n", version, build)
17-
18-
_, err := os.Stat(sdk.NativeBin)
19-
if err == nil {
20-
fmt.Println("native: ok")
21-
return
10+
d, err := driver.NewDriver(normalizer.ToNode, normalizer.Transformers)
11+
if err != nil {
12+
panic(err)
2213
}
2314

24-
fmt.Printf("native: %s\n", err)
25-
}
15+
s := driver.NewServer(d)
16+
if err := s.Start(); err != nil {
17+
panic(err)
18+
}
19+
}

driver/normalizer/annotation.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package normalizer
2+
3+
import (
4+
"github.com/bblfsh/sdk/uast/transformer/positioner"
5+
"gopkg.in/bblfsh/sdk.v1/uast"
6+
. "gopkg.in/bblfsh/sdk.v1/uast/ann"
7+
"gopkg.in/bblfsh/sdk.v1/uast/transformer"
8+
"gopkg.in/bblfsh/sdk.v1/uast/transformer/annotatter"
9+
)
10+
11+
// Transformers is the list of `transformer.Transfomer` to apply to a UAST, to
12+
// learn more about the Transformers and the available ones take a look to:
13+
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/transformers
14+
var Transformers = []transformer.Tranformer{
15+
annotatter.NewAnnotatter(AnnotationRules),
16+
positioner.NewFillLineColFromOffset(),
17+
}
18+
19+
// AnnotationRules describes how a UAST should be annotated with `uast.Role`.
20+
//
21+
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/ann
22+
var AnnotationRules = On(Any).Roles(uast.File)

0 commit comments

Comments
 (0)