Skip to content

Commit

Permalink
update depends cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Apr 27, 2024
1 parent 532980b commit 8f235e1
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
bali_suffix: zip
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Bootstrap Bali
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Project file `bali.toml`:
```toml
# https://toml.io/en/
name = "bali"
version = "2.1.1"
version = "2.2.0"
dirs = [
"cmd/bali", # dirs
]
Expand Down Expand Up @@ -113,7 +113,7 @@ Program build file `balisrc.toml`:
name = "bali"
description = "Bali - Minimalist Golang build and packaging tool"
destination = "bin"
version = "2.1.1"
version = "2.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Bali 同时支持 TOML 或者 JSON 格式的项目文件,JSON 使用内置解
```toml
# https://toml.io/en/
name = "bali"
version = "2.1.1"
version = "2.2.0"
dirs = [
"cmd/bali", # dirs
]
Expand All @@ -94,7 +94,7 @@ norename = true
name = "bali"
description = "Bali - Minimalist Golang build and packaging tool"
destination = "bin"
version = "2.1.1"
version = "2.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
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 = "2.1.1"
version = "2.2.0"
dirs = [
"cmd/bali", # dirs
"cmd/peassets",
Expand Down
6 changes: 3 additions & 3 deletions cmd/bali/bali.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"

"github.com/balibuild/bali/v2/base"
"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
)

// Executable todo
Expand Down Expand Up @@ -92,8 +92,8 @@ func (bm *Project) FileConfigure(workdir, outdir string) error {
return nil
}

// LoadTomlMetadata todo
func LoadTomlMetadata(file string, v interface{}) error {
// LoadMetadata todo
func LoadMetadata(file string, v interface{}) error {
fd, err := os.Open(file)
if err != nil {
return err
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 = "2.1.1"
version = "2.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/bali.ico"
manifest = "res/bali.manifest"
Expand Down
6 changes: 3 additions & 3 deletions cmd/bali/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (exe *Executable) MakeResources(wd, syso, binaryName string, be *Executor)
return base.ErrorCat("load manifest: ", err.Error())
}
}
b.FillVersion(exe.Version, be.bm.Version)
b.UpdateName(binaryName, be.bm.Name, exe.Description)
b.FillVersion(exe.Version, be.project.Version)
b.UpdateName(binaryName, be.project.Name, exe.Description)
return b.WriteSyso(syso, be.arch)
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func (be *Executor) loadExecutable(wd string) (*Executable, error) {
}
DbgPrint("%s support toml metadata", wd)
var exe Executable
if err := LoadTomlMetadata(balisrc, &exe); err != nil {
if err := LoadMetadata(balisrc, &exe); err != nil {
return nil, err
}
return &exe, nil
Expand Down
74 changes: 37 additions & 37 deletions cmd/bali/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type Executor struct {
makezip bool
zipmethod uint16
makepack bool
norename bool
noNewName bool
cleanup bool
environ []string // initialize environment
binaries []string
linkmap map[string]string
bm Project
project Project
suffix string
forceVerion string
withoutVersion bool
Expand Down Expand Up @@ -98,7 +98,7 @@ func (be *Executor) initializeProject() error {
return os.ErrNotExist
}
DbgPrint("%s support toml metadata", be.workdir)
return LoadTomlMetadata(balitoml, &be.bm)
return LoadMetadata(balitoml, &be.project)
}

// Initialize todo
Expand All @@ -107,10 +107,10 @@ func (be *Executor) Initialize() error {
return err
}
if len(be.forceVerion) != 0 {
be.bm.Version = be.forceVerion
be.project.Version = be.forceVerion
}
if len(be.bm.Version) == 0 {
be.bm.Version = "0.0.1"
if len(be.project.Version) == 0 {
be.project.Version = "0.0.1"
}
be.de = base.NewDerivator()
// Respect environmental variable settings
Expand Down Expand Up @@ -171,15 +171,15 @@ func (be *Executor) ExpandEnv(s string) string {

// TargetName todo
func (be *Executor) TargetName(name string) string {
if be.norename {
if be.noNewName {
return name
}
return base.StrCat(name, ".new")
}

// FileName todo
func (be *Executor) FileName(file *File) string {
if be.norename || file.NoRename {
if be.noNewName || file.NoRename {
return file.Base()
}
return base.StrCat(file.Base(), ".template")
Expand Down Expand Up @@ -210,17 +210,17 @@ func (be *Executor) PathInArchive(destination string) string {
return destination
}
if be.withoutVersion {
return filepath.Join(base.StrCat(be.bm.Name, "-", be.target, "-", be.arch), destination)
return filepath.Join(base.StrCat(be.project.Name, "-", be.target, "-", be.arch), destination)
}
return filepath.Join(base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, "-", be.bm.Version), destination)
return filepath.Join(base.StrCat(be.project.Name, "-", be.target, "-", be.arch, "-", be.project.Version), destination)
}

// Build todo
func (be *Executor) Build() error {
if err := be.bm.FileConfigure(be.workdir, be.out); err != nil {
if err := be.project.FileConfigure(be.workdir, be.out); err != nil {
return err
}
for _, d := range be.bm.Dirs {
for _, d := range be.project.Dirs {
wd := filepath.Join(be.workdir, d)
if err := be.Compile(wd); err != nil {
fmt.Fprintf(os.Stderr, "bali compile: \x1b[31m%s\x1b[0m\n", err)
Expand All @@ -246,25 +246,25 @@ func (be *Executor) Compress() error {
var outname string
if be.target == "windows" {
if be.withoutVersion {
outname = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, ".zip")
outname = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, ".zip")
} else {
outname = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, "-", be.bm.Version, ".zip")
outname = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, "-", be.project.Version, ".zip")
}
outfile = filepath.Join(be.destination, outname)
if fd, err = os.Create(outfile); err != nil {
return err
}
mw = io.MultiWriter(fd, h)
zpk := pack.NewZipPackerEx(mw, be.zipmethod)
if len(be.bm.Destination) != 0 {
zpk.SetComment(be.bm.Destination)
if len(be.project.Destination) != 0 {
zpk.SetComment(be.project.Destination)
}
pk = zpk
} else {
if be.withoutVersion {
outname = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, ".tar.gz")
outname = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, ".tar.gz")
} else {
outname = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, "-", be.bm.Version, ".tar.gz")
outname = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, "-", be.project.Version, ".tar.gz")
}

outfile = filepath.Join(be.destination, outname)
Expand Down Expand Up @@ -301,7 +301,7 @@ func (be *Executor) Compress() error {
return err
}
}
for _, f := range be.bm.Files {
for _, f := range be.project.Files {
file := filepath.Join(be.workdir, f.Path)
rel := filepath.Join(f.Destination, f.Base())
fmt.Fprintf(os.Stderr, "compress profile \x1b[32m%s\x1b[0m\n", f.Path)
Expand All @@ -320,39 +320,39 @@ func (be *Executor) PackWin() error {

// PackUNIX todo
func (be *Executor) PackUNIX() error {
var outfilename string
var outName string
if be.withoutVersion {
outfilename = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, ".sh")
outName = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, ".sh")
} else {
outfilename = base.StrCat(be.bm.Name, "-", be.target, "-", be.arch, "-", be.bm.Version, ".sh")
outName = base.StrCat(be.project.Name, "-", be.target, "-", be.arch, "-", be.project.Version, ".sh")
}
outfile := filepath.Join(be.destination, outfilename)
hashfd, err := pack.OpenHashableFile(outfile)
outfile := filepath.Join(be.destination, outName)
fd, err := pack.NewHashFD(outfile)
if err != nil {
return err
}
// Keep order
defer func() {
if err == nil {
hashfd.Hashsum(outfilename)
fd.Sum(outName)
fmt.Fprintf(os.Stderr, "create \x1b[32m%s\x1b[0m done\n", outfile)
fmt.Fprintf(os.Stderr, "Your can run '\x1b[32m./%s --prefix=/path/to/%s\x1b[0m' to install %s\n", outfilename, be.bm.Name, be.bm.Name)
fmt.Fprintf(os.Stderr, "bali create package \x1b[32m%s\x1b[0m success\n", outfilename)
fmt.Fprintf(os.Stderr, "Your can run '\x1b[32m./%s --prefix=/path/to/%s\x1b[0m' to install %s\n", outName, be.project.Name, be.project.Name)
fmt.Fprintf(os.Stderr, "bali create package \x1b[32m%s\x1b[0m success\n", outName)
}
}()
defer hashfd.Close()
pk := pack.NewTargzPacker(hashfd)
defer fd.Close()
pk := pack.NewTargzPacker(fd)
defer pk.Close()
var rw pack.RespondWriter
// bali post install script
if len(be.bm.Respond) != 0 {
if !base.PathExists(be.bm.Respond) {
return base.ErrorCat("respond file ", be.bm.Respond, " not found")
if len(be.project.Respond) != 0 {
if !base.PathExists(be.project.Respond) {
return base.ErrorCat("respond file ", be.project.Respond, " not found")
}
if err = pk.AddFileEx(be.bm.Respond, "bali_post_install", true); err != nil {
if err = pk.AddFileEx(be.project.Respond, "bali_post_install", true); err != nil {
return err
}
} else if !be.norename {
} else if !be.noNewName {
if err = rw.Initialize(); err != nil {
return err
}
Expand All @@ -369,7 +369,7 @@ func (be *Executor) PackUNIX() error {
}
fmt.Fprintf(os.Stderr, "compress target \x1b[32m%s\x1b[0m\n", rel)
nameInArchive := be.PathInArchive(rel)
if !be.norename {
if !be.noNewName {
nameInArchive = base.StrCat(nameInArchive, ".new")
}
if err = pk.AddFileEx(s, nameInArchive, true); err != nil {
Expand All @@ -387,11 +387,11 @@ func (be *Executor) PackUNIX() error {
return err
}
}
for _, f := range be.bm.Files {
for _, f := range be.project.Files {
file := filepath.Join(be.workdir, f.Path)
rel := filepath.Join(f.Destination, f.Base())
fmt.Fprintf(os.Stderr, "compress profile \x1b[32m%s\x1b[0m\n", rel)
if be.norename || f.NoRename {
if be.noNewName || f.NoRename {
if err = pk.AddFileEx(file, be.PathInArchive(rel), f.Executable); err != nil {
_ = rw.Close()
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/bali/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (

// version info
var (
VERSION = "2.1.1"
VERSION = "2.2.0"
BUILDTIME string = "NONE"
BUILDCOMMIT string = "NONE"
BUILDBRANCH string = "NONE"
Expand Down Expand Up @@ -142,7 +142,7 @@ func (be *Executor) Invoke(val int, oa, raw string) error {
case 1001:
be.cleanup = true
case 1002:
be.norename = true
be.noNewName = true
case 1003:
be.forceVerion = oa
case 1004:
Expand Down
2 changes: 1 addition & 1 deletion cmd/peassets/balisrc.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "peassets"
description = "peassets - PE executable program depends on aggregation tool"
destination = "bin"
version = "2.1.1"
version = "2.2.0"
versioninfo = "res/versioninfo.json"
icon = "res/peassets.ico"
manifest = "res/peassets.manifest"
Expand Down
2 changes: 1 addition & 1 deletion cmd/peassets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (

// version info
var (
VERSION = "2.1.1"
VERSION = "2.2.0"
BUILDTIME string = "NONE"
BUILDCOMMIT string = "NONE"
BUILDBRANCH string = "NONE"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/balibuild/bali/v2

go 1.21
go 1.22

require (
github.com/akavel/rsrc v0.10.2
Expand All @@ -10,7 +10,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/klauspost/compress v1.17.8
github.com/klauspost/pgzip v1.2.6
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.1
github.com/pkg/errors v0.9.1
github.com/ulikunitz/xz v0.5.12
)
22 changes: 20 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
Expand All @@ -15,10 +18,25 @@ github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ib
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 8f235e1

Please sign in to comment.