diff --git a/WORKSPACE b/WORKSPACE index 09fa85b8..c99f2aec 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -69,6 +69,9 @@ load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_depende rules_closure_dependencies() rules_closure_toolchains() +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") +bazel_skylib_workspace() + # See this documentation to understand how fetching Maven deps works in Bazel: # https://github.com/bazelbuild/rules_jvm_external # When you add a new maven dep run the following command to update new deps: diff --git a/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/BUILD b/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/BUILD index c31500cb..333963cd 100644 --- a/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/BUILD +++ b/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/BUILD @@ -1,16 +1,48 @@ load("//src/java/com/claro:claro_build_rules.bzl", "claro_module") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +SRCS = ["buggy_buggies_move_response.claro"] +# This example now demonstrates how Claro programs can leverage Bazel's builtin functionality to satisfy arbitrary +# configuration needs without the language itself being burdened with syntax for such a thing. This is a demonstration +# of compile-time configurability that comes with no runtime overhead of checking flags and such as you'd find in other +# existing Guice-like dependency injection frameworks. claro_module( name = "buggy_buggies_client", module_api_file = "buggy_buggies_client.claro_module_api", - srcs = [ - "buggy_buggies_client.claro", - "buggy_buggies_move_response.claro", - ], + srcs = select({ + ":dev": ["buggy_buggies_client_DEV.claro"] + SRCS, + ":prod": ["buggy_buggies_client_PROD.claro"] + SRCS, + }), optional_stdlib_deps = ["http"], visibility = [ "//src/java/com/claro/claro_programs/demo_server/buggy_buggies:__pkg__", "//src/java/com/claro/claro_programs/demo_server/buggy_buggies/endpoint_handlers:__pkg__", ], -) \ No newline at end of file +) + +# For demonstration purposes only, I'm defining a brand new flag here, so that it's obvious where all of the moving +# pieces in the above claro_module() target come from. +# +# If you want to actually override the default flag value, set following flag in your `bazel run` command: +# --//src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service:env_flag=dev +string_flag( + name = "env_flag", + values = [ + "dev", + "prod", + ], + build_setting_default = "prod", +) +config_setting( + name = "dev", + flag_values = { + ":env_flag": "dev" + } +) +config_setting( + name = "prod", + flag_values = { + ":env_flag": "prod" + } +) diff --git a/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client_DEV.claro b/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client_DEV.claro new file mode 100644 index 00000000..e23b1a6e --- /dev/null +++ b/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client_DEV.claro @@ -0,0 +1,5 @@ + +provider static_HTTP_CLIENT() -> HttpClient { + # This now only needs to happen once throughout the entire program. + return http::getHttpClient("http://localhost:4000"); +} diff --git a/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client.claro b/src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client_PROD.claro similarity index 100% rename from src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client.claro rename to src/java/com/claro/claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client_PROD.claro diff --git a/src/java/com/claro/intermediate_representation/expressions/term/IdentifierReferenceTerm.java b/src/java/com/claro/intermediate_representation/expressions/term/IdentifierReferenceTerm.java index b21105ce..af3019f6 100644 --- a/src/java/com/claro/intermediate_representation/expressions/term/IdentifierReferenceTerm.java +++ b/src/java/com/claro/intermediate_representation/expressions/term/IdentifierReferenceTerm.java @@ -220,10 +220,6 @@ public Type getValidatedExprType(ScopedHeap scopedHeap) throws ClaroTypeExceptio @Override public StringBuilder generateJavaSourceBodyOutput(ScopedHeap scopedHeap) { - if (scopedHeap.getIdentifierData(this.identifier).isStaticValue) { - System.err.println( - "TESTING!!! FOUND STATIC ID REF: " + this.identifier + " " + this.optionalDefiningModuleDisambiguator); - } ScopedHeap.IdentifierData identifierData = scopedHeap.getIdentifierData(this.identifier); identifierData.used = true; return new StringBuilder(