Skip to content

Commit

Permalink
refactor: move go files to the go folder
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 21, 2024
1 parent a2de88e commit 6439dad
Show file tree
Hide file tree
Showing 48 changed files with 155 additions and 144 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ on:
branches:
- main
paths:
- "lib/**"
- "*.go"
- "go/**"
- "go.mod"
- "go.sum"
workflow_dispatch:
Expand All @@ -24,14 +23,14 @@ jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
os: [macos-12, macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
go-version: 1.22
- name: Go code test
run: go test ./...
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,3 @@ _a.out_*.*
**/.DS_Store
**/.vscode
__pycache__

!lib/**/*.dylib
!lib/**/*.dll
!lib/**/*.lib
!lib/**/*.so
!lib/**/*.exe
!scripts/*.exe
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Write the Code
package main

import (
"kcl-lang.io/lib"
"kcl-lang.io/lib/go/install"
)

func main() {
path = "path/to/install/lib"
_ := lib.InstallKclvm(path)
_ := install.InstallKclvm(path)
}
```

Expand Down
6 changes: 6 additions & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

!lib/**/*.dylib
!lib/**/*.dll
!lib/**/*.lib
!lib/**/*.so
!lib/**/*.exe
4 changes: 2 additions & 2 deletions spec.pb.go → go/api/spec.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 4 additions & 30 deletions install.go → go/install/install.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package lib
package install

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"

lib "kcl-lang.io/lib/go/lib"
)

const KCLVM_VERSION = "v0.9.3"
Expand Down Expand Up @@ -60,7 +62,7 @@ func InstallKclvm(installRoot string) error {
}

// Install kclvm binary.
err = installBin(binPath, "kclvm_cli", kclvmCliBin, versionMatched)
err = installBin(binPath, "kclvm_cli", lib.CliBin, versionMatched)
if err != nil {
return err
}
Expand All @@ -82,31 +84,3 @@ func InstallKclvm(installRoot string) error {

return nil
}

func installBin(binDir, binName string, content []byte, versionMatched bool) error {
binPath := findPath(binName)
if binPath == "" || !versionMatched {
if runtime.GOOS == "windows" {
binName += ".exe"
}
binPath = filepath.Join(binDir, binName)
err := os.MkdirAll(binDir, 0777)
if err != nil {
return err
}
binFile, err := os.Create(binPath)
defer func() {
binFile.Close()
}()
if err != nil {
return err
}
_, err = binFile.Write(content)
if err != nil {
return err
}
fileMode := os.FileMode(0777)
os.Chmod(binPath, fileMode)
}
return nil
}
35 changes: 35 additions & 0 deletions go/install/install_bin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package install

import (
"os"
"path/filepath"
"runtime"
)

func installBin(binDir, binName string, content []byte, versionMatched bool) error {
binPath := findPath(binName)
if binPath == "" || !versionMatched {
if runtime.GOOS == "windows" {
binName += ".exe"
}
binPath = filepath.Join(binDir, binName)
err := os.MkdirAll(binDir, 0777)
if err != nil {
return err
}
binFile, err := os.Create(binPath)
defer func() {
binFile.Close()
}()
if err != nil {
return err
}
_, err = binFile.Write(content)
if err != nil {
return err
}
fileMode := os.FileMode(0777)
os.Chmod(binPath, fileMode)
}
return nil
}
6 changes: 4 additions & 2 deletions install_lib_unix.go → go/install/install_lib_unix.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//go:build linux || darwin
// +build linux darwin

package lib
package install

import (
"runtime"

lib "kcl-lang.io/lib/go/lib"
)

func installLib(libDir, libName string, versionMatched bool) error {
Expand All @@ -15,5 +17,5 @@ func installLib(libDir, libName string, versionMatched bool) error {
case "linux":
libFullName = libFullName + ".so"
}
return writeLib(libDir, libFullName, kclvmCliLib, versionMatched)
return writeLib(libDir, libFullName, lib.CliLib, versionMatched)
}
13 changes: 13 additions & 0 deletions go/install/install_lib_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package install

import lib "kcl-lang.io/lib/go/lib"

func installLib(libDir, libName string, versionMatched bool) error {
libFullName := libName + ".dll"
exportLibFullName := libName + ".lib"
err := writeLib(libDir, libFullName, lib.CliLib, versionMatched)
if err != nil {
return err
}
return writeLib(libDir, exportLibFullName, lib.ExportLib, versionMatched)
}
2 changes: 1 addition & 1 deletion util_unix.go → go/install/util_unix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build linux || darwin
// +build linux darwin

package lib
package install

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion util_windows.go → go/install/util_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package install

import (
"os"
Expand Down
Loading

0 comments on commit 6439dad

Please sign in to comment.