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
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") {
28 "//components/policy/core/browser",
29 "//components/policy/core/common",
32 group("policy_component_browser") {
37 group("policy_component_common") {
42 } else { # Compile to separate libraries.
43 group("policy_component") {
45 ":policy_component_browser",
46 ":policy_component_common",
49 component("policy_component_browser") {
51 "//components/policy/core/browser",
54 component("policy_component_common") {
56 "//components/policy/core/common",
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
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)
92 chrome_version_abspath,
93 "resources/policy_templates.json",
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,
104 if (target_os != "android") {
105 outputs -= [ app_restrictions_path ]
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),
124 rebase_path("resources/policy_templates.json", root_build_dir),
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
134 outputs += policy_templates_android_outputs
137 outputs += policy_templates_linux_outputs
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"
146 mac_bundle_id = "org.chromium.Chromium"
148 defines = [ "mac_bundle_id=$mac_bundle_id" ]
151 outputs += policy_templates_windows_outputs
155 # Run the proto compiler over the generated file and make it a component.
156 component("cloud_policy_proto_generated_compile") {
158 ":cloud_policy_proto_generated_compile_proto",
161 proto_library("cloud_policy_proto_generated_compile_proto") {
162 visibility = [ ":cloud_policy_proto_generated_compile" ]
164 cloud_policy_proto_path,
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" ]
173 ":cloud_policy_code_generate",
177 # This target builds the "full" protobuf, used for tests only.
178 proto_library("chrome_settings_proto_generated_compile") {
180 chrome_settings_proto_path,
182 proto_out_dir = "policy/proto"
185 ":cloud_policy_code_generate",
186 ":cloud_policy_proto_generated_compile",
190 # The dependencies here are kind of messed up.
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
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") {
205 constants_header_path,
206 constants_source_path,
207 protobuf_decoder_path,
210 defines = [ "POLICY_COMPONENT_IMPLEMENTATION" ]
213 ":cloud_policy_code_generate",
214 ":cloud_policy_proto_generated_compile",
216 "//third_party/protobuf:protobuf_lite",
220 group("test_support") {
222 ":chrome_settings_proto_generated_compile",
227 source_set("policy_component_test_support") {
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",
264 "core/common/cloud/mock_user_cloud_policy_store.cc",
265 "core/common/cloud/mock_user_cloud_policy_store.h",
272 "//components/policy/proto",
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) {
288 app_restrictions_path,
291 "$generated_resources_dir/xml-v21/app_restrictions.xml",
294 ":cloud_policy_code_generate",
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
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"
310 zip_target_name = "${resources_name}__create_zip"
311 action(zip_target_name) {
312 script = "//build/android/gn/zip.py"
314 "$root_build_dir/$resources_zip",
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)
323 "--inputs=$rebased_inputs",
324 "--output=$resources_zip",
325 "--base-dir=$rebased_resources_dir",
328 ":$consolidate_target_name",
329 ":policy_templates_grit", # For policy_templates_android_outputs.
333 group("app_restrictions_resources") {
335 ":$build_config_target_name",
341 #TODO(GYP) chrome_manifest_bundle