Skip to content

Commit

Permalink
The great Skylark -> Starlark class migration:
Browse files Browse the repository at this point in the history
For rules in tests:
 - More renamings of test target names
 - Various symbol renamings

PiperOrigin-RevId: 315913067
  • Loading branch information
gregestren authored and copybara-github committed Jun 11, 2020
1 parent 96622c4 commit 0503fee
Show file tree
Hide file tree
Showing 38 changed files with 403 additions and 401 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,24 @@ private static StarlarkBuiltinDoc findGlobalModule(
}

private static void writePage(String outputDir, StarlarkBuiltinDoc module) throws IOException {
File skylarkDocPath = new File(outputDir + "/" + module.getName() + ".html");
File starlarkDocPath = new File(outputDir + "/" + module.getName() + ".html");
Page page = TemplateEngine.newPage(DocgenConsts.STARLARK_LIBRARY_TEMPLATE);
page.add("module", module);
page.write(skylarkDocPath);
page.write(starlarkDocPath);
}

private static void writeCategoryPage(
StarlarkDocumentationCategory category,
String outputDir,
Map<StarlarkDocumentationCategory, List<StarlarkBuiltinDoc>> modules)
throws IOException {
File skylarkDocPath = new File(String.format("%s/skylark-%s.html",
outputDir, category.getTemplateIdentifier()));
File starlarkDocPath =
new File(String.format("%s/skylark-%s.html", outputDir, category.getTemplateIdentifier()));
Page page = TemplateEngine.newPage(DocgenConsts.STARLARK_MODULE_CATEGORY_TEMPLATE);
page.add("category", category);
page.add("modules", modules.get(category));
page.add("description", StarlarkDocUtils.substituteVariables(category.getDescription()));
page.write(skylarkDocPath);
page.write(starlarkDocPath);
}

private static void writeNavPage(String outputDir, List<StarlarkBuiltinDoc> navModules)
Expand All @@ -174,14 +174,14 @@ private static void writeOverviewPage(
List<StarlarkBuiltinDoc> globalModules,
Map<StarlarkDocumentationCategory, List<StarlarkBuiltinDoc>> modulesPerCategory)
throws IOException {
File skylarkDocPath = new File(outputDir + "/skylark-overview.html");
File starlarkDocPath = new File(outputDir + "/skylark-overview.html");
Page page = TemplateEngine.newPage(DocgenConsts.STARLARK_OVERVIEW_TEMPLATE);
page.add("global_name", globalModuleName);
page.add("global_functions", globalFunctions);
page.add("global_constants", globalConstants);
page.add("global_modules", globalModules);
page.add("modules", modulesPerCategory);
page.write(skylarkDocPath);
page.write(starlarkDocPath);
}

private static void parseOptions(String... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,17 +1082,17 @@ public <C extends TransitiveInfoProvider> List<C> getPrerequisites(
* the specified attribute of this target in the BUILD file.
*/
public <T extends Info> List<T> getPrerequisites(
String attributeName, TransitionMode mode, final NativeProvider<T> skylarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), skylarkKey);
String attributeName, TransitionMode mode, final NativeProvider<T> starlarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), starlarkKey);
}

/**
* Returns all the declared providers (native and Starlark) for the specified constructor under
* the specified attribute of this target in the BUILD file.
*/
public <T extends Info> List<T> getPrerequisites(
String attributeName, TransitionMode mode, final BuiltinProvider<T> skylarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), skylarkKey);
String attributeName, TransitionMode mode, final BuiltinProvider<T> starlarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), starlarkKey);
}

/**
Expand All @@ -1102,9 +1102,9 @@ public <T extends Info> List<T> getPrerequisites(
*/
@Nullable
public <T extends Info> T getPrerequisite(
String attributeName, TransitionMode mode, final NativeProvider<T> skylarkKey) {
String attributeName, TransitionMode mode, final NativeProvider<T> starlarkKey) {
TransitiveInfoCollection prerequisite = getPrerequisite(attributeName, mode);
return prerequisite == null ? null : prerequisite.get(skylarkKey);
return prerequisite == null ? null : prerequisite.get(starlarkKey);
}

/**
Expand All @@ -1114,9 +1114,9 @@ public <T extends Info> T getPrerequisite(
*/
@Nullable
public <T extends Info> T getPrerequisite(
String attributeName, TransitionMode mode, final BuiltinProvider<T> skylarkKey) {
String attributeName, TransitionMode mode, final BuiltinProvider<T> starlarkKey) {
TransitiveInfoCollection prerequisite = getPrerequisite(attributeName, mode);
return prerequisite == null ? null : prerequisite.get(skylarkKey);
return prerequisite == null ? null : prerequisite.get(starlarkKey);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Metadata getMetadata() {
"cc_binary", // NB: linkshared=1
"cc_library",
"genrule",
"genproto", // TODO(bazel-team): we should filter using providers instead (skylark rule).
"genproto", // TODO(bazel-team): we should filter using providers instead (starlark rule).
"java_import",
"java_library",
"java_proto_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ public Build.Target toTargetProtoBuffer(Target target, Object extraDataForAttrHa
}

if (inputFile.getName().equals("BUILD")) {
Iterable<Label> skylarkLoadLabels =
Iterable<Label> starlarkLoadLabels =
aspectResolver == null
? inputFile.getPackage().getStarlarkFileDependencies()
: aspectResolver.computeBuildFileDependencies(inputFile.getPackage());

for (Label skylarkLoadLabel : skylarkLoadLabels) {
input.addSubinclude(skylarkLoadLabel.toString());
for (Label starlarkLoadLabel : starlarkLoadLabels) {
input.addSubinclude(starlarkLoadLabel.toString());
}

for (String feature : inputFile.getPackage().getFeatures()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public int compareTo(DottedVersion other) {
}

@Override
public int compareTo_skylark(DottedVersion other) {
public int compareTo_starlark(DottedVersion other) {
return compareTo(other);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ void addProviders(ConfiguredAspect.Builder aspect) throws InterruptedException {
aspect.addNativeDeclaredProvider(
createCcLinkingInfo(ruleContext, aspectCommon.getProtoRuntimeDeps()));

JavaStarlarkApiProvider skylarkApiProvider = JavaStarlarkApiProvider.fromRuleContext();
JavaStarlarkApiProvider starlarkApiProvider = JavaStarlarkApiProvider.fromRuleContext();
aspect
.addStarlarkTransitiveInfo(JavaStarlarkApiProvider.NAME, skylarkApiProvider)
.addStarlarkTransitiveInfo(JavaStarlarkApiProvider.NAME, starlarkApiProvider)
.addNativeDeclaredProvider(javaInfo.build())
.addProvider(
new JavaProtoLibraryAspectProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static class DumpOptions extends OptionsBase {
help =
"Dumps a pprof-compatible memory profile to the specified path. To learn more please"
+ " see https://github.com/google/pprof.")
public String skylarkMemory;
public String starlarkMemory;

@Option(
name = "skyframe",
Expand Down Expand Up @@ -206,7 +206,7 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
|| dumpOptions.dumpActionGraph != null
|| dumpOptions.dumpRuleClasses
|| dumpOptions.dumpRules
|| dumpOptions.skylarkMemory != null
|| dumpOptions.starlarkMemory != null
|| (dumpOptions.dumpSkyframe != SkyframeDumpOption.OFF);
if (!anyOutput) {
Collection<Class<? extends OptionsBase>> optionList = new ArrayList<>();
Expand Down Expand Up @@ -275,9 +275,9 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
out.println();
}

if (dumpOptions.skylarkMemory != null) {
if (dumpOptions.starlarkMemory != null) {
try {
dumpStarlarkHeap(env.getBlazeWorkspace(), dumpOptions.skylarkMemory, out);
dumpStarlarkHeap(env.getBlazeWorkspace(), dumpOptions.starlarkMemory, out);
} catch (IOException e) {
String message = "Could not dump Starlark memory";
env.getReporter().error(null, message, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private BzlLoadValue computeInternalWithAST(
}
StarlarkFile file = astLookupValue.getAST();
if (!file.ok()) {
throw BzlLoadFailedException.skylarkErrors(filePath);
throw BzlLoadFailedException.starlarkErrors(filePath);
}

// Process the load statements in the file,
Expand All @@ -576,7 +576,7 @@ private BzlLoadValue computeInternalWithAST(
getLoadLabels(env.getListener(), file, label.getPackageIdentifier(), repoMapping);
if (loads == null) {
// malformed load statements
throw BzlLoadFailedException.skylarkErrors(filePath);
throw BzlLoadFailedException.starlarkErrors(filePath);
}

// Compute Skyframe key for each label in 'loads'.
Expand Down Expand Up @@ -959,7 +959,7 @@ static BzlLoadFailedException labelCrossesPackageBoundary(
containingPackageLookupValue));
}

static BzlLoadFailedException skylarkErrors(PathFragment file) {
static BzlLoadFailedException starlarkErrors(PathFragment file) {
return new BzlLoadFailedException(String.format("Extension '%s' has errors", file));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,11 @@ private static List<BzlLoadValue> computeBzlLoadsNoInlining(
throws InterruptedException, BzlLoadFailedException, InconsistentFilesystemException {
List<BzlLoadValue> bzlLoads = Lists.newArrayListWithExpectedSize(keys.size());
Map<SkyKey, ValueOrException2<BzlLoadFailedException, InconsistentFilesystemException>>
skylarkLookupResults =
starlarkLookupResults =
env.getValuesOrThrow(
keys, BzlLoadFailedException.class, InconsistentFilesystemException.class);
for (BzlLoadValue.Key key : keys) {
bzlLoads.add((BzlLoadValue) skylarkLookupResults.get(key).get());
bzlLoads.add((BzlLoadValue) starlarkLookupResults.get(key).get());
}
return env.valuesMissing() ? null : bzlLoads;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ public interface DottedVersionApi<SelfT extends DottedVersionApi<?>>
type = DottedVersionApi.class,
doc = "The other dotted version.")
})
int compareTo_skylark(SelfT other);
int compareTo_starlark(SelfT other);
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ private static ImmutableList<Value> getChildren(
}

private static ImmutableList<Value> getChildren(
ThreadObjectMap objectMap, StarlarkValue skylarkValue) {
ThreadObjectMap objectMap, StarlarkValue starlarkValue) {
StarlarkSemantics semantics = StarlarkSemantics.DEFAULT; // TODO(adonovan): obtain from thread.
Set<String> fieldNames;
try {
fieldNames = CallUtils.getFieldNames(semantics, skylarkValue);
fieldNames = CallUtils.getFieldNames(semantics, starlarkValue);
} catch (IllegalArgumentException e) {
// silently return no children
return ImmutableList.of();
Expand All @@ -142,7 +142,7 @@ private static ImmutableList<Value> getChildren(
try {
children.add(
getValueProto(
objectMap, fieldName, CallUtils.getField(semantics, skylarkValue, fieldName)));
objectMap, fieldName, CallUtils.getField(semantics, starlarkValue, fieldName)));
} catch (EvalException | InterruptedException | IllegalArgumentException e) {
// silently ignore errors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class FakeDottedVersion implements DottedVersionApi<FakeDottedVersion> {

@Override
public int compareTo_skylark(FakeDottedVersion other) {
public int compareTo_starlark(FakeDottedVersion other) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public StarlarkList<Integer> getMutableList() {
return null;
}

@StarlarkMethod(name = "skylark", doc = "skylark")
@StarlarkMethod(name = "starlark", doc = "starlark")
public Sequence<Integer> getStarlarkList() {
return null;
}
Expand Down Expand Up @@ -453,7 +453,7 @@ public void testStarlarkContainerReturnTypesWithoutAnnotations() throws Exceptio
assertThat(signatures)
.contains(
"<a class=\"anchor\" href=\"list.html\">sequence</a> "
+ "MockClassWithContainerReturnValues.skylark()");
+ "MockClassWithContainerReturnValues.starlark()");
}

@Test
Expand Down
Loading

0 comments on commit 0503fee

Please sign in to comment.