Skip to content

Commit

Permalink
Issue 6364 Bump copyright notice (#6375)
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Feb 21, 2022
1 parent 9199e44 commit f289b76
Show file tree
Hide file tree
Showing 1,828 changed files with 10,332 additions and 2,857 deletions.
227 changes: 121 additions & 106 deletions apply_license.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/usr/bin/env python3
import os
import time
import re
import subprocess

LICENSE = '''Copyright 2020 The Defold Foundation
RE_LICENSE = r"(.*?\n?\r?)[/#;-]?[/#;-]\sCopyright .* The Defold Foundation.*specific language governing permissions and limitations under the License.(.*)"

YEAR = str(time.localtime().tm_year)
LICENSE = ('''Copyright 2020-%s The Defold Foundation
Copyright 2014-2020 King
Copyright 2009-2014 Ragnar Svensson, Christian Murray
Licensed under the Defold License version 1.0 (the "License"); you may not use
this file except in compliance with the License.
Expand All @@ -10,28 +19,35 @@
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.'''

extensions = [ ".h", ".c", ".cpp", ".inl", ".m", ".mm", ".sh", ".py", ".java", ".clj", ".go", ".lua" ]

ext_to_comment = {
".h": "// ",
".c": "// ",
".cpp": "// ",
".inl": "// ",
".m": "// ",
".mm": "// ",
".java": "// ",
".sh": "# ",
".py": "# ",
".clj": ";; ",
".go": "// ",
".lua": "-- ",
specific language governing permissions and limitations under the License.''') % YEAR

def license(comment):
return "\n".join([comment + line for line in LICENSE.split("\n")])

# map extensions to strings with the commented license
ext_to_license = {
".h": license("// "),
".c": license("// "),
".cpp": license("// "),
".inl": license("// "),
".m": license("// "),
".mm": license("// "),
".java": license("// "),
".sh": license("# "),
".py": license("# "),
".clj": license(";; "),
".lua": license("-- "),
".script": license("-- "),
".gui_script": license("-- "),
".render_script": license("-- "),
}

exluded_files = [
excluded_files = [
"apply_license.py"
"ddfc.py",
"edn.lua",
"mobdebug.lua",
"start.lua",
"test_props.lua",
"test_props_url.lua",
"test_props_number.lua",
Expand All @@ -40,112 +56,111 @@
"test_props_vec4.lua",
"test_props_quat.lua",
"test_props_bool.lua",
"test_props_material.lua"
"test_props_material.lua",
# resource test files:
"file5.script",
"liveupdate.file6.script",
]

exluded_patterns = [
"build/"
"dynamo_home/"
"engine/glfw/tests",
"engine/glfw/examples",
"engine/sound/src/openal",
"dlib/src/zlib",
"lua/src/lua",
"lua/scripts",
"script/src/luasocket",
"script/src/bitop",
"com.dynamo.cr.bob/generated",
"luajit",
"jagatoo",
"Box2D",
"jsmn",
"msbranco"
excluded_paths = [
"./.git",
"./.github",
"./external",
"./engine/dlib/src/basis/encoder",
"./engine/dlib/src/basis/transcoder",
"./engine/dlib/src/dlib/jsmn",
"./engine/dlib/src/lz4",
"./engine/dlib/src/mbedtls",
"./engine/dlib/src/stb",
"./engine/dlib/src/zlib",
"./engine/glfw/tests",
"./engine/glfw/examples",
"./engine/lua",
"./engine/physics/src/box2d",
"./engine/sound/src/openal",
"./engine/script/src/bitop",
"./engine/script/src/luasocket",
"./com.dynamo.cr/com.dynamo.cr.bob/src/org/jagatoo",
]

include_patterns = [
"rig.cpp",
"dstrings.cpp",
"package_win32_sdk.sh",
"Protocol.java",
"script_bitop.cpp",
]
dryrun = False


def match_patterns(s, patterns):
for pattern in patterns:
if pattern in s:
return True
return False

def skip_path(fullpath):
return match_patterns(fullpath, excluded_paths)

def force_include(fullpath):
if match_patterns(fullpath, include_patterns):
return True
return False

def skip_filename(fullpath, basename):
if basename in exluded_files:
return True

if match_patterns(fullpath, exluded_patterns):
return True
def skip_filename(fullpath):
return match_patterns(fullpath, excluded_files)

return False
def has_defold_license(s):
return re.search(RE_LICENSE, s[0:2000], flags=re.DOTALL) is not None

def has_other_license(s):
return "Copyright" in s or "License" in s
return ("Copyright" in s or "License" in s) and not ("The Defold Foundation" in s)

def get_comment_style_for_file(fullpath):
ext = os.path.splitext(fullpath)[1]
if ext == ".go" and not fullpath.startswith("./go/"):
def get_license_for_file(filepath):
ext = os.path.splitext(filepath)[1]
if not ext in ext_to_license:
return None
return ext_to_comment.get(ext)
return ext_to_license[ext]

def apply_license(license, contents):
# Preserve shebang
if contents.startswith("#!"):
firstline = contents.partition('\n')[0]
contents = contents.replace(firstline, "")
license = firstline + "\n" + license
return license + "\n\n" + contents

def check_ignored(path):
return subprocess.call(['git', 'check-ignore', '-q', path]) == 0

for subdir, dirs, files in os.walk("."):
# Ignore tmp and build folders
if subdir.startswith("./tmp") or "build" in subdir:
continue
for file in files:
filepath = subdir + os.sep + file
ext = os.path.splitext(filepath)[1]
if ext not in extensions:
continue

comment = get_comment_style_for_file(filepath)
if comment is None:
continue

should_include = force_include(filepath)
if not should_include and skip_filename(filepath, file):
print("Excluded " + filepath)
continue

with open(filepath, "rb+") as f:
contents = f.read()
# Already applied the Defold License?
if "Defold Foundation" in contents:
print("Already applied Defold license to " + filepath)
continue;

# Some other license in the file
if not should_include and has_other_license(contents):
print("Other license in " + filepath)
continue;

# Make the license text into a language specific comment, based on extension
lines = LICENSE.split("\n")
lines = [comment + line for line in lines]
license = "\n".join(lines)

# Preserve shebang
if contents.startswith("#!"):
firstline = contents.partition('\n')[0]
contents = contents.replace(firstline, "")
license = firstline + "\n" + license

print("Applying Defold License to " + filepath + (" (force included)" if should_include else ""))


def process_file(filepath):
# skip ignored files
if skip_filename(os.path.basename(file)) or check_ignored(filepath):
return

license = get_license_for_file(filepath)
if not license:
return

with open(filepath, "rb+") as f:
contents = f.read().decode('utf-8')

# Some other license in the file
if has_other_license(contents):
return;

# Already applied the Defold License?
# Remove it and reapply if file has been modified after license year
if has_defold_license(contents):
contents = re.sub(RE_LICENSE, r"\1" + license + r"\2", contents, flags=re.DOTALL)
print("Updated: " + filepath)
else:
contents = apply_license(license, contents)
print("Applied: " + filepath)

if not dryrun:
f.seek(0)
f.write(license + "\n\n")
f.write(contents)
f.write(contents.encode('utf-8'))
f.truncate()


for root, dirs, files in os.walk(".", topdown=True):
# exclude dirs to avoid traversing them at all
# with topdown set to True we can make in place modifications of dirs to
# have os.walk() skip directories
dirs[:] = [ d for d in dirs if not skip_path(os.path.join(root, d)) and not check_ignored(os.path.join(root, d)) ]

for file in files:
process_file(os.path.join(root, file))

print("NOTE! Manually update ddfc.py!")
15 changes: 15 additions & 0 deletions build_tools/BuildUtility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#! /usr/bin/env python
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.



import os, subprocess, exceptions;

Expand Down
16 changes: 15 additions & 1 deletion build_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
#! /usr/bin/env python
#! /usr/bin/env python
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

14 changes: 14 additions & 0 deletions build_tools/github.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import mimetypes

def _fix_url(url):
Expand Down
14 changes: 14 additions & 0 deletions build_tools/http_cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import sys, os, os.path, glob, urlparse, urllib2
from urllib2 import HTTPError

Expand Down
14 changes: 14 additions & 0 deletions build_tools/log.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import sys

def log(msg):
Expand Down
14 changes: 14 additions & 0 deletions build_tools/release_to_github.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from datetime import datetime
from log import log
from string import Template
Expand Down
14 changes: 14 additions & 0 deletions build_tools/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from log import log
import subprocess
import sys
Expand Down
Loading

0 comments on commit f289b76

Please sign in to comment.