|
336 | 336 |
|
337 | 337 | # Test the genrule that specifically depends on :bar_runtime.
|
338 | 338 | bazel cquery --max_config_changes_to_show=0 --implicit_deps 'deps(//:with_java)' >& $TEST_log
|
339 |
| - expect_not_log "foo" |
340 |
| - expect_log "bar" |
| 339 | + expect_log "dummy_java" |
| 340 | + expect_log "dummy_javac" |
341 | 341 | expect_not_log "embedded_jdk"
|
342 | 342 | expect_not_log "remotejdk_"
|
343 | 343 | expect_not_log "remotejdk11_"
|
|
353 | 353 | expect_not_log "remotejdk11_"
|
354 | 354 | }
|
355 | 355 |
|
| 356 | + |
| 357 | +function test_fully_generated_jdk() { |
| 358 | + cat << EOF >> WORKSPACE |
| 359 | +load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") |
| 360 | +local_java_repository( |
| 361 | + name = "foo_javabase", |
| 362 | + java_home = "$PWD/foo", |
| 363 | + version = "11", |
| 364 | +) |
| 365 | +EOF |
| 366 | + |
| 367 | + mkdir -p foo/bin bar/bin |
| 368 | + |
| 369 | + cat << EOF > defs.bzl |
| 370 | +
|
| 371 | +def _make_jdk_impl(ctx): |
| 372 | + dummy_java = ctx.actions.declare_file(ctx.attr.name + "_dummy_java") |
| 373 | + ctx.actions.write(dummy_java, "dummy_java", is_executable = True) |
| 374 | + dummy_javac = ctx.actions.declare_file(ctx.attr.name + "_dummy_javac") |
| 375 | + ctx.actions.write(dummy_javac, "dummy_javac", is_executable = True) |
| 376 | +
|
| 377 | + return [DefaultInfo( |
| 378 | + executable = dummy_java, |
| 379 | + files = depset([dummy_java, dummy_javac]) |
| 380 | + )] |
| 381 | +
|
| 382 | +make_jdk = rule(implementation = _make_jdk_impl, executable = True) |
| 383 | +
|
| 384 | +EOF |
| 385 | + |
| 386 | + cat << EOF > BUILD |
| 387 | +load(":defs.bzl", "make_jdk") |
| 388 | +
|
| 389 | +make_jdk(name = "generated_jdk") |
| 390 | +
|
| 391 | +java_runtime( |
| 392 | + name = "bar_runtime", |
| 393 | + visibility = ["//visibility:public"], |
| 394 | + executable = "generated_jdk", |
| 395 | +) |
| 396 | +
|
| 397 | +genrule( |
| 398 | + name = "without_java", |
| 399 | + srcs = ["in"], |
| 400 | + outs = ["out_without"], |
| 401 | + cmd = "cat \$(SRCS) > \$(OUTS)", |
| 402 | +) |
| 403 | +
|
| 404 | +genrule( |
| 405 | + name = "with_java", |
| 406 | + srcs = ["in"], |
| 407 | + outs = ["out_with"], |
| 408 | + cmd = "echo \$(JAVA) > \$(OUTS)", |
| 409 | + toolchains = [":bar_runtime"], |
| 410 | +) |
| 411 | +EOF |
| 412 | + |
| 413 | + # Use --max_config_changes_to_show=0, as changed option names may otherwise |
| 414 | + # erroneously match the expected regexes. |
| 415 | + |
| 416 | + # Test the genrule with no java dependencies. |
| 417 | + bazel cquery --max_config_changes_to_show=0 --implicit_deps 'deps(//:without_java)' >& $TEST_log |
| 418 | + expect_not_log "dummy_java" |
| 419 | + expect_not_log "dummy_javac" |
| 420 | + expect_not_log "embedded_jdk" |
| 421 | + expect_not_log "remotejdk_" |
| 422 | + expect_not_log "remotejdk11_" |
| 423 | + |
| 424 | + # Test the genrule that specifically depends on :bar_runtime. |
| 425 | + bazel cquery --max_config_changes_to_show=0 --implicit_deps 'deps(//:with_java)' >& $TEST_log |
| 426 | + expect_log "dummy_java" |
| 427 | + expect_log "dummy_javac" |
| 428 | + expect_not_log "embedded_jdk" |
| 429 | + expect_not_log "remotejdk_" |
| 430 | + expect_not_log "remotejdk11_" |
| 431 | + |
| 432 | + # Setting the javabase should not change the use of :bar_runtime from the |
| 433 | + # roolchains attribute. |
| 434 | + bazel cquery --max_config_changes_to_show=0 --implicit_deps 'deps(//:with_java)' \ |
| 435 | + --tool_java_runtime_version=foo_javabase >& $TEST_log |
| 436 | + expect_log "dummy_java" |
| 437 | + expect_log "dummy_javac" |
| 438 | + expect_not_log "embedded_jdk" |
| 439 | + expect_not_log "remotejdk_" |
| 440 | + expect_not_log "remotejdk11_" |
| 441 | +} |
| 442 | + |
356 | 443 | run_suite "Tests of specifying custom server_javabase/host_javabase and javabase."
|
0 commit comments