use ./cmd as a package (#1994)

This commit is contained in:
Davies Liu
2022-05-11 13:20:49 +08:00
committed by GitHub
parent 95fba0e118
commit 8df1d8f9be
48 changed files with 105 additions and 95 deletions

View File

@@ -114,7 +114,7 @@ jobs:
- name: Build Juicefs
run: |
go build -ldflags="-s -w" -o juicefs.exe ./cmd
go build -ldflags="-s -w" -o juicefs.exe .
- name: Juicefs Format
run: |

View File

@@ -18,7 +18,7 @@ builds:
flags:
- -buildmode
- exe
main: ./cmd
main: .
goos:
- windows
goarch:
@@ -28,7 +28,7 @@ builds:
- CC=o64-clang
- CXX=o64-clang++
ldflags: -s -w -X github.com/juicedata/juicefs/pkg/version.version={{.Version}} -X github.com/juicedata/juicefs/pkg/version.revision={{.ShortCommit}} -X github.com/juicedata/juicefs/pkg/version.revisionDate={{.Env.REVISIONDATE}}
main: ./cmd
main: .
goos:
- darwin
goarch:
@@ -38,7 +38,7 @@ builds:
- CC=oa64-clang
- CXX=oa64-clang++
ldflags: -s -w -X github.com/juicedata/juicefs/pkg/version.version={{.Version}} -X github.com/juicedata/juicefs/pkg/version.revision={{.ShortCommit}} -X github.com/juicedata/juicefs/pkg/version.revisionDate={{.Env.REVISIONDATE}}
main: ./cmd
main: .
goos:
- darwin
goarch:
@@ -47,7 +47,7 @@ builds:
env:
- CC=/usr/bin/musl-gcc
ldflags: -s -w -X github.com/juicedata/juicefs/pkg/version.version={{.Version}} -X github.com/juicedata/juicefs/pkg/version.revision={{.ShortCommit}} -X github.com/juicedata/juicefs/pkg/version.revisionDate={{.Env.REVISIONDATE}} -linkmode external -extldflags '-static'
main: ./cmd
main: .
goos:
- linux
goarch:
@@ -56,7 +56,7 @@ builds:
env:
- CC=aarch64-linux-gnu-gcc
ldflags: -s -w -X github.com/juicedata/juicefs/pkg/version.version={{.Version}} -X github.com/juicedata/juicefs/pkg/version.revision={{.ShortCommit}} -X github.com/juicedata/juicefs/pkg/version.revisionDate={{.Env.REVISIONDATE}}
main: ./cmd
main: .
goos:
- linux
goarch:

View File

@@ -20,20 +20,20 @@ ifdef STATIC
endif
juicefs: Makefile cmd/*.go pkg/*/*.go go.*
go build -ldflags="$(LDFLAGS)" -o juicefs ./cmd
go build -ldflags="$(LDFLAGS)" -o juicefs .
juicefs.lite: Makefile cmd/*.go pkg/*/*.go
go build -tags nogateway,nowebdav,nocos,nobos,nohdfs,noibmcos,noobs,nooss,noqingstor,noscs,nosftp,noswift,noupyun,noazure,nogs,noufile,nob2,nosqlite,nomysql,nopg,notikv,nobadger,noetcd \
-ldflags="$(LDFLAGS)" -o juicefs.lite ./cmd
-ldflags="$(LDFLAGS)" -o juicefs.lite .
juicefs.ceph: Makefile cmd/*.go pkg/*/*.go
go build -tags ceph -ldflags="$(LDFLAGS)" -o juicefs.ceph ./cmd
go build -tags ceph -ldflags="$(LDFLAGS)" -o juicefs.ceph .
# This is the script for compiling the Linux version on the MacOS platform.
# Please execute the `brew install FiloSottile/musl-cross/musl-cross` command before using it.
juicefs.linux:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CGO_LDFLAGS="-static" go build -ldflags="$(LDFLAGS)" -o juicefs ./cmd
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CGO_LDFLAGS="-static" go build -ldflags="$(LDFLAGS)" -o juicefs .
/usr/local/include/winfsp:
sudo mkdir -p /usr/local/include/winfsp
@@ -41,7 +41,7 @@ juicefs.linux:
juicefs.exe: /usr/local/include/winfsp cmd/*.go pkg/*/*.go
GOOS=windows CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc \
go build -ldflags="$(LDFLAGS)" -buildmode exe -o juicefs.exe ./cmd
go build -ldflags="$(LDFLAGS)" -buildmode exe -o juicefs.exe .
.PHONY: snapshot release test
snapshot:

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"os"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bufio"
@@ -207,7 +207,7 @@ func config(ctx *cli.Context) error {
if !ctx.Bool("force") {
if storage {
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
return err
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"encoding/json"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"
@@ -119,7 +119,7 @@ func destroy(ctx *cli.Context) error {
if uuid := ctx.Args().Get(1); uuid != format.UUID {
logger.Fatalf("UUID %s != expected %s", uuid, format.UUID)
}
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("create object storage: %s", err)
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"io"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"context"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"os"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bytes"
@@ -180,7 +180,7 @@ func fixObjectSize(s int) int {
return s
}
func createStorage(format meta.Format) (object.ObjectStorage, error) {
func CreateStorage(format meta.Format) (object.ObjectStorage, error) {
if err := format.Decrypt(); err != nil {
return nil, fmt.Errorf("format decrypt: %s", err)
}
@@ -405,7 +405,7 @@ func format(c *cli.Context) error {
}
}
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"context"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"
@@ -66,7 +66,7 @@ func fsck(ctx *cli.Context) error {
CacheDir: "memory",
}
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -17,7 +17,7 @@
* limitations under the License.
*/
package main
package cmd
import (
_ "net/http/pprof"
@@ -185,7 +185,7 @@ func initForSvc(c *cli.Context, mp string, metaUrl string) (meta.Meta, chunk.Chu
}
chunkConf := getChunkConf(c, format)
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}

View File

@@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
package cmd
import (
"errors"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"os"
@@ -101,7 +101,7 @@ func gc(ctx *cli.Context) error {
CacheDir: "memory",
}
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"context"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"io"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"
@@ -80,13 +80,6 @@ func Main(args []string) error {
}
func main() {
err := Main(os.Args)
if err != nil {
logger.Fatal(err)
}
}
func handleSysMountArgs(args []string) []string {
optionToCmdFlag := map[string]string{
"attrcacheto": "attr-cache",

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"reflect"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"net"
@@ -282,7 +282,7 @@ func getMetaConf(c *cli.Context, mp string, readOnly bool) *meta.Config {
}
func newStore(format *meta.Format, chunkConf *chunk.Config, registerer prometheus.Registerer) (object.ObjectStorage, chunk.ChunkStore) {
blob, err := createStorage(*format)
blob, err := CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"context"

View File

@@ -17,7 +17,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bytes"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"github.com/juicedata/juicefs/pkg/meta"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bufio"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"encoding/json"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"encoding/json"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bytes"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"errors"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"bufio"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"fmt"

View File

@@ -18,7 +18,7 @@
*
*/
package main
package cmd
import (
"github.com/juicedata/juicefs/pkg/fs"

View File

@@ -17,7 +17,7 @@
* limitations under the License.
*/
package main
package cmd
import (
"errors"

View File

@@ -231,7 +231,7 @@ Download MinGW-w64 and add its `bin` directory to the system environment variabl
3. Compile client
```shell
go build -ldflags="-s -w" -o juicefs.exe ./cmd
go build -ldflags="-s -w" -o juicefs.exe .
```
### Cross-compiling Windows clients on Linux

View File

@@ -231,7 +231,7 @@ CMD [ "juicefs" ]
3. 编译客户端
```shell
go build -ldflags="-s -w" -o juicefs.exe ./cmd
go build -ldflags="-s -w" -o juicefs.exe .
```
### 在 Linux 中交叉编译 Windows 客户端

33
main.go Normal file
View File

@@ -0,0 +1,33 @@
/*
* JuiceFS, Copyright 2022 Juicedata, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"os"
"github.com/juicedata/juicefs/cmd"
"github.com/juicedata/juicefs/pkg/utils"
)
var logger = utils.GetLogger("juicefs")
func main() {
err := cmd.Main(os.Args)
if err != nil {
logger.Fatal(err)
}
}

View File

@@ -22,18 +22,16 @@ import (
"context"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
"io"
"net"
"sort"
"time"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/model"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/client_golang/prometheus"
)
const (

View File

@@ -29,9 +29,8 @@ import (
"testing"
"time"
"github.com/prometheus/common/model"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
)
func TestSanitize(t *testing.T) {

View File

@@ -42,6 +42,7 @@ import (
"time"
"unsafe"
"github.com/juicedata/juicefs/cmd"
"github.com/juicedata/juicefs/pkg/chunk"
"github.com/juicedata/juicefs/pkg/fs"
"github.com/juicedata/juicefs/pkg/meta"
@@ -294,23 +295,6 @@ func getOrCreate(name, user, group, superuser, supergroup string, f func() *fs.F
return h
}
func createStorage(format meta.Format) (object.ObjectStorage, error) {
if err := format.Decrypt(); err != nil {
return nil, fmt.Errorf("format decrypt: %s", err)
}
var blob object.ObjectStorage
var err error
if format.Shards > 1 {
blob, err = object.NewSharded(strings.ToLower(format.Storage), format.Bucket, format.AccessKey, format.SecretKey, format.Shards)
} else {
blob, err = object.CreateStorage(strings.ToLower(format.Storage), format.Bucket, format.AccessKey, format.SecretKey)
}
if err != nil {
return nil, err
}
return object.WithPrefix(blob, format.Name+"/"), nil
}
func push2Gateway(pushGatewayAddr, pushAuth string, pushInterVal time.Duration, registry *prometheus.Registry, commonLabels map[string]string) {
pusher := push.New(pushGatewayAddr, "juicefs").Gatherer(registry)
for k, v := range commonLabels {
@@ -374,7 +358,8 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) uintp
var jConf javaConf
err := json.Unmarshal([]byte(C.GoString(jsonConf)), &jConf)
if err != nil {
logger.Fatalf("invalid json: %s", C.GoString(jsonConf))
logger.Errorf("invalid json: %s", C.GoString(jsonConf))
return nil
}
if jConf.Debug || os.Getenv("JUICEFS_DEBUG") != "" {
utils.SetLogLevel(logrus.DebugLevel)
@@ -407,7 +392,8 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) uintp
m := meta.NewClient(jConf.MetaURL, metaConf)
format, err := m.Load(true)
if err != nil {
logger.Fatalf("load setting: %s", err)
logger.Errorf("load setting: %s", err)
return nil
}
var registerer prometheus.Registerer
if jConf.PushGateway != "" || jConf.PushGraphite != "" {
@@ -440,7 +426,7 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) uintp
if jConf.Bucket != "" {
format.Bucket = jConf.Bucket
}
blob, err := createStorage(*format)
blob, err := cmd.CreateStorage(*format)
if err != nil {
logger.Fatalf("object storage: %s", err)
}
@@ -492,7 +478,8 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) uintp
})
err = m.NewSession()
if err != nil {
logger.Fatalf("new session: %s", err)
logger.Errorf("new session: %s", err)
return nil
}
conf := &vfs.Config{