Skip to content

Commit

Permalink
Rewrite GUI in Go (jstaf#227)
Browse files Browse the repository at this point in the history
* initial ui

* start writing dir chooser

* make dir chooser functional

* remove pointless gtk.Init call

* move main.go to cmd/

* tests!

* move systemd stuff to own package

* failing tests for systemd unit functions

* unit enabling/disabling now works

* UnitIsActive now works

* finish ui buttons

* fix mountpointisvalid

* check for mountpoints on startup

* row-activated now can get mount name

* feature parity with C UI

* remove c ui code

* enable ui tests (minus systemd/dbus stuff)

* local test fixes

* disable CGo for UI tests

* disable dir_chooser.go for tests

* double ci timeout

* better test feedback

* fix version injection into cli, add more logging to ui

* update package build files

* faster ui tests in ci

* fix by use shell
  • Loading branch information
jstaf authored Jan 25, 2022
1 parent 91b4264 commit 91785d8
Show file tree
Hide file tree
Showing 27 changed files with 827 additions and 1,521 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ current_version = 0.12.0
commit = False
tag = False

[bumpversion:file:main.go]
[bumpversion:file:cmd/common/common.go]

[bumpversion:file:resources/onedriver.1]

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
name: Run tests
runs-on: ubuntu-20.04
timeout-minutes: 15
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -47,8 +47,6 @@ jobs:
- name: Check that the app compiles successfully
run: make
env:
CFLAGS: -g

- name: Copy auth tokens from S3
run: |
Expand All @@ -64,7 +62,10 @@ jobs:

- name: Run tests
run: |
go get -u github.com/rakyll/gotest
go get -u github.com/rakyll/gotest
# cannot run systemd tests here because github actions runners don't have dbus setup +
# if CGO is on, the UI tests will take foreverrrrr
CGO_ENABLED=0 gotest -v -covermode=count -coverpkg=./ui/... -coverprofile=ui.coverage ./ui
gotest -v -covermode=count -coverpkg=./fs/... -coverprofile=graph.coverage ./fs/graph
gotest -v -covermode=count -coverpkg=./fs/... -coverprofile=fs.coverage ./fs
go test -c -covermode=count -coverpkg=./fs/... ./fs/offline
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ __debug_bin
onedriver
onedriver-headless
onedriver-launcher
c-tests
onedriver-*/
!cmd/onedriver-launcher
!cmd/onedriver
vendor/

Expand Down
63 changes: 23 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all, test, c-test, srpm, rpm, changes, dsc, deb, clean, install
.PHONY: all, test, srpm, rpm, changes, dsc, deb, clean, install

# autocalculate software/package versions
VERSION := $(shell grep Version onedriver.spec | sed 's/Version: *//g')
Expand All @@ -10,30 +10,28 @@ RPM_FULL_VERSION = $(VERSION)-$(RELEASE)$(DIST)
TEST_UID := $(shell id -u)
TEST_GID := $(shell id -g)

# c build variables
DEPS = gtk+-3.0 gio-2.0 glib-2.0 json-glib-1.0
SRCS := $(shell find launcher/ -name *.c | grep -v _test)
OBJS := $(SRCS:%.c=build/%.o)
INC_DIRS := $(shell find launcher/ -type d | grep -v _test)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS := -std=gnu11 ${CFLAGS} $(INC_FLAGS) $(shell pkg-config --cflags $(DEPS))
LDFLAGS := $(shell pkg-config --libs $(DEPS))

# c test variables
TEST_SRCS := $(shell find launcher/ -name *.c | grep -v launcher/main.c)
TEST_OBJS := $(TEST_SRCS:%.c=build/%.o)
TEST_LDFLAGS := $(shell pkg-config --libs $(DEPS)) -lrt -lm
all: onedriver onedriver-launcher


all: onedriver onedriver-launcher
onedriver: $(shell find fs/ -type f) cmd/onedriver/main.go
go build \
-ldflags="-X github.com/jstaf/onedriver/cmd/common.commit=$(shell git rev-parse HEAD)" \
./cmd/onedriver


onedriver: $(shell find fs/ -type f) main.go
go build -ldflags="-X main.commit=$(shell git rev-parse HEAD)"
onedriver-headless: $(shell find fs/ -type f) cmd/onedriver/main.go
CGO_ENABLED=0 go build -o onedriver-headless \
-ldflags="-X github.com/jstaf/onedriver/cmd/common.commit=$(shell git rev-parse HEAD)" \
./cmd/onedriver


onedriver-headless: $(shell find fs/ -type f) main.go
CGO_ENABLED=0 go build -o onedriver-headless -ldflags="-X main.commit=$(shell git rev-parse HEAD)"
# -Wno-deprecated-declarations is for gotk3, which uses deprecated methods for older
# glib compatibility: https://github.com/gotk3/gotk3/issues/762#issuecomment-919035313
onedriver-launcher: $(shell find ui/ -type f) cmd/onedriver-launcher/main.go
CGO_CFLAGS=-Wno-deprecated-declarations go build -v \
-ldflags="-X github.com/jstaf/onedriver/cmd/common.commit=$(shell git rev-parse HEAD)" \
./cmd/onedriver-launcher


install: onedriver onedriver-launcher
Expand All @@ -48,23 +46,6 @@ install: onedriver onedriver-launcher
mandb


onedriver-launcher: $(OBJS)
gcc -o $@ $^ $(LDFLAGS)


build/%.o: %.c
mkdir -p $(shell dirname $@)
gcc -o $@ -c $^ $(CFLAGS)


build/c-test: $(TEST_OBJS)
gcc -o $@ $^ $(TEST_LDFLAGS)


c-test: build/c-test
$<


# used to create release tarball for rpmbuild
v$(VERSION).tar.gz: $(shell git ls-files)
rm -rf onedriver-$(VERSION)
Expand Down Expand Up @@ -126,11 +107,13 @@ dmel.fa:
# For offline tests, the test binary is built online, then network access is
# disabled and tests are run. sudo is required - otherwise we don't have
# permission to mount the fuse filesystem.
test: build/c-test onedriver dmel.fa
$<
test: onedriver onedriver-launcher dmel.fa
rm -f *.race* fusefs_tests.log
GORACE="log_path=fusefs_tests.race strip_path_prefix=1" gotest -race -v -parallel=8 -count=1 ./fs/graph
GORACE="log_path=fusefs_tests.race strip_path_prefix=1" gotest -race -v -parallel=8 -count=1 ./fs
CGO_ENABLED=0 gotest -v -parallel=8 -count=1 $(shell go list ./ui/... | grep -v offline)
GORACE="log_path=fusefs_tests.race strip_path_prefix=1" \
gotest -race -v -parallel=8 -count=1 ./fs/graph
GORACE="log_path=fusefs_tests.race strip_path_prefix=1" \
gotest -race -v -parallel=8 -count=1 ./fs
go test -c ./fs/offline
@echo "sudo is required to run tests of offline functionality:"
sudo unshare -n -S $(TEST_UID) -G $(TEST_GID) ./offline.test -test.v -test.parallel=8 -test.count=1
Expand All @@ -141,5 +124,5 @@ test: build/c-test onedriver dmel.fa
clean:
fusermount -uz mount/ || true
rm -f *.db *.rpm *.deb *.dsc *.changes *.build* *.upload *.xz filelist.txt .commit
rm -f *.log *.fa *.gz *.test vgcore.* onedriver onedriver-headless onedriver-launcher unshare .auth_tokens.json
rm -f *.log *.fa *.gz *.test vgcore.* onedriver onedriver-headless onedriver-launcher .auth_tokens.json
rm -rf util-linux-*/ onedriver-*/ vendor/ build/
45 changes: 45 additions & 0 deletions cmd/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// common functions used by both binaries
package common

import (
"fmt"
"strings"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

const version = "0.12.0"

var commit string

// Version returns the current version string
func Version() string {
clen := 0
if len(commit) > 7 {
clen = 8
}
return fmt.Sprintf("v%s %s", version, commit[:clen])
}

// StringToLevel converts a string to a LogLevel in a case-insensitive manner.
func StringToLevel(level string) zerolog.Level {
level = strings.ToLower(level)
switch level {
case "fatal":
return zerolog.FatalLevel
case "error":
return zerolog.ErrorLevel
case "warn":
return zerolog.WarnLevel
case "info":
return zerolog.InfoLevel
case "debug":
return zerolog.DebugLevel
case "trace":
return zerolog.TraceLevel
default:
log.Error().Msgf("Unrecognized log level \"%s\", defaulting to \"trace\".\n", level)
return zerolog.TraceLevel
}
}
Loading

0 comments on commit 91785d8

Please sign in to comment.