123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- # Copyright 2014 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/apple/convert_plist.gni")
- import("//build/config/chrome_build.gni")
- import("//build/config/chromeos/ui_mode.gni")
- import("//build/config/features.gni")
- import("//build/timestamp.gni")
- import("//build/toolchain/toolchain.gni")
- import("//components/policy/resources/policy_templates.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_chromeos = is_chromeos_ash
- 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
- gen_policy_templates_chromeos = 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 file is used by chrome/browser/privacy/traffic_annotation.proto as it
- # needs a version without LITE_RUNTIME optimization.
- cloud_policy_full_runtime_proto_path =
- "$target_gen_dir/proto/cloud_policy_full_runtime.proto"
- # This protobuf contains the common definitions of the shared messages
- # between user and device policies
- policy_common_definitions_proto_abspath =
- "//components/policy/proto/policy_common_definitions.proto"
- # This file is used by chrome/browser/privacy/traffic_annotation.proto as it
- # needs a version without LITE_RUNTIME optimization.
- policy_common_definitions_full_runtime_proto_path =
- "$target_gen_dir/proto/policy_common_definitions_full_runtime.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"
- # This file is used by chrome/browser/privacy/traffic_annotation.proto as it
- # needs a version without LITE_RUNTIME optimization.
- chrome_settings_full_runtime_proto_path =
- "$target_gen_dir/proto/chrome_settings_full_runtime.proto"
- constants_header_path = "$target_gen_dir/policy_constants.h"
- constants_source_path = "$target_gen_dir/policy_constants.cc"
- app_restrictions_path = "$target_gen_dir/app_restrictions.xml"
- risk_tag_header_path = "$target_gen_dir/risk_tag.h"
- policy_templates_generated_json_path =
- "$policy_templates_base_dir/policy_templates.json"
- action("policy_code_generate") {
- script = "tools/generate_policy_source.py"
- chrome_version_abspath = "//chrome/VERSION"
- chrome_version_path = rebase_path(chrome_version_abspath, root_build_dir)
- deps = [ ":generate_policy_templates" ]
- inputs = [
- chrome_version_abspath,
- policy_templates_generated_json_path,
- ]
- outputs = [
- constants_header_path,
- constants_source_path,
- chrome_settings_proto_path,
- cloud_policy_proto_path,
- app_restrictions_path,
- risk_tag_header_path,
- ]
- if (target_os != "android") {
- outputs -= [ app_restrictions_path ]
- }
- args = [
- # Input information
- "--chrome-version-file=" + chrome_version_path,
- "--policy-templates-file=" +
- rebase_path(policy_templates_generated_json_path, root_build_dir),
- "--target-platform=" + target_os,
- # Output files to be generated
- "--policy-constants-header=" +
- rebase_path(constants_header_path, root_build_dir),
- "--policy-constants-source=" +
- rebase_path(constants_source_path, root_build_dir),
- "--chrome-settings-protobuf=" +
- rebase_path(chrome_settings_proto_path, root_build_dir),
- "--cloud-policy-protobuf=" +
- rebase_path(cloud_policy_proto_path, root_build_dir),
- "--app-restrictions-definition=" +
- rebase_path(app_restrictions_path, root_build_dir),
- "--risk-tag-header=" + rebase_path(risk_tag_header_path, root_build_dir),
- ]
- }
- action("full_runtime_code_generate") {
- script = "tools/generate_policy_source.py"
- chrome_version_abspath = "//chrome/VERSION"
- chrome_version_path = rebase_path(chrome_version_abspath, root_build_dir)
- deps = [ ":generate_policy_templates" ]
- inputs = [
- chrome_version_abspath,
- policy_templates_generated_json_path,
- ]
- outputs = [
- cloud_policy_full_runtime_proto_path,
- chrome_settings_full_runtime_proto_path,
- policy_common_definitions_full_runtime_proto_path,
- ]
- args = [
- # Input information
- "--chrome-version-file=" + chrome_version_path,
- "--target-platform=" + target_os,
- "--policy-templates-file=" +
- rebase_path(policy_templates_generated_json_path, root_build_dir),
- "--target-platform=" + target_os,
- # Output files to be generated
- "--cloud-policy-full-runtime-protobuf=" +
- rebase_path(cloud_policy_full_runtime_proto_path, root_build_dir),
- "--chrome-settings-full-runtime-protobuf=" +
- rebase_path(chrome_settings_full_runtime_proto_path, root_build_dir),
- "--policy-common-definitions-protobuf=" +
- rebase_path(policy_common_definitions_proto_abspath, root_build_dir),
- "--policy-common-definitions-full-runtime-protobuf=" +
- rebase_path(policy_common_definitions_full_runtime_proto_path,
- root_build_dir),
- ]
- }
- policy_templates_grd_file = "resources/policy_templates.grd"
- # Generates a single policy_templates.json with a real JSON format.
- action("generate_policy_templates") {
- script = "resources/policy_templates.py"
- inputs = [ "resources/policy_templates.json" ]
- outputs = [ policy_templates_generated_json_path ]
- args = [
- "--dest",
- rebase_path(policy_templates_generated_json_path, root_build_dir),
- ]
- }
- # Translates policy_templates.json into various languages.
- grit("translate_policy_templates") {
- source = policy_templates_grd_file
- inputs = [ "resources/policy_templates.json" ]
- output_dir = "$root_gen_dir/chrome"
- outputs = policy_templates_translation_outputs
- }
- # 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_chromeos) {
- outputs += policy_templates_chromeos_outputs
- args += [
- "--chromeos_adml",
- rebase_path(policy_templates_chromeos_adml_path, root_build_dir),
- "--chromeos_admx",
- rebase_path(policy_templates_chromeos_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_chromeos_google_outputs
- args += [
- "--google_adml",
- rebase_path(policy_templates_chromeos_google_adml_path, root_build_dir),
- "--google_admx",
- rebase_path(policy_templates_chromeos_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" ]
- link_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" ]
- link_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",
- ":full_runtime_code_generate",
- ":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 = [ app_restrictions_path ]
- 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_chromeos_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),
- "--add",
- rebase_path(policy_templates_chromeos_adml_path, root_build_dir),
- "--add",
- rebase_path(policy_templates_chromeos_admx_path, root_build_dir),
- ]
- if (is_chrome_branded) {
- inputs += policy_templates_win_google_outputs
- inputs += policy_templates_chromeos_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),
- "--add",
- rebase_path(policy_templates_chromeos_google_adml_path, root_build_dir),
- "--add",
- rebase_path(policy_templates_chromeos_google_admx_path, root_build_dir),
- ]
- }
- deps = [
- ":add_version",
- ":policy_templates",
- ]
- }
- }
|