Skip to content

Commit 74dff11

Browse files
chinmaygardednfield
authored andcommitted
Add a script that checks that all source files have a valid license block. (#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/flutter#97686.
1 parent 841bb99 commit 74dff11

File tree

9 files changed

+116
-0
lines changed

9 files changed

+116
-0
lines changed

impeller/fixtures/sample.vert

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
#include "types.h"
26

37
uniform UniformBufferObject {

impeller/geometry/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ impeller_component("geometry") {
88
sources = [
99
"color.cc",
1010
"color.h",
11+
"constants.cc",
12+
"constants.h",
1113
"matrix.cc",
1214
"matrix.h",
1315
"matrix_decomposition.cc",

impeller/geometry/constants.cc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/geometry/constants.h"
6+
7+
namespace impeller {
8+
9+
//
10+
11+
} // namespace impeller

impeller/playground/imgui/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
15
import("//flutter/impeller/tools/impeller.gni")
26

37
impeller_shaders("imgui_shaders") {

impeller/playground/imgui/imgui_impl_impeller.cc

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
#include "imgui_impl_impeller.h"
26

37
#include <algorithm>

impeller/playground/imgui/imgui_impl_impeller.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
#pragma once
26

37
#include <memory>
48

59
#include "third_party/imgui/imgui.h"
610

711
namespace impeller {
12+
813
class Context;
914
class RenderPass;
15+
1016
} // namespace impeller
1117

1218
IMGUI_IMPL_API bool ImGui_ImplImpeller_Init(

impeller/playground/imgui/imgui_raster.frag

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
in vec2 frag_texture_coordinates;
26
in vec4 frag_vertex_color;
37

impeller/playground/imgui/imgui_raster.vert

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
uniform UniformBuffer {
26
mat4 mvp;
37
}

impeller/tools/check_licenses.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import argparse
6+
import os
7+
8+
9+
def ContainsLicenseBlock(source_file):
10+
# This check is somewhat easier than in the engine because all sources need to
11+
# have the same license.
12+
py_license = '''# Copyright 2013 The Flutter Authors. All rights reserved.
13+
# Use of this source code is governed by a BSD-style license that can be
14+
# found in the LICENSE file.'''
15+
c_license = py_license.replace("#", "//")
16+
17+
# Make sure we don't read the entire file into memory.
18+
read_size = (max(len(py_license), len(c_license)))
19+
20+
for license in [c_license, py_license]:
21+
with open(source_file) as source:
22+
if source.read(read_size).startswith(license):
23+
return True
24+
25+
return False
26+
27+
28+
def IsSourceFile(path):
29+
known_extensions = [
30+
".cc",
31+
".cpp",
32+
".c",
33+
".h",
34+
".hpp",
35+
".py",
36+
".sh",
37+
".gn",
38+
".gni",
39+
".glsl",
40+
".sl.h",
41+
".vert",
42+
".frag",
43+
".tesc",
44+
".tese",
45+
".yaml",
46+
".dart",
47+
]
48+
for extension in known_extensions:
49+
if os.path.basename(path).endswith(extension):
50+
return True
51+
return False;
52+
53+
54+
# Checks that all source files have the same license preamble.
55+
def Main():
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument("--source-root",
58+
type=str, required=True,
59+
help="The source root.")
60+
args = parser.parse_args()
61+
62+
assert(os.path.exists(args.source_root))
63+
64+
source_files = set()
65+
66+
for root, dirs, files in os.walk(os.path.abspath(args.source_root)):
67+
for file in files:
68+
file_path = os.path.join(root, file)
69+
if IsSourceFile(file_path):
70+
source_files.add(file_path)
71+
72+
for source_file in source_files:
73+
if not ContainsLicenseBlock(source_file):
74+
raise Exception("Could not find valid license block in source ", source_file)
75+
76+
if __name__ == '__main__':
77+
Main()

0 commit comments

Comments
 (0)