bazelbuild / bazel-watcher

Tools for building Bazel targets when source files change.
Apache License 2.0
441 stars 118 forks source link

How do you enable JS serving? #358

Closed sgammon closed 4 years ago

sgammon commented 4 years ago

I've noticed libraries like rules_closure are able to trigger the live-reload server to activate, such that it serves the JS code to enable live-reloading at a local port (http://localhost:35729/livereload.js, for example), and so on. But how does one opt-in to this behavior?

I've affixed ibazel_live_reload and iblaze_notify_changes to my binary target, but to no avail. The endpoint still refuses connection for me. Am I missing a step?

sgammon commented 4 years ago

@achew22 / @dougkoch would you possibly know how to address this? thank you in advance for any help you are able to offer

achew22 commented 4 years ago

Did you add those as a tag on the target? Can you create an example repo that demonstrates this failure?

sgammon commented 4 years ago

@achew22 i added the tags to a java_binary target, yeah. I’ll try to dig in and create a repro, but I’m not entirely sure it’s a failure vs. user error

if all it should take is the tags, then I suppose this is a bug?

achew22 commented 4 years ago

It should only take the tags, and I use this on a daily basis through ts_devserver so I don't believe it's broken.

It's a bug only if you can provide a reproduction that I can observe and add a test case for. Otherwise I'm just guessing in the dark at something that might be user error. I don't work on this professionally so I can't provide the service you're asking for. I'm sorry.

sgammon commented 4 years ago

@achew22 no worries, i honestly appreciate the effort nonetheless, especially if you don't manage the repo for Google! lol

sgammon commented 4 years ago

@achew22 i'll give it a try in an isolated repro, or perhaps dig into how ts_devserver uses it and see if i can spot any differences. thank you, will report back.

github-actions[bot] commented 4 years ago

Stale issue message

achew22 commented 4 years ago

@sgammon, I wanted to follow up here and point you at an example server https://github.com/bazelbuild/bazel-watcher/pull/378. It works great, but I can't quite a different e2e test that I wrote to work with it in Windows. Buyer beware, but hopefully that'll get you off to the races on how to parse the STDIN signaling.

I'm going to close this, if you have any more issues please, please file another issue or reopen this one.

sgammon commented 4 years ago

@achew22 apologies but i'm still unable to grab the IBAZEL_LIVERELOAD_URL variable.

for context, i'm running my app this way: Makefile > ibazel > bazelisk > bazel > java_binary wrapper script > jar

when i run the app, i've made sure the nolive_reload is not passed to ibazel. under those conditions, theoretically, IBAZEL_LIVERELOAD_URL should show up when running the jar, right? at the moment, i still don't see it when executing one of my controllers.

i do, however, see the IBAZEL=true variable. so, presumably, ibazel is working, and is able to inject env variables that make it down to the jar. right? is there any other reason that variable wouldn't show up?

sgammon commented 4 years ago

oh wait, what do you mean by stdin signaling?

achew22 commented 4 years ago

Could you try querying the target and outputting it in build form?

If you run ibazel build //path/to:thingy you would run

bazel query --output=build //path/to:thingy

and print that out here?

sgammon commented 4 years ago

here's the java_binary rule, which is what i get when i print the target i'm running:

java_binary(
  name = "ExampleServer",
  tags = ["__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__", "ibazel_live_reload", "iblaze_notify_changes"],
  generator_name = "ExampleServer",
  generator_function = "_micronaut_application",
  generator_location = "src/BUILD.bazel:154:22",
  data = [],
  runtime_deps = ["@javax_inject//:javax_inject", "@javax_annotation_api//:javax_annotation_api", "@gust//java:framework", "@gust//defs/toolchain/java/plugins:picocli", "@gust//defs/toolchain/java/plugins:micronaut", "@gust//java/gust/backend/runtime:logging", "@com_google_guava//:com_google_guava", "@com_google_template_soy//:com_google_template_soy", "@com_google_common_html_types//:com_google_common_html_types", "@com_google_code_findbugs_jsr305//:com_google_code_findbugs_jsr305", "@io_micronaut_micronaut_views//:io_micronaut_micronaut_views", "@io_micronaut_micronaut_views_soy//:io_micronaut_micronaut_views_soy", "@org_brotli//java/org/brotli/wrapper/enc:enc", "@maven//:org_slf4j_slf4j_api", "@maven//:com_google_protobuf_protobuf_java", "@maven//:io_micronaut_micronaut_aop", "@maven//:io_micronaut_micronaut_core", "@maven//:io_micronaut_micronaut_http", "@maven//:io_micronaut_micronaut_http_client", "@maven//:io_micronaut_micronaut_security_annotations", "@maven//:io_micronaut_micronaut_inject", "@maven//:io_micronaut_micronaut_inject_java", "@maven//:io_micronaut_micronaut_validation", "@maven//:io_micronaut_micronaut_http_server", "@maven//:io_micronaut_micronaut_http_server_netty", "@maven//:io_micronaut_micronaut_graal", "@maven//:io_micronaut_micronaut_router", "@maven//:io_micronaut_micronaut_tracing", "@maven//:io_micronaut_micronaut_session", "@maven//:io_micronaut_micronaut_security", "@maven//:io_micronaut_micronaut_messaging", "@maven//:io_micronaut_micronaut_websocket", "@maven//:io_micronaut_micronaut_multitenancy", "@maven//:io_micronaut_micronaut_runtime", "@maven//:io_reactivex_rxjava2_rxjava", "@gust//java/gust/backend:AssetController", "@gust//java/gust/backend/builtin:BuiltinsController", "//src:AppService", "//src:ReflectionService", "//src:HomeController", "@gust//java/gust/backend:TemplateProvider", "@maven//:ch_qos_logback_logback_classic", "@gust//java/gust/backend:backend"],
  srcs = [],
  resources = [],
  resource_jars = ["//src:ExampleServer-assets"],
  classpath_resources = ["//src:application.yml", "//src:logback.xml"],
  jvm_flags = select({"@gust//defs/config:live_reload": ["-DLIVE_RELOAD=enabled", "-Dgust.dev=true", "-Dgust.debug=true", "-Dgust.version=1.0.0-alpha4", "-Dframework=gust"], "//conditions:default": ["-Dgust.dev=true", "-Dgust.debug=true", "-Dgust.version=1.0.0-alpha4", "-Dframework=gust"]}) + select({"@gust//defs/config:release": [], "@gust//defs/config:debug": ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"], "//conditions:default": ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"]}),
  main_class = "gust.backend.Application",
)
achew22 commented 4 years ago

Hrm... it looks like the target is configured correctly. Is there any chance you can break this out as a separate repo so that I can see what you're doing? I promise that this code works, we have an example client and tests in //e2e to verify it. Maybe you can use that as a guide to resolve the situation?

sgammon commented 4 years ago

@achew22 could we re-open? i'm happy to get you a sample :) there is a framework here so i can enclose it in the example

achew22 commented 4 years ago

Totally! Always feel free to reopen things if they get closed by the bot.

sgammon commented 3 years ago

@achew22 can we re-open just one more time? i'm about to submit a PR that fixes this (by adding a flag to force serving -- i still don't know why it isn't finding the tag).