Code Monkey home page Code Monkey logo

gbb's Issues

支持编译目录下的符号链接目录

total 8240
-rw-r--r--   1 voidint  staff   634B  9 11 21:58 Dockerfile
-rw-r--r--   1 voidint  staff    11K 12 17  2016 LICENSE
-rw-r--r--   1 voidint  staff    13K  9 11 21:59 README.md
drwxr-xr-x   4 voidint  staff   136B  9 11 21:58 build
drwxr-xr-x  10 voidint  staff   340B  9 11 21:58 cmd
drwxr-xr-x   4 voidint  staff   136B  9 11 21:58 config
-rwxr-xr-x   1 voidint  staff   4.0M  9 19 14:09 gbb
-rw-r--r--   1 voidint  staff   455B  9 11 22:08 gbb.json
-rw-r--r--   1 voidint  staff   181B 12 17  2016 main.go
lrwxr-xr-x   1 voidint  staff    24B  9 13 13:35 ngrok -> /Users/voidint/bin/ngrok
drwxr-xr-x   8 voidint  staff   272B  9 11 21:58 tool
lrwxr-xr-x   1 voidint  staff    18B  9 19 13:59 tty -> /Users/voidint/tty
lrwxr-xr-x   1 voidint  staff    19B  9 13 13:52 tty2 -> /Users/voidint/tty2
drwxr-xr-x  10 voidint  staff   340B  9 19 13:28 util
drwxr-xr-x  10 voidint  staff   340B  9 11 21:58 variable
drwxr-xr-x   4 voidint  staff   136B  9  3  2017 vendor

以上面这个工程目录为例,要求做到如下几点:

  • 若链接源不存在,则给出错误提示。
  • 若链接的是一个非目录文件,则跳过,不作任何处理。如ngrok
  • 若提供了-a的命令行选项,则需要对链接的源目录及其子孙目录进行编译。

*NIX系统下通过shell对命令形式的变量表达式进行求值

{
    "version": "0.5.0",
    "tool": "go build  -ldflags='-s -w' -gcflags='-N -l'",
    "importpath": "github.com/voidint/gbb/build",
    "variables": [
        {
            "variable": "Branch",
            "value": "$(git branch | grep '*' | awk {'print $2'})"
        }
    ]
}

对于git branch | grep '*' | awk {'print $2'}这种由多个命令组合而成的复杂命令表达式,显然无法直接使用exec.Command()来获得最终结果。而通过shell来执行此类复杂命令,却可以极大简化整个表达式求值过程。

生成含丰富版本信息的可执行文件的功能作为可选功能出现

{
    "version": "0.0.1",
    "tool": "gb build",
    "package": "build",
    "variables": [
        {
            "variable": "Date",
            "value": "{{.date}}"
        },
        {
            "variable": "Commit",
            "value": "{{.gitCommit}}"
        }
    ]
}

以上gbb.json中的packagevariables作为可选配置项,若没有这两项内容,那么gbb就是一个单纯的辅助编译工具。

gbb具有一键编译项目目录下所有入口程序的能力,如果手工执行go build/install去编译issue#4中所提到的这类项目,那会有多么繁琐。

错误信息输出不够友好

类似这样的错误输出,不明确到底是gbb在调用其他工具时报错,还是gbb本身报错。

$ gbb --debug
exit status 128

debug信息缺少变量表达式求值的信息

{
    "version": "0.2.0",
    "tool": "go build",
    "package": "github.com/voidint/gbb/build",
    "variables": [
        {
            "variable": "Date",
            "value": "{{.date}}"
        },
        {
            "variable": "Commit",
            "value": "{{.gitCommit}}"
        }
    ]
}

对于以上{{.date}}{{.gitCommit}}这类表达式的求值过程并没有在debug信息中输出。在没有debug信息情况下,如果在变量表达式求值的过程中发生错误,错误的定位将比较困难。

添加build子命令

  • 添加build子命令,将现有的gbb编译功能代码转移到build子命令下。
  • 理想情况下,兼容现有gbb调用方式。即未指定子命令(即只输入了gbb)情况下,则等价于调用gbb build。保持用户使用习惯不变。

支持在项目根目录通过go build/install编译整个项目

以下描述都有一个这样的前提:gbb.json中的tool属性指定的是go_build或者go_install

./github.com/voidint/test
├── gbb.json
└── main.go

对于这样目录形式的项目,那么在项目根目录(test)下执行gbb是可以编译成功的。

如果换成👇
./github.com/voidint/test
├── cmd
│   ├── cmd1
│   │   └── main.go
│   ├── cmd2
│   │   └── main.go
│   └── cmd3
│   └── main.go
└── gbb.json

这样的目录结构,在根目录(test)下执行gbb是没法直接编译的。今后将设法支持这种目录结构的编译,达到与gb相同的体验。

gbb.json中variables[].value内容支持“命令表达式”

{
    "version": "0.0.1",
    "tool": "go install",
    "package": "main",
    "variables": [
        {
            "variable": "Date",
            "value": "{{.date}}"
        },
        {
            "variable": "Commit",
            "value": "{{.gitCommit}}"
        }
    ]
}

如上,{{.date}}{{.gitCommit}}都是内建表达式,这些表达式的逻辑是内建的,或者说逻辑都是硬编码的。应该支持通过执行命令来获得结果,比如👇

{
            "variable": "Commit",
            "value": "${git rev-parse HEAD}"
}

通过执行${}内的命令来获得最终的值。

gbb 的目的是什么

刚看到这个工具,之前我也遇到过类似的问题,我在 idcos/cloudcli 中用 makefile 的方式来处理的。
其实就是改下默认的编译命令,编译时动态赋值变量,比如(编译是加入当前的 revision number):

gb build -ldflags "-X main.build=git rev-parse HEAD"

golang 中 gb 这个工具的目的是管理golang 的工程,还可以安装,卸载,升级第三方包等。
gbb 这个工具的目的是类似的,还是只是为了编译。如果只是编译,其实可以用

alias gbb='gb build -ldflags "-X main.build=git rev-parse HEAD"' 之类的一行脚本就行。

添加clean子命令

假设待编译的项目结构类似这样

./go
└── cmd
    ├── cmd1
    │   └── main.go
    ├── cmd2
    │   └── main.go
    └── cmd3
        └── main.go

并且在gbb.json中指定的toolgo build,那么编译后必然在每个cmd子目录下留下一个可执行文件。原生的go clean命令仅支持清除当前目录下的编译产物,gbb clean将遍历所有的子命令目录并清除编译产物。

gbb clean命令将支持go clean命令的所有命令行选项:

The -i flag causes clean to remove the corresponding installed
archive or binary (what 'go install' would create).

The -n flag causes clean to print the remove commands it would execute,
but not run them.

The -r flag causes clean to be applied recursively to all the
dependencies of the packages named by the import paths.

The -x flag causes clean to print remove commands as it executes them.

若gbb.json的tool属性值包含空格则无法正常编译

{
    "version": "0.4.0",
    "tool": "go build -gcflags='-N -l'",
    "importpath": "github.com/voidint/gbb/build",
    "variables": [
        {
            "variable": "Date",
            "value": "{{.Date}}"
        },
        {
            "variable": "Commit",
            "value": "{{.GitCommit}}"
        }
    ]
}

若使用以上的配置文件,那么无法进行正常的编译。

strings.Fields("go build -gcflags='-N -l'")将拆分成gobuild-gcflags='-N-l',与预期不符。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.