@@ -3,36 +3,48 @@ RUSTUP = rustup
3
3
TOOLCHAIN = $(shell cat rust-toolchain)
4
4
CARGO = $(RUSTUP ) run --install $(TOOLCHAIN ) cargo --color always
5
5
6
- NIGHTLY_TOOLCHAIN = " nightly-2019-07-31"
6
+ NIGHTLY_TOOLCHAIN = nightly-2019-07-31
7
7
CARGO_NIGHTLY = $(RUSTUP ) run --install $(NIGHTLY_TOOLCHAIN ) cargo --color always
8
8
9
9
GIT_HOOKS_PATH = ".githooks"
10
10
GIT_HOOKS = $(wildcard $(GIT_HOOKS_PATH ) /* )
11
11
12
+ INSTALLED_TOOLCHAINS = $(shell $(RUSTUP ) toolchain list)
13
+ INSTALLED_COMPONENTS = $(shell $(RUSTUP ) component list --installed --toolchain $(TOOLCHAIN ) )
14
+ INSTALLED_NIGHTLY_COMPONENTS = $(shell $(RUSTUP ) component list --installed --toolchain $(NIGHTLY_TOOLCHAIN ) )
15
+ AVAILABLE_CARGO_COMMANDS = $(shell $(CARGO ) --list)
16
+
12
17
default : init_git_hooks build format
13
18
14
- init_git_hooks : $( GIT_HOOKS )
19
+ init_git_hooks :
15
20
git config core.hooksPath $(GIT_HOOKS_PATH )
16
21
22
+ # # Dev environment
23
+
17
24
install_rust :
18
- $(RUSTUP ) toolchain list | grep -q $(TOOLCHAIN ) || $(RUSTUP ) install $(TOOLCHAIN )
25
+ ifeq (,$(findstring $(TOOLCHAIN ) ,$(INSTALLED_TOOLCHAINS ) ) )
26
+ $(RUSTUP) install $(TOOLCHAIN)
27
+ endif
19
28
20
29
install_rust_nightly :
21
- $( RUSTUP ) toolchain list | grep -q $(NIGHTLY_TOOLCHAIN ) || $( RUSTUP ) install $( NIGHTLY_TOOLCHAIN )
22
-
23
- # # Dev environment
30
+ ifeq (, $( findstring $(NIGHTLY_TOOLCHAIN ) , $( INSTALLED_TOOLCHAINS ) ) )
31
+ $(RUSTUP) install $(NIGHTLY_TOOLCHAIN)
32
+ endif
24
33
25
34
install_clippy : install_rust
26
- $(RUSTUP ) component list --installed --toolchain $(TOOLCHAIN ) | grep -q clippy || $(RUSTUP ) component add clippy --toolchain $(TOOLCHAIN )
35
+ ifeq (,$(findstring clippy,$(INSTALLED_COMPONENTS ) ) )
36
+ $(RUSTUP) component add clippy --toolchain $(TOOLCHAIN)
37
+ endif
27
38
28
39
install_rustfmt : install_rust_nightly
29
- $(RUSTUP ) component list --installed --toolchain $(NIGHTLY_TOOLCHAIN ) | grep -q rustfmt || $(RUSTUP ) component add rustfmt --toolchain $(NIGHTLY_TOOLCHAIN )
40
+ ifeq (,$(findstring rustfmt,$(INSTALLED_NIGHTLY_COMPONENTS ) ) )
41
+ $(RUSTUP) component add rustfmt --toolchain $(NIGHTLY_TOOLCHAIN)
42
+ endif
30
43
31
44
install_tomlfmt : install_rust
32
- $(CARGO ) --list | grep -q tomlfmt || $(CARGO ) install cargo-tomlfmt
33
-
34
- yarn_install :
35
- (cd ./api_tests; yarn install)
45
+ ifeq (,$(findstring tomlfmt,$(AVAILABLE_CARGO_COMMANDS ) ) )
46
+ $(CARGO) install cargo-tomlfmt
47
+ endif
36
48
37
49
# # User install
38
50
@@ -46,13 +58,6 @@ clean:
46
58
47
59
all : format build clippy test doc e2e_scripts
48
60
49
- format : install_rustfmt install_tomlfmt yarn_install
50
- $(CARGO_NIGHTLY ) fmt
51
- $(CARGO ) tomlfmt -p Cargo.toml
52
- $(CARGO ) tomlfmt -p cnd/Cargo.toml
53
- $(CARGO ) tomlfmt -p libp2p-comit/Cargo.toml
54
- (cd ./api_tests; yarn run fix)
55
-
56
61
ci : check_format doc clippy test build e2e
57
62
58
63
build :
@@ -77,16 +82,42 @@ test:
77
82
doc :
78
83
$(CARGO ) doc
79
84
85
+ e2e : build
86
+ (cd ./api_tests; yarn install; yarn test)
87
+
80
88
check_format : check_rust_format check_toml_format check_ts_format
81
89
90
+ STAGED_FILES = $(shell git diff --staged --name-only)
91
+ STAGED_RUST_FILES = $(filter % .rs,$(STAGED_FILES ) )
92
+ STAGED_TOML_FILES = $(filter % .toml,$(STAGED_FILES ) )
93
+ STAGED_TYPESCRIPT_FILES = $(filter % .ts % .json % .yml,$(STAGED_FILES ) )
94
+
95
+ format : install_rustfmt install_tomlfmt
96
+ ifneq (,$(STAGED_RUST_FILES ) )
97
+ $(CARGO_NIGHTLY) fmt
98
+ endif
99
+ ifneq (,$(STAGED_TOML_FILES ) )
100
+ $(CARGO) tomlfmt -p Cargo.toml
101
+ $(CARGO) tomlfmt -p cnd/Cargo.toml
102
+ $(CARGO) tomlfmt -p libp2p-comit/Cargo.toml
103
+ endif
104
+ ifneq (,$(STAGED_TYPESCRIPT_FILES ) )
105
+ (cd ./api_tests; yarn install; yarn run fix)
106
+ endif
107
+
82
108
check_rust_format : install_rustfmt
109
+ ifneq (,$(STAGED_RUST_FILES ) )
83
110
$(CARGO_NIGHTLY) fmt -- --check
111
+ endif
84
112
85
113
check_toml_format : install_tomlfmt
114
+ ifneq (,$(STAGED_TOML_FILES ) )
86
115
$(CARGO) tomlfmt -d -p Cargo.toml
87
-
88
- check_ts_format : yarn_install
89
- (cd ./api_tests; yarn run check)
90
-
91
- e2e : yarn_install
92
- (cd ./api_tests; yarn test)
116
+ $(CARGO) tomlfmt -d -p cnd/Cargo.toml
117
+ $(CARGO) tomlfmt -d -p libp2p-comit/Cargo.toml
118
+ endif
119
+
120
+ check_ts_format :
121
+ ifneq (,$(STAGED_TYPESCRIPT_FILES ) )
122
+ (cd ./api_tests; yarn install; yarn run check)
123
+ endif
0 commit comments