Skip to content

Commit

Permalink
Remove uses of genrule.exec_tools from tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542989406
Change-Id: If64e8b4b20d244ab011f480251211d61711aa7f6
  • Loading branch information
katre authored and copybara-github committed Jun 23, 2023
1 parent 5a02197 commit 7f7017a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ public void testBuildSettingTransitionsWorkWithExecTransitions() throws Exceptio
" srcs = [],",
" outs = ['with_exec_tool.out'],",
" cmd = 'echo hi > $@',",
" exec_tools = [':int_reader'])",
" tools = [':int_reader'])",
"int_flag_reading_rule(",
" name = 'int_reader',",
" out = 'int_reader.out')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public void constraintEnforcementDisabledExecConfig() throws Exception {
" srcs = [],",
" outs = ['gen.out'],",
" cmd = '',",
" exec_tools = [':main'])",
" tools = [':main'])",
getDependencyRule(),
getDependingRule(compatibleWith("//buildenv/foo:a")));
assertThat(getConfiguredTarget("//hello:gen")).isNotNull();
Expand Down Expand Up @@ -740,15 +740,15 @@ public void execDependenciesAreNotChecked() throws Exception {
new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
scratch.file(
"hello/BUILD",
"sh_binary(name = 'host_tool',",
" srcs = ['host_tool.sh'],",
"sh_binary(name = 'tool',",
" srcs = ['tool.sh'],",
" restricted_to = ['//buildenv/foo:b'])",
"genrule(",
" name = 'hello',",
" srcs = [],",
" outs = ['hello.out'],",
" cmd = '',",
" exec_tools = [':host_tool'],",
" tools = [':tool'],",
" compatible_with = ['//buildenv/foo:a'])");
assertThat(getConfiguredTarget("//hello:hello")).isNotNull();
assertNoEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,22 +617,22 @@ public void testDuplicateLocalFlags() throws Exception {
}

@Test
public void testExecToolsAreExecConfiguration() throws Exception {
public void testToolsHaveExecOutputDir() throws Exception {
scratch.file(
"config/BUILD",
"genrule(name='src', outs=['src.out'], cmd=':')",
"genrule(name='exec_tool', outs=['exec_tool.out'], cmd=':')",
"genrule(name='tool', outs=['tool.out'], cmd=':')",
"genrule(name='config', ",
" srcs=[':src'], exec_tools=[':exec_tool'], outs=['out'],",
" cmd='$(location :exec_tool)')");
" srcs=[':src'], tools=[':tool'], outs=['out'],",
" cmd='$(location :tool)')");

ConfiguredTarget parentTarget = getConfiguredTarget("//config");

// Cannot use getDirectPrerequisites, as this re-configures that target incorrectly.
Artifact out = getFilesToBuild(parentTarget).toList().get(0);
assertThat(getGeneratingAction(out).getTools().toList()).hasSize(1);
Artifact execTool = getGeneratingAction(out).getTools().getSingleton();
Artifact tool = getGeneratingAction(out).getTools().getSingleton();
// This is the output dir fragment for the execution transition.
assertThat(execTool.getExecPathString()).contains("-exec-");
assertThat(tool.getExecPathString()).contains("-exec-");
}
}
33 changes: 18 additions & 15 deletions src/test/py/bazel/bazel_windows_symlinks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ class BazelWindowsSymlinksTest(test_base.TestBase):

def createProjectFiles(self):
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
self.ScratchFile('foo/BUILD', [
'genrule(',
' name = "x",',
' srcs = ["sample"],',
' outs = ["link"],',
' exec_tools = ["sym.bat"],',
' cmd = "$(location sym.bat) $< $@",',
')',
'genrule(',
' name = "y",',
' outs = ["dangling-link"],',
' exec_tools = ["sym.bat"],',
' cmd = "$(location sym.bat) does-not-exist $@",',
')',
])
self.ScratchFile(
'foo/BUILD',
[
'genrule(',
' name = "x",',
' srcs = ["sample"],',
' outs = ["link"],',
' tools = ["sym.bat"],',
' cmd = "$(location sym.bat) $< $@",',
')',
'genrule(',
' name = "y",',
' outs = ["dangling-link"],',
' tools = ["sym.bat"],',
' cmd = "$(location sym.bat) does-not-exist $@",',
')',
],
)
self.ScratchFile(
'foo/sym.bat', [
'@set IN=%1',
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_symlink_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ genrule(
srcs = [],
outs = ["out"],
cmd = "touch $@",
exec_tools = [":a"],
tools = [":a"],
)
EOF

Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/platform_mapping_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ genrule(
name = "genrule1",
outs = ["genrule1.out"],
cmd = "echo hello > \$@",
exec_tools = [
tools = [
":genrule2",
],
)
genrule(
name = "genrule2",
outs = ["genrule2.out"],
cmd = "echo hello > \$@",
exec_tools = [
tools = [
":report",
],
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/platforms_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ genrule(
name = "hello",
outs = ["hello.txt"],
cmd = "echo 'Hello' > $@",
exec_tools = ["tool"],
tools = ["tool"],
)
genrule(
Expand Down
93 changes: 43 additions & 50 deletions src/test/shell/integration/action_env_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ genrule(
)
genrule(
name = "show_host_env_using_exec_tools",
exec_tools = ["env.txt"],
outs = ["exec_tools_env.txt"],
cmd = "cp \$(location env.txt) \"\$@\""
)
genrule(
name = "show_host_env_using_successive_exec_tools",
exec_tools = ["exec_tools_env.txt"],
outs = ["successive_exec_tools_env.txt"],
cmd = "cp \$(location exec_tools_env.txt) \"\$@\""
name = "show_host_env_using_successive_tools",
tools = ["tools_env.txt"],
outs = ["successive_tools_env.txt"],
cmd = "cp \$(location tools_env.txt) \"\$@\""
)
EOF
cat > pkg/build.bzl <<EOF
Expand Down Expand Up @@ -337,108 +330,108 @@ function test_latest_wins_env_using_tools() {
expect_not_log "FOO=foo"
}

function test_host_env_using_exec_tools_simple() {
function test_host_env_using_tools_simple() {
export FOO=baz

# If FOO is passed using --host_action_env, it should be listed in host env vars
bazel build --host_action_env=FOO=bar pkg:show_host_env_using_exec_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
bazel build --host_action_env=FOO=bar pkg:show_host_env_using_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=bar"

# But if FOO is passed using --action_env, it should not be listed in host env vars
bazel build --action_env=FOO=bar pkg:show_host_env_using_exec_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
bazel build --action_env=FOO=bar pkg:show_host_env_using_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_not_log "FOO=bar"
}

function test_host_env_using_exec_tools_latest_wins() {
function test_host_env_using_tools_latest_wins() {
export FOO=environmentfoo
export BAR=environmentbar
bazel build --host_action_env=FOO=foo \
--host_action_env=BAR=willbeoverridden --host_action_env=BAR=bar pkg:show_host_env_using_exec_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
--host_action_env=BAR=willbeoverridden --host_action_env=BAR=bar pkg:show_host_env_using_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=foo"
expect_log "BAR=bar"
}

function test_client_env_using_exec_tools() {
function test_client_env_using_tools() {
export FOO=startup_foo
bazel clean --expunge
bazel help build > /dev/null || fail "${PRODUCT_NAME} help failed"
export FOO=client_foo
bazel build --host_action_env=FOO pkg:show_host_env_using_exec_tools || \
fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
bazel build --host_action_env=FOO pkg:show_host_env_using_tools || \
fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=client_foo"
}

function test_redo_host_env_using_exec_tools() {
function test_redo_host_env_using_tools() {
export FOO=initial_foo
export UNRELATED=some_value
bazel build --host_action_env=FOO pkg:show_host_env_using_exec_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
bazel build --host_action_env=FOO pkg:show_host_env_using_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=initial_foo"

# If an unrelated value changes, we expect the action not to be executed again
export UNRELATED=some_other_value
bazel build --host_action_env=FOO -s pkg:show_host_env_using_exec_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
expect_not_log '^SUBCOMMAND.*pkg:show_host_env_using_exec_tools'
bazel build --host_action_env=FOO -s pkg:show_host_env_using_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"
expect_not_log '^SUBCOMMAND.*pkg:show_host_env_using_tools'

# However, if a used variable changes, we expect the change to be propagated
export FOO=changed_foo
bazel build --host_action_env=FOO -s pkg:show_host_env_using_exec_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
expect_log '^SUBCOMMAND.*pkg:show_host_env_using_exec_tools'
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
bazel build --host_action_env=FOO -s pkg:show_host_env_using_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"
expect_log '^SUBCOMMAND.*pkg:show_host_env_using_tools'
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=changed_foo"

# But repeating the build with no further changes, no action should happen
bazel build --host_action_env=FOO -s pkg:show_host_env_using_exec_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
expect_not_log '^SUBCOMMAND.*pkg:show_host_env_using_exec_tools'
bazel build --host_action_env=FOO -s pkg:show_host_env_using_tools 2> $TEST_log \
|| fail "${PRODUCT_NAME} build show_host_env_using_tools failed"
expect_not_log '^SUBCOMMAND.*pkg:show_host_env_using_tools'
}

function test_latest_wins_arg_using_exec_tools() {
function test_latest_wins_arg_using_tools() {
export FOO=bar
export BAR=baz
bazel build --host_action_env=BAR --host_action_env=FOO --host_action_env=FOO=foo \
pkg:show_host_env_using_exec_tools || fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
pkg:show_host_env_using_tools || fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=foo"
expect_log "BAR=baz"
expect_not_log "FOO=bar"
}

function test_latest_wins_env_using_exec_tools() {
function test_latest_wins_env_using_tools() {
export FOO=bar
export BAR=baz
bazel build --host_action_env=BAR --host_action_env=FOO=foo --host_action_env=FOO \
pkg:show_host_env_using_exec_tools || fail "${PRODUCT_NAME} build show_host_env_using_exec_tools failed"
pkg:show_host_env_using_tools || fail "${PRODUCT_NAME} build show_host_env_using_tools failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/tools_env.txt > $TEST_log
expect_log "FOO=bar"
expect_log "BAR=baz"
expect_not_log "FOO=foo"
}

function test_host_env_using_successive_exec_tools_simple() {
function test_host_env_using_successive_tools_simple() {
export FOO=baz

bazel build --host_action_env=FOO=bar pkg:show_host_env_using_successive_exec_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_successive_exec_tool failed"
bazel build --host_action_env=FOO=bar pkg:show_host_env_using_successive_tools \
|| fail "${PRODUCT_NAME} build show_host_env_using_successive_tool failed"

cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/successive_exec_tools_env.txt > $TEST_log
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/successive_tools_env.txt > $TEST_log
expect_log "FOO=bar"
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/integration/validation_actions_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ rule_with_implicit_and_host_deps(name = "target_with_implicit_and_host_deps")
rule_with_implicit_outs_and_validation(name = "some_tool_dep")
genrule(
name = "genrule_with_exec_tool_deps",
exec_tools = [":some_tool_dep"],
outs = ["genrule_with_exec_tool_deps_out"],
name = "genrule_with_tool_deps",
tools = [":some_tool_dep"],
outs = ["genrule_with_tool_deps_out"],
cmd = "touch $@",
)
Expand Down Expand Up @@ -380,7 +380,7 @@ function test_failing_validation_action_for_tool_dep_does_not_fail_build() {
# Validation actions in the exec configuration or from implicit deps should
# not fail the overall build, since those dependencies should have their own
# builds and tests that should surface any failing validations.
bazel build --experimental_run_validations //validation_actions:genrule_with_exec_tool_deps >& "$TEST_log" || fail "Expected build to succeed"
bazel build --experimental_run_validations //validation_actions:genrule_with_tool_deps >& "$TEST_log" || fail "Expected build to succeed"
expect_not_log "validation failed!"
}

Expand Down

0 comments on commit 7f7017a

Please sign in to comment.