mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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]. <!-- Links --> [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
This commit is contained in:
parent
f8f9506fc0
commit
bc30d1cd41
@ -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/.*
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
.*
|
||||
@ -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\.
|
||||
|
||||
@ -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.
|
||||
27
engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt
Normal file
27
engine/src/flutter/tools/licenses_cpp/data/licenses/sgi.txt
Normal file
@ -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.
|
||||
@ -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.
|
||||
@ -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 <https://www.unicode.org/copyright.html>
|
||||
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.
|
||||
21
engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt
Normal file
21
engine/src/flutter/tools/licenses_cpp/data/licenses/zlib.txt
Normal file
@ -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.
|
||||
@ -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<std::string> 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");
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<std::string_view, 4> kLicenseFileNames = {
|
||||
@ -68,10 +68,11 @@ absl::StatusOr<std::vector<std::string>> GitLsFiles(const fs::path& repo_path) {
|
||||
return files;
|
||||
}
|
||||
|
||||
std::optional<fs::path> FindLicense(const fs::path& path) {
|
||||
std::optional<fs::path> 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<fs::path> 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<fs::path> current_license = FindLicense(current);
|
||||
std::optional<fs::path> current_license = FindLicense(data, current);
|
||||
if (current_license.has_value()) {
|
||||
result.license_file = current_license;
|
||||
}
|
||||
@ -247,7 +250,7 @@ std::vector<absl::Status> 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());
|
||||
|
||||
@ -227,6 +227,7 @@ TEST_F(LicenseCheckerTest, UnknownLicense) {
|
||||
std::vector<absl::Status> 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<fs::path> temp_path = MakeTempDir();
|
||||
ASSERT_TRUE(temp_path.ok());
|
||||
|
||||
absl::StatusOr<Data> data = MakeTestData();
|
||||
ASSERT_TRUE(data.ok());
|
||||
|
||||
std::stringstream exclude;
|
||||
exclude << ".*/LICENSE" << std::endl;
|
||||
absl::StatusOr<Filter> 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<absl::Status> 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<fs::path> temp_path = MakeTempDir();
|
||||
ASSERT_TRUE(temp_path.ok());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user