1
+ SHELL = /bin/bash -o nounset -o pipefail -o errexit
2
+ MAKEFLAGS += --no-builtin-rules
3
+ .SUFFIXES :
4
+
1
5
# # Argument Variables ##
2
6
3
- CPUS : = $(shell nproc)
4
- MEMORY : = 10000
5
- DISK : = 300000
6
- DEVICE : =
7
- BACKEND : = local
8
- CHANNEL : = beta
9
- BUILD := user
10
- FLAVOR := aosp
11
- IMAGE := hashbang/aosp-build:latest
12
- IMAGE_OPTIONS : =
13
- NAME : = aosp-build-$(FLAVOR ) -$(BACKEND )
14
- SHELL := /bin/bash
7
+ CPUS = $(shell nproc)
8
+ MEMORY = 10000
9
+ DISK = 300000
10
+ DEVICE =
11
+ BACKEND = local
12
+ CHANNEL = beta
13
+ FLAVOR = aosp
14
+ IMAGE = hashbang/ aosp-build:latest
15
+ IMAGE_OPTIONS =
16
+ RUN_OPTIONS =
17
+ NAME = aosp-build-$(FLAVOR ) -$(BACKEND )
18
+ REQUIRED_FREE_SPACE_IN_GIB = 120
15
19
16
20
-include $(PWD ) /config/env/$(BACKEND ) .env
17
21
@@ -25,20 +29,24 @@ default: machine image fetch tools keys build release
25
29
# # Primary Targets ##
26
30
27
31
.PHONY : fetch
28
- fetch : submodule-update machine image
32
+ fetch :
29
33
$(contain ) fetch
30
34
31
35
.PHONY : keys
32
36
keys :
33
- $(contain ) keys
37
+ $(contain-keys ) keys
38
+
39
+ .PHONY : review
40
+ review :
41
+ $(contain ) review
34
42
35
43
.PHONY : build
36
- build :
44
+ build : ensure-enough-free-disk-space
37
45
$(contain ) build
38
46
39
47
.PHONY : release
40
48
release :
41
- $(contain ) release
49
+ $(contain-keys ) release
42
50
43
51
.PHONY : publish
44
52
publish :
@@ -52,28 +60,41 @@ clean:
52
60
mrproper : storage-delete machine-delete
53
61
rm -rf build
54
62
55
-
56
63
# # Secondary Targets ##
57
64
65
+ config/container/Dockerfile : config/container/Dockerfile.j2 config/container/render_template
66
+ ./config/container/render_template " $<" " {\" tags\" :[]}" > " $@ "
67
+
68
+ # # Support for different Docker image variants.
69
+ config/container/Dockerfile-golang :
70
+ config/container/Dockerfile-latest :
71
+ config/container/Dockerfile-% : config/container/Dockerfile.j2 config/container/render_template
72
+ ./config/container/render_template " $<" " {\" tags\" :[\" $* \" ]}" > " $@ "
73
+
58
74
.PHONY : image
59
- image :
75
+ image : config/container/Dockerfile
60
76
$(docker ) build \
61
77
--tag $(IMAGE ) \
62
- --file $(PWD ) /config/container/Dockerfile \
78
+ --file " $( PWD) /$< " \
63
79
$(IMAGE_OPTIONS ) \
64
80
$(PWD )
65
81
66
- config/container/Dockerfile.minimal : config/container/Dockerfile config/container/render_template
67
- ./config/container/render_template " $<" | grep -v ' ^#\s*$$' > " $@ "
68
-
69
- .PHONY : image-minimal
70
- image-minimal : config/container/Dockerfile.minimal
82
+ .PHONY : image-%
83
+ image-golang :
84
+ image-latest :
85
+ image-% : config/container/Dockerfile-%
71
86
$(docker ) build \
72
87
--tag $(IMAGE ) \
73
88
--file " $( PWD) /$<" \
74
89
$(IMAGE_OPTIONS ) \
75
90
$(PWD )
76
91
92
+ # # Note that the `image-latest` target should be used for pinning.
93
+ .PHONY : config/container/packages-pinned.list
94
+ config/container/packages-pinned.list :
95
+ $(contain-no-tty ) pin-packages > " $@ "
96
+
97
+
77
98
.PHONY : tools
78
99
tools :
79
100
mkdir -p config/keys build/base release build/external
@@ -97,14 +118,14 @@ kernel:
97
118
.PHONY : latest
98
119
latest : config submodule-latest fetch
99
120
100
- .PHONY : manifest
101
- manifest : config
102
- $(contain ) bash -c " source <(environment) && manifest"
103
-
104
121
.PHONY : config
105
122
config :
106
123
$(contain ) bash -c " source <(environment) && config"
107
124
125
+ .PHONY : manifest
126
+ manifest :
127
+ $(contain ) bash -c " source <(environment) && manifest"
128
+
108
129
.PHONY : test-repro
109
130
test-repro :
110
131
$(contain ) test-repro
@@ -114,18 +135,16 @@ test: test-repro
114
135
115
136
.PHONY : patches
116
137
patches :
117
- @$(contain ) bash -c " cd base; repo diff --absolute"
138
+ @$(contain ) bash -c " cd build/ base && repo diff --absolute"
118
139
119
140
.PHONY : shell
120
141
shell :
121
- $(docker ) inspect " $( NAME) " \
122
- && $(docker ) exec --interactive --tty " $( NAME) " shell \
123
- || $(contain ) shell
142
+ $(docker ) exec --interactive --tty " $( NAME) " shell \
143
+ || $(contain ) shell
124
144
125
145
.PHONY : monitor
126
146
monitor :
127
- $(docker ) inspect " $( NAME) " \
128
- && $(docker ) exec --interactive --tty " $( NAME) " htop
147
+ $(docker ) exec --interactive --tty " $( NAME) " htop
129
148
130
149
.PHONY : install
131
150
install : tools
@@ -250,22 +269,63 @@ endif
250
269
userid = $(shell id -u)
251
270
groupid = $(shell id -g)
252
271
docker_machine = docker-machine --storage-path "${PWD}/build/machine"
253
- contain := \
272
+
273
+ # Can be used mount aosp-build directory to /opt/aosp-build to allow fast
274
+ # development without the need to rebuild the container image all the time.
275
+ # See HashbangMobile for example.
276
+ contain-base-extend =
277
+
278
+ contain-base = \
254
279
$(docker ) run \
255
280
--rm \
256
- --tty \
257
281
--interactive \
258
282
--name "$(NAME ) " \
259
283
--hostname "$(NAME ) " \
260
284
--user $(userid ) :$(groupid ) \
261
285
--env DEVICE=$(DEVICE ) \
286
+ --privileged \
262
287
--security-opt seccomp=unconfined \
263
288
--volume $(PWD ) /config:/home/build/config \
264
289
--volume $(PWD ) /release:/home/build/release \
265
290
--volume $(PWD ) /scripts:/home/build/scripts \
266
- $(storage_flags ) \
291
+ $(contain-base-extend ) \
292
+ $(RUN_OPTIONS ) \
293
+ --shm-size="1g" \
294
+ $(storage_flags )
295
+
296
+ contain-no-tty = \
297
+ $(contain-base ) \
298
+ $(IMAGE )
299
+
300
+ contain-keys = \
301
+ $(contain-base ) \
302
+ --tty \
303
+ --volume $(PWD ) /keys:/home/build/keys \
304
+ $(IMAGE )
305
+
306
+ contain = \
307
+ $(contain-base ) \
308
+ --tty \
267
309
$(IMAGE )
268
310
311
+ # # Helpers ##
312
+
313
+ ensure-git-status-clean :
314
+ @if [ -z " $( shell git status --porcelain=v2) " ]; then \
315
+ echo " git status has no output. Working tree is clean." ; \
316
+ else \
317
+ git status; \
318
+ echo " Working tree is not clean as required. Exiting." ; \
319
+ exit 1; \
320
+ fi
321
+
322
+ ensure-enough-free-disk-space :
323
+ @free_space=$(shell df -k --output=avail "$$PWD" | tail -n1) ; \
324
+ needed_free_space=$$(( $(REQUIRED_FREE_SPACE_IN_GIB ) * 1024 * 1024 ) ); \
325
+ if [[ $$ free_space -lt $$ needed_free_space ]]; then \
326
+ echo " Not enought free space. $( REQUIRED_FREE_SPACE_IN_GIB) GiB are required." 1>&2 ; \
327
+ exit 1; \
328
+ fi
269
329
270
330
# # Required Binary Check ##
271
331
0 commit comments