Skip to content

Commit dc0acf2

Browse files
muhomorrthestinger
authored andcommitted
collect-state: add an option to automatically make prep OS build
1 parent a306cd2 commit dc0acf2

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

scripts/make-prep-build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
source build/envsetup.sh
5+
export OFFICIAL_BUILD=true
6+
lunch ${1}-user
7+
m

src/commands/collect-state.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { Command, flags } from '@oclif/command'
2+
import assert from 'assert'
3+
import { spawnSync } from 'child_process'
24
import { promises as fs } from 'fs'
5+
import path from 'path'
36

4-
import { DEVICE_CONFIG_FLAGS, loadDeviceConfigs } from '../config/device'
5-
import { COLLECTED_SYSTEM_STATE_DIR } from '../config/paths'
7+
import { DEVICE_CONFIG_FLAGS, DeviceBuildId, getDeviceBuildId, loadDeviceConfigs } from '../config/device'
8+
import { ADEVTOOL_DIR, COLLECTED_SYSTEM_STATE_DIR, OS_CHECKOUT_DIR } from '../config/paths'
69
import { collectSystemState, serializeSystemState } from '../config/system-state'
710
import { forEachDevice } from '../frontend/devices'
11+
import { DeviceImages, prepareFactoryImages } from '../frontend/source'
12+
import { loadBuildIndex } from '../images/build-index'
13+
import { spawnAsync } from '../util/process'
14+
import { generatePrep } from './generate-prep'
815

916
export default class CollectState extends Command {
1017
static description = 'collect built system state for use with other commands'
@@ -28,21 +35,46 @@ export default class CollectState extends Command {
2835
required: true,
2936
default: COLLECTED_SYSTEM_STATE_DIR,
3037
}),
38+
rebuild: flags.boolean({
39+
description: 'generate prep vendor module (same as generate-prep) and make an OS build before collecting state',
40+
default: false,
41+
}),
42+
allowOutReuse: flags.boolean({
43+
description: 'if --rebuild is specified, do not remove out/ dir before making an OS build',
44+
default: false,
45+
}),
3146
...DEVICE_CONFIG_FLAGS,
3247
}
3348

3449
async run() {
3550
let {
36-
flags: { aapt2: aapt2Path, devices, outRoot, parallel, outPath },
51+
flags: { aapt2: aapt2Path, devices, outRoot, parallel, outPath, rebuild, allowOutReuse },
3752
} = this.parse(CollectState)
3853

3954
let configs = await loadDeviceConfigs(devices)
4055

56+
let deviceImagesMap: Map<DeviceBuildId, DeviceImages>
57+
if (rebuild) {
58+
deviceImagesMap = await prepareFactoryImages(await loadBuildIndex(), configs)
59+
}
60+
4161
let isDir = (await fs.stat(outPath)).isDirectory()
4262
await forEachDevice(
4363
configs,
4464
parallel,
4565
async config => {
66+
if (rebuild) {
67+
let deviceImages = deviceImagesMap.get(getDeviceBuildId(config))
68+
assert(deviceImages !== undefined)
69+
await generatePrep(config, deviceImages.unpackedFactoryImageDir, config.device.build_id)
70+
if (!allowOutReuse) {
71+
await spawnAsync('rm', ['-rf', path.join(OS_CHECKOUT_DIR, 'out')])
72+
}
73+
let res = spawnSync(path.join(ADEVTOOL_DIR, 'scripts/make-prep-build.sh'),
74+
[config.device.name], { stdio: 'inherit' })
75+
console.assert(res.status === 0, `make-prep-build.sh failed, exit code ${res.status}`)
76+
}
77+
4678
let state = await collectSystemState(config.device.name, outRoot, aapt2Path)
4779

4880
// Write

src/commands/generate-prep.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { loadBuildIndex } from '../images/build-index'
1212
import { withSpinner } from '../util/cli'
1313
import { withTempDir } from '../util/fs'
1414

15+
export async function generatePrep(config: DeviceConfig, stockSrc: string, buildId: string) {
16+
await doDevice(config, stockSrc, buildId, false, false)
17+
}
18+
1519
const doDevice = (
1620
config: DeviceConfig,
1721
stockSrc: string,

0 commit comments

Comments
 (0)