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/features.gni")
6 import("resources/policy_templates.gni")
7 import("//third_party/protobuf/proto_library.gni")
8 import("//tools/grit/grit_rule.gni")
10 if (is_component_build) {
11 component("policy_component") {
13 "//components/policy/core/browser",
14 "//components/policy/core/common",
17 group("policy_component_browser") {
22 group("policy_component_common") {
27 } else { # Compile to separate libraries.
28 group("policy_component") {
30 ":policy_component_browser",
31 ":policy_component_common",
34 component("policy_component_browser") {
36 "//components/policy/core/browser",
39 component("policy_component_common") {
41 "//components/policy/core/common",
46 if (enable_configuration_policy) {
47 # TODO(brettw) this component should use target_gen_dir instead but the GYP
48 # build puts everything into the following directory. We do the same for now.
49 policy_gen_dir = "$root_gen_dir/policy"
51 # This protobuf is equivalent to chrome_settings.proto but shares messages
52 # for policies of the same type, so that less classes have to be generated
54 cloud_policy_proto_path = "$policy_gen_dir/cloud_policy.proto"
56 # This is the "full" protobuf, which defines one protobuf message per
57 # policy. It is also the format currently used by the server.
58 chrome_settings_proto_path = "$policy_gen_dir/chrome_settings.proto"
60 constants_header_path = "$policy_gen_dir/policy_constants.h"
61 constants_source_path = "$policy_gen_dir/policy_constants.cc"
62 protobuf_decoder_path = "$policy_gen_dir/cloud_policy_generated.cc"
63 app_restrictions_path = "$policy_gen_dir/app_restrictions.xml"
65 action("cloud_policy_code_generate") {
66 script = "tools/generate_policy_source.py"
75 "resources/policy_templates.json",
78 constants_header_path,
79 constants_source_path,
80 protobuf_decoder_path,
81 chrome_settings_proto_path,
82 cloud_policy_proto_path,
83 app_restrictions_path,
86 if (target_os != "android") {
87 outputs -= [ app_restrictions_path ]
91 "--policy-constants-header=" +
92 rebase_path(constants_header_path, root_build_dir),
93 "--policy-constants-source=" +
94 rebase_path(constants_source_path, root_build_dir),
95 "--chrome-settings-protobuf=" +
96 rebase_path(chrome_settings_proto_path, root_build_dir),
97 "--cloud-policy-protobuf=" +
98 rebase_path(cloud_policy_proto_path, root_build_dir),
99 "--cloud-policy-decoder=" +
100 rebase_path(protobuf_decoder_path, root_build_dir),
101 "--app-restrictions-definition=" +
102 rebase_path(app_restrictions_path, root_build_dir),
105 rebase_path("resources/policy_templates.json", root_build_dir),
109 grit("policy_templates") {
110 source = "resources/policy_templates.grd"
111 use_qualified_include = true
112 output_dir = "$root_gen_dir/chrome"
113 outputs = policy_templates_doc_outputs
115 outputs += policy_templates_android_outputs
118 outputs += policy_templates_linux_outputs
121 outputs += policy_templates_mac_outputs
123 # TODO(knn) : Move this out once more targets use this.
124 if (is_chrome_branded) {
125 mac_bundle_id = "com.google.Chrome"
127 mac_bundle_id = "org.chromium.Chromium"
129 defines = [ "mac_bundle_id=$mac_bundle_id" ]
132 outputs += policy_templates_windows_outputs
136 proto_library("cloud_policy_proto_generated_compile") {
138 cloud_policy_proto_path,
141 proto_out_dir = "policy/proto"
142 cc_generator_options = "dllexport_decl=POLICY_PROTO_EXPORT:"
143 cc_include = "components/policy/policy_proto_export.h"
144 defines = [ "POLICY_PROTO_COMPILATION" ]
147 ":cloud_policy_code_generate",
151 # This target builds the "full" protobuf, used for tests only.
152 proto_library("chrome_settings_proto_generated_compile") {
154 chrome_settings_proto_path,
156 proto_out_dir = "policy/proto"
159 ":cloud_policy_code_generate",
160 ":cloud_policy_proto_generated_compile",
164 # The dependencies here are kind of messed up.
166 # //components/policy/core/browser and .../common depend on this target,
167 # and require it to be compiled with POLICY_COMPONENT_IMPLEMENTATION to
168 # export the necessary symbols in a component build. But other targets like
169 # //chrome/browser also depend on this target, which in component build
170 # ends up in another shared library, but with the IMPLEMENTATION flag set
173 # This only reason this works is that this target is a shared library and
174 # the compilation units that this depends on in policy/core/common happen to
175 # not be brought in in the "bad" case. This needs serious untangling, maybe
176 # these files can just be put into policy/core/common?
177 static_library("policy") {
179 constants_header_path,
180 constants_source_path,
181 protobuf_decoder_path,
184 defines = [ "POLICY_COMPONENT_IMPLEMENTATION" ]
187 ":cloud_policy_code_generate",
188 ":cloud_policy_proto_generated_compile",
190 "//third_party/protobuf:protobuf_lite",
194 group("test_support") {
196 ":chrome_settings_proto_generated_compile",
198 "//components/policy/core/common",
202 static_library("policy_component_test_support") {
205 "core/browser/configuration_policy_pref_store_test.cc",
206 "core/browser/configuration_policy_pref_store_test.h",
207 "core/common/cloud/mock_cloud_external_data_manager.cc",
208 "core/common/cloud/mock_cloud_external_data_manager.h",
209 "core/common/cloud/mock_cloud_policy_client.cc",
210 "core/common/cloud/mock_cloud_policy_client.h",
211 "core/common/cloud/mock_cloud_policy_store.cc",
212 "core/common/cloud/mock_cloud_policy_store.h",
213 "core/common/cloud/mock_device_management_service.cc",
214 "core/common/cloud/mock_device_management_service.h",
215 "core/common/cloud/mock_user_cloud_policy_store.cc",
216 "core/common/cloud/mock_user_cloud_policy_store.h",
217 "core/common/cloud/policy_builder.cc",
218 "core/common/cloud/policy_builder.h",
219 "core/common/configuration_policy_provider_test.cc",
220 "core/common/configuration_policy_provider_test.h",
221 "core/common/fake_async_policy_loader.cc",
222 "core/common/fake_async_policy_loader.h",
223 "core/common/mock_configuration_policy_provider.cc",
224 "core/common/mock_configuration_policy_provider.h",
225 "core/common/mock_policy_service.cc",
226 "core/common/mock_policy_service.h",
227 "core/common/policy_test_utils.cc",
228 "core/common/policy_test_utils.h",
229 "core/common/preferences_mock_mac.cc",
230 "core/common/preferences_mock_mac.h",
231 "core/common/remote_commands/test_remote_command_job.cc",
232 "core/common/remote_commands/test_remote_command_job.h",
233 "core/common/remote_commands/testing_remote_commands_server.cc",
234 "core/common/remote_commands/testing_remote_commands_server.h",
239 "core/common/cloud/mock_user_cloud_policy_store.cc",
240 "core/common/cloud/mock_user_cloud_policy_store.h",
247 "//components/policy/proto",
254 import("//build/config/android/rules.gni")
255 group("app_restrictions_resources") {
256 resources_zip = "res.java/$target_name.zip"
257 generated_resources_dir = "$root_gen_dir/chrome/app/policy/android"
259 copy("${target_name}__consolidate_resources") {
261 "$root_gen_dir/policy/app_restrictions.xml",
264 "$generated_resources_dir/xml-v21/app_restrictions.xml",
271 # TODO(471115): The write_build_config template is in
272 # //build/config/android/internal_rules.gni and is not meant for external
273 # use. The public rules (in rules.gni) should be updated to support what
275 build_config_path = "$target_gen_dir/$target_name.build_config"
276 write_build_config("${target_name}__build_config") {
277 build_config = build_config_path
278 resources_zip = "$root_build_dir/$resources_zip"
279 type = "android_resources"
282 action("${target_name}__create_zip") {
283 script = "//build/android/gn/zip.py"
285 "$root_build_dir/$resources_zip",
287 generated_resources =
288 [ "$generated_resources_dir/xml-v21/app_restrictions.xml" ] +
289 policy_templates_android_outputs
290 inputs = generated_resources
291 rebased_inputs = rebase_path(generated_resources, root_build_dir)
292 rebased_resources_dir =
293 rebase_path(generated_resources_dir, root_build_dir)
295 "--inputs=$rebased_inputs",
296 "--output=$resources_zip",
297 "--base-dir=$rebased_resources_dir",
302 ":${target_name}__consolidate_resources",
303 ":${target_name}__build_config",
304 ":${target_name}__create_zip",
309 #TODO(GYP) chrome_manifest_bundle