Prechádzať zdrojové kódy

Adding main scripts, readme and Go 1.20.3

Matthias Ladkau 1 rok pred
commit
d64026c037

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/linux/

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+Go Development Environment
+==
+This repository contains a Go development environment for offline installation.
+
+Go Version: 1.20.3
+
+Installation:
+--
+1. Git clone into a directory:
+```
+~/ > git clone https://devt.de/krotik/env-go.git
+```
+
+2. Add bin directory to the PATH variable:
+```
+PATH=$PATH:~/env-go/bin
+```
+This is usually an entry in `~/.bashrc`. This will enable support scripts like `cover-go` (output the total test coverage of a project).  
+
+3. Run setup.sh:
+```
+~/env-go/setup/ > setup.sh
+```
+
+Usage:
+--
+Run in a Go repository `env-go`.

+ 17 - 0
bin/check-go

@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# check-go - Checks the code quality of a given Go repository.
+
+echo Running gofmt ...
+gofmt -l -w -s .
+echo Running go vet ...
+go vet ./...
+echo Running golint ...
+golint -set_exit_status ./...
+echo Running ineffassign ...
+ineffassign .
+echo Running misspell ...
+misspell .
+echo Running gocyclo ...
+gocyclo -over 15 .
+echo Done.

+ 77 - 0
bin/cover-go

@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# cover-go - Generate test coverage statistics for all Go packages.
+
+workdir=.cover
+
+mkdir -p $workdir
+
+profile="$workdir/cover.out"
+mode=count
+args=$*
+
+# Used for saving results when specifying --save-html
+
+if [[ $args == *--save-html* ]]; then
+    for lastarg; do true; done
+    outfile=$lastarg
+    echo "Outfile: $outfile"
+fi
+
+generate_cover_data() {
+    rm -rf "$workdir"
+    mkdir "$workdir"
+
+    for pkg in "$@"; do
+        f="$workdir/$(echo $pkg | tr / -).cover"
+        
+        go test -covermode="$mode" -coverprofile="$f" "$pkg"
+        
+        ret=$?
+        if [ $ret -ne 0 ]; then
+            if [[ $args == *--save-html* ]]; then
+                echo '<svg width="88" height="20" xmlns="http://www.w3.org/2000/svg"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h41v20H0z"/><path fill="#fc1" d="M41 0h40v20H41z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="20.5" y="14">tests</text><text x="60" y="14">fail</text></g></svg>' > $outfile.svg
+            fi
+
+            exit $ret
+        fi
+    done
+
+    echo "mode: $mode" >"$profile"
+    grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
+}
+
+show_cover_report() {
+    go tool cover -${1}="$profile" -o $profile.${1}
+    go tool cover -${1}="$profile"
+}
+
+save_cover_report() {
+
+    coverage=`go tool cover -func=.cover/cover.out | tee $outfile.txt | grep -En "^total:" | grep -o '[0-9]*.[0-9]*%$'`
+
+    echo $?
+
+    go tool cover -${1}="$profile" -o $outfile.html
+
+    if [ "$coverage" == "100.0%" ]; then
+        echo '<svg width="110" height="20" xmlns="http://www.w3.org/2000/svg"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#4c1" d="M61 0h50v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">coverage</text><text x="85" y="14">'$coverage'</text></g></svg>' > $outfile.svg
+    else
+        echo '<svg width="110" height="20" xmlns="http://www.w3.org/2000/svg"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#fc1" d="M61 0h50v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">coverage</text><text x="85" y="14">'$coverage'</text></g></svg>' > $outfile.svg
+    fi
+}
+
+generate_cover_data $(go list ./...)
+
+show_cover_report func
+case "$1" in
+"")
+    ;;
+--html)
+    show_cover_report html ;;
+--save-html)
+    save_cover_report html ;;
+*)
+    echo >&2 "error: invalid option: $1"; exit 1 ;;
+esac
+

+ 23 - 0
bin/env-go

@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# env-go - Setup Go development environment variables
+
+if [ "$0" == "env-go" ]; then
+    PATH_SCRIPT="."
+else
+    PATH_SCRIPT=${0/%\/env-go}
+fi
+
+CURRENT_PATH=`pwd`
+cd $PATH_SCRIPT
+PATH_SCRIPT=`pwd`
+
+cd $PATH_SCRIPT
+. ./go.env
+cd $CURRENT_PATH
+
+if [ "$1" == "" ]; then
+    bash
+else
+    $*
+fi

+ 9 - 0
bin/go.env

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+BIN_PATH=`pwd`
+
+export GOROOT=$BIN_PATH/../linux/go
+# export GOPATH= ??? - Deprecated in favor of modules (see blog post: https://blog.golang.org/modules2019)
+export LITEIDE=$BIN_PATH/../linux/liteide
+
+export PATH=$GOROOT/bin:$LITEIDE/bin:$BIN_PATH:$PATH

BIN
setup/mod/arm32/go/errcheck


BIN
setup/mod/arm32/go/gocyclo


BIN
setup/mod/arm32/go/golint


BIN
setup/mod/arm32/go/ineffassign


BIN
setup/mod/arm32/go/misspell


BIN
setup/mod/linux/go/errcheck


BIN
setup/mod/linux/go/gocyclo


BIN
setup/mod/linux/go/golint


BIN
setup/mod/linux/go/ineffassign


BIN
setup/mod/linux/go/misspell


BIN
setup/pkg/arm32/go1.20.3.linux-armv6l.tar.gz


BIN
setup/pkg/arm32/liteidex36.arm32-qt5.5.1.tar.gz


BIN
setup/pkg/linux/go1.20.3.linux-amd64.tar.gz


BIN
setup/pkg/linux/liteidex38.2.linux64-qt5.5.1.tar.gz


+ 45 - 0
setup/setup-arm32.sh

@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# setup-arm32.sh - Setup Go development software on a ARM32/ARMv6l platform.
+
+PATH_CURRENT=`pwd`
+SETUP_ENV_SCRIPT_NAME=setup-arm32.sh
+
+# Find out the path of the setup script
+
+if [ $0 == $SETUP_ENV_SCRIPT_NAME ]; then
+    PATH_SETUP_SH="."
+else
+    PATH_SETUP_SH=${0/%\/$SETUP_ENV_SCRIPT_NAME}
+fi
+
+cd $PATH_SETUP_SH/..
+
+# Root dir of env-go
+
+ROOT_PATH=`pwd`
+
+# Define the paths
+
+TARGET_PATH=$ROOT_PATH/linux
+SOURCE_PATH=$ROOT_PATH/setup/pkg/arm32
+MOD_PATH=$ROOT_PATH/setup/mod/arm32
+
+# Extract files in place
+
+rm -fR $TARGET_PATH
+mkdir -p $TARGET_PATH
+
+cd $TARGET_PATH
+for filename in $SOURCE_PATH/*; do
+    echo ${filename}
+    echo ${filename: -7}
+    if [ ${filename: -7} == ".tar.gz" ]; then
+        tar -xvzf ${filename}
+    fi
+done
+
+# Apply mods
+
+# Copy golint and errcheck into place
+cp $MOD_PATH/go/* $TARGET_PATH/go/bin

+ 45 - 0
setup/setup.sh

@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# setup.sh - Setup Go development software.
+
+PATH_CURRENT=`pwd`
+SETUP_ENV_SCRIPT_NAME=setup.sh
+
+# Find out the path of the setup script
+
+if [ $0 == $SETUP_ENV_SCRIPT_NAME ]; then
+    PATH_SETUP_SH="."
+else
+    PATH_SETUP_SH=${0/%\/$SETUP_ENV_SCRIPT_NAME}
+fi
+
+cd $PATH_SETUP_SH/..
+
+# Root dir of env-go
+
+ROOT_PATH=`pwd`
+
+# Define the paths
+
+TARGET_PATH=$ROOT_PATH/linux
+SOURCE_PATH=$ROOT_PATH/setup/pkg/linux
+MOD_PATH=$ROOT_PATH/setup/mod/linux
+
+# Extract files in place
+
+rm -fR $TARGET_PATH
+mkdir -p $TARGET_PATH
+
+cd $TARGET_PATH
+for filename in $SOURCE_PATH/*; do
+    echo ${filename}
+    echo ${filename: -7}
+    if [ ${filename: -7} == ".tar.gz" ]; then
+        tar -xvzf ${filename}
+    fi
+done
+
+# Apply mods
+
+# Copy golint and errcheck into place
+cp $MOD_PATH/go/* $TARGET_PATH/go/bin