Skip to content

Commit

Permalink
Remaining @nullable annotations.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 459475128
Change-Id: I2472aaf91527c7b4a8077d41b4802517e2c002f3
  • Loading branch information
meisterT authored and Copybara-Service committed Jul 7, 2022
1 parent 22f63d3 commit 818c5c8
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;

/**
* An implementation of the ActionCache interface that uses a {@link StringIndexer} to reduce memory
Expand Down Expand Up @@ -333,6 +334,7 @@ public static Path journalFile(Path cacheRoot) {
}

@Override
@Nullable
public ActionCache.Entry get(String key) {
int index = indexer.getIndex(key);
if (index < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,38 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;

/**
* Persistent version of the CanonicalStringIndexer.
*
* <p>This class is backed by a PersistentMap that holds one direction of the
* canonicalization mapping. The other direction is handled purely in memory
* and reconstituted at load-time.
* <p>This class is backed by a PersistentMap that holds one direction of the canonicalization
* mapping. The other direction is handled purely in memory and reconstituted at load-time.
*
* <p>Thread-safety is ensured by locking on all mutating operations from the
* superclass. Read-only operations are not locked, but rather backed by
* ConcurrentMaps.
* <p>Thread-safety is ensured by locking on all mutating operations from the superclass. Read-only
* operations are not locked, but rather backed by ConcurrentMaps.
*/
@ConditionallyThreadSafe // condition: each instance must instantiated with
// different dataFile.
// different dataFile.
final class PersistentStringIndexer extends CanonicalStringIndexer {

/**
* Persistent metadata map. Used as a backing map to provide a persistent
* implementation of the metadata cache.
* Persistent metadata map. Used as a backing map to provide a persistent implementation of the
* metadata cache.
*/
private static final class PersistentIndexMap extends PersistentMap<String, Integer> {
private static final class PersistentIndexMap extends PersistentMap<String, Integer> {
private static final int VERSION = 0x01;
private static final long SAVE_INTERVAL_NS = 3L * 1000 * 1000 * 1000;

private final Clock clock;
private long nextUpdate;

public PersistentIndexMap(Path mapFile, Path journalFile, Clock clock) throws IOException {
super(VERSION, PersistentStringIndexer.<String, Integer>newConcurrentMap(INITIAL_ENTRIES),
mapFile, journalFile);
super(
VERSION,
PersistentStringIndexer.<String, Integer>newConcurrentMap(INITIAL_ENTRIES),
mapFile,
journalFile);
this.clock = clock;
nextUpdate = clock.nanoTime();
load(/* failFast= */ true);
Expand All @@ -72,6 +74,7 @@ protected boolean updateJournal() {
}

@Override
@Nullable
public Integer remove(Object object) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public StarlarkPath which(String program, StarlarkThread thread) throws EvalExce
return null;
}

@Nullable
private StarlarkPath findCommandOnPath(String program) throws IOException {
String pathEnvVariable = envVariables.get("PATH");
if (pathEnvVariable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import javax.annotation.Nullable;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.annot.StarlarkMethod;
Expand Down Expand Up @@ -54,7 +55,7 @@ public boolean isImmutable() {

@Override
public boolean equals(Object obj) {
return (obj instanceof StarlarkPath) && path.equals(((StarlarkPath) obj).path);
return (obj instanceof StarlarkPath) && path.equals(((StarlarkPath) obj).path);
}

@Override
Expand Down Expand Up @@ -85,7 +86,9 @@ public ImmutableList<StarlarkPath> readdir() throws IOException {
@StarlarkMethod(
name = "dirname",
structField = true,
allowReturnNones = true,
doc = "The parent directory of this file, or None if this file does not have a parent.")
@Nullable
public StarlarkPath getDirname() {
Path parentPath = path.getParentDirectory();
return parentPath == null ? null : new StarlarkPath(parentPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkSemantics;
Expand Down Expand Up @@ -265,6 +266,7 @@ public boolean verifyMarkerData(Rule rule, Map<String, String> markerData, Envir
}

@Override
@Nullable
public RepositoryDirectoryValue.Builder fetch(
Rule rule,
Path outputDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

/** This class contains the common logic between Android NDK and SDK repository functions. */
abstract class AndroidRepositoryFunction extends RepositoryFunction {
Expand All @@ -48,6 +49,7 @@ abstract void throwInvalidPathException(Path path, Exception e)
* <p>First, we get a {@link FileValue} to check the {@code dirPath} exists and is a directory. If
* not, we throw an exception.
*/
@Nullable
final DirectoryListingValue getDirectoryListing(Path root, PathFragment dirPath, Environment env)
throws RepositoryFunctionException, InterruptedException {
RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), dirPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import javax.annotation.Nullable;
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.Starlark;

Expand Down Expand Up @@ -165,9 +166,7 @@ public String toString() {
private static final ImmutableList<String> PATH_ENV_VAR_AS_LIST = ImmutableList.of(PATH_ENV_VAR);
private static final ImmutableList<String> LOCAL_MAVEN_REPOSITORIES =
ImmutableList.of(
"extras/android/m2repository",
"extras/google/m2repository",
"extras/m2repository");
"extras/android/m2repository", "extras/google/m2repository", "extras/m2repository");

@Override
public boolean isLocal(Rule rule) {
Expand All @@ -185,6 +184,7 @@ public boolean verifyMarkerData(Rule rule, Map<String, String> markerData, Envir
}

@Override
@Nullable
public RepositoryDirectoryValue.Builder fetch(
Rule rule,
final Path outputDirectory,
Expand Down Expand Up @@ -316,13 +316,14 @@ public RepositoryDirectoryValue.Builder fetch(

String template = getStringResource("android_sdk_repository_template.txt");

String buildFile = template
.replace("%repository_name%", rule.getName())
.replace("%build_tools_version%", buildToolsVersion)
.replace("%build_tools_directory%", buildToolsDirectory)
.replace("%api_levels%", Iterables.toString(apiLevels))
.replace("%default_api_level%", String.valueOf(defaultApiLevel))
.replace("%system_image_dirs%", systemImageDirsList);
String buildFile =
template
.replace("%repository_name%", rule.getName())
.replace("%build_tools_version%", buildToolsVersion)
.replace("%build_tools_directory%", buildToolsDirectory)
.replace("%api_levels%", Iterables.toString(apiLevels))
.replace("%default_api_level%", String.valueOf(defaultApiLevel))
.replace("%system_image_dirs%", systemImageDirsList);

// All local maven repositories that are shipped in the Android SDK.
// TODO(ajmichael): Create SkyKeys so that if the SDK changes, this function will get rerun.
Expand All @@ -332,8 +333,9 @@ public RepositoryDirectoryValue.Builder fetch(
SdkMavenRepository sdkExtrasRepository =
SdkMavenRepository.create(Iterables.filter(localMavenRepositories, Path::isDirectory));
sdkExtrasRepository.writeBuildFiles(outputDirectory);
buildFile = buildFile.replace(
"%exported_files%", sdkExtrasRepository.getExportsFiles(outputDirectory));
buildFile =
buildFile.replace(
"%exported_files%", sdkExtrasRepository.getExportsFiles(outputDirectory));
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
Expand All @@ -354,8 +356,7 @@ private static PathFragment getAndroidHomeEnvironmentVar(

private static String getStringResource(String name) {
try {
return ResourceFileLoader.loadResource(
AndroidSdkRepositoryFunction.class, name);
return ResourceFileLoader.loadResource(AndroidSdkRepositoryFunction.class, name);
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down Expand Up @@ -401,8 +402,8 @@ private static Properties getBuildToolsSourceProperties(
Path directory, String buildToolsDirectory, Environment env)
throws RepositoryFunctionException, InterruptedException {

Path sourcePropertiesFilePath = directory.getRelative(
"build-tools/" + buildToolsDirectory + "/source.properties");
Path sourcePropertiesFilePath =
directory.getRelative("build-tools/" + buildToolsDirectory + "/source.properties");

SkyKey releaseFileKey =
FileValue.key(RootedPath.toRootedPath(Root.fromPath(directory), sourcePropertiesFilePath));
Expand All @@ -416,8 +417,9 @@ private static Properties getBuildToolsSourceProperties(
}
return properties;
} catch (IOException e) {
String error = String.format(
"Could not read %s in Android SDK: %s", sourcePropertiesFilePath, e.getMessage());
String error =
String.format(
"Could not read %s in Android SDK: %s", sourcePropertiesFilePath, e.getMessage());
throw new RepositoryFunctionException(new IOException(error), Transience.PERSISTENT);
}
}
Expand All @@ -443,6 +445,7 @@ private static void assertValidBuildToolsVersion(String buildToolsVersion) throw
*
* <p>If the sdk/system-images directory does not exist, an empty set is returned.
*/
@Nullable
private ImmutableSortedSet<PathFragment> getAndroidDeviceSystemImageDirs(
Path androidSdkPath, Environment env)
throws RepositoryFunctionException, InterruptedException {
Expand Down Expand Up @@ -484,6 +487,7 @@ private ImmutableSortedSet<PathFragment> getAndroidDeviceSystemImageDirs(
*
* <p>Ignores all non-directory files.
*/
@Nullable
private static ImmutableMap<PathFragment, DirectoryListingValue> getSubdirectoryListingValues(
final Path root, final PathFragment path, DirectoryListingValue directory, Environment env)
throws RepositoryFunctionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ java_library(
"//src/main/protobuf:crosstool_config_java_proto",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.lib.rules.java.JavaSemantics;
import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
import com.google.devtools.build.lib.util.ShellEscaper;
import javax.annotation.Nullable;

/** An implementation for the "android_local_test" rule. */
public class BazelAndroidLocalTest extends AndroidLocalTestBase {
Expand Down Expand Up @@ -87,6 +88,7 @@ protected TransitiveInfoCollection getAndCheckTestSupport(RuleContext ruleContex
}

@Override
@Nullable
// Bazel needs the android-all jars properties file in order for robolectric to
// run. If it does not find it in the deps of the android_local_test rule, it will
// throw an error.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/unix/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
],
)

Expand Down

0 comments on commit 818c5c8

Please sign in to comment.