Skip to content

Commit

Permalink
Add a script that checks that all source files have a valid license b…
Browse files Browse the repository at this point in the history
…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
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 841bb99 commit 74dff11
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 0 deletions.
4 changes: 4 additions & 0 deletions impeller/fixtures/sample.vert
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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 "types.h"

uniform UniformBufferObject {
Expand Down
2 changes: 2 additions & 0 deletions impeller/geometry/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ impeller_component("geometry") {
sources = [
"color.cc",
"color.h",
"constants.cc",
"constants.h",
"matrix.cc",
"matrix.h",
"matrix_decomposition.cc",
Expand Down
11 changes: 11 additions & 0 deletions impeller/geometry/constants.cc
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
4 changes: 4 additions & 0 deletions impeller/playground/imgui/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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("//flutter/impeller/tools/impeller.gni")

impeller_shaders("imgui_shaders") {
Expand Down
4 changes: 4 additions & 0 deletions impeller/playground/imgui/imgui_impl_impeller.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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 "imgui_impl_impeller.h"

#include <algorithm>
Expand Down
6 changes: 6 additions & 0 deletions impeller/playground/imgui/imgui_impl_impeller.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// 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.

#pragma once

#include <memory>

#include "third_party/imgui/imgui.h"

namespace impeller {

class Context;
class RenderPass;

} // namespace impeller

IMGUI_IMPL_API bool ImGui_ImplImpeller_Init(
Expand Down
4 changes: 4 additions & 0 deletions impeller/playground/imgui/imgui_raster.frag
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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.

in vec2 frag_texture_coordinates;
in vec4 frag_vertex_color;

Expand Down
4 changes: 4 additions & 0 deletions impeller/playground/imgui/imgui_raster.vert
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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.

uniform UniformBuffer {
mat4 mvp;
}
Expand Down
77 changes: 77 additions & 0 deletions impeller/tools/check_licenses.py
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()

0 comments on commit 74dff11

Please sign in to comment.