Makefile 8.21 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
# Setting variables
2
SHELL := /bin/bash
3
PIP_INSTALL := python3 -m pip install
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
## Colorful output
7
8
9
_INFO := $(shell echo -e '\033[1;36m')
_WARNING := $(shell echo -e '\033[1;33m')
_END := $(shell echo -e '\033[0m')
Gems Guo's avatar
Gems Guo committed
10
11

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

liuzhe-lz's avatar
liuzhe-lz committed
21
## Install directories
Zejun Lin's avatar
Zejun Lin committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

## For apt-get or pip installed virtualenv
ifdef VIRTUAL_ENV
    ROOT_FOLDER ?= $(VIRTUAL_ENV)
    BASH_COMP_PREFIX ?= ${HOME}/.bash_completion.d
else
    ROOT_FOLDER ?= $(shell python3 -c 'import site; from pathlib import Path; print(Path(site.getsitepackages()[0]).parents[2])')
    IS_SYS_PYTHON ?= $(shell [[ $(ROOT_FOLDER) == /usr* || $(ROOT_FOLDER) == /Library* ]] && echo TRUE || echo FALSE)

    ifeq ($(shell id -u), 0)  # is root
        _ROOT := 1
        BASH_COMP_PREFIX ?= /usr/share/bash-completion/completions
    else  # is normal user
        ifeq (TRUE, $(IS_SYS_PYTHON))
            ROOT_FOLDER := $(shell python3 -c 'import site; from pathlib import Path; print(Path(site.getusersitepackages()).parents[2])')
37
38
            PIP_MODE ?= --user
        endif
Zejun Lin's avatar
Zejun Lin committed
39
        BASH_COMP_PREFIX ?= ${HOME}/.bash_completion.d
liuzhe-lz's avatar
liuzhe-lz committed
40
    endif
41
endif
42
43
44
BASH_COMP_SCRIPT := $(BASH_COMP_PREFIX)/nnictl

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

Gems Guo's avatar
Gems Guo committed
46
BIN_FOLDER ?= $(ROOT_FOLDER)/bin
Gems Guo's avatar
Gems Guo committed
47
NNI_PKG_FOLDER ?= $(ROOT_FOLDER)/nni
SparkSnail's avatar
SparkSnail committed
48
NASUI_PKG_FOLDER ?= $(ROOT_FOLDER)/nni/nasui
Gems Guo's avatar
Gems Guo committed
49

liuzhe-lz's avatar
liuzhe-lz committed
50
## Dependency information
51
52
53
54
NNI_DEPENDENCY_FOLDER = /tmp/$(USER)
$(shell mkdir -p $(NNI_DEPENDENCY_FOLDER))
NNI_NODE_TARBALL ?= $(NNI_DEPENDENCY_FOLDER)/nni-node-$(OS_SPEC)-x64.tar.xz
NNI_NODE_FOLDER = $(NNI_DEPENDENCY_FOLDER)/nni-node-$(OS_SPEC)-x64
55
NNI_NODE ?= $(BIN_FOLDER)/node
56
NNI_NPM ?= $(BIN_FOLDER)/npm
57
58
NNI_YARN_TARBALL ?= $(NNI_DEPENDENCY_FOLDER)/nni-yarn.tar.gz
NNI_YARN_FOLDER ?= $(NNI_DEPENDENCY_FOLDER)/nni-yarn
59
NNI_YARN ?= PATH=$(BIN_FOLDER):$${PATH} $(NNI_YARN_FOLDER)/bin/yarn
liuzhe-lz's avatar
liuzhe-lz committed
60

Gems Guo's avatar
Gems Guo committed
61
## Version number
goooxu's avatar
goooxu committed
62
63
NNI_VERSION_VALUE = $(shell git describe --tags)
NNI_VERSION_TEMPLATE = 999.0.0-developing
Gems Guo's avatar
Gems Guo committed
64

liuzhe-lz's avatar
liuzhe-lz committed
65
66
67
# Main targets

.PHONY: build
Deshui Yu's avatar
Deshui Yu committed
68
build:
liuzhe-lz's avatar
liuzhe-lz committed
69
	#$(_INFO) Building NNI Manager $(_END)
Zejun Lin's avatar
Zejun Lin committed
70
	cd src/nni_manager && $(NNI_YARN) && $(NNI_YARN) build
71
	cp -rf src/nni_manager/config src/nni_manager/dist/
goooxu's avatar
goooxu committed
72
	#$(_INFO) Building WebUI $(_END)
Zejun Lin's avatar
Zejun Lin committed
73
	cd src/webui && $(NNI_YARN) && $(NNI_YARN) build
Yuge Zhang's avatar
Yuge Zhang committed
74
75
	#$(_INFO) Building NAS UI $(_END)
	cd src/nasui && $(NNI_YARN) && $(NNI_YARN) build
Deshui Yu's avatar
Deshui Yu committed
76

liuzhe-lz's avatar
liuzhe-lz committed
77
# All-in-one target for non-expert users
liuzhe-lz's avatar
liuzhe-lz committed
78
79
80
81
82
# 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
83
easy-install: install
liuzhe-lz's avatar
liuzhe-lz committed
84
easy-install: update-bash-config
liuzhe-lz's avatar
liuzhe-lz committed
85
easy-install:
Zejun Lin's avatar
Zejun Lin committed
86
	#$(_INFO) Complete! $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
87

Gems Guo's avatar
Gems Guo committed
88
89
90
91
92
93
94
95
96
97
# 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
98

Gems Guo's avatar
Gems Guo committed
99
100
101
102
103
104
105
106
# 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
107
108
109
110

# Target for NNI developers
# Creates symlinks instead of copying files
.PHONY: dev-install
Gems Guo's avatar
Gems Guo committed
111
112
dev-install: dev-install-python-modules
dev-install: dev-install-node-modules
liuzhe-lz's avatar
liuzhe-lz committed
113
114
dev-install: install-scripts
dev-install:
115
	#$(_INFO) Complete! You may want to add $(BIN_FOLDER) to your PATH environment $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
116
117
118

.PHONY: uninstall
uninstall:
119
120
	-cd build && $(PIP_UNINSTALL) -y nni
	-rm -rf build
121
	-rm -rf $(NNI_PKG_FOLDER)
122
123
	-rm -f $(BIN_FOLDER)/node
	-rm -f $(BIN_FOLDER)/nnictl
liuzhe-lz's avatar
liuzhe-lz committed
124
125
	-rm -f $(BASH_COMP_SCRIPT)

QuanluZhang's avatar
QuanluZhang committed
126
127
128
129
130
131
132
133
134
135
.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
SparkSnail's avatar
SparkSnail committed
136
137
	-rm -rf src/nasui/build
	-rm -rf src/nasui/node_modules
QuanluZhang's avatar
QuanluZhang committed
138

liuzhe-lz's avatar
liuzhe-lz committed
139
140
141
142
# Main targets end

# Helper targets

Zejun Lin's avatar
Zejun Lin committed
143
$(NNI_NODE_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
144
	#$(_INFO) Downloading Node.js $(_END)
145
	wget https://aka.ms/nni/nodejs-download/$(OS_SPEC) -O $(NNI_NODE_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
146

Zejun Lin's avatar
Zejun Lin committed
147
$(NNI_YARN_TARBALL):
liuzhe-lz's avatar
liuzhe-lz committed
148
	#$(_INFO) Downloading Yarn $(_END)
149
	wget https://aka.ms/yarn-download -O $(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
150

QuanluZhang's avatar
QuanluZhang committed
151
.PHONY: install-dependencies
Zejun Lin's avatar
Zejun Lin committed
152
install-dependencies: $(NNI_NODE_TARBALL) $(NNI_YARN_TARBALL)
liuzhe-lz's avatar
liuzhe-lz committed
153
	#$(_INFO) Extracting Node.js $(_END)
154
155
156
157
	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)
158
159
160
	rm -f $(NNI_NODE) $(NNI_NPM)
	ln -s $(NNI_NODE_FOLDER)/bin/node $(NNI_NODE)
	ln -s $(NNI_NODE_FOLDER)/bin/npm $(NNI_NPM)
Deshui Yu's avatar
Deshui Yu committed
161
	
liuzhe-lz's avatar
liuzhe-lz committed
162
	#$(_INFO) Extracting Yarn $(_END)
163
164
165
	rm -rf $(NNI_YARN_FOLDER)
	mkdir $(NNI_YARN_FOLDER)
	tar -xf $(NNI_YARN_TARBALL) -C $(NNI_YARN_FOLDER) --strip-components 1
166

liuzhe-lz's avatar
liuzhe-lz committed
167
168
169
.PHONY: install-python-modules
install-python-modules:
	#$(_INFO) Installing Python SDK $(_END)
170
	sed -ie 's/$(NNI_VERSION_TEMPLATE)/$(NNI_VERSION_VALUE)/' src/sdk/pynni/nni/__init__.py
SparkSnail's avatar
SparkSnail committed
171
	sed -ie 's/$(NNI_VERSION_TEMPLATE)/$(NNI_VERSION_VALUE)/' setup.py && $(PIP_INSTALL) $(PIP_MODE) .
172

Gems Guo's avatar
Gems Guo committed
173
174
175
.PHONY: dev-install-python-modules
dev-install-python-modules:
	#$(_INFO) Installing Python SDK $(_END)
176
	mkdir -p build
liuzhe-lz's avatar
liuzhe-lz committed
177
178
179
180
181
182
	ln -sfT ../src/sdk/pynni/nni build/nni
	ln -sfT ../src/sdk/pycli/nnicli build/nnicli
	ln -sfT ../tools/nni_annotation build/nni_annotation
	ln -sfT ../tools/nni_cmd build/nni_cmd
	ln -sfT ../tools/nni_trial_tool build/nni_trial_tool
	ln -sfT ../tools/nni_gpu_tool build/nni_gpu_tool
183
184
185
186
187
188
	cp setup.py build/
	cp README.md build/
	sed -ie 's/$(NNI_VERSION_TEMPLATE)/$(NNI_VERSION_VALUE)/' build/setup.py
	sed -ie 's/src\/sdk\/pynni\/nni/nni/g' build/setup.py
	sed -ie 's/tools\///g' build/setup.py
	cd build && $(PIP_INSTALL) $(PIP_MODE) -e .
SparkSnail's avatar
SparkSnail committed
189

Gems Guo's avatar
Gems Guo committed
190

liuzhe-lz's avatar
liuzhe-lz committed
191
192
.PHONY: install-node-modules
install-node-modules:
193
	#$(_INFO) Installing NNI Package $(_END)
194
195
196
	rm -rf $(NNI_PKG_FOLDER)
	cp -r src/nni_manager/dist $(NNI_PKG_FOLDER)
	cp src/nni_manager/package.json $(NNI_PKG_FOLDER)
goooxu's avatar
goooxu committed
197
	sed -ie 's/$(NNI_VERSION_TEMPLATE)/$(NNI_VERSION_VALUE)/' $(NNI_PKG_FOLDER)/package.json
198
199
	$(NNI_YARN) --prod --cwd $(NNI_PKG_FOLDER)
	cp -r src/webui/build $(NNI_PKG_FOLDER)/static
SparkSnail's avatar
SparkSnail committed
200
201
202
203
204
	# Install nasui
	mkdir -p $(NASUI_PKG_FOLDER)
	cp -rf src/nasui/build $(NASUI_PKG_FOLDER)
	cp src/nasui/server.js $(NASUI_PKG_FOLDER)

Deshui Yu's avatar
Deshui Yu committed
205

Gems Guo's avatar
Gems Guo committed
206
207
.PHONY: dev-install-node-modules
dev-install-node-modules:
208
	#$(_INFO) Installing NNI Package $(_END)
liuzhe-lz's avatar
liuzhe-lz committed
209
	ln -sfT ${PWD}/src/nni_manager/dist $(NNI_PKG_FOLDER)
210
	cp src/nni_manager/package.json $(NNI_PKG_FOLDER)
goooxu's avatar
goooxu committed
211
	sed -ie 's/$(NNI_VERSION_TEMPLATE)/$(NNI_VERSION_VALUE)/' $(NNI_PKG_FOLDER)/package.json
liuzhe-lz's avatar
liuzhe-lz committed
212
213
	ln -sfT ${PWD}/src/nni_manager/node_modules $(NNI_PKG_FOLDER)/node_modules
	ln -sfT ${PWD}/src/webui/build $(NNI_PKG_FOLDER)/static
214
	mkdir -p $(NASUI_PKG_FOLDER)
liuzhe-lz's avatar
liuzhe-lz committed
215
216
	ln -sfT ${PWD}/src/nasui/build $(NASUI_PKG_FOLDER)/build
	ln -sfT ${PWD}/src/nasui/server.js $(NASUI_PKG_FOLDER)/server.js
liuzhe-lz's avatar
liuzhe-lz committed
217
218
219

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

liuzhe-lz's avatar
liuzhe-lz committed
223
224
225
226
.PHONY: update-bash-config
ifndef _ROOT
update-bash-config:
	#$(_INFO) Updating bash configurations $(_END)
227
228
229
    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
230
231
232
233
234
235
236
    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
237
238
239
240
241
242
243
244
245
246
247
248
249
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
250
.PHONY: dev-check-perm
liuzhe-lz's avatar
liuzhe-lz committed
251
ifdef _ROOT
Gems Guo's avatar
Gems Guo committed
252
dev-check-perm:
liuzhe-lz's avatar
liuzhe-lz committed
253
	$(error You should not develop NNI as root)
Gems Guo's avatar
Gems Guo committed
254
255
else
dev-check-perm: ;
liuzhe-lz's avatar
liuzhe-lz committed
256
257
258
endif

# Helper targets end