Skip to content

Commit

Permalink
Port to Jbuilder
Browse files Browse the repository at this point in the history
As a consequence, Lambda Soup now requires OCaml 4.02.3.

The port also disables building with coverage in Travis, which is not
working for unknown reasons that I currently don't have time to
investigate.
  • Loading branch information
aantron committed Dec 12, 2017
1 parent 856825e commit 8084d5b
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 148 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
scratch/
_build/
*.install
.merlin
docs/html/
docs/*.zip
coverage/
bisect*.out
_coverage/
25 changes: 10 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
language: c
language: generic

env:
- PPA=avsm/ocaml312+opam12 SWITCH=system
- PPA=avsm/ocaml40+opam12 SWITCH=system
- PPA=avsm/ocaml41+opam12 SWITCH=system
- PPA=avsm/ocaml42+opam12 SWITCH=system
- PPA=avsm/ocaml42+opam12 SWITCH=4.03.0
- PPA=avsm/ocaml42+opam12 SWITCH=4.04.2
- PPA=avsm/ocaml42+opam12 SWITCH=4.05.0 DOCS=yes COVERAGE=yes
- PPA=avsm/ocaml42+opam12 SWITCH=4.06.0
- SWITCH=system
- SWITCH=4.03.0
- SWITCH=4.04.2
- SWITCH=4.05.0
- SWITCH=4.06.0

before_script:
- sudo add-apt-repository -y ppa:$PPA
- set -e
- sudo add-apt-repository -y ppa:avsm/ocaml42+opam12
- sudo apt-get update
- sudo apt-get install ocaml-nox opam python-bs4
- opam init -y --compiler $SWITCH
- eval `opam config env`
- "[ -z $COVERAGE ] || opam install -y bisect_ppx ocveralls"
- ocaml -version

script:
- make install
- make reverse-dependency-test
- opam pin add -y --no-action lambdasoup .
- opam install -y --deps-only lambdasoup
- opam install -y ounit
- make test
- make performance-test
- "[ -z $DOCS ] || make docs"
- "[ -z $COVERAGE ] || ocveralls --prefix _build bisect*.out --send"

notifications:
email:
Expand Down
114 changes: 29 additions & 85 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,41 @@
LIB := lambdasoup
VERSION := 0.6.1

OCAML_VERSION := \
$(shell ocamlc -version | grep -E -o '^[0-9]+\.[0-9]+' | sed 's/\.//')

ifeq ($(shell test $(OCAML_VERSION) -ge 402 && echo true),true)
SAFE_STRING := ,-safe-string
ifeq ($(shell ocamlfind query -qe -qo bisect_ppx && echo true),true)
COVERAGE := yes
COVERAGE_TAGS := \
-tag-line '<src/*>: package(bisect_ppx)' \
-tag-line '<test/*.native>: package(bisect_ppx)'
COVERAGE_DIR := coverage
endif
endif

ifeq ($(shell test $(OCAML_VERSION) -ge 400 && echo true),true)
BIN_ANNOT := ,-bin-annot
endif

ifdef TRAVIS_COMMIT
WERROR := ,-warn-error,+A-3
endif

CFLAGS := -cflags -w,+A$(BIN_ANNOT)$(SAFE_STRING)$(WERROR)

OCAMLBUILD := ocamlbuild -use-ocamlfind -no-links
DEP_TEST_DIR := test/dependency

.PHONY : build
build :
$(OCAMLBUILD) $(CFLAGS) lambdasoup.cma lambdasoup.cmxa

BS4_MISSING := Beautiful Soup not installed. Skipping Python performance test.
jbuilder build --dev

.PHONY : test
test :
@rm -f bisect*.out
$(OCAMLBUILD) $(COVERAGE_TAGS) $(CFLAGS) test.native --
@if [ "$(COVERAGE)" = yes ] ; then \
bisect-ppx-report -I _build -html $(COVERAGE_DIR) bisect*.out ; \
echo ; \
bisect-ppx-report -text - -summary-only bisect*.out \
| sed 's/Summary/Coverage/' ; \
echo "See $(COVERAGE_DIR)/index.html for coverage report" ; \
fi
jbuilder runtest --dev --no-buffer -j 1

BISECT_FILES_PATTERN := _build/default/test/bisect*.out
COVERAGE_DIR := _coverage

.PHONY : coverage
coverage :
BISECT_ENABLE=yes jbuilder build --dev @build-test
rm -rf $(BISECT_FILES_PATTERN)
(cd _build/default/test && ./test.exe)
bisect-ppx-report \
-I _build/default/ -html $(COVERAGE_DIR)/ \
-text - -summary-only \
$(BISECT_FILES_PATTERN)
@echo See $(COVERAGE_DIR)/index.html

BS4_MISSING := Beautiful Soup not installed. Skipping Python performance test.

.PHONY : performance-test
performance-test :
$(OCAMLBUILD) $(CFLAGS) performance.native --
$(OCAMLBUILD) $(CFLAGS) performance.byte --
jbuilder build --dev @build-performance-test
(cd _build/default/test/performance && ./performance.exe)
@((python -c "import bs4" 2> /dev/null \
|| (echo $(BS4_MISSING); exit 1)) \
&& (echo python test/performance.py; python test/performance.py)) \
|| exit 0

.PHONY : reverse-dependency-test
reverse-dependency-test :
cd $(DEP_TEST_DIR) && \
$(OCAMLBUILD) -clean && \
$(OCAMLBUILD) $(CFLAGS) dependency.native --

.PHONY : all-tests
all-tests : uninstall install test performance-test reverse-dependency-test
|| (echo $(BS4_MISSING); exit 1)) \
&& (echo python test/performance/performance.py; \
python test/performance/performance.py)) \
|| exit 0

# The docs targets are inactive for the time being.
HTML := docs/html
DOCFLAGS := -docflags -colorize-code

Expand Down Expand Up @@ -98,40 +70,12 @@ publish-docs : check-doc-prereqs docs
DOC_ZIP := docs/$(LIB)-$(VERSION)-doc.zip

.PHONY : package-docs
package-docs : check-doc-prereqs docs
package-docs : docs
rm -f $(DOC_ZIP)
zip -9j $(DOC_ZIP) $(HTML)/*

.PHONY : check-doc-prereqs
check-doc-prereqs :
@test $(OCAML_VERSION) -ne 402 \
|| (echo "\nocamldoc is broken in 4.02" && false)

INSTALL := \
_build/src/lambdasoup.cma _build/src/lambdasoup.cmxa \
_build/src/lambdasoup.a _build/src/soup.cmi _build/src/soup.mli \
_build/src/soup.cmti _build/src/soup.cmt _build/src/soup.cmx
PACKAGE := lambdasoup

.PHONY : ocamlfind-install
ocamlfind-install :
ocamlfind install $(PACKAGE) -optional src/META $(INSTALL)

.PHONY : ocamlfind-uninstall
ocamlfind-uninstall :
ocamlfind remove $(PACKAGE)

.PHONY : install
install :
opam pin add . -y

.PHONY : uninstall
uninstall :
opam pin remove $(PACKAGE) -y

.PHONY : clean
clean :
$(OCAMLBUILD) -clean
cd $(DEP_TEST_DIR) && $(OCAMLBUILD) -clean
rm -rf docs/html
rm -f bisect*.out
jbuilder clean
rm -rf $(COVERAGE_DIR)
# rm -rf docs/html
7 changes: 0 additions & 7 deletions _tags

This file was deleted.

8 changes: 1 addition & 7 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ The library source is organized as follows:
- `docs/`: files related to the `ocamldoc` documentation, such as extra HTML and
the postprocessing script.

To run tests, run `make all-tests`. This requires the `ounit` package. This
takes some time, because it reinstalls Lambda Soup. If you want to run only the
unit and performance tests, run `make test`.
To run tests, run `make test`. This requires the `ounit` package.

To generate docs, run `make docs`.

To install the library from your repo clone, run `make install`. This uses OPAM
to pin the repository and install a `lambdasoup` package. To undo this, run
`make uninstall`.

Make a branch off master, make your changes, rebase over master (if you have to)
when done, and submit a pull request :)

Expand Down
19 changes: 7 additions & 12 deletions lambdasoup.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "1.2"

version: "0.6.1"
version: "dev"
homepage: "https://github.com/aantron/lambda-soup"
doc: "http://aantron.github.io/lambda-soup"
bug-reports: "https://github.com/aantron/lambda-soup/issues"
Expand All @@ -11,20 +11,15 @@ maintainer: "Anton Bachin <antonbachin@yahoo.com>"
dev-repo: "https://github.com/aantron/lambda-soup.git"

depends: [
"ocamlfind" {build & >= "1.6.3"}
"ocamlbuild" {build}
# This should be removed for release.
"bisect_ppx" {>= "1.3.0"}
# As a consequence of depending on Jbuilder, Lambda Soup requires OCaml
# 4.02.3.
"jbuilder" {build & >= "1.0+beta10"}
"markup" {>= "0.7.1"}
"ounit" {test}
]

build: [
[make "build"]
["jbuilder" "build" "-p" name "-j" jobs]
]
build-test: [
[make "test"]
]
build-doc: [
[make "docs"]
]
install: [make "ocamlfind-install"]
remove: ["ocamlfind" "remove" "lambdasoup"]
5 changes: 0 additions & 5 deletions src/META

This file was deleted.

9 changes: 9 additions & 0 deletions src/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(jbuild_version 1)

(library
((name soup)
(public_name lambdasoup)
(synopsis "Easy functional HTML scraping and manipulation")
(flags (:standard -w +A -warn-error -3))
(preprocess (pps (bisect_ppx -conditional)))
(libraries (markup))))
1 change: 0 additions & 1 deletion src/lambdasoup.mllib

This file was deleted.

1 change: 0 additions & 1 deletion test/dependency/_tags

This file was deleted.

10 changes: 0 additions & 10 deletions test/dependency/dependency.ml

This file was deleted.

15 changes: 15 additions & 0 deletions test/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(jbuild_version 1)

(executable
((name test)
(flags (:standard -w +A))
(libraries (lambdasoup oUnit))))

(alias
((name build-test)
(deps (test.exe (files_recursively_in pages)))))

(alias
((name runtest)
(deps (test.exe (files_recursively_in pages)))
(action (run ${<}))))
10 changes: 10 additions & 0 deletions test/performance/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(jbuild_version 1)

(executable
((name performance)
(flags (:standard -w +A))
(libraries (lambdasoup unix))))

(alias
((name build-performance-test)
(deps (performance.exe (files_recursively_in ../pages)))))
2 changes: 1 addition & 1 deletion test/performance.ml → test/performance/performance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let measure runs name f =
open Soup

let () =
let html = read_file "test/pages/google.html" in
let html = read_file "../pages/google.html" in

measure 100 "parse" (fun () -> parse html |> ignore);
let soup = parse html in
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let map_option f = function
let page : string -> string =
let table = Hashtbl.create 7 in

let directory = "test/pages" in
let directory = "pages" in
Sys.readdir directory
|> Array.iter (fun file ->
let contents = file |> Filename.concat directory |> read_file in
Expand Down Expand Up @@ -1053,7 +1053,7 @@ let suites = [
"p");

("read_channel" >:: fun _ ->
let channel = open_in "test/pages/list.html" in
let channel = open_in "pages/list.html" in
let contents = read_channel channel in
close_in channel;

Expand Down

0 comments on commit 8084d5b

Please sign in to comment.