Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new build_policy_templates action #25699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ if (!is_ios) {
}
}

if (!is_android && !is_ios) {
group("brave_group_policy_templates") {
# Currently, group policy resources are only generated on Windows.
if (is_win) {
deps = [ "//brave/components/policy:pack_policy_templates" ]
}
}
}

if (!is_ios) {
brave_paks("packed_resources") {
if (is_mac) {
Expand Down
15 changes: 14 additions & 1 deletion components/policy/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# Copyright (c) 2024 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

# See `components/policy/BUILD.gn` for more info about how these files
# are generated. Also see:
# `chromium_src/components/policy/tools/generate_policy_source.py`
# for Brave specific group policy definitions.

if (is_win) {
action("pack_policy_templates") {
chrome_pack_policy_templates = "//components/policy:pack_policy_templates"
deps = [ chrome_pack_policy_templates ]
deps = [
"//components/policy:policy_templates",
chrome_pack_policy_templates,
]
script = "pack_policy_templates.py"
chrome_policy_templates_zip =
get_label_info(chrome_pack_policy_templates, "root_out_dir") +
Expand Down
64 changes: 36 additions & 28 deletions components/policy/pack_policy_templates.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

# Script that prepares a Brave-specific version of the policy_templates.zip
# file that folks expect for administering Brave via group policy.
#
# For more info, see:
# https://support.brave.com/hc/en-us/articles/360039248271-Group-Policy
# and
# https://github.com/brave/brave-browser/issues/26502
"""
Create a Zip file of Windows Group Policy templates similar to Chrome's.
"""
Expand All @@ -16,37 +23,38 @@
from zipfile import ZipFile, ZIP_DEFLATED

def main():
chrome_policy_zip, dest_zip = _get_args()
_pack_policy_templates(chrome_policy_zip, dest_zip)
chrome_policy_zip, dest_zip = _get_args()
_pack_policy_templates(chrome_policy_zip, dest_zip)

def _get_args():
parser = argparse.ArgumentParser()
parser.add_argument('chrome_policy_zip',
help="Path to Chrome's policy_templates.zip")
parser.add_argument('dest_zip',
help="Path to the Zip file to be created")
args = parser.parse_args()
return args.chrome_policy_zip, args.dest_zip
parser = argparse.ArgumentParser()
parser.add_argument('chrome_policy_zip',
help="Path to Chrome's policy_templates.zip")
parser.add_argument('dest_zip', help="Path to the Zip file to be created")
args = parser.parse_args()
return args.chrome_policy_zip, args.dest_zip

def _pack_policy_templates(chrome_policy_zip, dest_zip):
with TemporaryDirectory() as tmp_dir:
with ZipFile(chrome_policy_zip) as src_zip:
src_zip.extract('VERSION', tmp_dir)
namelist = src_zip.namelist()
for dir_ in ('windows/adm/', 'windows/admx/', 'windows/examples/'):
src_zip.extractall(tmp_dir, (n for n in namelist if n.startswith(dir_)))

# Some sanity checks:
assert exists(join(tmp_dir, 'windows/adm/en-US/chrome.adm'))
assert exists(join(tmp_dir, 'windows/admx/chrome.admx'))
assert exists(join(tmp_dir, 'windows/admx/en-US/chrome.adml'))

with ZipFile(dest_zip, 'w', ZIP_DEFLATED) as dest_zipfile:
for dirpath, _, filenames in os.walk(tmp_dir):
for filename in filenames:
filepath = join(dirpath, filename)
arcname = relpath(filepath, tmp_dir).replace('chrome', 'brave')
dest_zipfile.write(filepath, arcname=arcname)
with TemporaryDirectory() as tmp_dir:
with ZipFile(chrome_policy_zip) as src_zip:
src_zip.extract('VERSION', tmp_dir)
namelist = src_zip.namelist()
for dir_ in ('windows/adm/', 'windows/admx/', 'windows/examples/'):
src_zip.extractall(tmp_dir,
(n for n in namelist if n.startswith(dir_)))

# Some sanity checks:
assert exists(join(tmp_dir, 'windows/adm/en-US/chrome.adm'))
assert exists(join(tmp_dir, 'windows/admx/chrome.admx'))
assert exists(join(tmp_dir, 'windows/admx/en-US/chrome.adml'))

with ZipFile(dest_zip, 'w', ZIP_DEFLATED) as dest_zipfile:
for dirpath, _, filenames in os.walk(tmp_dir):
for filename in filenames:
filepath = join(dirpath, filename)
arcname = relpath(filepath,
tmp_dir).replace('chrome', 'brave')
dest_zipfile.write(filepath, arcname=arcname)

if __name__ == '__main__':
main()
main()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"gen_env": "node ./build/commands/scripts/genEnv.js",
"gen_gradle": "node ./build/commands/scripts/commands.js gen_gradle",
"ios_pack_js": "webpack --config ios/brave-ios/webpack.config.js",
"ios_bootstrap": "node ./build/commands/scripts/iosCommands.js ios_bootstrap"
"ios_bootstrap": "node ./build/commands/scripts/iosCommands.js ios_bootstrap",
"build_policy_templates": "node ./build/commands/scripts/commands.js build --target=brave_group_policy_templates"
},
"repository": {
"type": "git",
Expand Down
Loading