mirror of
https://github.com/mappu/miqt.git
synced 2025-02-08 22:10:23 +00:00
rcc: construct a more accurate go:generate line for rebuilding
This commit is contained in:
parent
d8cb5494a0
commit
730153c7f2
@ -10,9 +10,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultPackageName string = "main"
|
||||||
|
DefaultVariableName string = "_resourceRcc"
|
||||||
|
DefaultIsQt6 bool = false
|
||||||
|
DefaultRccBinary string = "rcc"
|
||||||
|
)
|
||||||
|
|
||||||
func RccExec() error {
|
func RccExec() error {
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
@ -20,10 +28,10 @@ func RccExec() error {
|
|||||||
input := flag.String("Input", "", "Path to .qrc input file")
|
input := flag.String("Input", "", "Path to .qrc input file")
|
||||||
outputGo := flag.String("OutputGo", "", "(Optional) Path to .go output file. If omitted, interred from the input file path")
|
outputGo := flag.String("OutputGo", "", "(Optional) Path to .go output file. If omitted, interred from the input file path")
|
||||||
outputRcc := flag.String("OutputRcc", "", "(Optional) Path to .rcc output file. If omitted, inferred from the output Go file path")
|
outputRcc := flag.String("OutputRcc", "", "(Optional) Path to .rcc output file. If omitted, inferred from the output Go file path")
|
||||||
packageName := flag.String("Package", "main", "Package to use in generated Go files")
|
packageName := flag.String("Package", DefaultPackageName, "Package to use in generated Go files")
|
||||||
variableName := flag.String("VariableName", "_resourceRcc", "Temporary global variable name for loading embedded data")
|
variableName := flag.String("VariableName", DefaultVariableName, "Temporary global variable name for loading embedded data")
|
||||||
useQt6 := flag.Bool("Qt6", false, "Use Qt 6 instead of Qt 5")
|
useQt6 := flag.Bool("Qt6", DefaultIsQt6, "Use Qt 6 instead of Qt 5")
|
||||||
rccBinary := flag.String("RccBinary", "rcc", "(Optional) Custom path to the Qt rcc program")
|
rccBinary := flag.String("RccBinary", DefaultRccBinary, "(Optional) Custom path to the Qt rcc program")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Check if input file exists
|
// Check if input file exists
|
||||||
@ -59,17 +67,38 @@ func RccExec() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Go file that loads the resource
|
// Figure out import statement
|
||||||
|
|
||||||
miqtImport := `"github.com/mappu/miqt/qt"`
|
miqtImport := `"github.com/mappu/miqt/qt"`
|
||||||
if *useQt6 {
|
if *useQt6 {
|
||||||
miqtImport = `qt "github.com/mappu/miqt/qt6"`
|
miqtImport = `qt "github.com/mappu/miqt/qt6"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Figure out regeneration command
|
||||||
|
|
||||||
|
generate := `miqt-rcc` +
|
||||||
|
` -Input ` + strconv.Quote(*input) +
|
||||||
|
` -OutputGo ` + strconv.Quote(filepath.Base(*outputGo)) +
|
||||||
|
` -OutputRcc ` + strconv.Quote(embedPath)
|
||||||
|
if *packageName != DefaultPackageName {
|
||||||
|
generate += ` -Package ` + strconv.Quote(*packageName)
|
||||||
|
}
|
||||||
|
if *variableName != DefaultVariableName {
|
||||||
|
generate += ` -Variable ` + strconv.Quote(*variableName)
|
||||||
|
}
|
||||||
|
if *useQt6 != DefaultIsQt6 {
|
||||||
|
generate += ` -Qt6`
|
||||||
|
}
|
||||||
|
if *rccBinary != DefaultRccBinary {
|
||||||
|
generate += ` -RccBinary ` + strconv.Quote(*rccBinary)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Go file that loads the resource
|
||||||
|
|
||||||
goSrcData := `
|
goSrcData := `
|
||||||
package ` + *packageName + `
|
package ` + *packageName + `
|
||||||
|
|
||||||
//go:generate miqt-rcc "` + strings.Join(os.Args[1:], `" "`) + `"
|
//go:generate ` + generate + `
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user