Skip to content

Commit

Permalink
v3 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Aug 24, 2024
1 parent 5085e4b commit 3fb30ca
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ goflags = [
"FileDescription": "Bali - Minimalist Golang build and packaging tool",
"FileVersion": "",
"InternalName": "bali.exe",
"LegalCopyright": "Copyright \u00A9 2022. Bali contributors",
"LegalCopyright": "Copyright \u00A9 2024. Bali contributors",
"LegalTrademarks": "",
"OriginalFilename": "bali.exe",
"PrivateBuild": "",
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ goflags = [
"FileDescription": "Bali - Minimalist Golang build and packaging tool",
"FileVersion": "",
"InternalName": "bali.exe",
"LegalCopyright": "Copyright \u00A9 2022. Bali contributors",
"LegalCopyright": "Copyright \u00A9 2024. Bali contributors",
"LegalTrademarks": "",
"OriginalFilename": "bali.exe",
"PrivateBuild": "",
Expand Down
25 changes: 25 additions & 0 deletions cmd/bali/balisrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,28 @@ goflags = [
"-ldflags",
"-X 'main.VERSION=$BUILD_VERSION' -X 'main.BUILDTIME=$BUILD_TIME' -X 'main.BUILDBRANCH=$BUILD_BRANCH' -X 'main.BUILDCOMMIT=$BUILD_COMMIT' -X 'main.BUILDREFNAME=$BUILD_REFNAME' -X 'main.GOVERSION=$BUILD_GOVERSION'",
]

[windows]
manifest = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<description>Bali</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
"""
11 changes: 11 additions & 0 deletions cmd/bali/command_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

type BuildCommand struct {
Target string `name:"target" short:"T" help:"Target OS for which the code is compiled" default:"${target}"` // windows/darwin
Arch string `name:"arch" short:"A" help:"Target architecture for which the code is compiled" default:"${arch}"` // amd64/arm64 ...
}

func (c *BuildCommand) Run(g *Globals) error {

return nil
}
9 changes: 9 additions & 0 deletions cmd/bali/command_clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

type CleanCommand struct {
}

func (c *CleanCommand) Run(g *Globals) error {

return nil
}
11 changes: 11 additions & 0 deletions cmd/bali/command_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

type UpdateCommand struct {
ALL bool `name:"all" help:"Update all dependencies"`
Modules []string `name:"modules" short:"m" help:"Update modules to the specified version"`
}

func (c *UpdateCommand) Run(g *Globals) error {

return nil
}
4 changes: 2 additions & 2 deletions cmd/bali/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (be *Executor) Compress() error {
var err error
var fd *os.File
var mw io.Writer
var pk pack.Packer
var pk pack.Builder
h := sha256.New()
var outname string
if be.target == "windows" {
Expand All @@ -255,7 +255,7 @@ func (be *Executor) Compress() error {
return err
}
mw = io.MultiWriter(fd, h)
zpk := pack.NewZipPackerEx(mw, be.zipmethod)
zpk := pack.NewZipBuilderEx(mw, be.zipmethod)
if len(be.project.Destination) != 0 {
zpk.SetComment(be.project.Destination)
}
Expand Down
42 changes: 42 additions & 0 deletions cmd/bali/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strings"

"github.com/alecthomas/kong"
"github.com/balibuild/bali/v3/base"
"github.com/balibuild/bali/v3/pack"
)
Expand Down Expand Up @@ -235,3 +236,44 @@ func main() {
}
}
}

type VersionFlag bool

func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true }
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
app.Exit(0)
return nil
}

type Globals struct {
M string `name:"module" short:"M" help:"Explicitly specify a module directory" default:"." type:"path"`
B string `name:"build" short:"B" help:"Explicitly specify a build directory" default:"build" type:"path"`
Verbose bool `name:"verbose" short:"V" help:"Make the operation more talkative"`
Version VersionFlag `name:"version" short:"v" help:"Print version information and quit"`
}

type App struct {
Globals
Build BuildCommand `cmd:"build" help:"Compile the current module (default)" default:"withargs"`
Update UpdateCommand `cmd:"update" help:"Update dependencies as recorded in the go.mod"`
Clean CleanCommand `cmd:"clean" help:"Remove generated artifacts"`
}

func Main() {
app := App{}

ctx := kong.Parse(&app,
kong.Name("bali"),
kong.Description("Bali - Minimalist Golang build and packaging tool"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
}),
kong.Vars{
"target": runtime.GOOS,
"arch": runtime.GOARCH,
})
err := ctx.Run(&app.Globals)
ctx.FatalIfErrorf(err)
}
2 changes: 1 addition & 1 deletion cmd/bali/res/versioninfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"FileDescription": "Bali - Minimalist Golang build and packaging tool",
"FileVersion": "",
"InternalName": "bali.exe",
"LegalCopyright": "Copyright \u00A9 2022. Bali contributors",
"LegalCopyright": "Copyright \u00A9 2024. Bali contributors",
"LegalTrademarks": "",
"OriginalFilename": "bali.exe",
"PrivateBuild": "",
Expand Down
2 changes: 1 addition & 1 deletion cmd/peassets/res/versioninfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"FileDescription": "peassets - PE executable program depends on aggregation tool",
"FileVersion": "",
"InternalName": "peassets.exe",
"LegalCopyright": "Copyright \u00A9 2022. Bali contributors",
"LegalCopyright": "Copyright \u00A9 2024. Bali contributors",
"LegalTrademarks": "",
"OriginalFilename": "peassets.exe",
"PrivateBuild": "",
Expand Down
2 changes: 1 addition & 1 deletion docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ File object:
"FileDescription": "Bali - Minimalist Golang build and packaging tool",
"FileVersion": "",
"InternalName": "bali.exe",
"LegalCopyright": "Copyright \u00A9 2022. Bali contributors",
"LegalCopyright": "Copyright \u00A9 2024. Bali contributors",
"LegalTrademarks": "",
"OriginalFilename": "bali.exe",
"PrivateBuild": "",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22

require (
github.com/akavel/rsrc v0.10.2
github.com/alecthomas/kong v0.9.0
github.com/andybalholm/brotli v1.1.0
github.com/dsnet/compress v0.0.1
github.com/fcharlie/buna v0.6.0
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
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/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -9,6 +15,8 @@ github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5Jflh
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/fcharlie/buna v0.6.0 h1:8v9jZ20AbRKLIKw8MhUBK95KbTLvtkllWJljbehrjg0=
github.com/fcharlie/buna v0.6.0/go.mod h1:nqUuAPM0tAsVvQWUFcxqyCAJbGpFjzfQtMDz2JulGWk=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
Expand Down
4 changes: 2 additions & 2 deletions pack/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package pack

import "os"

// Packer todo
type Packer interface {
// Builder todo
type Builder interface {
Close() error
AddFileEx(src, nameInArchive string, exerights bool) error
AddFile(src, nameInArchive string) error
Expand Down
5 changes: 0 additions & 5 deletions pack/pecoff.go

This file was deleted.

56 changes: 28 additions & 28 deletions pack/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,62 @@ const (
Store uint16 = 0 // no compression
Deflate uint16 = 8 // DEFLATE compressed
BZIP2 uint16 = 12 // bzip2
LZMA uint16 = 14 //LZMA
ZSTD uint16 = 93 //see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT.
XZ uint16 = 95 //XZ
LZMA uint16 = 14 // LZMA
ZSTD uint16 = 93 // see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT.
XZ uint16 = 95 // XZ
BROTLI uint16 = 121 // private
)

// ZipPacker todo
type ZipPacker struct {
zw *zip.Writer
FileMethod uint16 // zip filemethod
// ZipBuilder todo
type ZipBuilder struct {
zw *zip.Writer
Method uint16 // zip filemethod
}

// NewZipPacker todo
func NewZipPacker(w io.Writer) *ZipPacker {
return &ZipPacker{zw: zip.NewWriter(w), FileMethod: Deflate}
// NewZipBuilder todo
func NewZipBuilder(w io.Writer) *ZipBuilder {
return &ZipBuilder{zw: zip.NewWriter(w), Method: Deflate}
}

// NewZipPackerEx todo
func NewZipPackerEx(w io.Writer, method uint16) *ZipPacker {
zp := NewZipPacker(w)
// NewZipBuilderEx with compress method
func NewZipBuilderEx(w io.Writer, method uint16) *ZipBuilder {
b := NewZipBuilder(w)
switch method {
case BZIP2:
zp.zw.RegisterCompressor(BZIP2, func(out io.Writer) (io.WriteCloser, error) {
b.zw.RegisterCompressor(BZIP2, func(out io.Writer) (io.WriteCloser, error) {
return bzip2.NewWriter(out, nil)
})
zp.FileMethod = BZIP2
b.Method = BZIP2
case ZSTD:
zp.zw.RegisterCompressor(ZSTD, func(out io.Writer) (io.WriteCloser, error) {
b.zw.RegisterCompressor(ZSTD, func(out io.Writer) (io.WriteCloser, error) {
return zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.SpeedBestCompression))
//return zstd.ZipCompressor()(out)
})
zp.FileMethod = ZSTD
b.Method = ZSTD
case BROTLI:
zp.zw.RegisterCompressor(BROTLI, func(out io.Writer) (io.WriteCloser, error) {
b.zw.RegisterCompressor(BROTLI, func(out io.Writer) (io.WriteCloser, error) {
return brotli.NewWriter(out), nil
})
zp.FileMethod = BROTLI
b.Method = BROTLI
default:
}
return zp
return b
}

// Close todo
func (zp *ZipPacker) Close() error {
if zp.zw == nil {
func (b *ZipBuilder) Close() error {
if b.zw == nil {
return nil
}
return zp.zw.Close()
return b.zw.Close()
}

func (zp *ZipPacker) SetComment(comment string) error {
func (zp *ZipBuilder) SetComment(comment string) error {
return zp.zw.SetComment(comment)
}

// AddTargetLink create zip symlink
func (zp *ZipPacker) AddTargetLink(nameInArchive, linkName string) error {
func (zp *ZipBuilder) AddTargetLink(nameInArchive, linkName string) error {
var hdr zip.FileHeader
hdr.Modified = time.Now()
hdr.SetMode(0755 | os.ModeSymlink) // symlink
Expand All @@ -94,7 +94,7 @@ func (zp *ZipPacker) AddTargetLink(nameInArchive, linkName string) error {
}

// AddFileEx todo
func (zp *ZipPacker) AddFileEx(src, nameInArchive string, exerights bool) error {
func (zp *ZipBuilder) AddFileEx(src, nameInArchive string, exerights bool) error {
fi, err := os.Stat(src)
if err != nil {
return err
Expand All @@ -115,7 +115,7 @@ func (zp *ZipPacker) AddFileEx(src, nameInArchive string, exerights bool) error
hdr.SetMode(hdr.Mode() | 0755)
}
hdr.Name = filepath.ToSlash(nameInArchive)
hdr.Method = zp.FileMethod
hdr.Method = zp.Method
writer, err := zp.zw.CreateHeader(hdr)
if err != nil {
return base.ErrorCat(nameInArchive, ": making header:", err.Error())
Expand All @@ -142,6 +142,6 @@ func (zp *ZipPacker) AddFileEx(src, nameInArchive string, exerights bool) error
}

// AddFile file to zip packer
func (zp *ZipPacker) AddFile(src, nameInArchive string) error {
func (zp *ZipBuilder) AddFile(src, nameInArchive string) error {
return zp.AddFileEx(src, nameInArchive, false)
}
6 changes: 3 additions & 3 deletions script/bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

Write-Host -ForegroundColor Green "Bootstrap bali"
$TopLevel = Split-Path -Path $PSScriptRoot
$SrcDir = Join-Path $TopLevel -ChildPath "cmd/bali"
$SOURCE_DIR = Join-Path $TopLevel -ChildPath "cmd/bali"

$BALI_EXE = "$SrcDir/bali"
$BALI_EXE = "$SOURCE_DIR/bali"
$BALI_EXE_STAGE0 = "$TopLevel/bali.out"
if ($PSEdition -eq "Desktop" -or $IsWindows) {
$BALI_EXE += ".exe"
$BALI_EXE_STAGE0 += ".exe"
}

$ps = Start-Process -FilePath "go" -WorkingDirectory $SrcDir -ArgumentList "build" -PassThru -Wait -NoNewWindow
$ps = Start-Process -FilePath "go" -WorkingDirectory $SOURCE_DIR -ArgumentList "build" -PassThru -Wait -NoNewWindow
if ($ps.ExitCode -ne 0) {
Exit $ps.ExitCode
}
Expand Down
Loading

0 comments on commit 3fb30ca

Please sign in to comment.