Skip to content

Commit

Permalink
Add version information in CLI and output (#40)
Browse files Browse the repository at this point in the history
* Add version information in CLI and output

* Add missing file and remove TODO note
  • Loading branch information
DonnchaC authored Dec 22, 2023
1 parent ec585b6 commit 95be608
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
BUILD_FOLDER = "$(shell pwd)/build"
ASSETS_FOLDER = "$(shell pwd)/assets"

VERSION := $(shell git describe --always --long --dirty)
PACKAGE_PATH = github.com/mvt-project/androidqf

FLAGS_LINUX = GOOS=linux
FLAGS_DARWIN = GOOS=darwin
FLAGS_WINDOWS = GOOS=windows GOARCH=amd64 CC=i686-w64-mingw32-gcc CGO_ENABLED=1
LD_FLAGS = -s -w -X ${PACKAGE_PATH}/utils.Version=${VERSION}

# Set if binaries should be compressed with UPX. Zero disables UPX
UPX_COMPRESS ?= "0"
Expand Down Expand Up @@ -57,7 +61,7 @@ windows:

@echo "[builder] Building Windows binary for amd64"

$(FLAGS_WINDOWS) go build --ldflags '-s -w -extldflags "-static"' -o $(BUILD_FOLDER)/androidqf_windows_amd64.exe .
$(FLAGS_WINDOWS) go build --ldflags '$(LD_FLAGS) -extldflags "-static"' -o $(BUILD_FOLDER)/androidqf_windows_amd64.exe .

@echo "[builder] Done!"

Expand All @@ -75,8 +79,8 @@ darwin:

@echo "[builder] Building Darwin binary for amd64"

$(FLAGS_DARWIN) GOARCH=amd64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_darwin_amd64 .
$(FLAGS_DARWIN) GOARCH=arm64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_darwin_arm64 .
$(FLAGS_DARWIN) GOARCH=amd64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_darwin_amd64 .
$(FLAGS_DARWIN) GOARCH=arm64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_darwin_arm64 .

@echo "[builder] Done!"

Expand All @@ -94,8 +98,8 @@ linux:

@echo "[builder] Building Linux binary for amd64"

@$(FLAGS_LINUX) GOARCH=amd64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_linux_amd64 .
@$(FLAGS_LINUX) GOARCH=arm64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_linux_arm64 .
@$(FLAGS_LINUX) GOARCH=amd64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_linux_amd64 .
@$(FLAGS_LINUX) GOARCH=arm64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_linux_arm64 .

@echo "[builder] Done!"

Expand Down
17 changes: 10 additions & 7 deletions acquisition/acquisition.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,27 @@ import (
"github.com/mvt-project/androidqf/adb"
"github.com/mvt-project/androidqf/assets"
"github.com/mvt-project/androidqf/log"
"github.com/mvt-project/androidqf/utils"
)

// Acquisition is the main object containing all phone information
type Acquisition struct {
UUID string `json:"uuid"`
StoragePath string `json:"storage_path"`
Started time.Time `json:"started"`
Completed time.Time `json:"completed"`
Collector *adb.Collector `json:"collector"`
TmpDir string `json:"tmp_dir"`
Cpu string `json:"cpu"`
UUID string `json:"uuid"`
AndroidQFVersion string `json:"androidqf_version"`
StoragePath string `json:"storage_path"`
Started time.Time `json:"started"`
Completed time.Time `json:"completed"`
Collector *adb.Collector `json:"collector"`
TmpDir string `json:"tmp_dir"`
Cpu string `json:"cpu"`
}

// New returns a new Acquisition instance.
func New() (*Acquisition, error) {
acq := Acquisition{
UUID: uuid.New().String(),
Started: time.Now().UTC(),
AndroidQFVersion: utils.Version,
}

acq.StoragePath = filepath.Join(rt.GetExecutableDirectory(), acq.UUID)
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/mvt-project/androidqf/adb"
"github.com/mvt-project/androidqf/log"
"github.com/mvt-project/androidqf/modules"
"github.com/mvt-project/androidqf/utils"
)

func init() {
Expand All @@ -39,6 +40,7 @@ func systemPause() {
func main() {
var err error
var verbose bool
var version_flag bool
var list_modules bool
var fast bool
var module string
Expand All @@ -52,11 +54,18 @@ func main() {
flag.BoolVar(&list_modules, "l", false, "List modules and exit")
flag.StringVar(&module, "module", "", "Only execute a specific module")
flag.StringVar(&module, "m", "", "Only execute a specific module")
flag.BoolVar(&version_flag, "version", false, "Show version")

flag.Parse()
if verbose {
log.SetLogLevel(log.DEBUG)
}

if version_flag {
log.Infof("AndroidQF version: %s", utils.Version)
os.Exit(0)
}

if list_modules {
mods := modules.List()
log.Info("List of modules:")
Expand All @@ -66,7 +75,6 @@ func main() {
os.Exit(0)
}

// TODO: add version information
log.Debug("Starting androidqf")
adb.Client, err = adb.New()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions utils/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package utils

// Store the build verion information; set by linker flag
var Version string

0 comments on commit 95be608

Please sign in to comment.