aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/dex2oat.ts63
1 files changed, 52 insertions, 11 deletions
diff --git a/lib/compilers/dex2oat.ts b/lib/compilers/dex2oat.ts
index 5c46e2129..9c8000fc1 100644
--- a/lib/compilers/dex2oat.ts
+++ b/lib/compilers/dex2oat.ts
@@ -39,6 +39,7 @@ import type {
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {Dex2OatPassDumpParser} from '../parsers/dex2oat-pass-dump-parser.js';
+import * as utils from '../utils.js';
export class Dex2OatCompiler extends BaseCompiler {
static get key() {
@@ -118,6 +119,15 @@ export class Dex2OatCompiler extends BaseCompiler {
// Instantiate D8 compiler, which will in turn instantiate a Java or
// Kotlin compiler based on the current language.
const d8Compiler = global.handler_config.compileHandler.findCompiler(this.lang.id, this.d8Id);
+ if (!d8Compiler) {
+ return {
+ ...this.handleUserError(
+ {message: `Compiler ${this.lang.id} ${this.d8Id} not configured correctly`},
+ '',
+ ),
+ timedOut: false,
+ };
+ }
const d8DirPath = path.dirname(inputFilename);
const d8OutputFilename = d8Compiler.getOutputFilename(d8DirPath);
const d8Options = _.compact(
@@ -132,19 +142,20 @@ export class Dex2OatCompiler extends BaseCompiler {
),
);
- await d8Compiler.runCompiler(
+ const compileResult = await d8Compiler.runCompiler(
this.d8Path,
d8Options,
this.filename(inputFilename),
d8Compiler.getDefaultExecOptions(),
);
+ if (compileResult.code !== 0) {
+ return compileResult;
+ }
+
if (!execOptions) {
execOptions = this.getDefaultExecOptions();
}
- if (!execOptions.customCwd) {
- execOptions.customCwd = this.artArtifactDir;
- }
let useDefaultInsnSet = true;
let useDefaultCompilerFilter = true;
@@ -168,22 +179,35 @@ export class Dex2OatCompiler extends BaseCompiler {
const files = await fs.readdir(d8DirPath);
const dexFile = files.find(f => f.endsWith('.dex'));
+
+ let tmpDir = d8DirPath;
+ if (this.sandboxType === 'nsjail') {
+ tmpDir = '/app';
+ }
+
+ const bootclassjars = [
+ 'bootjars/core-oj.jar',
+ 'bootjars/core-libart.jar',
+ 'bootjars/okhttp.jar',
+ 'bootjars/bouncycastle.jar',
+ 'bootjars/apache-xml.jar',
+ ];
+
const dex2oatOptions = [
'--android-root=include',
'--generate-debug-info',
'--dex-location=/system/framework/classes.dex',
- `--dex-file=${d8DirPath}/${dexFile}`,
+ `--dex-file=${tmpDir}/${dexFile}`,
'--runtime-arg',
- '-Xbootclasspath:bootjars/core-oj.jar:bootjars/core-libart.jar:bootjars/okhttp.jar' +
- ':bootjars/bouncycastle.jar:bootjars/apache-xml.jar',
+ '-Xbootclasspath:' + bootclassjars.map(f => path.join(this.artArtifactDir, f)).join(':'),
'--runtime-arg',
'-Xbootclasspath-locations:/apex/com.android.art/core-oj.jar:/apex/com.android.art/core-libart.jar' +
':/apex/com.android.art/okhttp.jar:/apex/com.android.art/bouncycastle.jar' +
':/apex/com.android.art/javalib/apache-xml.jar',
'--boot-image=/nonx/boot.art',
- `--oat-file=${d8DirPath}/classes.odex`,
+ `--oat-file=${tmpDir}/classes.odex`,
'--force-allow-oj-inlines',
- `--dump-cfg=${d8DirPath}/classes.cfg`,
+ `--dump-cfg=${tmpDir}/classes.cfg`,
...userOptions,
];
if (useDefaultInsnSet) {
@@ -193,6 +217,8 @@ export class Dex2OatCompiler extends BaseCompiler {
dex2oatOptions.push('--compiler-filter=speed');
}
+ execOptions.customCwd = d8DirPath;
+
const result = await this.exec(this.compiler.exe, dex2oatOptions, execOptions);
return {
...this.transformToCompilationResult(result, d8OutputFilename),
@@ -236,8 +262,23 @@ export class Dex2OatCompiler extends BaseCompiler {
}
override async processAsm(result) {
- // result.asm is an array, but we only expect it to have one value.
- const asm = result.asm[0].text;
+ let asm: string = '';
+
+ if (typeof result.asm === 'string') {
+ const asmLines = utils.splitLines(result.asm);
+ if (asmLines.length === 1 && asmLines[0][0] === '<') {
+ return {
+ asm: [{text: asmLines[0], source: null}],
+ };
+ } else {
+ return {
+ asm: [{text: JSON.stringify(asmLines), source: null}],
+ };
+ }
+ } else {
+ // result.asm is an array, but we only expect it to have one value.
+ asm = result.asm[0].text;
+ }
const segments: ParsedAsmResultLine[] = [];
if (!this.fullOutput) {