use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class BinaryFileWriteAction method computeKey.
@Override
protected String computeKey() {
Fingerprint f = new Fingerprint();
f.addString(GUID);
f.addString(String.valueOf(makeExecutable));
try (InputStream in = source.openStream()) {
byte[] buffer = new byte[512];
int amountRead;
while ((amountRead = in.read(buffer)) != -1) {
f.addBytes(buffer, 0, amountRead);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return f.hexDigestAndReset();
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class TestRunnerAction method computeKey.
@Override
protected String computeKey() {
Fingerprint f = new Fingerprint();
f.addString(GUID);
f.addStrings(executionSettings.getArgs());
f.addString(executionSettings.getTestFilter() == null ? "" : executionSettings.getTestFilter());
RunUnder runUnder = executionSettings.getRunUnder();
f.addString(runUnder == null ? "" : runUnder.getValue());
f.addStringMap(getTestEnv());
f.addString(testProperties.getSize().toString());
f.addString(testProperties.getTimeout().toString());
f.addStrings(testProperties.getTags());
f.addInt(testProperties.isLocal() ? 1 : 0);
f.addInt(shardNum);
f.addInt(executionSettings.getTotalShards());
f.addInt(runNumber);
f.addInt(configuration.getRunsPerTestForLabel(getOwner().getLabel()));
f.addInt(configuration.isCodeCoverageEnabled() ? 1 : 0);
return f.hexDigestAndReset();
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class RepositoryDelegatorFunction method isFilesystemUpToDate.
/**
* Checks if the state of the repository in the file system is consistent with the rule in the
* WORKSPACE file.
*
* <p>
* Deletes the marker file if not so that no matter what happens after, the state of the file
* system stays consistent.
*
* <p>
* Returns null if the file system is not up to date and a hash of the marker file if the file
* system is up to date.
*/
@Nullable
private final byte[] isFilesystemUpToDate(Path markerPath, Rule rule, String ruleKey, RepositoryFunction handler, Environment env) throws RepositoryFunctionException, InterruptedException {
try {
if (!markerPath.exists()) {
return null;
}
String content = FileSystemUtils.readContent(markerPath, StandardCharsets.UTF_8);
String[] lines = content.split("\n");
Map<String, String> markerData = new TreeMap<>();
String markerRuleKey = "";
boolean firstLine = true;
for (String line : lines) {
if (firstLine) {
markerRuleKey = line;
firstLine = false;
} else {
int sChar = line.indexOf(' ');
String key = line;
String value = "";
if (sChar > 0) {
key = unescape(line.substring(0, sChar));
value = unescape(line.substring(sChar + 1));
}
markerData.put(key, value);
}
}
boolean result = false;
if (markerRuleKey.equals(ruleKey)) {
result = handler.verifyMarkerData(rule, markerData, env);
if (env.valuesMissing()) {
return null;
}
}
if (result) {
return new Fingerprint().addString(content).digestAndReset();
} else {
// So that we are in a consistent state if something happens while fetching the repository
markerPath.delete();
return null;
}
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class RepositoryDelegatorFunction method writeMarkerFile.
private final byte[] writeMarkerFile(Path markerPath, Map<String, String> markerData, String ruleKey) throws RepositoryFunctionException {
try {
StringBuilder builder = new StringBuilder();
builder.append(ruleKey).append("\n");
for (Map.Entry<String, String> data : markerData.entrySet()) {
String key = data.getKey();
String value = data.getValue();
builder.append(escape(key)).append(" ").append(escape(value)).append("\n");
}
String content = builder.toString();
FileSystemUtils.writeContent(markerPath, StandardCharsets.UTF_8, content);
return new Fingerprint().addString(content).digestAndReset();
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class MavenServerFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, RepositoryFunctionException {
String repository = (String) skyKey.argument();
Rule repositoryRule = null;
try {
repositoryRule = RepositoryFunction.getRule(repository, env);
} catch (RepositoryNotFoundException ex) {
// Ignored. We throw a new one below.
}
BlazeDirectories directories = PrecomputedValue.BLAZE_DIRECTORIES.get(env);
if (env.valuesMissing()) {
return null;
}
String serverName;
String url;
Map<String, FileValue> settingsFiles;
boolean foundRepoRule = repositoryRule != null && repositoryRule.getRuleClass().equals(MavenServerRule.NAME);
if (!foundRepoRule) {
if (repository.equals(MavenServerValue.DEFAULT_ID)) {
settingsFiles = getDefaultSettingsFile(directories, env);
serverName = MavenServerValue.DEFAULT_ID;
url = MavenConnector.getMavenCentralRemote().getUrl();
} else {
throw new RepositoryFunctionException(new IOException("Could not find maven repository " + repository), Transience.TRANSIENT);
}
} else {
WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(repositoryRule);
serverName = repositoryRule.getName();
try {
url = mapper.get("url", Type.STRING);
if (!mapper.isAttributeValueExplicitlySpecified("settings_file")) {
settingsFiles = getDefaultSettingsFile(directories, env);
} else {
PathFragment settingsFilePath = new PathFragment(mapper.get("settings_file", Type.STRING));
RootedPath settingsPath = RootedPath.toRootedPath(directories.getWorkspace().getRelative(settingsFilePath), PathFragment.EMPTY_FRAGMENT);
FileValue fileValue = (FileValue) env.getValue(FileValue.key(settingsPath));
if (fileValue == null) {
return null;
}
if (!fileValue.exists()) {
throw new RepositoryFunctionException(new IOException("Could not find settings file " + settingsPath), Transience.TRANSIENT);
}
settingsFiles = ImmutableMap.<String, FileValue>builder().put(USER_KEY, fileValue).build();
}
} catch (EvalException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
}
}
if (settingsFiles == null) {
return null;
}
Fingerprint fingerprint = new Fingerprint();
try {
for (Map.Entry<String, FileValue> entry : settingsFiles.entrySet()) {
fingerprint.addString(entry.getKey());
Path path = entry.getValue().realRootedPath().asPath();
if (path.exists()) {
fingerprint.addBoolean(true);
fingerprint.addBytes(path.getDigest());
} else {
fingerprint.addBoolean(false);
}
}
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
byte[] fingerprintBytes = fingerprint.digestAndReset();
if (settingsFiles.isEmpty()) {
return new MavenServerValue(serverName, url, new Server(), fingerprintBytes);
}
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
if (settingsFiles.containsKey(SYSTEM_KEY)) {
request.setGlobalSettingsFile(settingsFiles.get(SYSTEM_KEY).realRootedPath().asPath().getPathFile());
}
if (settingsFiles.containsKey(USER_KEY)) {
request.setUserSettingsFile(settingsFiles.get(USER_KEY).realRootedPath().asPath().getPathFile());
}
DefaultSettingsBuilder builder = (new DefaultSettingsBuilderFactory()).newInstance();
SettingsBuildingResult result;
try {
result = builder.build(request);
} catch (SettingsBuildingException e) {
throw new RepositoryFunctionException(new IOException("Error parsing settings files: " + e.getMessage()), Transience.TRANSIENT);
}
if (!result.getProblems().isEmpty()) {
throw new RepositoryFunctionException(new IOException("Errors interpreting settings file: " + Arrays.toString(result.getProblems().toArray())), Transience.PERSISTENT);
}
Settings settings = result.getEffectiveSettings();
Server server = settings.getServer(serverName);
server = server == null ? new Server() : server;
return new MavenServerValue(serverName, url, server, fingerprintBytes);
}
Aggregations