aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-01-03 18:04:08 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-01-03 20:24:29 +0200
commit23a7f3baa33265519840609dc54e950615ec39b1 (patch)
treeff2737f76b63a2acf5f8a9fffd5c15e3eb4c46c8 /tools
parentWebProfile refactoring (diff)
downloadsmolbote-23a7f3baa33265519840609dc54e950615ec39b1.tar.xz
Merge some QoL improvements from staging branch
- Build executable in top-level buildroot - Use meson sourceset - Pull in poi-crash and poi-update from staging - Remove extraneous scripts in tools/ - Pull in configure scripts in scripts/
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-license.rb18
-rwxr-xr-xtools/deploy/get-latest-builds.sh23
-rwxr-xr-xtools/format-code.sh4
-rw-r--r--tools/gpgkey.preset18
-rwxr-xr-xtools/list-authors.sh12
-rw-r--r--tools/meson.build36
-rwxr-xr-xtools/report-clang-tidy.sh16
-rwxr-xr-xtools/report-cppcheck.sh4
-rw-r--r--tools/src/crashhandler/defaults.go.in4
-rw-r--r--tools/src/crashhandler/main.go79
-rw-r--r--tools/src/updater/main.go47
-rw-r--r--tools/src/updater/manifest.go16
-rwxr-xr-xtools/ssl-keygen.py59
-rw-r--r--tools/updater/download.go88
-rw-r--r--tools/updater/main.go77
-rw-r--r--tools/updater/manifest.go41
16 files changed, 182 insertions, 360 deletions
diff --git a/tools/check-license.rb b/tools/check-license.rb
deleted file mode 100755
index 8eeb6bb..0000000
--- a/tools/check-license.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env ruby
-
-result = 0
-files = Dir.glob("src/**/*.h") + Dir.glob("src/**/*.cpp") \
- + Dir.glob("lib/**/*.h") + Dir.glob("lib/**/*.cpp") \
- + Dir.glob("plugins/**/*.h") + Dir.glob("plugins/**/*.cpp")
-
-puts 'Checking licenses...'
-files.each { |name|
- File.open(name) { |file|
- if file.grep(/SPDX-License-Identifier/).empty? then
- puts "Missing or incorrect license header: #{name}"
- result += 1
- end
- }
-}
-
-exit result
diff --git a/tools/deploy/get-latest-builds.sh b/tools/deploy/get-latest-builds.sh
deleted file mode 100755
index fc3046d..0000000
--- a/tools/deploy/get-latest-builds.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-echo Get build information
-curl -o project-meta.json -H "Content-Type: application/json" https://ci.appveyor.com/api/projects/XianNox/smolbote-hg
-
-commit=$(jq -r .build.commitId project-meta.json)
-echo Build commit: $commit
-
-for (( i=0; i<$(jq -r '.build.jobs | length' project-meta.json); i++ ))
-do
- jobId=$(jq -r .build.jobs[$i].jobId project-meta.json)
- osType=$(jq -r .build.jobs[$i].osType project-meta.json)
-
- echo Downloading $jobId-$osType
- curl -o smolbote-nightly-$commit-$osType.7z -L https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/smolbote.7z
-
- echo Extracting package
- 7za x smolbote-nightly-$commit-$osType.7z smolbote-install/bin
- mv smolbote-nightly-$commit-$osType.7z serve/
- mv smolbote-install/bin serve/smolbote-$commit-$osType
- rm -r smolbote-install
-done
-
diff --git a/tools/format-code.sh b/tools/format-code.sh
deleted file mode 100755
index 68be1d8..0000000
--- a/tools/format-code.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-# get names of staged files | filter out the header and cpp files | clang-format them
-git diff --staged --name-only | grep --regex="\.h\|\.cpp" | xargs clang-format -i
diff --git a/tools/gpgkey.preset b/tools/gpgkey.preset
deleted file mode 100644
index c33c12c..0000000
--- a/tools/gpgkey.preset
+++ /dev/null
@@ -1,18 +0,0 @@
-# https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html
-# To generate key: gpg2 --homedir=gpg-fakehome --batch --generate-key --expert gpgkey.preset
-# To list key: gpg2 --homedir=gpg-fakehome --list-keys
-%echo Generating GPG key (ed25519-sign)
-
-Key-Type: EdDSA
-Key-Curve: ed25519
-Key-Length: 256
-Key-Usage: sign
-
-Name-Real: smolbote build process
-Name-Email: smolbote@localhost
-
-Passphrase: null
-
-%commit
-%echo Generating key done
-
diff --git a/tools/list-authors.sh b/tools/list-authors.sh
deleted file mode 100755
index 430d4a9..0000000
--- a/tools/list-authors.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/bash
-
-# git shortlog:
-# -s (--summary): suppress commit description
-# -n (--numbered): sort according to number of commits per author
-# -e (--email): show email address of author
-
-# sed:
-# replace (any spaces)(any numbers)(any spaces) with ' - '
-# this replaces the commit numbers and turns it into a bullet list
-git shortlog -sne $1 | sed -e 's/^\s*[0-9]*\s*/ - /g'
-
diff --git a/tools/meson.build b/tools/meson.build
new file mode 100644
index 0000000..fd1547e
--- /dev/null
+++ b/tools/meson.build
@@ -0,0 +1,36 @@
+if get_option('crashhandler').enabled() or get_option('updater').enabled()
+ go = find_program('go', required: true)
+ go_args = [ '-buildmode=pie' ]
+endif
+
+if get_option('crashhandler').enabled()
+
+# normally, you'd use configure_file to create this file, but that would only place it in build,
+# and go will refuse to build from files in two different directories
+meson.add_postconf_script(meson.source_root()/'scripts/gen-crashhandler-default-go.py',
+ '--kconfig=' + meson.source_root()/'Kconfig',
+ '--dotconfig=' + meson.source_root()/host_machine.system()/'.config',
+ '--input=' + meson.current_source_dir()/'src/crashhandler/defaults.go.in',
+ '--output=' + meson.current_source_dir()/'src/crashhandler/defaults.go'
+)
+
+custom_target('poi-crash',
+ input: [ files('src/updater/main.go'), meson.current_source_dir()/'src/crashhandler/defaults.go' ],
+ output: 'poi-crash',
+ command: ['env', 'GOPATH='+meson.current_source_dir(), go, 'build', go_args, '-o=@OUTPUT@', 'crashhandler'],
+ build_by_default: true,
+ install: true,
+ install_dir: get_option('bindir'),
+)
+endif
+
+if get_option('updater').enabled()
+custom_target('poi-update',
+ input: files('src/updater/main.go'),
+ output: 'poi-update',
+ command: ['env', 'GOPATH='+meson.current_source_dir(), go, 'build', go_args, '-o=@OUTPUT@', 'updater'],
+ build_by_default: true,
+ install: true,
+ install_dir: get_option('bindir'),
+)
+endif
diff --git a/tools/report-clang-tidy.sh b/tools/report-clang-tidy.sh
deleted file mode 100755
index eddb703..0000000
--- a/tools/report-clang-tidy.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-cp build/compile_commands.json tidy/compile_commands.json
-
-# https://bugs.llvm.org/show_bug.cgi?id=37315
-sed -i 's/-pipe//g' tidy/compile_commands.json
-# do not scan system headers (replace -I with -isystem)
-sed -i 's/\-I\/usr\/include/\-isystem\/usr\/include/g' tidy/compile_commands.json
-
-for folder in $(find src lib -type d)
-do
- if [[ $folder != *'test' ]]; then
- clang-tidy -p tidy $folder/*.cpp $folder/*.h > reports/clangtidy-$(basename $folder).txt
- fi
-done
-
diff --git a/tools/report-cppcheck.sh b/tools/report-cppcheck.sh
deleted file mode 100755
index 2e42226..0000000
--- a/tools/report-cppcheck.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-cppcheck --enable=all --project=tidy/compile_commands.json 2> report.txt
-
diff --git a/tools/src/crashhandler/defaults.go.in b/tools/src/crashhandler/defaults.go.in
new file mode 100644
index 0000000..2ea5827
--- /dev/null
+++ b/tools/src/crashhandler/defaults.go.in
@@ -0,0 +1,4 @@
+package main
+
+var dumpPath = "@PATH_CRASHDUMP@"
+
diff --git a/tools/src/crashhandler/main.go b/tools/src/crashhandler/main.go
new file mode 100644
index 0000000..00ce0cd
--- /dev/null
+++ b/tools/src/crashhandler/main.go
@@ -0,0 +1,79 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "strings"
+)
+
+type CrashDump struct {
+ Name string
+ DumpPath string
+ MetadataPath string
+}
+
+func expandHomeDir(path string) (string, error) {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return path, err
+ }
+
+ return strings.Replace(path, "~/", home, -1), nil
+}
+
+func dumps(path string) ([]CrashDump, error) {
+ files, err := ioutil.ReadDir(path)
+ if err != nil {
+ return nil, err
+ }
+
+ var crashes []CrashDump
+
+ for i, file := range files {
+ if strings.HasSuffix(file.Name(), ".dmp") {
+ if i+1 < len(files) && files[i+1].Name() == file.Name()+".txt" {
+ crashes = append(crashes, CrashDump{Name: strings.TrimSuffix(file.Name(), ".dmp"),
+ DumpPath: file.Name(), MetadataPath: files[i+1].Name()})
+ } else {
+ crashes = append(crashes, CrashDump{Name: strings.TrimSuffix(file.Name(), ".dmp"), DumpPath: file.Name()})
+ }
+ }
+ }
+
+ return crashes, nil
+}
+
+func main() {
+ helpFlag := flag.Bool("help", false, "Show help information.")
+ flag.StringVar(&dumpPath, "crashd", dumpPath, "Crash dump path")
+
+ // create crash report flags
+ crashedFlag := flag.String("c", "", "Create crash report at specified location and write any specified data into it")
+
+ flag.Parse()
+ dumpPath, _ = expandHomeDir(dumpPath)
+
+ if *helpFlag {
+ flag.PrintDefaults()
+ return
+ }
+
+ if *crashedFlag != "" {
+ fmt.Println("Creating crash dump report", *crashedFlag)
+ contents := []byte("Additional information: " + strings.Join(flag.Args(), ""))
+ ioutil.WriteFile(*crashedFlag+".txt", contents, 0644)
+ return
+ }
+
+ fmt.Printf("[%s]\n", dumpPath)
+ c, err := dumps(dumpPath)
+ if err != nil {
+ panic(err)
+ }
+ for _, d := range c {
+ fmt.Printf("\t- %s\n", d.Name)
+ }
+
+}
diff --git a/tools/src/updater/main.go b/tools/src/updater/main.go
new file mode 100644
index 0000000..e6e1560
--- /dev/null
+++ b/tools/src/updater/main.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "net/http"
+ "encoding/json"
+ "io/ioutil"
+)
+
+func main() {
+ helpFlag := flag.Bool("help", false, "Show help information")
+ //verboseFlag := flag.Bool("verbose", false, "Print more information")
+ //repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote/downloads", "Repository path")
+ //dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download")
+
+ flag.Parse()
+
+ branchesRequest := "https://neueland.iserlohn-fortress.net/gitea/api/v1/repos/aqua/smolbote/branches"
+
+ // help flag --> show usage and exit
+ if *helpFlag {
+ flag.PrintDefaults()
+ return
+ }
+
+ response, err := http.Get(branchesRequest)
+ if err != nil {
+ panic(err)
+ } else if response.StatusCode != 200 {
+ fmt.Printf("Could not get manifest: %s\n", response.Status)
+ return
+ }
+ defer response.Body.Close()
+
+ body, _ := ioutil.ReadAll(response.Body)
+
+ var branches []BranchResponse
+ json.Unmarshal(body, &branches)
+
+
+ for _,v := range(branches) {
+ fmt.Printf("%s\t%s %s\n", v.Name, v.Commit.ID, v.Commit.Timestamp)
+ }
+ fmt.Println("done")
+
+}
diff --git a/tools/src/updater/manifest.go b/tools/src/updater/manifest.go
new file mode 100644
index 0000000..f9d3d86
--- /dev/null
+++ b/tools/src/updater/manifest.go
@@ -0,0 +1,16 @@
+package main
+
+import (
+ "time"
+)
+
+type CommitResponse struct {
+ ID string `json:"id"`
+ Timestamp time.Time `json:"timestamp"`
+}
+
+type BranchResponse struct {
+ Name string `json:"name"`
+ Commit CommitResponse `json:"commit"`
+}
+
diff --git a/tools/ssl-keygen.py b/tools/ssl-keygen.py
deleted file mode 100755
index 555b379..0000000
--- a/tools/ssl-keygen.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import sys
-import os.path
-import subprocess
-from functools import partial
-
-def generate_private_key(out_pem='privateKey.pem'):
- subprocess.run(['openssl', 'genrsa', '-out', out_pem, '4096'], check=True)
-
-def generate_public_key(in_pem='privateKey.pem', out_pem='publicKey.pem'):
- subprocess.run(['openssl', 'rsa', '-in', in_pem, '-pubout', '-out', out_pem], check=True)
-
-def hexdump(array_type, array_name, length_type, in_pem, out_h):
- n = 0
-
- print("// Autogenerated hex dump of OpenSSL public key, do not edit", file=out_h)
- print("{} {}[] = {{".format(array_type, array_name), file=out_h)
-
- for line in iter(partial(in_pem.read, 16), b''):
- l = list(line)
- for n, i in enumerate(l):
- l[n] = '0x{:02X}'.format(i)
-
- print(" {},".format(", ".join(l)), file=out_h)
-
- n += 1
-
- print("};", file=out_h)
- print("{} {}_len = {};".format(length_type, array_name, n), file=out_h)
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='Generate OpenSSL key and hexdump')
-
- parser.add_argument('--private', default='privateKey.pem', type=str, help='Private key input')
- parser.add_argument('--public', default='publicKey.pem', type=str, help='Public key input')
-
- parser.add_argument('--output', type=argparse.FileType('wt'), default=sys.stdout, help='Output file')
-
- parser.add_argument('--array-type', type=str, default='const unsigned char', help='Array type')
- parser.add_argument('--length-type', type=str, default='const unsigned int', help='Length type')
- parser.add_argument('--array-name', type=str, default='a', help='Array name')
-
- args=parser.parse_args()
-
- # check if public key exists
- if not os.path.isfile(args.public):
- # if there is no private key, generate one
- if not os.path.isfile(args.private):
- generate_private_key(args.private)
-
- # export public key from private
- generate_public_key(args.private, args.public)
-
- with open(args.public, "rb") as public_pem:
- hexdump(args.array_type, args.array_name, args.length_type, public_pem, args.output)
-
-
diff --git a/tools/updater/download.go b/tools/updater/download.go
deleted file mode 100644
index 8c9de9a..0000000
--- a/tools/updater/download.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package main
-
-import (
- "fmt"
- "io"
- "net/http"
- "os"
- "path/filepath"
- "strings"
-)
-
-func Min(x, y int64) int64 {
- if x < y {
- return x
- }
- return y
-}
-
-func Max(x, y int64) int64 {
- if x > y {
- return x
- }
- return y
-}
-
-// WriteCounter counts the number of bytes written to it
-type WriteCounter struct {
- ContentLength int64
- BytesWritten uint64
-
- Step int64
-}
-
-func NewWriteCounter(contentLength int64) *WriteCounter {
- ptr := new(WriteCounter)
- ptr.ContentLength = contentLength
- ptr.Step = Max(contentLength/20, 1)
-
- return ptr
-}
-
-func (wc *WriteCounter) Write(p []byte) (int, error) {
- n := len(p)
- wc.BytesWritten += uint64(n)
- wc.PrintProgress()
- return n, nil
-}
-
-func (wc *WriteCounter) PrintProgress() {
- // clear the line by using a character return to go back to the start of the
- // line and remove the remaining characters
- fmt.Printf("\r%s", strings.Repeat(" ", 35))
-
- // steps can be at most 20 -> get the minimum of (n_steps) and 20
- steps := int(Min(int64(wc.BytesWritten)/wc.Step, 20))
-
- fmt.Printf("\r[%s%s] %d/%d bytes complete", strings.Repeat("#", steps), strings.Repeat(" ", 20-steps), wc.BytesWritten, wc.ContentLength)
-}
-
-func downloadFile(path string, url string) error {
- // make sure dir exists
- os.MkdirAll(filepath.Dir(path), 0755)
-
- // create .part file
- output, err := os.Create(path + ".part")
- if err != nil {
- return err
- }
- defer output.Close()
-
- // get data
- response, err := http.Get(url)
- if err != nil {
- return err
- }
- defer response.Body.Close()
-
- // create progress reporter
- counter := NewWriteCounter(response.ContentLength)
- _, err = io.Copy(output, io.TeeReader(response.Body, counter))
- if err != nil {
- return err
- }
-
- fmt.Printf("\n")
- output.Close()
- return os.Rename(path+".part", path)
-}
diff --git a/tools/updater/main.go b/tools/updater/main.go
deleted file mode 100644
index baef1f1..0000000
--- a/tools/updater/main.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package main
-
-import (
- "bufio"
- "flag"
- "fmt"
- "net/http"
- "os"
- "runtime"
- "strings"
-)
-
-func fail(err error) {
- fmt.Printf("An error has occurred:\n%s\n", err.Error())
- if runtime.GOOS == "windows" {
- fmt.Print("Press 'Enter' to continue...")
- fmt.Scanln()
- }
- os.Exit(-1)
-}
-
-func main() {
- helpFlag := flag.Bool("help", false, "Show help information")
- verboseFlag := flag.Bool("verbose", false, "Print more information")
- repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote/downloads", "Repository path")
- platformFlag := flag.String("platform", runtime.GOOS, "Platform")
- dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download")
-
- flag.Parse()
-
- manifestPath := fmt.Sprintf("%s/%s-sha512.txt", *repoFlag, *platformFlag)
- repoPath := fmt.Sprintf("%s/%s/", *repoFlag, *platformFlag)
-
- // help flag --> show usage and exit
- if *helpFlag {
- fmt.Println("Usage:")
- flag.PrintDefaults()
-
- fmt.Println("Paths:")
- fmt.Println(" manifest ", manifestPath)
- fmt.Println(" repository ", repoPath)
- return
- }
-
- response, err := http.Get(manifestPath)
- if err != nil {
- fail(err)
- } else if response.StatusCode != 200 {
- fmt.Printf("Could not get manifest: %s\n", response.Status)
- return
- }
- defer response.Body.Close()
-
- // read through manifest
- scanner := bufio.NewScanner(response.Body)
- for scanner.Scan() {
- s := strings.Split(scanner.Text(), " ")
-
- filepath := s[1]
- checksum := s[0]
-
- if same, err := checkFile(filepath, checksum); err != nil {
- fail(err)
- } else {
- if *verboseFlag {
- fmt.Printf("[%s]: %t\n", filepath, same)
- }
-
- if !same && !*dryRunFlag {
- if err := downloadFile(filepath, repoPath+filepath); err != nil {
- fail(err)
- }
- }
- }
- }
-
-}
diff --git a/tools/updater/manifest.go b/tools/updater/manifest.go
deleted file mode 100644
index 0d8bfae..0000000
--- a/tools/updater/manifest.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package main
-
-import (
- "crypto/sha512"
- "fmt"
- "io"
- "os"
-)
-
-func checkFile(filepath string, checksum string) (bool, error) {
- if _, err := os.Stat(filepath); os.IsNotExist(err) {
- return false, nil
- }
-
- // file exists, check checksum
- lsum, err := hash(filepath)
- if err != nil {
- return false, err
- }
-
- if checksum != fmt.Sprintf("%x", lsum) {
- return false, nil
- }
-
- return true, nil
-}
-
-func hash(filepath string) ([]byte, error) {
- file, err := os.Open(filepath)
- if err != nil {
- return nil, err
- }
- defer file.Close()
-
- hasher := sha512.New()
- if _, err := io.Copy(hasher, file); err != nil {
- return nil, err
- }
-
- return hasher.Sum(nil), nil
-}