Skip to content

Commit

Permalink
use ./cmd as a package (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored May 11, 2022
1 parent 95fba0e commit 8df1d8f
Show file tree
Hide file tree
Showing 48 changed files with 105 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
10 changes: 5 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ builds:
flags:
- -buildmode
- exe
main: ./cmd
main: .
goos:
- windows
goarch:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ 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
sudo cp hack/winfsp_headers/* /usr/local/include/winfsp

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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"os"
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"bufio"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"io"
Expand Down
2 changes: 1 addition & 1 deletion cmd/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"os"
Expand Down
6 changes: 3 additions & 3 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"bytes"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions cmd/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fsck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

package main
package cmd

import (
_ "net/http/pprof"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
package cmd

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions cmd/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"os"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"io"
Expand Down
9 changes: 1 addition & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"fmt"
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"reflect"
Expand Down
4 changes: 2 additions & 2 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"net"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

package main
package cmd

import (
"bytes"
Expand Down
Loading

0 comments on commit 8df1d8f

Please sign in to comment.