blob: 2098a66ef4187a2273f2c513b69f7c50c574ab41 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Fixes Chromium Updater's generated LICENSE file to remove licenses for
components not shipped as part of a compiled binary (for example, licenses
that apply only to build configuration scripts), and verify that restrictive
licenses imposing conditions we don't want the updater to be subjected to
are not present in the file. This is not a comprehensive check -- items are
manually added here after other automation discovers a problem, and we add
the check up at this earlier stage to catch it sooner.
"""
import argparse
# Text of licenses to be removed, matched exactly. All text to remove must
# be present in the string constants.
REMOVE_THESE_LICENSES = [
"""
----------------------------------------------------------------------
File: aclocal.m4 (only for ICU4C)
Section: pkg.m4 - Macros to locate and utilise pkg-config.
Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
As a special exception to the GNU General Public License, if you
distribute this file as part of a program that contains a
configuration script generated by Autoconf, you may include it under
the same distribution terms that you use for the rest of that
program.
(The condition for the exception is fulfilled because
ICU4C includes a configuration script generated by Autoconf,
namely the `configure` script.)
""",
"""
----------------------------------------------------------------------
File: config.guess (only for ICU4C)
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>.
As a special exception to the GNU General Public License, if you
distribute this file as part of a program that contains a
configuration script generated by Autoconf, you may include it under
the same distribution terms that you use for the rest of that
program. This Exception is an additional permission under section 7
of the GNU General Public License, version 3 ("GPLv3").
(The condition for the exception is fulfilled because
ICU4C includes a configuration script generated by Autoconf,
namely the `configure` script.)
""",
"""
----------------------------------------------------------------------
File: install-sh (only for ICU4C)
Copyright 1991 by the Massachusetts Institute of Technology
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of M.I.T. not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission. M.I.T. makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty.
""",
]
# When banning a license, we don't need to include the entire text, only enough
# to uniquely identify the license, since we aren't using it to trim the file.
BANNED_LICENSES = [
"Alliance for Open Media Patent License",
]
def _Main():
cmd_parser = argparse.ArgumentParser(
description="Creates a trimmed copy of Chromium Updater's LICENSE.")
cmd_parser.add_argument("--src",
dest="src",
type=str,
required=True,
help="Path to untrimmed LICENSE file.")
cmd_parser.add_argument("--dest",
dest="dest",
type=str,
required=True,
help="Path to save trimmed file into.")
flags = cmd_parser.parse_args()
with open(flags.src, "r", encoding="utf-8") as f:
license_content = f.read()
for s in REMOVE_THESE_LICENSES:
license_content = license_content.replace(s, "")
for s in BANNED_LICENSES:
if s in license_content:
raise ValueError(f"Found banned license! Matched text:\n{s}")
with open(flags.dest, "wt", encoding="utf-8") as f:
f.write(license_content)
if __name__ == "__main__":
_Main()