-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadb-ci.js
More file actions
71 lines (51 loc) · 1.74 KB
/
adb-ci.js
File metadata and controls
71 lines (51 loc) · 1.74 KB
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
#!/usr/bin/env node
'use strict';
const fs = require('fs'),
path = require('path');
const IS_CI = process.env.CI;
const original_location = `${process.env.ANDROID_HOME}/platform-tools/adb`;
let args = process.argv.slice(2);
const logPath = path.join(__dirname, 'adb-ci.txt');
const currentDate = new Date();
if (IS_CI) {
// See https://developer.android.com/studio/command-line/adb.html
let command_pos, command
if (args[0] === '-d' || args[0] === '-e') {
command_pos = 1;
} else if (args[0] === '-s') {
command_pos = 2;
} else {
command_pos = 0;
}
command = args[command_pos];
if (command === 'install') {
// look for -g option
let install_options = args.slice(command_pos + 1);
if (!install_options.includes('-g')) {
install_options.unshift('-g');
args = args.slice(0, command_pos + 1).concat(install_options);
}
}
}
fs.appendFileSync(logPath, `${currentDate.toLocaleString()} adb-ci spawn: ${JSON.stringify(args)}\n`);
const
spawn = require('child_process').spawn,
adb = spawn(original_location, args, {
stdio: 'inherit'
});
adb.on('exit', code => {
fs.appendFileSync(logPath, `${currentDate.toLocaleString()} adb-ci exit: ${code}\n`);
// Do not use process.exit, see http://stackoverflow.com/a/37592669/1691132
process.exitCode = code;
});
adb.on('error', () => {
fs.appendFileSync(logPath,`${currentDate.toLocaleString()} adb-ci error\n`);
console.log(`adb-ci wrapper could not start adb at ${original_location}`);
process.exitCode = 1;
});
adb.on('SIGHUP', function() {
fs.appendFileSync(logPath,`${currentDate.toLocaleString()} adb-ci SIGHUP\n`);
});
process.on('exit', code => {
fs.appendFileSync(logPath,`${currentDate.toLocaleString()} adb-ci process exit\n`);
});