Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (79 loc) · 5.6 KB
/
Copy pathMakefile
File metadata and controls
105 lines (79 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
LINDERA_SQLITE_VERSION ?= $(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-sqlite") | .version')
USER_AGENT ?= $(shell curl --version | head -n1 | awk '{print $1"/"$2}')
USER ?= $(shell whoami)
HOSTNAME ?= $(shell hostname)
.DEFAULT_GOAL := help
# The features of the tests of the IPADIC, UniDic and JUMAN configurations and of the dependency
# filter, which test-features runs and lint-features lints.
TEST_FEATURES := embed-ipadic,embed-unidic,embed-jumandic,embed-dependency-ipadic
# The features of the package e2e for its test `dependency_pair_indexes`, which lint-e2e lints it
# with.
E2E_FEATURES := dependency-pair-indexes
# The features of the package of the examples in Rust for the Lindera of its example
# `dependency_pairs` with IPADIC, which check-dependency-pairs runs it with and lint-examples lints
# it with.
EXAMPLES_FEATURES := embed-ipadic,embed-dependency-ipadic
# The dictionary that dependency-pairs runs the example `dependency_pairs` with: ipadic or unidic.
DICTIONARY ?= ipadic
# The directory of the built extension that check-dependency-pairs runs the example with.
LINDERA_SQLITE_LIB_DIR ?= $(CURDIR)/target/debug
clean: ## Clean the project
cargo clean
format: ## Format the code
cargo fmt
cargo fmt --manifest-path e2e/Cargo.toml
cargo fmt --manifest-path examples/rust/Cargo.toml
lint: ## Run clippy on all targets, with warnings as errors
cargo clippy --all-targets --features=embed-cjk -- -D warnings
lint-features: ## Run clippy on all targets with the features of test-features, with warnings as errors
cargo clippy --all-targets --features=$(TEST_FEATURES) -- -D warnings
lint-e2e: ## Run clippy on all targets of the package e2e, with warnings as errors
cargo clippy --manifest-path e2e/Cargo.toml --all-targets --features=$(E2E_FEATURES) -- -D warnings
lint-examples: ## Run clippy on all targets of the examples in Rust, with warnings as errors
cargo clippy --manifest-path examples/rust/Cargo.toml --all-targets --features=$(EXAMPLES_FEATURES) -- -D warnings
# rustdoc runs twice. The first pass documents the public items only, as docs.rs publishes them,
# and fails on a public item that links to a private one. The second adds the private items, whose
# documentation the first does not read. Both with the default features, which docs.rs builds the
# crate with.
check-docs: ## Check the documentation with rustdoc, with warnings as errors
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --document-private-items
build: ## Build the project
cargo build --release --features=embed-cjk
test: ## Run tests
LINDERA_CONFIG_FILE=./resources/lindera.yml cargo test --features=embed-cjk
test-features: ## Run the tests of the IPADIC, UniDic and JUMAN configurations and the dependency filter
LINDERA_CONFIG_FILE=./resources/lindera.yml cargo test --features=$(TEST_FEATURES)
# Without this, make takes the directory of the same name for an up-to-date target.
.PHONY: e2e
e2e: ## Load the extension into SQLite and test it
cargo build --features=embed-cjk
LINDERA_CONFIG_FILE=$(CURDIR)/resources/lindera.yml LINDERA_SQLITE_LIB_DIR=$(CURDIR)/target/debug cargo test --manifest-path e2e/Cargo.toml
test-examples: ## Run the tests of the library of the examples in Rust
cargo test --manifest-path examples/rust/Cargo.toml
dependency-pairs: ## Build the extension and run the example of search with dependency pairs (DICTIONARY=ipadic or unidic)
cargo build --features=embed-$(DICTIONARY)
LINDERA_SQLITE_LIB_DIR=$(CURDIR)/target/debug cargo run --manifest-path examples/rust/Cargo.toml --bin dependency_pairs --features=embed-$(DICTIONARY),embed-dependency-$(DICTIONARY) -- $(DICTIONARY)
# examples/rust/README.md shows the output of the example with IPADIC in the code block between two
# markers, which awk prints. The extension has to be built with IPADIC already, in
# LINDERA_SQLITE_LIB_DIR.
check-dependency-pairs: ## Compare the output of the example of dependency pairs, with IPADIC, with examples/rust/README.md
LINDERA_SQLITE_LIB_DIR=$(LINDERA_SQLITE_LIB_DIR) cargo run --quiet --manifest-path examples/rust/Cargo.toml --bin dependency_pairs --features=$(EXAMPLES_FEATURES) > target/dependency_pairs.txt
awk '/^<!-- the output of dependency_pairs -->$$/ { m = 1 } /^<!-- end of the output of dependency_pairs -->$$/ { m = 0 } m && /^```/ { f = !f; next } m && f' examples/rust/README.md | diff -u - target/dependency_pairs.txt
# The test runs the statements and the query of the section "Index dependency pairs" of README.md,
# and compares the output with the one the section shows. The extension has to be built with
# IPADIC and the dependency filter already, in LINDERA_SQLITE_LIB_DIR.
check-dependency-pair-indexes: ## Run the statements and the query of "Index dependency pairs" in README.md, and compare the output
LINDERA_SQLITE_LIB_DIR=$(LINDERA_SQLITE_LIB_DIR) cargo test --manifest-path e2e/Cargo.toml --features=dependency-pair-indexes --test dependency_pair_indexes
bench: ## Run benchmarks
LINDERA_CONFIG_FILE=./resources/lindera.yml cargo bench --features=embed-cjk
tag: ## Make a new tag for the current version
git tag v$(LINDERA_SQLITE_VERSION)
git push origin v$(LINDERA_SQLITE_VERSION)
publish: ## Publish the crate to crates.io
ifeq ($(shell curl -s -XGET -H "User-Agent: $(USER_AGENT) ($(USER)@$(HOSTNAME))" https://crates.io/api/v1/crates/lindera-sqlite | jq -r '.versions[].num' | grep $(LINDERA_SQLITE_VERSION)),)
(cargo package && cargo publish)
endif
help: ## Show help
@echo "Available targets:"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'