Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qexport 增强建议:支持合并既有的导出包 #76

Closed
xushiwei opened this issue May 21, 2016 · 2 comments
Closed

qexport 增强建议:支持合并既有的导出包 #76

xushiwei opened this issue May 21, 2016 · 2 comments
Assignees
Milestone

Comments

@xushiwei
Copy link
Member

xushiwei commented May 21, 2016

既有的导出包如果已经存在,里面可能有部分代码是手工改动后的,直接覆盖不是很合适。建议:

如果已经存在目标的包,则找到目标包的 Exports 表,如果里面已经存在某个函数就不必再导出。例如假设我们要导出一个名为 foo 的包,但是这个目标包已经存在,内容如下:

package foo
...

// Exports is the export table of this module.
//
var Exports = map[string]interface{}{
    "bar": newBar,
    ...
}

比较适合的执行流程是:

  • 在 Exports 表前插入可能新增的一些代码
  • 在 Exports 表尾部插入还没有添加到表中的函数

另外还有一个需要注意的细节是:有些 Exports 函数由于是特定版本增加的,它未必出现在 Exports 表中,而是通过 func init() 函数添加。例如:

// +build go1.6

package runtime

import "runtime"

func init() {
    Exports["readTrace"] = runtime.ReadTrace
    Exports["startTrace"] = runtime.StartTrace
    Exports["stopTrace"] = runtime.StopTrace
}

对于这样的函数,也没有必要在 Exports 表中重复添加。

@xushiwei xushiwei added this to the qlang.v3 milestone May 21, 2016
@visualfc
Copy link
Member

visualfc commented Jun 7, 2016

#112 支持特定版本导出

@visualfc
Copy link
Member

#137
支持包合并功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants