Skip to content

Commit

Permalink
The great Skylark -> Starlark class migration:
Browse files Browse the repository at this point in the history
Replace all known remaining references*

*Except java_rules_skylark.bzl. This is depended on in third_party/jformatstring (https://github.com/bazelbuild/bazel/blob/a8353612b4791531ae4e2ed463cf0e5d8a4009e8/third_party/jformatstring/BUILD#L17), so breaking the dependency is a bit more complex.

I'm excluding as part of this migration project:

 - "skylark" in URLs. We can't just break URLs. And our docs generation pipeline may bake in assumptions. This would have to be its own docs effort.
 - "skylark-lang", etc. build targets that alandonovan@ is migrating to java.net.starlark.
 - --skylark_* builds flags. Changing these without warning is higher risk since we don't know who uses these flags for what. These should go through their own dedicated migration processes.

PiperOrigin-RevId: 326283275
  • Loading branch information
gregestren authored and copybara-github committed Aug 12, 2020
1 parent 4f2991c commit 72e559d
Show file tree
Hide file tree
Showing 40 changed files with 190 additions and 190 deletions.
2 changes: 1 addition & 1 deletion examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ filegroup(
"//examples/cpp:srcs",
"//examples/gen:srcs",
"//examples/java-native:srcs",
"//examples/java-skylark:srcs",
"//examples/java-starlark:srcs",
"//examples/py:srcs",
"//examples/py_native:srcs",
"//examples/shell:srcs",
Expand Down
10 changes: 0 additions & 10 deletions examples/java-skylark/BUILD

This file was deleted.

10 changes: 10 additions & 0 deletions examples/java-starlark/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//examples/java-starlark/src/main/java/com/example/myproject:srcs",
"//examples/java-starlark/src/main/resources:srcs",
"//examples/java-starlark/src/test/java/com/example/myproject:srcs",
],
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ java_binary(
java_library(
name = "hello-lib",
srcs = ["Greeter.java"],
data = ["//examples/java-skylark/src/main/resources:greeting"],
data = ["//examples/java-starlark/src/main/resources:greeting"],
)

filegroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void hello(String obj) throws Exception {
String greeting = "Hello";
try {
String greetFile = getRunfiles()
+ "/io_bazel/examples/java-skylark/src/main/resources/greeting.txt";
+ "/io_bazel/examples/java-starlark/src/main/resources/greeting.txt";
greeting = convertStreamToString(new FileInputStream(greetFile));
} catch (FileNotFoundException e) {
// use default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java_test(
srcs = ["TestHello.java"],
deps = [
":junit4",
"//examples/java-skylark/src/main/java/com/example/myproject:hello-lib",
"//examples/java-starlark/src/main/java/com/example/myproject:hello-lib",
],
)

Expand All @@ -23,5 +23,5 @@ java_test(
filegroup(
name = "srcs",
srcs = glob(["**/*.java"]) + ["BUILD"],
visibility = ["//examples/java-skylark:__pkg__"],
visibility = ["//examples/java-starlark:__pkg__"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ java_library(
#

bootstrap_java_library(
name = "skylark-deps",
name = "starlark-deps",
srcs = ["//:bootstrap-derived-java-srcs"],
jars = [
"//third_party:auto_value-jars",
Expand Down Expand Up @@ -199,7 +199,7 @@ bootstrap_java_binary(
main_class = "com.google.devtools.build.buildjar.VanillaJavaBuilder",
tags = ["manual"],
deps = [
":skylark-deps",
":starlark-deps",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:bootstrap_jarhelper",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bootstrap_java_binary(
main_class = "com.google.devtools.build.buildjar.genclass.GenClass",
tags = ["manual"],
deps = [
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:skylark-deps",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:starlark-deps",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:bootstrap_jarhelper",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ bootstrap_java_library(
],
tags = ["manual"],
deps = [
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:skylark-deps",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:starlark-deps",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ bootstrap_java_library(
deps = [
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:bootstrap_JarOwner",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:bootstrap_invalid_command_line_exception",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:skylark-deps",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:starlark-deps",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ java_binary(
#

bootstrap_java_library(
name = "skylark-deps",
name = "starlark-deps",
jars = [
"//third_party:jsr305-jars",
],
Expand All @@ -96,7 +96,7 @@ bootstrap_java_binary(
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
":skylark-deps",
"//src/main/java/com/google/devtools/build/lib/shell:shell-skylark",
":starlark-deps",
"//src/main/java/com/google/devtools/build/lib/shell:shell-starlark",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ build information (that is, information that cannot always be derived strictly
from BUILD files). The contents of these configurations can be inspected by
looking at `rules/objc/ObjcConfiguration.java` and
`rules/apple/AppleConfiguration.java`. To access a configuration fragment from
skylark, the fragment must be declared in the rule definition:
Starlark, the fragment must be declared in the rule definition:

```
def __impl(ctx):
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/devtools/build/lib/shell/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ java_library(
load("//tools/build_rules:java_rules_skylark.bzl", "bootstrap_java_library")

bootstrap_java_library(
name = "shell-skylark",
name = "shell-starlark",
srcs = glob(
["*.java"],
exclude = ["ExecutionStatistics.java"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Test for exec groups. Functionality related to rule context tested in {@link
* com.google.devtools.build.lib.skylark.StarlarkRuleContextTest}.
* com.google.devtools.build.lib.starlark.StarlarkRuleContextTest}.
*/
@RunWith(JUnit4.class)
public class StarlarkExecGroupTest extends BuildViewTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ public void testStarlarkCanCreateObjcProviderWithStrictDepsPreMigration() throws
.containsExactly(PathFragment.create("path1"));

scratch.file(
"examples/objc_skylark2/BUILD",
"examples/objc_starlark2/BUILD",
"objc_library(",
" name = 'direct_dep',",
" deps = ['//examples/objc_starlark:my_target']",
Expand All @@ -1325,13 +1325,13 @@ public void testStarlarkCanCreateObjcProviderWithStrictDepsPreMigration() throws
")");

ObjcProvider starlarkProviderDirectDepender =
getConfiguredTarget("//examples/objc_skylark2:direct_dep")
getConfiguredTarget("//examples/objc_starlark2:direct_dep")
.get(ObjcProvider.STARLARK_CONSTRUCTOR);
assertThat(starlarkProviderDirectDepender.include())
.containsExactly(PathFragment.create("path2"));

ObjcProvider starlarkProviderIndirectDepender =
getConfiguredTarget("//examples/objc_skylark2:indirect_dep")
getConfiguredTarget("//examples/objc_starlark2:indirect_dep")
.get(ObjcProvider.STARLARK_CONSTRUCTOR);
assertThat(starlarkProviderIndirectDepender.include())
.containsExactly(PathFragment.create("path2"));
Expand All @@ -1358,14 +1358,14 @@ public void testStarlarkCanCreateObjcProviderWithStrictDepsPostMigration() throw
.containsExactly(PathFragment.create("path1"));

scratch.file(
"examples/objc_skylark2/BUILD",
"examples/objc_starlark2/BUILD",
"objc_library(",
" name = 'direct_dep',",
" deps = ['//examples/objc_starlark:my_target']",
")");

ObjcProvider starlarkProviderDirectDepender =
getConfiguredTarget("//examples/objc_skylark2:direct_dep")
getConfiguredTarget("//examples/objc_starlark2:direct_dep")
.get(ObjcProvider.STARLARK_CONSTRUCTOR);
assertThat(starlarkProviderDirectDepender.include()).isEmpty();
}
Expand All @@ -1384,14 +1384,14 @@ public void testStarlarkCanCreateObjcProviderWithStrictDepsDirectly() throws Exc
.containsExactly(PathFragment.create("path"));

scratch.file(
"examples/objc_skylark2/BUILD",
"examples/objc_starlark2/BUILD",
"objc_library(",
" name = 'direct_dep',",
" deps = ['//examples/objc_starlark:my_target']",
")");

ObjcProvider starlarkProviderDirectDepender =
getConfiguredTarget("//examples/objc_skylark2:direct_dep")
getConfiguredTarget("//examples/objc_starlark2:direct_dep")
.get(ObjcProvider.STARLARK_CONSTRUCTOR);
assertThat(starlarkProviderDirectDepender.getStrictDependencyIncludes()).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void foo() {}
}

/**
* A mock class that implements two unrelated module interfaces. This is invalid as the skylark
* A mock class that implements two unrelated module interfaces. This is invalid as the Starlark
* type of such an object is ambiguous.
*/
public static class ImplementsTwoUnrelatedInterfaceModules
Expand Down
10 changes: 5 additions & 5 deletions src/test/py/bazel/action_temp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _AssertTempDir(self,
self.assertEqual(len(outputs), 2)
self._AssertOutputFileContents(outputs['genrule'], input_file_contents,
expected_tmpdir_regex)
self._AssertOutputFileContents(outputs['skylark'], input_file_contents,
self._AssertOutputFileContents(outputs['starlark'], input_file_contents,
expected_tmpdir_regex)

def _UpdateInputFile(self, content):
Expand Down Expand Up @@ -189,7 +189,7 @@ def _CreateWorkspace(self, build_flags=None):
')',
'',
'foorule(',
' name = "skylark",',
' name = "starlark",',
' src = "input.txt",',
' tool = "%s",' % toolname,
')',
Expand Down Expand Up @@ -224,16 +224,16 @@ def _ReadFile(path):
'--verbose_failures',
'--spawn_strategy=%s' % strategy,
'//foo:genrule',
'//foo:skylark',
'//foo:starlark',
], env_remove, env_add)
self.AssertExitCode(exit_code, 0, stderr)
self.assertTrue(
os.path.exists(os.path.join(bazel_genfiles, 'foo/genrule.txt')))
self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'foo/skylark.txt')))
self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'foo/starlark.txt')))

return {
'genrule': _ReadFile(os.path.join(bazel_genfiles, 'foo/genrule.txt')),
'skylark': _ReadFile(os.path.join(bazel_bin, 'foo/skylark.txt'))
'starlark': _ReadFile(os.path.join(bazel_bin, 'foo/starlark.txt'))
}

def _AssertOutputFileContents(self, lines, input_file_line,
Expand Down
10 changes: 5 additions & 5 deletions src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ function test_python() {
expect_log "Hello"
}

function test_java_skylark() {
local java_pkg=examples/java-skylark/src/main/java/com/example/myproject
function test_java_starlark() {
local java_pkg=examples/java-starlark/src/main/java/com/example/myproject
assert_build_output ./bazel-bin/${java_pkg}/libhello-lib.jar ${java_pkg}:hello-lib
assert_build_output ./bazel-bin/${java_pkg}/hello-data ${java_pkg}:hello-data
assert_build_output ./bazel-bin/${java_pkg}/hello-world ${java_pkg}:hello-world
Expand All @@ -177,9 +177,9 @@ function test_java_skylark() {
assert_binary_run_from_subdir "bazel-bin/${java_pkg}/hello-data foo" "Heyo foo"
}

function test_java_test_skylark() {
setup_skylark_javatest_support
javatests=examples/java-skylark/src/test/java/com/example/myproject
function test_java_test_starlark() {
setup_starlark_javatest_support
javatests=examples/java-starlark/src/test/java/com/example/myproject
assert_build //${javatests}:pass
assert_test_ok //${javatests}:pass
assert_test_fails //${javatests}:fail
Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/bazel/bazel_execlog_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \

function test_dir_depends() {
create_new_workspace
cat > skylark.bzl <<'EOF'
cat > starlark.bzl <<'EOF'
def _dir_impl(ctx):
output_dir = ctx.actions.declare_directory(ctx.attr.outdir)
ctx.actions.run_shell(
Expand All @@ -45,7 +45,7 @@ gen_dir = rule(
)
EOF
cat > BUILD <<'EOF'
load(":skylark.bzl", "gen_dir")
load(":starlark.bzl", "gen_dir")
gen_dir(
name = "dir",
Expand Down Expand Up @@ -145,7 +145,7 @@ EOF

function test_no_output() {
create_new_workspace
cat > skylark.bzl <<'EOF'
cat > starlark.bzl <<'EOF'
def _impl(ctx):
ctx.actions.write(ctx.outputs.executable, content="echo hello world", is_executable=True)
return DefaultInfo()
Expand All @@ -157,7 +157,7 @@ my_test = rule(
EOF

cat > BUILD <<'EOF'
load(":skylark.bzl", "my_test")
load(":starlark.bzl", "my_test")
my_test(
name = "little_test",
Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,9 @@ function test_java_info_constructor_e2e() {
cat > java/com/google/foo/BUILD << EOF
load(":my_rule.bzl", "my_rule")
my_rule(
name = 'my_skylark_rule',
output_jar = 'my_skylark_rule_lib.jar',
source_jars = ['my_skylark_rule_src.jar'],
name = 'my_starlark_rule',
output_jar = 'my_starlark_rule_lib.jar',
source_jars = ['my_starlark_rule_src.jar'],
)
EOF

Expand Down Expand Up @@ -1485,7 +1485,7 @@ my_rule = rule(
)
EOF

bazel build java/com/google/foo:my_skylark_rule >& "$TEST_log" || fail "Expected success"
bazel build java/com/google/foo:my_starlark_rule >& "$TEST_log" || fail "Expected success"
}

# This test builds a simple java deploy jar using remote singlejar and ijar
Expand Down
Loading

0 comments on commit 72e559d

Please sign in to comment.