-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathMakefile
205 lines (159 loc) · 5.73 KB
/
Makefile
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# opentrons app desktop shell makefile
include ../scripts/push.mk
# using bash instead of /bin/bash in SHELL prevents macOS optimizing away our PATH update
SHELL := bash
# add node_modules/.bin to PATH
PATH := $(shell cd .. && yarn bin):$(PATH)
# dev server port
PORT ?= 3000
# dep directories for production build
# TODO(mc, 2018-08-07): figure out a better way to do this
ui_dir := ../app
# Path of source package
SRC_PATH = app-shell
# cross-platform noop command
noop := cd .
# build and publish options
dist_files = $(if $(filter $(1),robot-stack),"dist/**/Opentrons-*","dist/**/Opentrons-OT3-*")
update_files := "dist/@(alpha|beta|latest)*.@(yml|json)"
publish_dir := dist/publish
# These variables can be overriden when make is invoked to customize the
# behavior of jest. For instance,
# make test tests=src/__tests__/http.test.ts would run only the
# specified test
tests ?= $(SRC_PATH)/src
cov_opts ?= --coverage=true
test_opts ?=
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)
# TODO(mc, 2018-03-27): move all this to some sort of envfile
# build id suffix to add to artifacts
# if no build number -> dev
# if tagged build (tag ~= ^v.+) -> b$(BUILD_NUMBER)
# if branch exists -> b$(BUILD_NUMBER)-$(BRANCH_NAME)
# only copy update files publish directory on tagged builds that match the provided OPENTRONS_PROJECT
# environment variable (i.e. if OT_TAG is vxxx and OPENTRONS_PROJECT is robot-stack, or OT_TAG is ot3@xxx
# and OPENTRONS_PROJECT is ot3)
_publish_ot2 := $(and $(filter v%,$(OT_TAG)), $(filter robot-stack,$(OPENTRONS_PROJECT)))
_publish_ot3 := $(and $(filter ot3@%,$(OT_TAG)), $(filter ot3,$(OPENTRONS_PROJECT)))
publish_update := $(or $(_publish_ot2),$(_publish_ot3))
branch_suffix := $(if $(publish_update),,-$(subst /,-,$(OT_BRANCH)))
build_id := $(or $(and $(OT_BUILD),b$(OT_BUILD)$(branch_suffix)),dev)
OPENTRONS_PROJECT ?= $(if $(filter ot3@%,$(publish_update)),ot3,robot-stack)
# set this to anything on command-line invocations of this makefile to skip bundling
# standalone python, as is necessary for on-device app builds:
# make dist no_python_bundle=true or =1 or whatever
no_python_bundle ?=
builder := yarn electron-builder \
--config electron-builder.config.js \
--config.electronVersion=33.2.1 \
--publish never
electron := yarn electron . \
--devtools \
--log.level.console="debug" \
--disable_ui.webPreferences.webSecurity \
--ui.url.protocol="http:" \
--ui.url.path="localhost:$(PORT)" \
--python.pathToPythonOverride=$(shell cd ../api && pipenv --venv)
electron-dist := yarn electron . \
--devtools \
--log.level.console="debug" \
--disable_ui.webPreferences.webSecurity \
--ui.url.protocol="file:" \
--ui.url.path="$(ui_dir)/dist/index.html"
--python.pathToPythonOverride=$(shell cd ../api && pipenv --venv)
# standard targets
#####################################################################
.PHONY: branch-suffix
branch-suffix:
echo $(branch_suffix)
.PHONY: all
all: package
.PHONY: setup
# must be wrapped in yarn run otherwise `prebuild-install` will fail silently
# due to how `electron-rebuild` calls `prebuild-install`
setup:
yarn rebuild
.PHONY: clean
clean:
yarn shx rm -rf lib dist python
# artifacts
#####################################################################
.PHONY: lib
lib: export NODE_ENV := production
lib:
echo "Building app shell JS bundle (electron layer)"
vite build
.PHONY: deps
deps:
$(MAKE) -C $(ui_dir)
.PHONY: package-deps
package-deps: clean lib deps
package dist-posix dist-osx dist-linux dist-win: export NODE_ENV := production
package dist-posix dist-osx dist-linux dist-win: export BUILD_ID := $(build_id)
package dist-posix dist-osx dist-linux dist-win: export NO_PYTHON := $(if $(no_python_bundle),true,false)
package dist-posix dist-osx dist-linux dist-win: export USE_HARD_LINKS := false
# Note: these depend on make -C app dist having been run; do not do this automatically because we separate these
# tasks in CI and even if you have a file dep it's easy to accidentally make the dist run.
.PHONY: package
package:
$(builder) --dir
.PHONY: dist-posix
dist-posix: clean lib
$(builder) --linux --mac
$(MAKE) _dist-collect-artifacts
.PHONY: dist-osx
dist-osx: clean lib
$(builder) --mac --x64
$(MAKE) _dist-collect-artifacts
.PHONY: dist-linux
dist-linux: clean lib
$(builder) --linux
$(MAKE) _dist-collect-artifacts
.PHONY: dist-win
dist-win: clean lib
$(builder) --win --x64
$(MAKE) _dist-collect-artifacts
.PHONY: dist-ot3
dist-ot3: clean lib
NO_PYTHON=true $(builder) --linux --arm64 --dir
cd dist/linux-arm64-unpacked
# Aliases matching github actions OS names for easier calling in
# workflows
.PHONY: dist-macos-latest
dist-macos-latest: dist-osx
.PHONY: dist-ubuntu-latest
dist-ubuntu-latest: dist-linux
.PHONY: dist-ubuntu-22.04
dist-ubuntu-22.04: dist-linux
.PHONY: dist-windows-2019
dist-windows-2019: dist-win
.PHONY: dist-windows-2022
dist-windows-2022: dist-win
# copy distributable artifacts to the publish directory
# update files will not exist for all OSs, so noop if cp errors
.PHONY: _dist-collect-artifacts
_dist-collect-artifacts:
shx mkdir -p dist/publish
shx cp $(call dist_files,$(OPENTRONS_PROJECT)) $(publish_dir)
$(and $(publish_update),shx cp $(update_files) $(publish_dir) || $(noop))
# development
#####################################################################
.PHONY: dev-app-update-file
dev-app-update-file:
cp ./dev-app-update-$(OPENTRONS_PROJECT).yml ./dev-app-update.yml
.PHONY: dev
dev: export NODE_ENV := development
dev: export OPENTRONS_PROJECT := $(OPENTRONS_PROJECT)
dev: dev-app-update-file
vite build
$(electron)
.PHONY: dev-dist
dev: export NODE_ENV := development
dev-dist: export OPENTRONS_PROJECT := $(OPENTRONS_PROJECT)
dev-dist: package-deps
vite build
$(electron-dist)
.PHONY: test
test:
$(MAKE) -C .. test-js-app-shell