Skip to content

Commit

Permalink
Declare global define aliases that J2clUtilGetDefineRewriterPass can …
Browse files Browse the repository at this point in the history
…read from

This will allow goog.defines declared in goog.modules to be consumable by J2CL's
System.getProperty infrastructure. Since these reads are out-of-scope of the
declaration, we need to provide some hook to link the two. To do this we define
a global variable to serve as a well-known alias to the define.

For the J2CL pass we can assume what the global variable is based on the define
name, so we just simply replace the getProperty references with the appropriate
global, if it exists.

PiperOrigin-RevId: 719370016
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Jan 24, 2025
1 parent 8c9ecf4 commit a626721
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load(
"//transpiler/javatests/com/google/j2cl/integration:integration_test.bzl",
"integration_test",
Expand All @@ -8,10 +9,36 @@ package(
licenses = ["notice"],
)

closure_js_library(
name = "zoo",
srcs = ["Zoo.js"],
deps = ["//:jre"],
)

alias(
name = "zoo-j2cl",
actual = ":zoo",
)

alias(
name = "zoo-j2wasm",
actual = ":zoo",
)

integration_test(
name = "systemgetproperty",
srcs = glob(["*.java"]),
srcs = glob(
[
"*.java",
"*.js",
],
exclude = ["Zoo.js"],
),
closure_defines = {
"zoo": "buzz",
},
# This test is specific to J2CL's implementation of System.getProperty().
enable_jvm_test = False,
enable_kt = False,
deps = [":zoo"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @suppress {extraRequire} */
goog.require('systemgetproperty.Zoo');
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2025 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

goog.module('systemgetproperty.Zoo');

const jre = goog.require('jre');

/** @define {string} */
const localZoo = goog.define('zoo', 'default');
jre.addSystemPropertyFromGoogDefine('zoo', localZoo);

0 comments on commit a626721

Please sign in to comment.