From bc30d1cd419023289007091d6d09129efec09213 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Mon, 23 Jun 2025 09:18:37 -0700 Subject: [PATCH] License cpp jun20 (#170948) I'm down to 40 exceptions and runtime 20s. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- .../tools/licenses_cpp/data/exclude.txt | 13 +++++ .../tools/licenses_cpp/data/licenses/asis.txt | 29 +++++------ .../licenses_cpp/data/licenses/asis_beer.txt | 23 +++++++++ .../tools/licenses_cpp/data/licenses/dart.txt | 4 +- .../licenses_cpp/data/licenses/flutter.txt | 2 +- .../data/licenses/flutter_header.txt | 5 ++ .../data/licenses/google_commented.txt | 4 +- .../licenses_cpp/data/licenses/harfbuzz.txt | 2 +- .../data/licenses/libturbojpeg.txt | 18 +++++++ .../tools/licenses_cpp/data/licenses/mit.txt | 7 ++- .../data/licenses/mit_materials.txt | 19 ++++++++ .../tools/licenses_cpp/data/licenses/sgi.txt | 27 +++++++++++ .../licenses_cpp/data/licenses/sqlite.txt | 25 ++++++++++ .../licenses_cpp/data/licenses/unicode.txt | 48 +++++++++++++++++++ .../tools/licenses_cpp/data/licenses/zlib.txt | 21 ++++++++ .../licenses_cpp/src/comments_unittests.cc | 15 ++++++ .../tools/licenses_cpp/src/comments_util.cc | 2 +- .../tools/licenses_cpp/src/license_checker.cc | 17 ++++--- .../src/license_checker_unittests.cc | 33 +++++++++++++ 19 files changed, 279 insertions(+), 35 deletions(-) create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/asis_beer.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/flutter_header.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/libturbojpeg.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/mit_materials.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/sqlite.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/unicode.txt create mode 100644 engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt diff --git a/engine/src/flutter/tools/licenses_cpp/data/exclude.txt b/engine/src/flutter/tools/licenses_cpp/data/exclude.txt index b16cace63a8..6081cdc3527 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/exclude.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/exclude.txt @@ -1,27 +1,40 @@ # This file describes all the files we don't need to do a copyright header # check on. +.*/flutter/build/.* +.*/flutter/sky/packages/sky_engine/LICENSE .*/flutter/third_party/angle/third_party/.* +.*/flutter/third_party/angle/tools/.* +.*/flutter/third_party/angle/util/.* .*/flutter/third_party/benchmark/.* .*/flutter/third_party/dart/pkg/.* +.*/flutter/third_party/dart/third_party/binary_size/.* .*/flutter/third_party/dart/third_party/binaryen/.* +.*/flutter/third_party/dart/third_party/d3/.* .*/flutter/third_party/dart/third_party/pkg/.* +.*/flutter/third_party/dart/third_party/requirejs/.* .*/flutter/third_party/depot_tools/.* .*/flutter/third_party/harfbuzz/.*\.py .*/flutter/third_party/harfbuzz/perf/.* .*/flutter/third_party/harfbuzz/src/harfbuzz.cc +.*/flutter/third_party/icu/scripts/.* +.*/flutter/third_party/imgui/.* .*/flutter/third_party/inja/third_party/amalgamate/.* .*/flutter/third_party/inja/third_party/include/doctest/.* .*/flutter/third_party/libpng/contrib/.* +.*/flutter/third_party/libwebp/.*\.py .*/flutter/third_party/libwebp/examples/.* .*/flutter/third_party/libwebp/swig/.* .*/flutter/third_party/llvm-project/.* .*/flutter/third_party/ocmock/.* .*/flutter/third_party/pkg/archive/.* +.*/flutter/third_party/pkg/flutter_packages/.* .*/flutter/third_party/pkg/gcloud/.* .*/flutter/third_party/pkg/googleapis/.* .*/flutter/third_party/pkg/process/.* .*/flutter/third_party/pkg/vector_math/.* .*/flutter/third_party/protobuf/.* +.*/flutter/third_party/pyyaml/.* +.*/flutter/third_party/swiftshader/third_party/.* .*/flutter/third_party/swiftshader/third_party/llvm-10.0/.* .*/flutter/third_party/swiftshader/third_party/llvm-16.0/.* .*/flutter/third_party/vulkan-deps/spirv-headers/.* diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/asis.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/asis.txt index 5b89789ec2e..2c307cb3a1d 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/asis.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/asis.txt @@ -1,23 +1,18 @@ as is -This software is provided 'as-is' -(?s)Copyright \(c\).* +(?s)^Copyright.*This software is provided 'as-is'.*3\. This notice +(?s)Copyright.* This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - +arising from the use of this software.\s* Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. If you meet \(any of\) the author\(s\), you're encouraged to buy them a beer, - a drink or whatever is suited to the situation, given that you like the - software. -4. This notice may not be removed or altered from any source - distribution. +freely, subject to the following restrictions:\s* +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would + be appreciated but is not required.\s* +2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software.\s* +3. This notice may not be removed or altered from any source + distribution. diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/asis_beer.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/asis_beer.txt new file mode 100644 index 00000000000..52dc44005d3 --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/asis_beer.txt @@ -0,0 +1,23 @@ +as is (beer) +(?s)This software is provided 'as-is'.*buy them a beer +(?s)Copyright \(c\).* + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. If you meet \(any of\) the author\(s\), you're encouraged to buy them a beer, + a drink or whatever is suited to the situation, given that you like the + software. +4. This notice may not be removed or altered from any source + distribution. diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/dart.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/dart.txt index 974606b7480..ea2d91a7601 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/dart.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/dart.txt @@ -1,10 +1,10 @@ dart Copyright \d+, the Dart project authors. -Copyright \d+, the Dart project authors. +Copyright \d+, the Dart project authors.\s* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are -met: +met:\s* \* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. \* Redistributions in binary form must reproduce the above diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter.txt index b412fd97245..a7acf3149bb 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter.txt @@ -1,5 +1,5 @@ flutter -^Copyright \d+ The Flutter Authors +(?s)^Copyright \d+ The Flutter Authors.*?Redistribution Copyright \d+ The Flutter Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter_header.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter_header.txt new file mode 100644 index 00000000000..55537cef80f --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/flutter_header.txt @@ -0,0 +1,5 @@ +flutter header +(?s)Copyright \d+ The Flutter Authors.*found in the LICENSE file +Copyright \d+ The Flutter Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. \ No newline at end of file diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/google_commented.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/google_commented.txt index 8083e56ac4a..4f83d964ca6 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/google_commented.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/google_commented.txt @@ -1,6 +1,6 @@ google commented -^// Copyright \(c\) \d+ Google Inc -// Copyright \(c\) \d+ Google Inc. All rights reserved. +^// Copyright \(c\) \d+ (?:Google Inc|The RE2 Authors) +// Copyright \(c\) \d+ (?:Google Inc|The RE2 Authors). All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/harfbuzz.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/harfbuzz.txt index 6b26e03ff38..cf2f05ee0a1 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/harfbuzz.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/harfbuzz.txt @@ -1,6 +1,6 @@ harfbuzz This is part of HarfBuzz, a text shaping library. -(?s)Copyright.*This is part of HarfBuzz, a text shaping library\..* +(?s)(?:Copyright.*)?\s*This is part of HarfBuzz, a text shaping library\..* Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/libturbojpeg.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/libturbojpeg.txt new file mode 100644 index 00000000000..077c18316ab --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/libturbojpeg.txt @@ -0,0 +1,18 @@ +libjpeg-turbo +^libjpeg-turbo Licenses +(?s)libjpeg-turbo Licenses +.* +libjpeg-turbo is covered by three compatible BSD-style open source licenses: +.* +- The IJG \(Independent JPEG Group\) License.* +- The Modified \(3-clause\) BSD License.* +- The zlib License.* +Complying with the libjpeg-turbo Licenses +.*You cannot alter or remove any existing copyright or license notices +.*You must add your own copyright notice to the header of each source +.*You must include the IJG README file, and you must not alter any of the +.*Your product documentation must include a message stating: +.*your product documentation must include the text of the Modified BSD +.*You cannot use the name of the IJG or The libjpeg-turbo Project or the +.*The IJG and The libjpeg-turbo Project do not warrant libjpeg-turbo to be +.* \ No newline at end of file diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/mit.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/mit.txt index 8a637ff7c34..80c76e4c468 100644 --- a/engine/src/flutter/tools/licenses_cpp/data/licenses/mit.txt +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/mit.txt @@ -1,5 +1,5 @@ MIT -(?s)^(?:MIT License)?\s*Copyright.*Permission is hereby granted.*\n.*following conditions: +(?s)^(?:MIT License)?\s*Copyright.*Permission is hereby granted.*\n.*following conditions:.*THE SOFTWARE IS PROVIDED (?s)^(?:MIT License)?\s*Copyright \(c\) .* Permission is hereby granted, free of charge, to any person obtaining a copy @@ -9,12 +9,11 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in\s+all\s+copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\s+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN.*THE.*SOFTWARE\. diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/mit_materials.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/mit_materials.txt new file mode 100644 index 00000000000..e3fad4b1136 --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/mit_materials.txt @@ -0,0 +1,19 @@ +MIT (materials) +(?s)Copyright \(c\).*MATERIALS +(?s)Copyright \(c\).* +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and/or associated documentation files \(the +"Materials"\), to deal in the Materials without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Materials, and to +permit persons to whom the Materials are furnished to do so, subject to +the following conditions:.* +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Materials..* +THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. \ No newline at end of file diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt new file mode 100644 index 00000000000..709306089f7 --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt @@ -0,0 +1,27 @@ +sgi +\*\* SGI FREE SOFTWARE LICENSE B \(Version 2.0, Sept. 18, 2008\) +\*\* SGI FREE SOFTWARE LICENSE B \(Version 2.0, Sept. 18, 2008\) +\*\* Copyright \(C\) \[dates of first publication\] Silicon Graphics, Inc. +\*\* All Rights Reserved. +\*\* +\*\* Permission is hereby granted, free of charge, to any person obtaining a copy +\*\* of this software and associated documentation files \(the "Software"\), to deal +\*\* in the Software without restriction, including without limitation the rights +\*\* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +\*\* of the Software, and to permit persons to whom the Software is furnished to do so, +\*\* subject to the following conditions: +\*\* +\*\* The above copyright notice including the dates of first publication and either this +\*\* permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be +\*\* included in all copies or substantial portions of the Software. +\*\* +\*\* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +\*\* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +\*\* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. +\*\* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +\*\* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +\*\* OR OTHER DEALINGS IN THE SOFTWARE. +\*\* +\*\* Except as contained in this notice, the name of Silicon Graphics, Inc. shall not +\*\* be used in advertising or otherwise to promote the sale, use or other dealings in +\*\* this Software without prior written authorization from Silicon Graphics, Inc. \ No newline at end of file diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/sqlite.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/sqlite.txt new file mode 100644 index 00000000000..b637274e81a --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/sqlite.txt @@ -0,0 +1,25 @@ +sqlite +The source code for SQLite is in the public domain +The source code for SQLite is in the public domain. No claim of +copyright is made on any part of the core source code. \(The +documentation and test code is a different matter - some sections of +documentation and test logic are governed by open-source licenses.\) +All contributors to the SQLite core software have signed affidavits +specifically disavowing any copyright interest in the code. This means +that anybody is able to legally do anything they want with the SQLite +source code. + +There are other SQL database engines with liberal licenses that allow +the code to be broadly and freely used. But those other engines are +still governed by copyright law. SQLite is different in that copyright +law simply does not apply. + +The source code files for other SQL database engines typically begin +with a comment describing your legal rights to view and copy that +file. The SQLite source code contains no license since it is not +governed by copyright. Instead of a license, the SQLite source code +offers a blessing: + +May you do good and not evil +May you find forgiveness for yourself and forgive others +May you share freely, never taking more than you give. diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/unicode.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/unicode.txt new file mode 100644 index 00000000000..21d95c354ca --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/unicode.txt @@ -0,0 +1,48 @@ +unicode +UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE +UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE + +See Terms of Use +for definitions of Unicode Inc.’s Data Files and Software. + +NOTICE TO USER: Carefully read the following legal agreement. +BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S +DATA FILES \("DATA FILES"\), AND/OR SOFTWARE \("SOFTWARE"\), +YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. +IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE +THE DATA FILES OR SOFTWARE. + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 1991-2022 Unicode, Inc. All rights reserved. +Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Unicode data files and any associated documentation +\(the "Data Files"\) or Unicode software and any associated documentation +\(the "Software"\) to deal in the Data Files or Software +without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, and/or sell copies of +the Data Files or Software, and to permit persons to whom the Data Files +or Software are furnished to do so, provided that either +\(a\) this copyright and permission notice appear with all copies +of the Data Files or Software, or +\(b\) this copyright and permission notice appear in associated +Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS +NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL +DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THE DATA FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in these Data Files or Software without prior +written authorization of the copyright holder. diff --git a/engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt b/engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt new file mode 100644 index 00000000000..c507de9a228 --- /dev/null +++ b/engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt @@ -0,0 +1,21 @@ +zlib +version 1.2.12, March 27th, 2022 +version 1.2.12, March 27th, 2022 + +Copyright \(C\) 1995-2022 Jean-loup Gailly and Mark Adler + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/engine/src/flutter/tools/licenses_cpp/src/comments_unittests.cc b/engine/src/flutter/tools/licenses_cpp/src/comments_unittests.cc index 7405f0b50c0..94e8c81c351 100644 --- a/engine/src/flutter/tools/licenses_cpp/src/comments_unittests.cc +++ b/engine/src/flutter/tools/licenses_cpp/src/comments_unittests.cc @@ -98,3 +98,18 @@ world*/ ASSERT_EQ(comments.size(), 1u); EXPECT_EQ(comments[0], "hello\nworld"); } + +TEST(CommentsTest, HashComments) { + std::string test = R"test( +# Hello +# World +)test"; + + std::vector comments; + IterateComments(test.c_str(), test.size(), [&](std::string_view comment) { + comments.push_back(std::string(comment)); + }); + + ASSERT_EQ(comments.size(), 1u); + EXPECT_EQ(comments[0], "Hello\nWorld"); +} diff --git a/engine/src/flutter/tools/licenses_cpp/src/comments_util.cc b/engine/src/flutter/tools/licenses_cpp/src/comments_util.cc index dcfb6c45a2e..9d162ff3ac4 100644 --- a/engine/src/flutter/tools/licenses_cpp/src/comments_util.cc +++ b/engine/src/flutter/tools/licenses_cpp/src/comments_util.cc @@ -8,7 +8,7 @@ void CommentsUtil::AddTrimLine(std::string* buffer, const char* text, size_t length) { - RE2 regex(R"regex(^(?:\s*//\s?)(.*))regex"); + RE2 regex(R"regex(^(?:\s*(?://|#)\s?)(.*))regex"); re2::StringPiece captured_content; RE2::FullMatch(re2::StringPiece(text), regex, &captured_content); buffer->append(captured_content); diff --git a/engine/src/flutter/tools/licenses_cpp/src/license_checker.cc b/engine/src/flutter/tools/licenses_cpp/src/license_checker.cc index 9f5205a355c..ed9025f99b7 100644 --- a/engine/src/flutter/tools/licenses_cpp/src/license_checker.cc +++ b/engine/src/flutter/tools/licenses_cpp/src/license_checker.cc @@ -22,7 +22,7 @@ namespace fs = std::filesystem; -const char* LicenseChecker::kHeaderLicenseRegex = "(License|Copyright)"; +const char* LicenseChecker::kHeaderLicenseRegex = "(?i)(license|copyright)"; namespace { const std::array kLicenseFileNames = { @@ -68,10 +68,11 @@ absl::StatusOr> GitLsFiles(const fs::path& repo_path) { return files; } -std::optional FindLicense(const fs::path& path) { +std::optional FindLicense(const Data& data, const fs::path& path) { for (std::string_view license_name : kLicenseFileNames) { fs::path license_path = path / license_name; - if (fs::exists(license_path)) { + if (fs::exists(license_path) && + !data.exclude_filter.Matches(license_path.string())) { return license_path; } } @@ -129,17 +130,19 @@ struct Package { std::optional license_file; }; -Package GetPackage(const fs::path& working_dir, const fs::path& full_path) { +Package GetPackage(const Data& data, + const fs::path& working_dir, + const fs::path& full_path) { Package result = { .name = working_dir.filename(), - .license_file = FindLicense(working_dir), + .license_file = FindLicense(data, working_dir), }; fs::path relative = fs::relative(full_path, working_dir); bool after_third_party = false; fs::path current = working_dir; for (const fs::path& component : relative) { current /= component; - std::optional current_license = FindLicense(current); + std::optional current_license = FindLicense(data, current); if (current_license.has_value()) { result.license_file = current_license; } @@ -247,7 +250,7 @@ std::vector LicenseChecker::Run(std::string_view working_dir, continue; } - Package package = GetPackage(working_dir_path, full_path); + Package package = GetPackage(data, working_dir_path, full_path); if (package.license_file.has_value()) { auto [_, is_new_item] = seen_license_files.insert(package.license_file.value()); diff --git a/engine/src/flutter/tools/licenses_cpp/src/license_checker_unittests.cc b/engine/src/flutter/tools/licenses_cpp/src/license_checker_unittests.cc index b83b222f817..223b16c43f1 100644 --- a/engine/src/flutter/tools/licenses_cpp/src/license_checker_unittests.cc +++ b/engine/src/flutter/tools/licenses_cpp/src/license_checker_unittests.cc @@ -227,6 +227,7 @@ TEST_F(LicenseCheckerTest, UnknownLicense) { std::vector errors = LicenseChecker::Run(temp_path->string(), ss, *data); EXPECT_EQ(errors.size(), 1u); + ASSERT_TRUE(!errors.empty()); EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound, "Unknown license in.*LICENSE")) << errors[0]; @@ -253,6 +254,38 @@ TEST_F(LicenseCheckerTest, SimpleMissingFileLicense) { "Expected copyright in.*main.cc")); } +TEST_F(LicenseCheckerTest, CanIgnoreLicenseFiles) { + absl::StatusOr temp_path = MakeTempDir(); + ASSERT_TRUE(temp_path.ok()); + + absl::StatusOr data = MakeTestData(); + ASSERT_TRUE(data.ok()); + + std::stringstream exclude; + exclude << ".*/LICENSE" << std::endl; + absl::StatusOr exclude_filter = Filter::Open(exclude); + ASSERT_TRUE(exclude_filter.ok()); + data->exclude_filter = std::move(exclude_filter.value()); + + fs::current_path(*temp_path); + ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok()); + ASSERT_TRUE(WriteFile(kLicense, *temp_path / "LICENSE").ok()); + Repo repo; + repo.Add(*temp_path / "main.cc"); + repo.Add(*temp_path / "LICENSE"); + ASSERT_TRUE(repo.Commit().ok()); + + std::stringstream ss; + std::vector errors = + LicenseChecker::Run(temp_path->string(), ss, *data); + EXPECT_EQ(errors.size(), 0u) << errors[0]; + + EXPECT_EQ(ss.str(), R"output(engine + +Copyright Test +)output"); +} + TEST_F(LicenseCheckerTest, SimpleWritesFileLicensesFile) { absl::StatusOr temp_path = MakeTempDir(); ASSERT_TRUE(temp_path.ok());