From 287b4f66113d97eb8c68c677dce90f49f306200e Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Mon, 29 Oct 2018 10:42:59 +0200 Subject: [PATCH] Add license header converter --- apply_boilerplate.rb | 90 +++++++++++++++++++++++++++++++++++++++++ license_header | 22 ++++++++++ original_license_header | 20 +++++++++ 3 files changed, 132 insertions(+) create mode 100755 apply_boilerplate.rb create mode 100644 license_header create mode 100644 original_license_header diff --git a/apply_boilerplate.rb b/apply_boilerplate.rb new file mode 100755 index 000000000..cb083dd27 --- /dev/null +++ b/apply_boilerplate.rb @@ -0,0 +1,90 @@ +#!/usr/bin/env ruby +# +# Part of Metta OS. Check https://metta.systems for latest version. +# +# Copyright Stanislav Karchebnyy +# +# Distributed under the Boost Software License, Version 1.0. +# (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt) +# +# Apply license changes to text source files. +# Run as ./apply_boilerplate.rb +# +require 'find' + +exclude_dirs = ['./_build_', './_conan_build_', './Telegram/ThirdParty'] +# Files that shouldn't update license headers +no_license = [ + './apply_boilerplate.rb', + './Telegram/Resources/winrc/resource.h', + './Telegram/SourceFiles/qt_functions.cpp', + './Telegram/SourceFiles/backports/is_invocable.h', + './Telegram/SourceFiles/boxes/mute_settings_box.h', + './Telegram/SourceFiles/boxes/mute_settings_box.cpp' +] + +class Array + def do_not_has?(path) + count {|x| path.start_with?(x)} === 0 + end +end + +license = IO.readlines('license_header').join +orig_license = IO.readlines('original_license_header').join +exts = { + '.cpp'=>[license, orig_license], + '.c'=>[license, orig_license], + '.h'=>[license, orig_license], + '.m'=>[license, orig_license], + '.mm'=>[license, orig_license], + '.strings'=>[license, orig_license], + '.s'=>[license.gsub(/^\/\//,";"), orig_license], + '.rb'=>[license.gsub(/^\/\//,"#"), orig_license], + '.lua'=>[license.gsub(/^\/\//,"--"), orig_license], + '.if'=>[license.gsub(/^\/\//,"#"), orig_license] +} + +ok_count = 0 +modified_count = 0 +modified_files = [] + +Find.find('./') do |f| + ext = File.extname(f) + dir = File.dirname(f) + if File.file?(f) && exts.include?(ext) && exclude_dirs.do_not_has?(dir) + lic = exts[ext][0] + orig = exts[ext][1] + modified = false + content = IO.readlines(f).join + if !content.index(orig).nil? + # Strip-off original license header + content.gsub!(orig, '') + end + if content.index(lic).nil? && no_license.do_not_has?(dir) && no_license.do_not_has?(f) + content = lic + content + modified = true + end + if modified + File.open(f+".new", "w") do |out| + out.write content + end + begin + File.rename(f+".new", f) + rescue SystemCallError + puts "Couldn't rename file #{f+".new"} to #{f}:", $! + end + puts "#{f} is UPDATED" + modified_count += 1 + modified_files << f + else + puts "#{f} is ok" + ok_count += 1 + end + end +end + +puts "#{modified_count} files changed, #{ok_count} files ok." +unless modified_files.empty? + puts "Modified files:" + modified_files.each { |f| puts f } +end diff --git a/license_header b/license_header new file mode 100644 index 000000000..d40139780 --- /dev/null +++ b/license_header @@ -0,0 +1,22 @@ +// +// This file is part of Kepka, +// an unofficial desktop version of Telegram messaging app, +// see https://github.com/procxx/kepka +// +// Kepka is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// It is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// In addition, as a special exception, the copyright holders give permission +// to link the code of portions of this program with the OpenSSL library. +// +// Full license: https://github.com/procxx/kepka/blob/master/LICENSE +// Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +// Copyright (c) 2017- Kepka Contributors, https://github.com/procxx +// diff --git a/original_license_header b/original_license_header new file mode 100644 index 000000000..2aa4f28bf --- /dev/null +++ b/original_license_header @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/