Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wide refactoring #234

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
!*.iml
!*.xml

# So as Makefile
!Makefile


# Don't ignore Github Actions
!.github/workflows/*

Expand All @@ -34,4 +38,4 @@
*.out

# Output of the build script
build/**
build/**
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: build help generate generateAll

help:
@echo "Makefile usage:"
@echo -e "make [help] \tto show this message"
@echo -e "make build \tto build all utilities for host arch"
@echo
@echo -e "./scripts/build.sh usage:"
./scripts/build.sh -h

internal/exclude/exclude.go: internal/exclude/gen.go internal/exclude/genexclude.go
go generate ./internal/exclude

generate: internal/exclude/exclude.go

generateAll:
go generate ./...

build: generate
./scripts/build.sh
File renamed without changes.
11 changes: 6 additions & 5 deletions src/appimaged/appimage.go → cmd/appimaged/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import (
"bytes"
"crypto/md5"
"encoding/hex"
"net/url"

"gopkg.in/ini.v1"

"log"
"net/url"
"os"
"path/filepath"
"strings"
"time"

"gopkg.in/ini.v1"

"github.com/adrg/xdg"

"github.com/probonopd/go-appimage/internal/helpers"
"github.com/probonopd/go-appimage/src/goappimage"
"github.com/probonopd/go-appimage/pkg/goappimage"

"go.lsp.dev/uri"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (
"strings"

"github.com/otiai10/copy"
"github.com/probonopd/go-appimage/internal/exclude"
"github.com/probonopd/go-appimage/internal/helpers"
)

var excludedLibraries = exclude.ExcludedLibraries

type QMLImport struct {
Classname string `json:"classname,omitempty"`
Name string `json:"name"`
Expand Down Expand Up @@ -236,12 +239,12 @@ func AppDirDeploy(path string) {

qtVersionDetected := 0

if containsString(allELFs, "libQt5Core.so.5") == true {
if helpers.ContainsString(allELFs, "libQt5Core.so.5") == true {
log.Println("Detected Qt 5")
qtVersionDetected = 5
}

if containsString(allELFs, "libQtCore.so.4") == true {
if helpers.ContainsString(allELFs, "libQtCore.so.4") == true {
log.Println("Detected Qt 4")
qtVersionDetected = 4
}
Expand Down Expand Up @@ -408,7 +411,7 @@ func deployInterpreter(appdir helpers.AppDir) (string, error) {
// deployElf deploys an ELF (executable or shared library) to the AppDir
// if it is not on the exclude list and it is not yet at the target location
func deployElf(lib string, appdir helpers.AppDir, err error) {
for _, excludePrefix := range ExcludedLibraries {
for _, excludePrefix := range excludedLibraries {
if strings.HasPrefix(filepath.Base(lib), excludePrefix) == true && !options.standalone {
log.Println("Skipping", lib, "because it is on the excludelist")
return
Expand Down Expand Up @@ -513,7 +516,7 @@ func deployCopyrightFiles(appdir helpers.AppDir) {
for _, lib := range allELFs {

shouldDoIt := true
for _, excludePrefix := range ExcludedLibraries {
for _, excludePrefix := range excludedLibraries {
if strings.HasPrefix(filepath.Base(lib), excludePrefix) == true && options.standalone == false {
log.Println("Skipping copyright file for ", lib, "because it is on the excludelist")
shouldDoIt = false
Expand Down Expand Up @@ -797,7 +800,7 @@ func deployGtkDirectory(appdir helpers.AppDir, gtkVersion int) {
// appendLib appends library in path to allELFs and adds its location as well as any pre-existing rpaths to libraryLocations
func appendLib(path string) {

for _, excludedlib := range ExcludedLibraries {
for _, excludedlib := range excludedLibraries {
if filepath.Base(path) == excludedlib && !options.standalone {
// log.Println("Skipping", excludedlib, "because it is on the excludelist")
return
Expand Down
16 changes: 16 additions & 0 deletions cmd/appimagetool/appimagetool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// TODO: Use https://github.com/src-d/go-git or https://github.com/google/go-github to
// * Get changelog history and publish it on PubSub

package main

// ============================
// CONSTANTS
// ============================

// https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html
// The build script needs to set, e.g.,
// go build -ldflags "-X main.commit=$TRAVIS_BUILD_NUMBER"
var commit string

// path to libc
var LibcDir = "libc"
36 changes: 23 additions & 13 deletions src/appimagetool/cli.go → cmd/appimagetool/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"path/filepath"
"time"

"github.com/probonopd/go-appimage/internal/helpers"
"github.com/urfave/cli/v2"

"github.com/probonopd/go-appimage/internal/helpers"
"github.com/probonopd/go-appimage/internal/signing"
"github.com/probonopd/go-appimage/pkg/goappimage"
)

// array of string, Sections contains
Expand All @@ -20,7 +23,8 @@ var Sections = []string{".upd_info", ".sha256_sig", ".sig_key", ".digest_md5"}

// bootstrapAppImageDeploy wrapper function to deploy an AppImage
// from Desktop file
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapAppImageDeploy(c *cli.Context) error {
// make sure the user provided one and one only desktop
if c.NArg() != 1 {
Expand All @@ -38,7 +42,8 @@ func bootstrapAppImageDeploy(c *cli.Context) error {
}

// bootstrapValidateAppImage wrapper function to validate a AppImage
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapValidateAppImage(c *cli.Context) error {

// make sure that we received only 1 file path
Expand Down Expand Up @@ -79,14 +84,16 @@ func bootstrapValidateAppImage(c *cli.Context) error {

// bootstrapSetupSigning wrapper function to setup signing in
// the current Git repository
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapSetupSigning(c *cli.Context) error {
return setupSigning(c.Bool("overwrite"))
return signing.Setup(c.Bool("overwrite"))
}

// bootstrapAppImageSections is a function which converts cli.Context to
// string based arguments. Wrapper function to show the sections of the AppImage
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapAppImageSections(c *cli.Context) error {
// check if the number of arguments are stictly 1, if not
// return
Expand Down Expand Up @@ -135,7 +142,8 @@ func bootstrapAppImageSections(c *cli.Context) error {
// check if all the necessary dependencies exist,
// finally check if the provided argument, AppDir is a directly.
// Call GenerateAppImage with the converted arguments
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapAppImageBuild(c *cli.Context) error {

// check if the number of arguments are stictly 1, if not
Expand Down Expand Up @@ -164,15 +172,17 @@ func bootstrapAppImageBuild(c *cli.Context) error {
// updateinformation: "" (empty string, we want to guess the update information from
// scratch, and if we fail to guess it, then no update metadata for
// the appimage)
GenerateAppImage(
if err = goappimage.GenerateAppImage(
fileToAppDir, "",
true,
"",
"zstd",
true,
"",
"appimagetool",
)
); err != nil {
log.Fatalln("ERROR: in AppImage generation", err)
}
} else {
// TODO: If it is a file, then check if it is an AppImage and if yes, extract it
log.Fatal("Supplied argument is not a directory \n" +
Expand All @@ -199,7 +209,7 @@ func main() {
}

// let the user know that we are running within a docker container
checkRunningWithinDocker()
helpers.CheckRunningWithinDocker()

// build the Command Line interface
// https://github.com/urfave/cli/blob/master/docs/v2/manual.md
Expand All @@ -220,7 +230,7 @@ func main() {

// Add the location of the executable to the $PATH
helpers.AddHereToPath()

// fmt.Println("PATH:", os.Getenv("PATH"))

// Check for needed files on $PATH
Expand All @@ -231,12 +241,12 @@ func main() {
if err != nil {
os.Exit(1)
}

// Check whether we have a sufficient version of mksquashfs for -offset
if helpers.CheckIfSquashfsVersionSufficient("mksquashfs") == false {
os.Exit(1)
}

// define subcommands, like 'deploy', 'validate', ...
app.Commands = []*cli.Command{
{
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 15 additions & 6 deletions src/mkappimage/mkappimage.go → cmd/mkappimage/mkappimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import (
"path/filepath"
"time"

"github.com/probonopd/go-appimage/internal/helpers"
"github.com/urfave/cli/v2"

"github.com/probonopd/go-appimage/internal/helpers"
"github.com/probonopd/go-appimage/pkg/goappimage"
)

// https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html
// The build script needs to set, e.g.,
// go build -ldflags "-X main.commit=$TRAVIS_BUILD_NUMBER"
var commit string

// listFilesInAppImage lists the files in the AppImage, similar to
// the ls command in UNIX systems
func listFilesInAppImage(path string) {
Expand Down Expand Up @@ -38,7 +45,8 @@ func listLongFilesInAppImage(path string) {
// check if all the necessary dependencies exist,
// finally check if the provided argument, AppDir is a directly.
// Call GenerateAppImage with the converted arguments
// Args: c: cli.Context
//
// Args: c: cli.Context
func bootstrapMkAppImage(c *cli.Context) error {

// check if the number of arguments are stictly 1, if not
Expand Down Expand Up @@ -112,7 +120,7 @@ func bootstrapMkAppImage(c *cli.Context) error {
}

// now generate the appimage
GenerateAppImage(
if err := goappimage.GenerateAppImage(
fileToAppDir,
fileToAppImageOutput,
shouldGuessUpdateInformation,
Expand All @@ -121,8 +129,9 @@ func bootstrapMkAppImage(c *cli.Context) error {
shouldValidateAppstream,
receivedUpdateInformation,
"mkappimage",
)

); err != nil {
log.Fatalln("ERROR: in AppImage generation", err)
}
} else {
if c.Bool("list") || c.Bool("listlong") {
// check if the file provided as argument is an AppImage
Expand Down Expand Up @@ -162,7 +171,7 @@ func main() {
}

// let the user know that we are running within a docker container
checkRunningWithinDocker()
helpers.CheckRunningWithinDocker()

// build the Command Line interface
// https://github.com/urfave/cli/blob/master/docs/v2/manual.md
Expand Down
12 changes: 3 additions & 9 deletions src/appimagetool/exclude.go → internal/exclude/exclude.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/exclude/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package exclude

//go:generate go run genexclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main

import (
"errors"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -81,7 +82,7 @@ var packageTemplate = template.Must(template.New("").Parse(`// Code generated by
// {{ .Timestamp }}
// using data from
// {{ .URL }}
package main
package exclude

var ExcludedLibraries = []string{
{{- range .Libraries }}
Expand Down
Loading