Skip to content

Commit cbbfcf0

Browse files
committed
refactor: move go files to the go folder
Signed-off-by: peefy <[email protected]>
1 parent a2de88e commit cbbfcf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+143
-134
lines changed

.github/workflows/go-test.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ on:
1111
branches:
1212
- main
1313
paths:
14-
- "lib/**"
15-
- "*.go"
14+
- "go/**"
1615
- "go.mod"
1716
- "go.sum"
1817
workflow_dispatch:
@@ -24,14 +23,14 @@ jobs:
2423
test:
2524
strategy:
2625
matrix:
27-
os: [macos-latest, ubuntu-latest, windows-latest]
26+
os: [macos-12, macos-latest, ubuntu-latest, windows-latest]
2827
runs-on: ${{ matrix.os }}
2928
steps:
3029
- name: Git checkout
3130
uses: actions/checkout@v2
3231
- name: Set up Go
3332
uses: actions/setup-go@v2
3433
with:
35-
go-version: 1.21
34+
go-version: 1.22
3635
- name: Go code test
3736
run: go test ./...

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,3 @@ _a.out_*.*
3131
**/.DS_Store
3232
**/.vscode
3333
__pycache__
34-
35-
!lib/**/*.dylib
36-
!lib/**/*.dll
37-
!lib/**/*.lib
38-
!lib/**/*.so
39-
!lib/**/*.exe
40-
!scripts/*.exe

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ Write the Code
4848
package main
4949

5050
import (
51-
"kcl-lang.io/lib"
51+
"kcl-lang.io/lib/go/install"
5252
)
5353

5454
func main() {
5555
path = "path/to/install/lib"
56-
_ := lib.InstallKclvm(path)
56+
_ := install.InstallKclvm(path)
5757
}
5858
```
5959

go/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
!lib/**/*.dylib
3+
!lib/**/*.dll
4+
!lib/**/*.lib
5+
!lib/**/*.so
6+
!lib/**/*.exe

spec.pb.go renamed to go/api/spec.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install.go renamed to go/install/install.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
package lib
1+
package install
22

33
import (
44
"fmt"
55
"os"
66
"os/exec"
77
"path/filepath"
88
"runtime"
9+
10+
lib "kcl-lang.io/lib/go/lib"
911
)
1012

1113
const KCLVM_VERSION = "v0.9.3"
@@ -60,7 +62,7 @@ func InstallKclvm(installRoot string) error {
6062
}
6163

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

8385
return nil
8486
}
85-
86-
func installBin(binDir, binName string, content []byte, versionMatched bool) error {
87-
binPath := findPath(binName)
88-
if binPath == "" || !versionMatched {
89-
if runtime.GOOS == "windows" {
90-
binName += ".exe"
91-
}
92-
binPath = filepath.Join(binDir, binName)
93-
err := os.MkdirAll(binDir, 0777)
94-
if err != nil {
95-
return err
96-
}
97-
binFile, err := os.Create(binPath)
98-
defer func() {
99-
binFile.Close()
100-
}()
101-
if err != nil {
102-
return err
103-
}
104-
_, err = binFile.Write(content)
105-
if err != nil {
106-
return err
107-
}
108-
fileMode := os.FileMode(0777)
109-
os.Chmod(binPath, fileMode)
110-
}
111-
return nil
112-
}

go/install/install_bin.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package install
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"runtime"
7+
)
8+
9+
func installBin(binDir, binName string, content []byte, versionMatched bool) error {
10+
binPath := findPath(binName)
11+
if binPath == "" || !versionMatched {
12+
if runtime.GOOS == "windows" {
13+
binName += ".exe"
14+
}
15+
binPath = filepath.Join(binDir, binName)
16+
err := os.MkdirAll(binDir, 0777)
17+
if err != nil {
18+
return err
19+
}
20+
binFile, err := os.Create(binPath)
21+
defer func() {
22+
binFile.Close()
23+
}()
24+
if err != nil {
25+
return err
26+
}
27+
_, err = binFile.Write(content)
28+
if err != nil {
29+
return err
30+
}
31+
fileMode := os.FileMode(0777)
32+
os.Chmod(binPath, fileMode)
33+
}
34+
return nil
35+
}

install_lib_unix.go renamed to go/install/install_lib_unix.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//go:build linux || darwin
22
// +build linux darwin
33

4-
package lib
4+
package install
55

66
import (
77
"runtime"
8+
9+
lib "kcl-lang.io/lib/go/lib"
810
)
911

1012
func installLib(libDir, libName string, versionMatched bool) error {
@@ -15,5 +17,5 @@ func installLib(libDir, libName string, versionMatched bool) error {
1517
case "linux":
1618
libFullName = libFullName + ".so"
1719
}
18-
return writeLib(libDir, libFullName, kclvmCliLib, versionMatched)
20+
return writeLib(libDir, libFullName, lib.CliLib, versionMatched)
1921
}

install_lib_windows.go renamed to go/install/install_lib_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package lib
1+
package install
22

33
func installLib(libDir, libName string, versionMatched bool) error {
44
libFullName := libName + ".dll"

util_unix.go renamed to go/install/util_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build linux || darwin
22
// +build linux darwin
33

4-
package lib
4+
package install
55

66
import (
77
"fmt"

util_windows.go renamed to go/install/util_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package lib
1+
package install
22

33
import (
44
"os"

0 commit comments

Comments
 (0)