use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class AaptPackageResourcesIntegrationTest method testEditingLayoutChangesPackageHash.
@Test
public void testEditingLayoutChangesPackageHash() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
// This is too low-level of a test. Ideally, we'd be able to save the rule graph generated
// by the build and query it directly, but runBuckCommand doesn't support that, so just
// test the files directly for now.
Path pathRelativeToProjectRoot = BuildInfo.getPathToMetadataDirectory(BuildTargetFactory.newInstance("//apps/sample:app#aapt_package"), new ProjectFilesystem(workspace.getDestPath())).resolve(AaptPackageResources.RESOURCE_PACKAGE_HASH_KEY);
String firstHash = workspace.getFileContents(pathRelativeToProjectRoot);
workspace.replaceFileContents(PATH_TO_LAYOUT_XML, "white", "black");
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
String secondHash = workspace.getFileContents(pathRelativeToProjectRoot);
Sha1HashCode firstHashCode = Sha1HashCode.of(firstHash);
Sha1HashCode secondHashCode = Sha1HashCode.of(secondHash);
assertNotEquals(firstHashCode, secondHashCode);
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class AndroidResourceFilterIntegrationTest method testStringArtifactsAreCached.
@Test
public void testStringArtifactsAreCached() throws IOException {
Assume.assumeFalse(true);
workspace.enableDirCache();
workspace.runBuckBuild("//apps/sample:app_comp_str").assertSuccess();
BuckBuildLog buildLog = workspace.getBuildLog();
Sha1HashCode androidBinaryRuleKey = buildLog.getRuleKey("//apps/sample:app_comp_str");
ArtifactCache cache = TestArtifactCaches.createDirCacheForTest(workspace.getPath("."), filesystem.getBuckPaths().getCacheDir());
Path cachedFile = DirArtifactCacheTestUtil.getPathForRuleKey(cache, new RuleKey(androidBinaryRuleKey.getHash()), Optional.empty());
Files.delete(workspace.resolve(cachedFile));
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckBuild("//apps/sample:app_comp_str").assertSuccess();
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class PreDexMerge method addMetadataWriteStep.
private void addMetadataWriteStep(final PreDexedFilesSorter.Result result, final ImmutableList.Builder<Step> steps, final Path metadataFilePath) {
StringBuilder nameBuilder = new StringBuilder(30);
final boolean isRootModule = result.apkModule.equals(apkModuleGraph.getRootAPKModule());
final String storeId = result.apkModule.getName();
nameBuilder.append("write_");
if (!isRootModule) {
nameBuilder.append(storeId);
nameBuilder.append("_");
}
nameBuilder.append("metadata_txt");
steps.add(new AbstractExecutionStep(nameBuilder.toString()) {
@Override
public StepExecutionResult execute(ExecutionContext executionContext) {
Map<Path, DexWithClasses> metadataTxtEntries = result.metadataTxtDexEntries;
List<String> lines = Lists.newArrayListWithCapacity(metadataTxtEntries.size());
lines.add(".id " + storeId);
if (isRootModule) {
if (dexSplitMode.getDexStore() == DexStore.RAW) {
lines.add(".root_relative");
}
} else {
for (APKModule dependency : apkModuleGraph.getGraph().getOutgoingNodesFor(result.apkModule)) {
lines.add(".requires " + dependency.getName());
}
}
try {
for (Map.Entry<Path, DexWithClasses> entry : metadataTxtEntries.entrySet()) {
Path pathToSecondaryDex = entry.getKey();
String containedClass = Iterables.get(entry.getValue().getClassNames(), 0);
containedClass = containedClass.replace('/', '.');
Sha1HashCode hash = getProjectFilesystem().computeSha1(pathToSecondaryDex);
lines.add(String.format("%s %s %s", pathToSecondaryDex.getFileName(), hash, containedClass));
}
getProjectFilesystem().writeLinesToPath(lines, metadataFilePath);
} catch (IOException e) {
executionContext.logError(e, "Failed when writing metadata.txt multi-dex.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class PreDexMerge method addStepsForSplitDex.
private void addStepsForSplitDex(ImmutableList.Builder<Step> steps, BuildableContext buildableContext) {
// Collect all of the DexWithClasses objects to use for merging.
ImmutableMultimap.Builder<APKModule, DexWithClasses> dexFilesToMergeBuilder = ImmutableMultimap.builder();
dexFilesToMergeBuilder.putAll(FluentIterable.from(preDexDeps.entries()).transform(input -> new AbstractMap.SimpleEntry<>(input.getKey(), DexWithClasses.TO_DEX_WITH_CLASSES.apply(input.getValue()))).filter(input -> input.getValue() != null).toSet());
final SplitDexPaths paths = new SplitDexPaths();
final ImmutableSet.Builder<Path> secondaryDexDirectories = ImmutableSet.builder();
if (dexSplitMode.getDexStore() == DexStore.RAW) {
// Raw classes*.dex files go in the top-level of the APK.
secondaryDexDirectories.add(paths.jarfilesSubdir);
} else {
// Otherwise, we want to include the metadata and jars as assets.
secondaryDexDirectories.add(paths.metadataDir);
secondaryDexDirectories.add(paths.jarfilesDir);
}
//always add additional dex stores and metadata as assets
secondaryDexDirectories.add(paths.additionalJarfilesDir);
// Do not clear existing directory which might contain secondary dex files that are not
// re-merged (since their contents did not change).
steps.add(new MkdirStep(getProjectFilesystem(), paths.jarfilesSubdir));
steps.add(new MkdirStep(getProjectFilesystem(), paths.additionalJarfilesSubdir));
steps.add(new MkdirStep(getProjectFilesystem(), paths.successDir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.metadataSubdir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.scratchDir));
buildableContext.addMetadata(SECONDARY_DEX_DIRECTORIES_KEY, secondaryDexDirectories.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
buildableContext.recordArtifact(primaryDexPath);
buildableContext.recordArtifact(paths.jarfilesSubdir);
buildableContext.recordArtifact(paths.metadataSubdir);
buildableContext.recordArtifact(paths.successDir);
buildableContext.recordArtifact(paths.additionalJarfilesSubdir);
PreDexedFilesSorter preDexedFilesSorter = new PreDexedFilesSorter(Optional.ofNullable(DexWithClasses.TO_DEX_WITH_CLASSES.apply(dexForUberRDotJava)), dexFilesToMergeBuilder.build(), dexSplitMode.getPrimaryDexPatterns(), apkModuleGraph, paths.scratchDir, // to set the dex weight limit during pre-dex merging.
dexSplitMode.getLinearAllocHardLimit(), dexSplitMode.getDexStore(), paths.jarfilesSubdir, paths.additionalJarfilesSubdir);
final ImmutableMap<String, PreDexedFilesSorter.Result> sortResults = preDexedFilesSorter.sortIntoPrimaryAndSecondaryDexes(getProjectFilesystem(), steps);
PreDexedFilesSorter.Result rootApkModuleResult = sortResults.get(APKModuleGraph.ROOT_APKMODULE_NAME);
if (rootApkModuleResult == null) {
throw new HumanReadableException("No classes found in primary or secondary dexes");
}
Multimap<Path, Path> aggregatedOutputToInputs = HashMultimap.create();
ImmutableMap.Builder<Path, Sha1HashCode> dexInputHashesBuilder = ImmutableMap.builder();
for (PreDexedFilesSorter.Result result : sortResults.values()) {
if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
Path dexOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName());
steps.add(new MkdirStep(getProjectFilesystem(), dexOutputPath));
}
aggregatedOutputToInputs.putAll(result.secondaryOutputToInputs);
dexInputHashesBuilder.putAll(result.dexInputHashes);
}
final ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesBuilder.build();
steps.add(new SmartDexingStep(getProjectFilesystem(), primaryDexPath, Suppliers.ofInstance(rootApkModuleResult.primaryDexInputs), Optional.of(paths.jarfilesSubdir), Optional.of(Suppliers.ofInstance(aggregatedOutputToInputs)), () -> dexInputHashes, paths.successDir, DX_MERGE_OPTIONS, dxExecutorService, xzCompressionLevel, dxMaxHeapSize));
// Record the primary dex SHA1 so exopackage apks can use it to compute their ABI keys.
// Single dex apks cannot be exopackages, so they will never need ABI keys.
steps.add(new RecordFileSha1Step(getProjectFilesystem(), primaryDexPath, PRIMARY_DEX_HASH_KEY, buildableContext));
for (PreDexedFilesSorter.Result result : sortResults.values()) {
if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
Path dexMetadataOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName()).resolve("metadata.txt");
addMetadataWriteStep(result, steps, dexMetadataOutputPath);
}
}
addMetadataWriteStep(rootApkModuleResult, steps, paths.metadataFile);
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class StubJarTest method abiSafeChangesResultInTheSameOutputJar.
@Test
public void abiSafeChangesResultInTheSameOutputJar() throws IOException {
JarPaths paths = createFullAndStubJars(EMPTY_CLASSPATH, "A.java", Joiner.on("\n").join(ImmutableList.of("package com.example.buck;", "public class A {", " protected final static int count = 42;", " public String getGreeting() { return \"hello\"; }", " Class<?> clazz;", " public int other;", "}")));
Sha1HashCode originalHash = filesystem.computeSha1(paths.stubJar);
paths = createFullAndStubJars(EMPTY_CLASSPATH, "A.java", Joiner.on("\n").join(ImmutableList.of("package com.example.buck;", "public class A {", " protected final static int count = 42;", " public String getGreeting() { return \"merhaba\"; }", " Class<?> clazz = String.class;", " public int other = 32;", "}")));
Sha1HashCode secondHash = filesystem.computeSha1(paths.stubJar);
assertEquals(originalHash, secondHash);
}
Aggregations