BUILD.gn 17 KB

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