cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / policy / BUILD.gn
blob13fc47878b9898ea5b743f73ee54fcfb2d1e0a65
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/chrome_build.gni")
6 import("//build/config/features.gni")
7 import("//components/policy/resources/policy_templates.gni")
8 import("//third_party/protobuf/proto_library.gni")
9 import("//tools/grit/grit_rule.gni")
11 # About the policy component:
13 # There should really be two components. One called "policy" that includes all
14 # generated code, and one "policy/proto" like we have now. The proto needs to
15 # be separate for cases like SesssionManagerClient which uses the protos to
16 # communicate with the Chrome OS system layer, but doesn't need the rest of the
17 # policy stuff).
19 # The reason the rest of the targets exist are artifacts of the way the GYP
20 # build works. The current "policy" target which is really just some generated
21 # code (which should be folded into the new "policy" component described above)
22 # exists so code outside which depends on the generated headers can depend on
23 # the hard policy target without having to make all policy targets hard
24 # dependencies (GN will do the right thing without this extra target).
25 if (is_component_build) {
26   component("policy_component") {
27     deps = [
28       "//components/policy/core/browser",
29       "//components/policy/core/common",
30     ]
31   }
32   group("policy_component_browser") {
33     deps = [
34       ":policy_component",
35     ]
36   }
37   group("policy_component_common") {
38     deps = [
39       ":policy_component",
40     ]
41   }
42 } else {  # Compile to separate libraries.
43   group("policy_component") {
44     deps = [
45       ":policy_component_browser",
46       ":policy_component_common",
47     ]
48   }
49   component("policy_component_browser") {
50     deps = [
51       "//components/policy/core/browser",
52     ]
53   }
54   component("policy_component_common") {
55     deps = [
56       "//components/policy/core/common",
57     ]
58   }
61 if (enable_configuration_policy) {
62   # TODO(brettw) this component should use target_gen_dir instead but the GYP
63   # build puts everything into the following directory. We do the same for now.
64   policy_gen_dir = "$root_gen_dir/policy"
66   # This protobuf is equivalent to chrome_settings.proto but shares messages
67   # for policies of the same type, so that less classes have to be generated
68   # and compiled.
69   cloud_policy_proto_path = "$policy_gen_dir/cloud_policy.proto"
71   # This is the "full" protobuf, which defines one protobuf message per
72   # policy. It is also the format currently used by the server.
73   chrome_settings_proto_path = "$policy_gen_dir/chrome_settings.proto"
75   constants_header_path = "$policy_gen_dir/policy_constants.h"
76   constants_source_path = "$policy_gen_dir/policy_constants.cc"
77   protobuf_decoder_path = "$policy_gen_dir/cloud_policy_generated.cc"
78   app_restrictions_path = "$policy_gen_dir/app_restrictions.xml"
80   action("cloud_policy_code_generate") {
81     script = "tools/generate_policy_source.py"
82     chrome_version_abspath = "//chrome/VERSION"
83     chrome_version_path = rebase_path(chrome_version_abspath, root_build_dir)
85     if (is_chromeos) {
86       chromeos_flag = "1"
87     } else {
88       chromeos_flag = "0"
89     }
91     inputs = [
92       chrome_version_abspath,
93       "resources/policy_templates.json",
94     ]
95     outputs = [
96       constants_header_path,
97       constants_source_path,
98       protobuf_decoder_path,
99       chrome_settings_proto_path,
100       cloud_policy_proto_path,
101       app_restrictions_path,
102     ]
104     if (target_os != "android") {
105       outputs -= [ app_restrictions_path ]
106     }
108     args = [
109       "--policy-constants-header=" +
110           rebase_path(constants_header_path, root_build_dir),
111       "--policy-constants-source=" +
112           rebase_path(constants_source_path, root_build_dir),
113       "--chrome-settings-protobuf=" +
114           rebase_path(chrome_settings_proto_path, root_build_dir),
115       "--cloud-policy-protobuf=" +
116           rebase_path(cloud_policy_proto_path, root_build_dir),
117       "--cloud-policy-decoder=" +
118           rebase_path(protobuf_decoder_path, root_build_dir),
119       "--app-restrictions-definition=" +
120           rebase_path(app_restrictions_path, root_build_dir),
121       chrome_version_path,
122       target_os,
123       chromeos_flag,
124       rebase_path("resources/policy_templates.json", root_build_dir),
125     ]
126   }
128   grit("policy_templates") {
129     source = "resources/policy_templates.grd"
130     use_qualified_include = true
131     output_dir = "$root_gen_dir/chrome"
132     outputs = policy_templates_doc_outputs
133     if (is_android) {
134       outputs += policy_templates_android_outputs
135     }
136     if (is_linux) {
137       outputs += policy_templates_linux_outputs
138     }
139     if (is_mac) {
140       outputs += policy_templates_mac_outputs
142       # TODO(knn) : Move this out once more targets use this.
143       if (is_chrome_branded) {
144         mac_bundle_id = "com.google.Chrome"
145       } else {
146         mac_bundle_id = "org.chromium.Chromium"
147       }
148       defines = [ "mac_bundle_id=$mac_bundle_id" ]
149     }
150     if (is_win) {
151       outputs += policy_templates_windows_outputs
152     }
153   }
155   # Run the proto compiler over the generated file and make it a component.
156   component("cloud_policy_proto_generated_compile") {
157     public_deps = [
158       ":cloud_policy_proto_generated_compile_proto",
159     ]
160   }
161   proto_library("cloud_policy_proto_generated_compile_proto") {
162     visibility = [ ":cloud_policy_proto_generated_compile" ]
163     sources = [
164       cloud_policy_proto_path,
165     ]
167     proto_out_dir = "policy/proto"
168     cc_generator_options = "dllexport_decl=POLICY_PROTO_EXPORT:"
169     cc_include = "components/policy/policy_proto_export.h"
170     defines = [ "POLICY_PROTO_COMPILATION" ]
172     deps = [
173       ":cloud_policy_code_generate",
174     ]
175   }
177   # This target builds the "full" protobuf, used for tests only.
178   proto_library("chrome_settings_proto_generated_compile") {
179     sources = [
180       chrome_settings_proto_path,
181     ]
182     proto_out_dir = "policy/proto"
184     deps = [
185       ":cloud_policy_code_generate",
186       ":cloud_policy_proto_generated_compile",
187     ]
188   }
190   # The dependencies here are kind of messed up.
191   #
192   # //components/policy/core/browser and .../common depend on this target,
193   # and require it to be compiled with POLICY_COMPONENT_IMPLEMENTATION to
194   # export the necessary symbols in a component build. But other targets like
195   # //chrome/browser also depend on this target, which in component build
196   # ends up in another shared library, but with the IMPLEMENTATION flag set
197   # incorrectly.
198   #
199   # This only reason this works is that this target is a shared library and
200   # the compilation units that this depends on in policy/core/common happen to
201   # not be brought in in the "bad" case. This needs serious untangling, maybe
202   # these files can just be put into policy/core/common?
203   static_library("policy") {
204     sources = [
205       constants_header_path,
206       constants_source_path,
207       protobuf_decoder_path,
208     ]
210     defines = [ "POLICY_COMPONENT_IMPLEMENTATION" ]
212     public_deps = [
213       ":cloud_policy_code_generate",
214       ":cloud_policy_proto_generated_compile",
215       "//base",
216       "//third_party/protobuf:protobuf_lite",
217     ]
218   }
220   group("test_support") {
221     public_deps = [
222       ":chrome_settings_proto_generated_compile",
223       ":policy_component",
224     ]
225   }
227   source_set("policy_component_test_support") {
228     testonly = true
229     sources = [
230       "core/browser/configuration_policy_pref_store_test.cc",
231       "core/browser/configuration_policy_pref_store_test.h",
232       "core/common/cloud/mock_cloud_external_data_manager.cc",
233       "core/common/cloud/mock_cloud_external_data_manager.h",
234       "core/common/cloud/mock_cloud_policy_client.cc",
235       "core/common/cloud/mock_cloud_policy_client.h",
236       "core/common/cloud/mock_cloud_policy_store.cc",
237       "core/common/cloud/mock_cloud_policy_store.h",
238       "core/common/cloud/mock_device_management_service.cc",
239       "core/common/cloud/mock_device_management_service.h",
240       "core/common/cloud/mock_user_cloud_policy_store.cc",
241       "core/common/cloud/mock_user_cloud_policy_store.h",
242       "core/common/cloud/policy_builder.cc",
243       "core/common/cloud/policy_builder.h",
244       "core/common/configuration_policy_provider_test.cc",
245       "core/common/configuration_policy_provider_test.h",
246       "core/common/fake_async_policy_loader.cc",
247       "core/common/fake_async_policy_loader.h",
248       "core/common/mock_configuration_policy_provider.cc",
249       "core/common/mock_configuration_policy_provider.h",
250       "core/common/mock_policy_service.cc",
251       "core/common/mock_policy_service.h",
252       "core/common/policy_test_utils.cc",
253       "core/common/policy_test_utils.h",
254       "core/common/preferences_mock_mac.cc",
255       "core/common/preferences_mock_mac.h",
256       "core/common/remote_commands/test_remote_command_job.cc",
257       "core/common/remote_commands/test_remote_command_job.h",
258       "core/common/remote_commands/testing_remote_commands_server.cc",
259       "core/common/remote_commands/testing_remote_commands_server.h",
260     ]
262     if (is_chromeos) {
263       sources -= [
264         "core/common/cloud/mock_user_cloud_policy_store.cc",
265         "core/common/cloud/mock_user_cloud_policy_store.h",
266       ]
267     }
269     public_deps = [
270       ":policy_component",
271       ":test_support",
272       "//components/policy/proto",
273       "//testing/gmock",
274       "//testing/gtest",
275     ]
276   }
278   if (is_android) {
279     import("//build/config/android/rules.gni")
281     resources_name = "app_restrictions_resources"
282     resources_zip = "res.java/$resources_name.zip"
283     generated_resources_dir = "$root_gen_dir/chrome/app/policy/android"
285     consolidate_target_name = "${resources_name}__consolidate_resources"
286     copy(consolidate_target_name) {
287       sources = [
288         app_restrictions_path,
289       ]
290       outputs = [
291         "$generated_resources_dir/xml-v21/app_restrictions.xml",
292       ]
293       deps = [
294         ":cloud_policy_code_generate",
295         ":policy_templates",
296       ]
297     }
299     # TODO(471115): The write_build_config template is in
300     # //build/config/android/internal_rules.gni and is not meant for external
301     # use. The public rules (in rules.gni) should be updated to support what
302     # we are doing here.
303     build_config_target_name = "${resources_name}__build_config"
304     write_build_config(build_config_target_name) {
305       build_config = "$target_gen_dir/$resources_name.build_config"
306       resources_zip = "$root_build_dir/$resources_zip"
307       type = "android_resources"
308     }
310     zip_target_name = "${resources_name}__create_zip"
311     action(zip_target_name) {
312       script = "//build/android/gn/zip.py"
313       outputs = [
314         "$root_build_dir/$resources_zip",
315       ]
316       generated_resources = get_target_outputs(":$consolidate_target_name") +
317                             policy_templates_android_outputs
318       inputs = generated_resources
319       rebased_inputs = rebase_path(generated_resources, root_build_dir)
320       rebased_resources_dir =
321           rebase_path(generated_resources_dir, root_build_dir)
322       args = [
323         "--inputs=$rebased_inputs",
324         "--output=$resources_zip",
325         "--base-dir=$rebased_resources_dir",
326       ]
327       deps = [
328         ":$consolidate_target_name",
329         ":policy_templates_grit",  # For policy_templates_android_outputs.
330       ]
331     }
333     group("app_restrictions_resources") {
334       deps = [
335         ":$build_config_target_name",
336         ":$zip_target_name",
337       ]
338     }
339   }
341 #TODO(GYP) chrome_manifest_bundle