blob: b4670dc3743779c292226eb9ab13f99d9a58471c [file] [log] [blame]
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package util.build;
import org.jf.smali.Smali;
import org.jf.smali.SmaliOptions;
import java.io.File;
/**
* BuildStep that invokes the Smali Java API to
* assemble test cases written in Smali.
*/
class SmaliBuildStep extends BuildStep {
SmaliBuildStep(BuildFile inputFile, BuildFile outputFile) {
super(inputFile, outputFile);
}
@Override
boolean build() {
if (super.build()) {
return assemble(inputFile.fileName, outputFile.fileName);
}
return false;
}
private boolean assemble(File input, File output) {
SmaliOptions options = new SmaliOptions();
options.verboseErrors = true;
options.outputDexFile = output.getAbsolutePath();
try {
File destDir = output.getParentFile();
if (!destDir.exists()) {
destDir.mkdirs();
}
return Smali.assemble(options, input.getAbsolutePath());
} catch(Exception e) {
if(BuildDalvikSuite.DEBUG)
e.printStackTrace();
System.err.println("Exception <" + e.getClass().getName() + ">" + e.getMessage());
return false;
}
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
SmaliBuildStep other = (SmaliBuildStep) obj;
return inputFile.equals(other.inputFile)
&& outputFile.equals(other.outputFile);
}
return false;
}
@Override
public int hashCode() {
return inputFile.hashCode() ^ outputFile.hashCode();
}
}