Skip to content

Commit

Permalink
bali 1.2.0 support toml format project file
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Aug 4, 2020
1 parent fe5fc1a commit 4a89990
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bali /path/to/project -p -d /tmp/output

## Bali build file format

Bali chose JSON as the file format. The advantage of using JSON is that Golang has built-in support for parsing, and it can be formatted using an editor. There are two types of Bali build files. One is the project file `bali.json`, which is usually in the root directory of the project. It can also be used to create this file in other directories. When running the build, use `bali -w` or `bali /path/to/buildroot` specifies the directory where `bali.json` is located, you can also run `bali` in that directory; another build file is the `balisrc.json` file under the specific program source code directory, `balisrc.json` There should be a `main` package in the directory where bali resolves `balisrc.json` by parsing `dirs` of `bali.json`, similar to the `add_subdirectory` instruction of `cmake`. Examples of both are as follows:
You can choose to write project files in json or toml format.. There are two types of Bali build files. One is the project file `bali.json`(`bali.toml`), which is usually in the root directory of the project. It can also be used to create this file in other directories. When running the build, use `bali -w` or `bali /path/to/buildroot` specifies the directory where `bali.json` is located, you can also run `bali` in that directory; another build file is the `balisrc.json`(`balisrc.toml`) file under the specific program source code directory, `balisrc.json` There should be a `main` package in the directory where bali resolves `balisrc.json` by parsing `dirs` of `bali.json`, similar to the `add_subdirectory` instruction of `cmake`. Examples of both are as follows:

Project file `bali.json`:

Expand Down Expand Up @@ -109,6 +109,24 @@ Project file `bali.json`:
}
```

Project file `bali.toml`:

```toml
# https://toml.io/en/
name = "bali"
version = "1.2.0"
dirs = [
"cmd/bali", # dirs
]

[[files]]
path = "LICENSE"
destination = "share"
newname = "LICENSE.bali"
norename = true

```

Built-in environment variables:

+ `BUILD_VERSION` is filled by the `version` field of balisrc.json
Expand Down Expand Up @@ -149,6 +167,24 @@ Program build file `balisrc.json`:
}
```

Program build file `balisrc.toml`:

```toml
name = "bali"
description = "Bali - Minimalist Golang build and packaging tool"
destination = "bin"
version = "1.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
links = ["bin/baligo"]
goflags = [
"-ldflags",
"-X 'main.VERSION=$BUILD_VERSION' -X 'main.BUILDTIME=$BUILD_TIME' -X 'main.BUILDBRANCH=$BUILD_BRANCH' -X 'main.BUILDCOMMIT=$BUILD_COMMIT' -X 'main.GOVERSION=$BUILD_GOVERSION'",
]

```

`versioninfo.json:`

```json
Expand Down
40 changes: 38 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bali /path/to/project -p -d /tmp/output

## Bali 构建文件格式

Bali 选择了 JSON 作为文件格式,使用 JSON 的好处在于 Golang 内置支持解析,并且可以使用编辑器的格式化。Bali 构建文件有两种,一种是项目文件 `bali.json`,通常在项目根目录下,用于也可以在其他目录创建此文件,运行构建时,通过 `bali -w` 或者 `bali /path/to/buildroot` 指定 `bali.json` 所在目录,也可以在那个目录下运行 `bali`;另一种构建文件是特定程序源码目录下的 `balisrc.json` 文件,`balisrc.json` 所在目录应当存在 `main` 包,bali 通过解析 `bali.json``dirs` 解析 `balisrc.json`,与 `cmake``add_subdirectory` 指令类似。二者示例如下:
Bali 同时支持 TOML 或者 JSON 格式的项目文件,JSON 使用内置解析不支持注释,TOML 支持注释。Bali 构建文件有两种,一种是项目文件 `bali.json`(`bali.toml`),通常在项目根目录下,用于也可以在其他目录创建此文件,运行构建时,通过 `bali -w` 或者 `bali /path/to/buildroot` 指定 `bali.json` 所在目录,也可以在那个目录下运行 `bali`;另一种构建文件是特定程序源码目录下的 `balisrc.json`(`balisrc.toml`) 文件,`balisrc.json` 所在目录应当存在 `main` 包,bali 通过解析 `bali.json``dirs` 解析 `balisrc.json`,与 `cmake``add_subdirectory` 指令类似。二者示例如下:

项目文件 `bali.json`:

Expand Down Expand Up @@ -101,6 +101,24 @@ Bali 选择了 JSON 作为文件格式,使用 JSON 的好处在于 Golang 内
}
```

项目文件 `bali.toml`:

```toml
# https://toml.io/en/
name = "bali"
version = "1.2.0"
dirs = [
"cmd/bali", # dirs
]

[[files]]
path = "LICENSE"
destination = "share"
newname = "LICENSE.bali"
norename = true

```

程序构建文件 `balisrc.json`:

```js
Expand Down Expand Up @@ -131,9 +149,27 @@ Bali 选择了 JSON 作为文件格式,使用 JSON 的好处在于 Golang 内
}
```

程序构建文件 `balisrc.toml`:

```toml
name = "bali"
description = "Bali - Minimalist Golang build and packaging tool"
destination = "bin"
version = "1.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
links = ["bin/baligo"]
goflags = [
"-ldflags",
"-X 'main.VERSION=$BUILD_VERSION' -X 'main.BUILDTIME=$BUILD_TIME' -X 'main.BUILDBRANCH=$BUILD_BRANCH' -X 'main.BUILDCOMMIT=$BUILD_COMMIT' -X 'main.GOVERSION=$BUILD_GOVERSION'",
]

```

内置环境变量:

+ `BUILD_VERSION` 由 balisrc.json 的 `version` 字段填充
+ `BUILD_VERSION` 由 balisrc.json/balisrc.toml`version` 字段填充
+ `BUILD_TIME` 由构建时间按照 `RFC3339` 格式化后填充
+ `BUILD_COMMIT` 由存储库(为 git 存储库时) 的 commit id 填充
+ `BUILD_GOVERSION``go version` 输出(删除了 `go version` 前缀)填充
Expand Down
2 changes: 1 addition & 1 deletion bali.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bali",
"version": "1.1.0",
"version": "1.2.0",
"files": [
{
"path": "LICENSE",
Expand Down
2 changes: 1 addition & 1 deletion bali.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://toml.io/en/
name = "bali"
version = "1.1.0"
version = "1.2.0"
dirs = [
"cmd/bali", # dirs
]
Expand Down
2 changes: 1 addition & 1 deletion cmd/bali/balisrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bali",
"description": "Bali - Minimalist Golang build and packaging tool",
"destination": "bin",
"version": "1.1.0",
"version": "1.2.0",
"links": [
"bin/baligo"
],
Expand Down
2 changes: 1 addition & 1 deletion cmd/bali/balisrc.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "bali"
description = "Bali - Minimalist Golang build and packaging tool"
destination = "bin"
version = "1.1.0"
version = "1.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bali/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func init() {
// becasue we print message to stderr
h := os.Stderr.Fd()
if r, _, _ := procGetConsoleMode.Call(h, uintptr(unsafe.Pointer(&mode))); r != 0 {
procSetConsoleMode.Call(h, uintptr(mode|EnableVirtualTerminalProcessingMode))
_, _, _ = procSetConsoleMode.Call(h, uintptr(mode|EnableVirtualTerminalProcessingMode))
}
}

0 comments on commit 4a89990

Please sign in to comment.