Add .compilation-options file support
This commit is contained in:
parent
b73519ba9c
commit
4bf9ac9c60
@ -23,6 +23,12 @@ func CompileSourcePackage(archiveFilename, outputFilename string, skipChecks boo
|
|||||||
return errors.New("cannot compile a non-source package")
|
return errors.New("cannot compile a non-source package")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read compilation options file in current directory
|
||||||
|
compilationOptions, err := readCompilationOptionsFile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get HOME directory
|
// Get HOME directory
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,7 +87,12 @@ func CompileSourcePackage(archiveFilename, outputFilename string, skipChecks boo
|
|||||||
env = append(env, "BPM_PKG_NAME="+bpmpkg.PkgInfo.Name)
|
env = append(env, "BPM_PKG_NAME="+bpmpkg.PkgInfo.Name)
|
||||||
env = append(env, "BPM_PKG_VERSION="+bpmpkg.PkgInfo.Version)
|
env = append(env, "BPM_PKG_VERSION="+bpmpkg.PkgInfo.Version)
|
||||||
env = append(env, "BPM_PKG_REVISION="+strconv.Itoa(bpmpkg.PkgInfo.Revision))
|
env = append(env, "BPM_PKG_REVISION="+strconv.Itoa(bpmpkg.PkgInfo.Revision))
|
||||||
env = append(env, "BPM_PKG_ARCH="+GetArch())
|
// Check for architecture override in compilation options
|
||||||
|
if val, ok := compilationOptions["ARCH"]; ok {
|
||||||
|
env = append(env, "BPM_PKG_ARCH="+val)
|
||||||
|
} else {
|
||||||
|
env = append(env, "BPM_PKG_ARCH="+GetArch())
|
||||||
|
}
|
||||||
env = append(env, BPMConfig.CompilationEnvironment...)
|
env = append(env, BPMConfig.CompilationEnvironment...)
|
||||||
|
|
||||||
// Execute prepare and build functions in source.sh script
|
// Execute prepare and build functions in source.sh script
|
||||||
@ -200,3 +211,47 @@ func CompileSourcePackage(archiveFilename, outputFilename string, skipChecks boo
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readCompilationOptionsFile() (options map[string]string, err error) {
|
||||||
|
// Initialize options map
|
||||||
|
options = make(map[string]string)
|
||||||
|
|
||||||
|
// Check if file compilation options file exists
|
||||||
|
stat, err := os.Stat(".compilation-options")
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure it is a regular file
|
||||||
|
if !stat.Mode().IsRegular() {
|
||||||
|
return nil, fmt.Errorf("%s is not a regular file", stat.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read file data
|
||||||
|
data, err := os.ReadFile(stat.Name())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(data), "\n") {
|
||||||
|
// Trim line
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
|
||||||
|
// Skip empty lines
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split line
|
||||||
|
split := strings.SplitN(line, "=", 2)
|
||||||
|
|
||||||
|
// Throw error if line isn't valid
|
||||||
|
if len(split) < 2 {
|
||||||
|
return nil, fmt.Errorf("invalid line in compilation-options file: '%s'", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
options[split[0]] = split[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return options, nil
|
||||||
|
}
|
||||||
|
@ -12,7 +12,7 @@ func GetArch() string {
|
|||||||
uname := syscall.Utsname{}
|
uname := syscall.Utsname{}
|
||||||
err := syscall.Uname(&uname)
|
err := syscall.Uname(&uname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
var byteString [65]byte
|
var byteString [65]byte
|
||||||
|
Loading…
x
Reference in New Issue
Block a user