use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class IjProjectWriter method writeToFile.
@VisibleForTesting
protected void writeToFile(ST contents, Path path) throws IOException {
StringWriter stringWriter = new StringWriter();
AutoIndentWriter noIndentWriter = new AutoIndentWriter(stringWriter);
contents.write(noIndentWriter);
byte[] renderedContentsBytes = noIndentWriter.toString().getBytes(StandardCharsets.UTF_8);
if (projectFilesystem.exists(path)) {
Sha1HashCode fileSha1 = projectFilesystem.computeSha1(path);
Sha1HashCode contentsSha1 = Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(renderedContentsBytes));
if (fileSha1.equals(contentsSha1)) {
return;
}
}
boolean danglingTempFile = false;
Path tempFile = projectFilesystem.createTempFile(IDEA_CONFIG_DIR_PREFIX, path.getFileName().toString(), ".tmp");
try {
danglingTempFile = true;
try (OutputStream outputStream = projectFilesystem.newFileOutputStream(tempFile)) {
outputStream.write(contents.render().getBytes());
}
projectFilesystem.createParentDirs(path);
projectFilesystem.move(tempFile, path, StandardCopyOption.REPLACE_EXISTING);
danglingTempFile = false;
} finally {
if (danglingTempFile) {
projectFilesystem.deleteFileAtPath(tempFile);
}
}
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class BuckBuildLog method fromLogContents.
public static BuckBuildLog fromLogContents(Path root, List<String> logContents) {
ImmutableMap.Builder<BuildTarget, BuildLogEntry> builder = ImmutableMap.builder();
for (String line : logContents) {
Matcher matcher = BUILD_LOG_FINISHED_RULE_REGEX.matcher(line);
if (!matcher.matches()) {
continue;
}
String buildTargetRaw = matcher.group("BuildTarget");
BuildTarget buildTarget = BuildTargetFactory.newInstance(root, buildTargetRaw);
String statusRaw = matcher.group("Status");
BuildRuleStatus status = BuildRuleStatus.valueOf(statusRaw);
String ruleKeyRaw = matcher.group("RuleKey");
Sha1HashCode ruleKey = Sha1HashCode.of(ruleKeyRaw);
CacheResult cacheResult = null;
BuildRuleSuccessType successType = null;
if (status == BuildRuleStatus.SUCCESS) {
String cacheResultRaw = matcher.group("CacheResult");
cacheResult = CacheResult.valueOf(cacheResultRaw);
String successTypeRaw = matcher.group("SuccessType");
successType = BuildRuleSuccessType.valueOf(successTypeRaw);
}
builder.put(buildTarget, new BuildLogEntry(status, Optional.ofNullable(successType), Optional.ofNullable(cacheResult), ruleKey));
}
return new BuckBuildLog(root, builder.build());
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class ComputeExopackageDepsAbi method addToHash.
private void addToHash(Hasher hasher, String role, Path absolutePath, Path relativePath) throws IOException {
// No need to check relative path. That's already been done for us.
Preconditions.checkState(absolutePath.isAbsolute(), "Expected absolute path to be absolute: %s", absolutePath);
hasher.putUnencodedChars(relativePath.toString());
hasher.putByte((byte) 0);
Sha1HashCode fileSha1 = getProjectFilesystem().computeSha1(absolutePath);
fileSha1.update(hasher);
hasher.putByte((byte) 0);
hasher.putUnencodedChars(role);
hasher.putByte((byte) 0);
LOG.verbose("file %s(%s) = %s", relativePath, role, fileSha1);
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class CopyNativeLibraries method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getBinPath()));
final Path pathToNativeLibs = getPathToNativeLibsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibs));
final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibsAssets));
for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(nativeLibDir), pathToNativeLibs, cpuFilters, steps);
}
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibRules, pathToNativeLibs, steps);
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibAssetRules, pathToNativeLibsAssets, steps);
final Path pathToMetadataTxt = getPathToMetadataTxt();
steps.add(new AbstractExecutionStep("hash_native_libs") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
ProjectFilesystem filesystem = getProjectFilesystem();
ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
try {
for (Path nativeLib : filesystem.getFilesUnderPath(getPathToAllLibsDir())) {
Sha1HashCode filesha1 = filesystem.computeSha1(nativeLib);
Path relativePath = getPathToAllLibsDir().relativize(nativeLib);
metadataLines.add(String.format("%s %s", relativePath, filesha1));
}
filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
} catch (IOException e) {
context.logError(e, "There was an error hashing native libraries.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
buildableContext.recordArtifact(pathToNativeLibs);
buildableContext.recordArtifact(pathToNativeLibsAssets);
buildableContext.recordArtifact(pathToMetadataTxt);
return steps.build();
}
use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.
the class DexProducedFromJavaLibrary method computeAbiKey.
@VisibleForTesting
static Sha1HashCode computeAbiKey(ImmutableSortedMap<String, HashCode> classNames) {
Hasher hasher = Hashing.sha1().newHasher();
for (Map.Entry<String, HashCode> entry : classNames.entrySet()) {
hasher.putUnencodedChars(entry.getKey());
hasher.putByte((byte) 0);
hasher.putUnencodedChars(entry.getValue().toString());
hasher.putByte((byte) 0);
}
return Sha1HashCode.fromHashCode(hasher.hash());
}
Aggregations