linuxdeepin / developer-center

Deepin developer center, provide developer wiki and community forum.
452 stars 73 forks source link

统一调整源码中 Copyright 格式 #30

Closed fasheng closed 8 years ago

fasheng commented 8 years ago

现统一使用下面的 Copyright 格式,其中年份是当前文件创建时所在的年份,且后期无需累计(即不要更改为 2015-20162015, 2016

/**
 * Copyright (C) 2015 Deepin Technology Co., Ltd.
 *
 * This program 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.
 **/

若没有问题,随后会把需要调整的项目列表及负责人贴上。 @linuxdeepin/dde-team @linuxdeepin/app-team

Iceyer commented 8 years ago

Author/Maintainer都不用了?

snyh commented 8 years ago

可以做一个CI检测吧.  实现起来也比较简单.  也能节省以后的人工复查问题 Auhtor/Maintainer就自动描生成吧. git shortlog -n -s -e | cut -f2- | sort

Iceyer commented 8 years ago

也好,反正Copyright写了也不会有人想去修改的 :smile:

fasheng commented 8 years ago

CI 检测不清楚好不好实现。。。

  1. 先判断是不是有效的源码文件
  2. 判断头部有没有特定的 Copyright 信息,又分两步: 1) 如果是 go 源码,要处理第一行 //+build 2) 处理不同类型的 comment 格式
snyh commented 8 years ago

我很怀疑 jenkis已经有这方面的插件了.  我去检测检查.

自己实现的话,其实不需要那么准确, 比如前200行里面如果有Copyright的格式就算通过了. (即使判断错误也没多大个事.)

snyh commented 8 years ago

@choldrim 看看自动化这个能玩不.  我们其他人先在 @fasheng 的带领下 人肉进行这个任务.

fasheng commented 8 years ago

需要调整的项目列表如下,修改完成后在前面打上对号即可(应该有权限吧) :)

@jouyouyun

@kosl90

@Iceyer

@XuShaohua

@Match-Yang

@dragondjf

@hualet

@sbwtw

@pangpangpang3

@sonald

@fasheng

@snyh

sbwtw commented 8 years ago

这个东西应该有小工具管理的吧

fasheng commented 8 years ago

有工具,不过都不是太好用

fasheng commented 8 years ago

忘了说,review topic 就用 improve-copyright 吧~

Iceyer commented 8 years ago

for f in $(find /tmp -name '.cpp' -or -name '.h'); do cat ~/copyright.txt $f >$f.new && mv $f.new $f done

tmp 和 ~/copyright.txt位置改成自己的 谨慎使用 :laughing:

sbwtw commented 8 years ago

要的就是这种神奇的小命令~

On 01/02/16 15:23, Iceyer wrote:

for f in $(find /tmp -name '/.cpp' -or -name '/.h'); do cat ~/copyright.txt $f >$f.new && mv $f.new $f done

谨慎使用 :laughing:

— Reply to this email directly or view it on GitHub https://github.com/linuxdeepin/developer-center/issues/30#issuecomment-177820751.

石博文

fasheng commented 8 years ago

上面的命令只能给未添加过任何 Copyright 信息的项目使用啊,等下会构建个用于更新已有 Copyright 的bash 命令,不过也无法通吃。。。

fasheng commented 8 years ago
begin='\/\*\*\n'   # => "\**"
end=' \*\*\/\n'     # => " **/"
words='Copyright'
replace='/**
 * Copyright (C) 2015 Deepin Technology Co., Ltd.
 *
 * This program 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.
 **/'

find . -type f -iname '*.go' | xargs perl -0777pe 's#'"${begin}"'(?:(?!'"${end}"').)*?'"${words}"'.*?\n'"${end}"'#'"${replace}"'\n#s' -i

把命令贴到 bash 即可,可以更新 go 源码中已有的 Copyright 内容,无法正确处理年份,直接写死的 2015 。。

sbwtw commented 8 years ago

libdui 和 dde-control-center 已改,但我的确没有权限 :(

fasheng commented 8 years ago

@sbwtw 再试下看看 :)

sbwtw commented 8 years ago

@fasheng 搞定 ˊ_>ˋ

Match-Yang commented 8 years ago

我的也勾不上额

fasheng commented 8 years ago

@Match-Yang 额,你还没加入组织,看 github 的系统提示…

Match-Yang commented 8 years ago

什么组织,没有提示呀

fasheng commented 8 years ago

你进入 github linuxdeepin 主页,会有 invitation 提示

Match-Yang commented 8 years ago

好了

sonald commented 8 years ago

@fasheng deepin-metacity 改copyright好么,原始代码都是第三方的

fasheng commented 8 years ago

@sonald 嗯,只改我们自己创建的文件

sonald commented 8 years ago
#!/bin/bash 

# store content in license.txt
if [ ! -f license.txt ]; then
cat > license.txt <<EOF
/**
 * Copyright (C) 2015 Deepin Technology Co., Ltd.
 *
 * This program 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.
 **/
EOF

fi

declare -a range
range=(`awk -e '
$0 ~ /\/\*/ { start = NR; has_copyright = 0; }
$0 ~ /copyright/i { has_copyright = 1; }
$0 ~ /\*\// { 
    if (has_copyright) {
        end = NR;
        exit;
    }
    start = 0; 
    has_copyright = 0;
}

END { print start, end }
' $1`)

#echo ${range[0]}
#echo ${range[1]}

sed -i -e "${range[0]},${range[1]}d" -e "${range[0]},${range[0]}r license.txt" $1
if [[ $? != 0 ]]; then
    echo "failed for $1"
fi

我用来改C代码的脚本,好费劲

fasheng commented 8 years ago

:+1:

hualet commented 8 years ago

搞定了,太不容易了。。。

fasheng commented 8 years ago

感谢大家的协助, copyright 的格式问题基本处理完毕. 另今天花时间写了个检测工具把漏掉的文件又处理了一遍, 应该没什么太大问题了, 先关闭任务.

copyright 小工具的使用说明可以参考这里 https://github.com/linuxdeepin/team-robots/tree/master/update-copyright (虽然来的有点晚, 不过至少下次不用这么折腾了~

manateelazycat commented 8 years ago

路过点赞!

sonald commented 8 years ago

话说update-copyright有个函数看着好眼熟啊:)

fasheng commented 8 years ago

嘻嘻, 参考了曹哥的awk脚本 ;)