Makefile 7.04 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
# Setting variables

Zejun Lin's avatar
Zejun Lin committed
3
PIP_INSTALL := python3 -m pip install --no-cache-dir
Gems Guo's avatar
Gems Guo committed
4
PIP_UNINSTALL := python3 -m pip uninstall
liuzhe-lz's avatar
liuzhe-lz committed
5

Gems Guo's avatar
Gems Guo committed
6
7
8
9
10
11
## Colorful output
_INFO := $(shell echo -e '\e[1;36m')
_WARNING := $(shell echo -e '\e[1;33m')
_END := $(shell echo -e '\e[0m')

## Detect OS
12
13
14
15
16
17
18
19
20
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
	OS_SPEC := linux
else ifeq ($(UNAME_S), Darwin)
	OS_SPEC := darwin
else
	$(error platform $(UNAME_S) not supported)
endif

liuzhe-lz's avatar
liuzhe-lz committed
21
22
23
## Install directories
ifeq ($(shell id -u), 0)  # is root
    _ROOT := 1
Gems Guo's avatar
Gems Guo committed
24
    ROOT_FOLDER ?= $(shell python3 -c 'import site; from pathlib import Path; print(Path(site.getsitepackages()[0]).parents[2])')
25
    BASH_COMP_PREFIX ?= /usr/share/bash-completion/completions
liuzhe-lz's avatar
liuzhe-lz committed
26
else  # is normal user
Gems Guo's avatar
Gems Guo committed
27
    ROOT_FOLDER ?= $(shell python3 -c 'import site; from pathlib import Path; print(Path(site.getusersitepackages()).parents[2])')
liuzhe-lz's avatar
liuzhe-lz committed
28
29
30
    ifndef VIRTUAL_ENV
        PIP_MODE ?= --user
    endif
31
    BASH_COMP_PREFIX ?= ${HOME}/.bash_completion.d
32
endif
33
34
35
BASH_COMP_SCRIPT := $(BASH_COMP_PREFIX)/nnictl

NNI_INSTALL_PATH ?= $(INSTALL_PREFIX)/nni
Deshui Yu's avatar
Deshui Yu committed
36

Gems Guo's avatar
Gems Guo committed
37
BIN_FOLDER ?= $(ROOT_FOLDER)/bin
Gems Guo's avatar
Gems Guo committed
38
NNI_PKG_FOLDER ?= $(ROOT_FOLDER)/nni
Gems Guo's avatar
Gems Guo committed
39

liuzhe-lz's avatar
liuzhe-lz committed
40
## Dependency information
41
42
NNI_NODE_TARBALL ?= /tmp/nni-node-$(OS_SPEC)-x64.tar.xz
NNI_NODE_FOLDER = /tmp/nni-node-$(OS_SPEC)-x64
43
44
45
46
NNI_NODE ?= $(BIN_FOLDER)/node
NNI_YARN_TARBALL ?= /tmp/nni-yarn.tar.gz
NNI_YARN_FOLDER ?= /tmp/nni-yarn
NNI_YARN := PATH=$(BIN_FOLDER):$${PATH} $(NNI_YARN_FOLDER)/bin/yarn
liuzhe-lz's avatar
liuzhe-lz committed
47

Gems Guo's avatar
Gems Guo committed
48
49
50
## Version number
NNI_VERSION = $(shell git describe --tags)

liuzhe-lz's avatar
liuzhe-lz committed
51
52
53
# Main targets

.PHONY: build
Deshui Yu's avatar
Deshui Yu committed
54
build:
liuzhe-lz's avatar
liuzhe-lz committed
55
	#$(_INFO) Building NNI Manager $(_END)
Zejun Lin's avatar
Zejun Lin committed
56
	cd src/nni_manager && $(NNI_YARN) && $(NNI_YARN) build
goooxu's avatar
goooxu committed
57
	#$(_INFO) Building WebUI $(_END)
Zejun Lin's avatar
Zejun Lin committed
58
	cd src/webui && $(NNI_YARN) && $(NNI_YARN) build
liuzhe-lz's avatar
liuzhe-lz committed
59
	#$(_INFO) Building Python SDK $(_END)
Deshui Yu's avatar
Deshui Yu committed
60
	cd src/sdk/pynni && python3 setup.py build
liuzhe-lz's avatar
liuzhe-lz committed
61
	#$(_INFO) Building nnictl $(_END)
Deshui Yu's avatar
Deshui Yu committed
62
63
	cd tools && python3 setup.py build

liuzhe-lz's avatar
liuzhe-lz committed
64
# All-in-one target for non-expert users
liuzhe-lz's avatar
liuzhe-lz committed
65
66
67
68
69
# Installs NNI as well as its dependencies, and update bashrc to set PATH
.PHONY: easy-install
easy-install: check-perm
easy-install: install-dependencies
easy-install: build
liuzhe-lz's avatar
liuzhe-lz committed
70
easy-install: install
liuzhe-lz's avatar
liuzhe-lz committed
71
easy-install: update-bash-config
liuzhe-lz's avatar
liuzhe-lz committed
72
easy-install:
Zejun Lin's avatar
Zejun Lin committed
73
	#$(_INFO) Complete! $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
74

Gems Guo's avatar
Gems Guo committed
75
76
77
78
79
80
81
82
83
84
# All-in-one target for developer users
# Install NNI as well as its dependencies, and update bashrc to set PATH
.PHONY: dev-easy-install
dev-easy-install: dev-check-perm
dev-easy-install: install-dependencies
dev-easy-install: build
dev-easy-install: dev-install
dev-easy-install: update-bash-config
dev-easy-install:
	#$(_INFO) Complete! $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
85

Gems Guo's avatar
Gems Guo committed
86
87
88
89
90
91
92
93
# Standard installation target
# Must be invoked after building
.PHONY: install
install: install-python-modules
install: install-node-modules
install: install-scripts
install:
	#$(_INFO) Complete! You may want to add $(BIN_FOLDER) to your PATH environment $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
94
95
96
97

# Target for NNI developers
# Creates symlinks instead of copying files
.PHONY: dev-install
Gems Guo's avatar
Gems Guo committed
98
99
dev-install: dev-install-python-modules
dev-install: dev-install-node-modules
liuzhe-lz's avatar
liuzhe-lz committed
100
101
dev-install: install-scripts
dev-install:
102
	#$(_INFO) Complete! You may want to add $(BIN_FOLDER) to your PATH environment $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
103

Gems Guo's avatar
Gems Guo committed
104
105
106
107
108
109
110
111
# Target for setup.py
# Do not invoke this manually
.PHONY: pip-install
pip-install: install-dependencies
pip-install: build
pip-install: install-node-modules
pip-install: install-scripts
pip-install: update-bash-config
liuzhe-lz's avatar
liuzhe-lz committed
112
113
114

.PHONY: uninstall
uninstall:
Zejun Lin's avatar
Zejun Lin committed
115
116
	-$(PIP_UNINSTALL) -y nni
	-$(PIP_UNINSTALL) -y nnictl
117
	-rm -rf $(NNI_PKG_FOLDER)
118
119
	-rm -f $(BIN_FOLDER)/node
	-rm -f $(BIN_FOLDER)/nnictl
liuzhe-lz's avatar
liuzhe-lz committed
120
121
	-rm -f $(BASH_COMP_SCRIPT)

QuanluZhang's avatar
QuanluZhang committed
122
123
124
125
126
127
128
129
130
131
132
.PHONY: clean
clean:
	-rm -rf tools/build
	-rm -rf tools/nnictl.egg-info
	-rm -rf src/nni_manager/dist
	-rm -rf src/nni_manager/node_modules
	-rm -rf src/sdk/pynni/build
	-rm -rf src/sdk/pynni/nni_sdk.egg-info
	-rm -rf src/webui/build
	-rm -rf src/webui/node_modules

liuzhe-lz's avatar
liuzhe-lz committed
133
134
135
136
# Main targets end

# Helper targets

Zejun Lin's avatar
Zejun Lin committed
137
$(NNI_NODE_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
138
	#$(_INFO) Downloading Node.js $(_END)
139
	wget https://aka.ms/nni/nodejs-download/$(OS_SPEC) -O $(NNI_NODE_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
140

Zejun Lin's avatar
Zejun Lin committed
141
$(NNI_YARN_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
142
	#$(_INFO) Downloading Yarn $(_END)
143
	wget https://aka.ms/yarn-download -O $(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
144

QuanluZhang's avatar
QuanluZhang committed
145
.PHONY: install-dependencies
Zejun Lin's avatar
Zejun Lin committed
146
install-dependencies: $(NNI_NODE_TARBALL) $(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
147
	#$(_INFO) Extracting Node.js $(_END)
148
149
150
151
152
153
	rm -rf $(NNI_NODE_FOLDER)
	mkdir $(NNI_NODE_FOLDER)
	tar -xf $(NNI_NODE_TARBALL) -C $(NNI_NODE_FOLDER) --strip-components 1
	mkdir -p $(BIN_FOLDER)
	rm -f $(NNI_NODE)
	cp $(NNI_NODE_FOLDER)/bin/node $(NNI_NODE)
Deshui Yu's avatar
Deshui Yu committed
154
	
liuzhe-lz's avatar
liuzhe-lz committed
155
	#$(_INFO) Extracting Yarn $(_END)
156
157
158
	rm -rf $(NNI_YARN_FOLDER)
	mkdir $(NNI_YARN_FOLDER)
	tar -xf $(NNI_YARN_TARBALL) -C $(NNI_YARN_FOLDER) --strip-components 1
159

liuzhe-lz's avatar
liuzhe-lz committed
160
161
162
.PHONY: install-python-modules
install-python-modules:
	#$(_INFO) Installing Python SDK $(_END)
Gems Guo's avatar
Gems Guo committed
163
	cd src/sdk/pynni && sed -ie 's/NNI_VERSION/$(NNI_VERSION)/' setup.py && $(PIP_INSTALL) $(PIP_MODE) .
164
	
liuzhe-lz's avatar
liuzhe-lz committed
165
	#$(_INFO) Installing nnictl $(_END)
Gems Guo's avatar
Gems Guo committed
166
	cd tools && sed -ie 's/NNI_VERSION/$(NNI_VERSION)/' setup.py && $(PIP_INSTALL) $(PIP_MODE) .
167

Gems Guo's avatar
Gems Guo committed
168
169
170
.PHONY: dev-install-python-modules
dev-install-python-modules:
	#$(_INFO) Installing Python SDK $(_END)
Gems Guo's avatar
Gems Guo committed
171
	cd src/sdk/pynni && sed -ie 's/NNI_VERSION/$(NNI_VERSION)/' setup.py && $(PIP_INSTALL) $(PIP_MODE) -e .
Gems Guo's avatar
Gems Guo committed
172
173
	
	#$(_INFO) Installing nnictl $(_END)
Gems Guo's avatar
Gems Guo committed
174
	cd tools && sed -ie 's/NNI_VERSION/$(NNI_VERSION)/' setup.py && $(PIP_INSTALL) $(PIP_MODE) -e .
Gems Guo's avatar
Gems Guo committed
175

liuzhe-lz's avatar
liuzhe-lz committed
176
177
.PHONY: install-node-modules
install-node-modules:
178
	#$(_INFO) Installing NNI Package $(_END)
179
180
181
	rm -rf $(NNI_PKG_FOLDER)
	cp -r src/nni_manager/dist $(NNI_PKG_FOLDER)
	cp src/nni_manager/package.json $(NNI_PKG_FOLDER)
Gems Guo's avatar
Gems Guo committed
182
	sed -ie 's/NNI_VERSION/$(NNI_VERSION)/' $(NNI_PKG_FOLDER)/package.json
183
184
	$(NNI_YARN) --prod --cwd $(NNI_PKG_FOLDER)
	cp -r src/webui/build $(NNI_PKG_FOLDER)/static
Deshui Yu's avatar
Deshui Yu committed
185

Gems Guo's avatar
Gems Guo committed
186
187
.PHONY: dev-install-node-modules
dev-install-node-modules:
188
	#$(_INFO) Installing NNI Package $(_END)
189
190
191
192
	rm -rf $(NNI_PKG_FOLDER)
	ln -sf ${PWD}/src/nni_manager/dist $(NNI_PKG_FOLDER)
	ln -sf ${PWD}/src/nni_manager/node_modules $(NNI_PKG_FOLDER)/node_modules
	ln -sf ${PWD}/src/webui/build $(NNI_PKG_FOLDER)/static
liuzhe-lz's avatar
liuzhe-lz committed
193
194
195

.PHONY: install-scripts
install-scripts:
196
197
	mkdir -p $(BASH_COMP_PREFIX)
	install -m644 tools/bash-completion $(BASH_COMP_SCRIPT)
Deshui Yu's avatar
Deshui Yu committed
198

liuzhe-lz's avatar
liuzhe-lz committed
199
200
201
202
.PHONY: update-bash-config
ifndef _ROOT
update-bash-config:
	#$(_INFO) Updating bash configurations $(_END)
203
204
205
    ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_FOLDER)'))  # $(BIN_FOLDER) not in PATH
	#$(_WARNING) NOTE: adding $(BIN_FOLDER) to PATH in bashrc $(_END)
	echo 'export PATH="$$PATH:$(BIN_FOLDER)"' >> ~/.bashrc
liuzhe-lz's avatar
liuzhe-lz committed
206
207
208
209
210
211
212
    endif
    ifeq (, $(shell (source ~/.bash_completion ; command -v _nnictl) 2>/dev/null))  # completion not installed
	#$(_WARNING) NOTE: adding $(BASH_COMP_SCRIPT) to ~/.bash_completion $(_END)
	echo '[[ -f $(BASH_COMP_SCRIPT) ]] && source $(BASH_COMP_SCRIPT)' >> ~/.bash_completion
    endif
else
update-bash-config: ;
liuzhe-lz's avatar
liuzhe-lz committed
213
214
215
216
217
218
219
220
221
222
223
224
225
endif

.PHONY: check-perm
ifdef _ROOT
check-perm:
	#$(_WARNING) Run easy-install as root is not optimal $(_END)
	#$(_WARNING) Suggest run as non-privileged user or manually install instead $(_END)
	#$(_WARNING) Continue easy-install as root? (y/N) $(_END)
	@read CONFIRM && [ "$$CONFIRM" = y ]
else
check-perm: ;
endif

Gems Guo's avatar
Gems Guo committed
226
.PHONY: dev-check-perm
liuzhe-lz's avatar
liuzhe-lz committed
227
ifdef _ROOT
Gems Guo's avatar
Gems Guo committed
228
dev-check-perm:
liuzhe-lz's avatar
liuzhe-lz committed
229
	$(error You should not develop NNI as root)
Gems Guo's avatar
Gems Guo committed
230
231
else
dev-check-perm: ;
liuzhe-lz's avatar
liuzhe-lz committed
232
233
234
endif

# Helper targets end