forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script that checks that all source files have a valid license b…
…lock. (flutter#63) Also fixes the files with missing licenses. This check is somewhat easy with Impeller than in the engine because all source files must have the same license block. Resolves an action item in the umbrella issue flutter#97686.
- Loading branch information
1 parent
841bb99
commit 74dff11
Showing
9 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2013 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. | ||
|
||
#include "impeller/geometry/constants.h" | ||
|
||
namespace impeller { | ||
|
||
// | ||
|
||
} // namespace impeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2013 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. | ||
|
||
import argparse | ||
import os | ||
|
||
|
||
def ContainsLicenseBlock(source_file): | ||
# This check is somewhat easier than in the engine because all sources need to | ||
# have the same license. | ||
py_license = '''# Copyright 2013 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.''' | ||
c_license = py_license.replace("#", "//") | ||
|
||
# Make sure we don't read the entire file into memory. | ||
read_size = (max(len(py_license), len(c_license))) | ||
|
||
for license in [c_license, py_license]: | ||
with open(source_file) as source: | ||
if source.read(read_size).startswith(license): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def IsSourceFile(path): | ||
known_extensions = [ | ||
".cc", | ||
".cpp", | ||
".c", | ||
".h", | ||
".hpp", | ||
".py", | ||
".sh", | ||
".gn", | ||
".gni", | ||
".glsl", | ||
".sl.h", | ||
".vert", | ||
".frag", | ||
".tesc", | ||
".tese", | ||
".yaml", | ||
".dart", | ||
] | ||
for extension in known_extensions: | ||
if os.path.basename(path).endswith(extension): | ||
return True | ||
return False; | ||
|
||
|
||
# Checks that all source files have the same license preamble. | ||
def Main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--source-root", | ||
type=str, required=True, | ||
help="The source root.") | ||
args = parser.parse_args() | ||
|
||
assert(os.path.exists(args.source_root)) | ||
|
||
source_files = set() | ||
|
||
for root, dirs, files in os.walk(os.path.abspath(args.source_root)): | ||
for file in files: | ||
file_path = os.path.join(root, file) | ||
if IsSourceFile(file_path): | ||
source_files.add(file_path) | ||
|
||
for source_file in source_files: | ||
if not ContainsLicenseBlock(source_file): | ||
raise Exception("Could not find valid license block in source ", source_file) | ||
|
||
if __name__ == '__main__': | ||
Main() |