1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/apple/convert_plist.gni")
import("//build/config/chrome_build.gni")
import("//build/config/features.gni")
import("//build/timestamp.gni")
import("//build/toolchain/toolchain.gni")
import("//components/policy/resources/policy_templates.gni")
import("//components/policy/tools/generate_policy_source.gni")
import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")
import("//third_party/protobuf/proto_library.gni")
import("//tools/grit/grit_args.gni")
import("//tools/grit/grit_rule.gni")
# To generate policy documentation for local use, set this to true for the
# links between pages and subpages to work.
gen_policy_templates_local = false
# To test policy generation for platforms different than your OS, override and
# enable these flags (but don't check that in!).
gen_policy_templates_common = true
gen_policy_templates_win = is_win
gen_policy_templates_linux = is_linux || is_chromeos
gen_policy_templates_android = is_android
gen_policy_templates_mac = is_mac
gen_policy_templates_ios = is_ios
# The zip file is grabbed from the Windows build right now.
gen_policy_templates_zip = is_win
# Make sure all dependencies of the zip are built.
if (gen_policy_templates_zip) {
gen_policy_templates_common = true
gen_policy_templates_win = true
}
if (is_mac) {
import("//build/util/branding.gni")
} else if (gen_policy_templates_mac) {
chrome_mac_bundle_id = "DUMMY_MAC_BUNDLE_ID"
}
if (is_component_build) {
# External code should depend on either //components/policy/core/browser or
# .../common depending on what code it needs.
component("policy") {
output_name = "policy_component"
visibility = [
"//components/policy/core/browser",
"//components/policy/core/common",
]
public_deps = [
"//build:branding_buildflags",
"//components/policy/core/browser:internal",
"//components/policy/core/common:internal",
"//components/policy/core/common:policy_namespace_internal",
]
}
}
# Used by targets that compile into the implementation.
config("component_implementation") {
defines = [ "POLICY_COMPONENT_IMPLEMENTATION" ]
}
# This protobuf is equivalent to chrome_settings.proto but shares messages
# for policies of the same type, so that less classes have to be generated
# and compiled.
cloud_policy_proto_path = "$target_gen_dir/proto/cloud_policy.proto"
# This is the "full" protobuf, which defines one protobuf message per
# policy. It is also the format currently used by the server.
chrome_settings_proto_path = "$target_gen_dir/proto/chrome_settings.proto"
constants_header_path = "$target_gen_dir/policy_constants.h"
constants_source_path = "$target_gen_dir/policy_constants.cc"
risk_tag_header_path = "$target_gen_dir/risk_tag.h"
policy_templates_deps_file = "$policy_templates_base_dir/policy_templates.d"
policy_templates_generated_json_path =
"$policy_templates_base_dir/policy_templates.json"
generate_policy_source("policy_code_generate") {
chunking = true
}
policy_templates_grd_file = "resources/policy_templates.build.grd"
# Generates a single policy_templates.json with a real JSON format.
action("generate_policy_templates") {
script = "resources/policy_templates.py"
depfile = policy_templates_deps_file
outputs = [
"$policy_templates_generated_json_path",
"$policy_templates_deps_file",
]
args = [
"--dest",
rebase_path(policy_templates_generated_json_path, root_build_dir),
"--depfile",
rebase_path(policy_templates_deps_file, root_build_dir),
]
}
# Translates policy_templates.json into various languages.
grit("translate_policy_templates") {
deps = [ ":generate_policy_templates" ]
source = policy_templates_grd_file
inputs = [ policy_templates_generated_json_path ]
output_dir = "$root_gen_dir/chrome"
outputs = policy_templates_translation_outputs
grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
"-E",
"root_src_dir=" + rebase_path("//", root_build_dir),
]
}
# Generate the various templates and docs (admx, doc, json, etc.)
action("policy_templates") {
script = "tools/template_writers/template_formatter.py"
chrome_version_abspath = "//chrome/VERSION"
chrome_version_path = rebase_path(chrome_version_abspath, root_build_dir)
deps = [ ":translate_policy_templates_grit" ]
inputs = [ chrome_version_abspath ] + policy_templates_translation_outputs
outputs = []
args = [
"--translations",
rebase_path(policy_templates_translation_json_path, root_build_dir),
"--languages",
policy_templates_languages_str,
"--version_path",
chrome_version_path,
] + grit_args
if (gen_policy_templates_local) {
args += [ "--local" ]
}
if (gen_policy_templates_common) {
outputs += policy_templates_common_outputs
args += [
"--doc",
rebase_path(policy_templates_doc_path, root_build_dir),
"--doc_atomic_groups",
rebase_path(policy_templates_doc_atomic_groups_path, root_build_dir),
]
}
if (gen_policy_templates_android) {
outputs += policy_templates_android_outputs
args += [
"--android_policy",
rebase_path(policy_templates_android_policy_path, root_build_dir),
]
}
if (gen_policy_templates_linux) {
outputs += policy_templates_linux_outputs
args += [
"--json",
rebase_path(policy_templates_json_path, root_build_dir),
]
}
if (gen_policy_templates_mac) {
outputs += policy_templates_mac_outputs
args += [
"--plist",
rebase_path(policy_templates_plist_path, root_build_dir),
"--plist_strings",
rebase_path(policy_templates_plist_strings_path, root_build_dir),
"--jamf",
rebase_path(policy_templates_jamf_path, root_build_dir),
"-D",
"mac_bundle_id=$chrome_mac_bundle_id",
]
}
if (gen_policy_templates_win) {
outputs += policy_templates_win_outputs
args += [
"--reg",
rebase_path(policy_templates_win_reg_path, root_build_dir),
"--adm",
rebase_path(policy_templates_win_adm_path, root_build_dir),
"--adml",
rebase_path(policy_templates_win_adml_path, root_build_dir),
"--admx",
rebase_path(policy_templates_win_admx_path, root_build_dir),
]
if (is_chrome_branded) {
# Create google.admx and google.adml files that define a common 'Google'
# category used for Chrome, Chrome OS and possibly external tools, see
# crbug.com/665400.
outputs += policy_templates_win_google_outputs
args += [
"--google_adml",
rebase_path(policy_templates_win_google_adml_path, root_build_dir),
"--google_admx",
rebase_path(policy_templates_win_google_admx_path, root_build_dir),
]
}
}
if (gen_policy_templates_ios) {
outputs += policy_templates_ios_outputs
args += [
"--ios_app_config",
rebase_path(policy_templates_ios_app_config_path, root_build_dir),
]
}
}
# Run the proto compiler over the generated file and make it a component.
component("cloud_policy_proto_generated_compile") {
public_deps = [ ":cloud_policy_proto_generated_compile_proto" ]
}
proto_library("cloud_policy_proto_generated_compile_proto") {
visibility = [ ":cloud_policy_proto_generated_compile" ]
sources = [ cloud_policy_proto_path ]
import_dirs = [ "//components/policy/proto" ]
proto_out_dir = "components/policy/proto"
cc_generator_options = "dllexport_decl=POLICY_PROTO_EXPORT:"
cc_include = "components/policy/proto/policy_proto_export.h"
component_build_force_source_set = true
defines = [ "POLICY_PROTO_COMPILATION" ]
deps = [ "//components/policy/proto:policy_common_definitions_compile_proto" ]
proto_deps = [ ":policy_code_generate" ]
}
# This target builds the "full" protobuf, used for tests only.
component("chrome_settings_proto_generated_compile") {
testonly = true
public_deps = [ ":chrome_settings_proto_generated_compile_proto" ]
}
proto_library("chrome_settings_proto_generated_compile_proto") {
testonly = true
visibility = [ ":chrome_settings_proto_generated_compile" ]
sources = [ chrome_settings_proto_path ]
import_dirs = [ "//components/policy/proto" ]
proto_out_dir = "components/policy/proto"
cc_generator_options = "dllexport_decl=POLICY_CHROME_SETTINGS_PROTO_EXPORT:"
cc_include = "components/policy/proto/policy_proto_export.h"
component_build_force_source_set = true
defines = [ "POLICY_CHROME_SETTINGS_PROTO_COMPILATION" ]
deps = [ "//components/policy/proto:policy_common_definitions_compile_proto" ]
proto_deps = [ ":policy_code_generate" ]
}
static_library("generated") {
sources = [
constants_header_path,
constants_source_path,
risk_tag_header_path,
]
defines = [ "POLICY_COMPONENT_IMPLEMENTATION" ]
public_deps = [
":cloud_policy_proto_generated_compile",
":policy_code_generate",
"//base",
"//components/policy/core/common:common_constants",
"//components/policy/proto:policy_common_definitions_compile_proto",
"//third_party/protobuf:protobuf_lite",
]
deps = [ "//build:branding_buildflags" ]
}
if (gen_policy_templates_android && is_android) {
import("//build/config/android/rules.gni")
_generated_resources_dir = "$root_gen_dir/chrome/app/policy/android"
copy("app_restrictions_resources_copy") {
sources = [ "$target_gen_dir/app_restrictions.xml" ]
outputs = [ "$_generated_resources_dir/xml-v21/app_restrictions.xml" ]
deps = [
":policy_code_generate",
":policy_templates",
]
}
android_resources("app_restrictions_resources") {
sources = policy_templates_android_outputs +
[ "$_generated_resources_dir/xml-v21/app_restrictions.xml" ]
deps = [
":app_restrictions_resources_copy",
":policy_templates",
]
}
} else if (gen_policy_templates_mac && is_mac) {
convert_plist("convert_mcx_plist") {
source = "$policy_templates_base_dir/mac/app-Manifest.plist"
output = "$target_gen_dir/$chrome_mac_bundle_id.manifest"
format = "xml1"
deps = [ ":policy_templates" ]
}
bundle_data("manifest_bundle_data") {
sources = get_target_outputs(":convert_mcx_plist")
outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
public_deps = [ ":convert_mcx_plist" ]
}
# The reason we are not enumerating all the locales is that
# the translations would eat up 3.5MB disk space in the
# application bundle.
bundle_data("manifest_strings_bundle_data") {
sources = [
"$policy_templates_base_dir/mac/strings/en.lproj/Localizable.strings",
]
outputs = [ "{{bundle_resources_dir}}/en.lproj/{{source_file_part}}" ]
public_deps = [ ":policy_templates" ]
}
create_bundle("chrome_manifest_bundle") {
bundle_root_dir = "$root_out_dir/$chrome_mac_bundle_id.manifest"
bundle_contents_dir = "$bundle_root_dir/Contents"
bundle_resources_dir = "$bundle_contents_dir/Resources"
deps = [
":manifest_bundle_data",
":manifest_strings_bundle_data",
]
}
}
if (gen_policy_templates_zip) {
version_path = "$policy_templates_base_dir/VERSION"
copy("add_version") {
sources = [ "//chrome/VERSION" ]
outputs = [ version_path ]
}
action("pack_policy_templates") {
output_zip_file = "$root_out_dir/policy_templates.zip"
script = "tools/make_policy_zip.py"
inputs = [ version_path ] + policy_templates_win_outputs +
policy_templates_common_outputs
outputs = [ output_zip_file ]
args = [
"--output",
rebase_path(output_zip_file, root_build_dir),
"--timestamp",
build_timestamp,
"--base_dir",
rebase_path(policy_templates_base_dir, root_build_dir),
"--languages",
policy_templates_languages_str,
"--add",
rebase_path(version_path, root_build_dir),
"--add",
rebase_path(policy_templates_doc_path, root_build_dir),
"--add",
rebase_path(policy_templates_doc_atomic_groups_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_reg_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_adm_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_adml_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_admx_path, root_build_dir),
]
if (is_chrome_branded) {
inputs += policy_templates_win_google_outputs
args += [
"--add",
rebase_path(policy_templates_win_google_adml_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_google_admx_path, root_build_dir),
]
}
deps = [
":add_version",
":policy_templates",
]
}
}
|