summaryrefslogtreecommitdiffstats
path: root/ios/web/js_compile.gni
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2015-10-21 17:41:11 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-22 00:42:04 +0000
commitaa7c1cf96274a0a531629f934bd9091a55439270 (patch)
treef3e5ee07adc85ceaa0ad217c92e0489b1989af6e /ios/web/js_compile.gni
parent945f0b0bb8395df906781961116065caec94e22f (diff)
downloadchromium_src-aa7c1cf96274a0a531629f934bd9091a55439270.zip
chromium_src-aa7c1cf96274a0a531629f934bd9091a55439270.tar.gz
chromium_src-aa7c1cf96274a0a531629f934bd9091a55439270.tar.bz2
[iOS][GN] Port ios_web_unittests to build with gn
Add template to run a java command as an "script", i.e. templates java_action/java_action_foreach similar to action/action_foreach. Add template to compile a bunch of JavaScript to a bundle and to compile JavaScript files with closure compile (only enable checks that are known to work). Fix gcdwebserver public configuration to add the dependency on libz to libs instead of using ldflags. Add files missing from //ui/base:test_support when building for iOS with gn (they are present in the gyp build). BUG=459705 Review URL: https://codereview.chromium.org/1393303003 Cr-Commit-Position: refs/heads/master@{#355460}
Diffstat (limited to 'ios/web/js_compile.gni')
-rw-r--r--ios/web/js_compile.gni171
1 files changed, 171 insertions, 0 deletions
diff --git a/ios/web/js_compile.gni b/ios/web/js_compile.gni
new file mode 100644
index 0000000..6c9590a
--- /dev/null
+++ b/ios/web/js_compile.gni
@@ -0,0 +1,171 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/util/java_action.gni")
+
+declare_args() {
+ # Control whether the JavaScript files shipped with Chrome on iOS are
+ # compiled with closure_compiler or not. Useful for debugging.
+ compile_javascript = true
+}
+
+closure_compiler_path = "//third_party/closure_compiler/compiler/compiler.jar"
+
+# Defines a target that create a JavaScript bundle using the closure compiler.
+#
+# Variables
+# sources:
+# List of JavaScript files to compile into the bundle.
+#
+# closure_entry_point:
+# Name of the entry point closure module.
+#
+# deps (optional)
+# List of targets required by this target.
+#
+# visibility (optional)
+# Visibility restrictions.
+#
+# Generates a single JavaScript bundle file that can be put in the application
+# bundle.
+#
+# TODO(eugenebut): this should uses the same error flags as js_compile_checked.
+template("js_compile_bundle") {
+ assert(defined(invoker.sources),
+ "Need sources in $target_name listing the js files.")
+
+ assert(defined(invoker.closure_entry_point),
+ "Need closure_entry_point in $target_name for generated js file.")
+
+ java_action(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "visibility",
+ ])
+
+ script = closure_compiler_path
+ sources = invoker.sources
+ outputs = [
+ "$target_gen_dir/$target_name.js",
+ ]
+
+ args = [
+ "--compilation_level",
+ "SIMPLE_OPTIMIZATIONS",
+ "--js_output_file",
+ rebase_path("$target_gen_dir/$target_name.js", root_build_dir),
+ "--only_closure_dependencies",
+ "--closure_entry_point",
+ invoker.closure_entry_point,
+ "--js",
+ ] + rebase_path(sources, root_build_dir)
+
+ # TODO(crbug.com/546283): add the generated bundle to the list of files to
+ # move in the application bundle, equivalent to the following gyp code:
+ #
+ # "link_settings": {
+ # "mac_bundle_resources": [
+ # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js",
+ # ],
+ # },
+ }
+}
+
+# Defines a target that compile JavaScript files with error checking using the
+# closure compiler.
+#
+# Variables
+# sources:
+# List of JavaScript files to compile.
+#
+# deps (optional)
+# List of targets required by this target.
+#
+# visibility (optional)
+# Visibility restrictions.
+#
+# TODO(eugenebut): use flags from third_party/closure_compiler/closure_args.gni
+# once they are the same.
+template("js_compile_checked") {
+ assert(defined(invoker.sources),
+ "Need sources in $target_name listing the js files.")
+
+ if (compile_javascript) {
+ java_action_foreach(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "visibility",
+ ])
+
+ script = closure_compiler_path
+ sources = invoker.sources
+ outputs = [
+ "$target_gen_dir/{{source_file_part}}",
+ ]
+
+ # TODO(eugenebut): need to enable the following compilation checks once
+ # the corresponding errors have been fixed:
+ # --jscomp_error=checkTypes
+ # --jscomp_error=checkVars
+ # --jscomp_error=missingProperties
+ # --jscomp_error=missingReturn
+ # --jscomp_error=undefinedVars
+
+ args = [
+ "--compilation_level",
+ "SIMPLE_OPTIMIZATIONS",
+ "--jscomp_error=accessControls",
+ "--jscomp_error=ambiguousFunctionDecl",
+ "--jscomp_error=constantProperty",
+ "--jscomp_error=deprecated",
+ "--jscomp_error=externsValidation",
+ "--jscomp_error=globalThis",
+ "--jscomp_error=invalidCasts",
+ "--jscomp_error=nonStandardJsDocs",
+ "--jscomp_error=suspiciousCode",
+ "--jscomp_error=undefinedNames",
+ "--jscomp_error=unknownDefines",
+ "--jscomp_error=uselessCode",
+ "--jscomp_error=visibility",
+ "--js",
+ "{{source}}",
+ "--js_output_file",
+ rebase_path("$target_gen_dir/{{source_file_part}}", root_build_dir),
+ ]
+
+ # TODO(crbug.com/546283): add the generated bundle to the list of files
+ # to move in the application bundle, equivalent to the following gyp code:
+ #
+ # "link_settings": {
+ # "mac_bundle_resources": [
+ # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js",
+ # ],
+ # },
+ }
+ } else {
+ copy(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "visibility",
+ ])
+
+ sources = invoker.sources
+ outputs = [
+ "$target_gen_dir/{{source_file_part}}",
+ ]
+
+ # TODO(crbug.com/546283): add the generated bundle to the list of files
+ # to move in the application bundle, equivalent to the following gyp code:
+ #
+ # "link_settings": {
+ # "mac_bundle_resources": [
+ # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js",
+ # ],
+ # },
+ }
+ }
+}