clone and build rosettax87
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.burkey.co/eburk/epochcli/pkg/epoch"
|
||||
"github.com/go-git/go-git/v6"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -84,29 +85,15 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
log.Debugf("Successfully copied %s to %s", resourceName, destPath)
|
||||
}
|
||||
|
||||
log.Debugf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
|
||||
if err := os.RemoveAll(targetRosettaX87Dir); err != nil {
|
||||
log.Debugf("Warning: could not remove existing rosettax87 folder '%s': %v", targetRosettaX87Dir, err)
|
||||
}
|
||||
if err := os.MkdirAll(targetRosettaX87Dir, 0755); err != nil {
|
||||
errMsg := fmt.Sprintf("failed to create directory %s: %v", targetRosettaX87Dir, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
|
||||
rosettaFilesToCopy := map[string]string{
|
||||
"rosettax87/rosettax87": filepath.Join(targetRosettaX87Dir, "rosettax87"),
|
||||
"rosettax87/libRuntimeRosettax87": filepath.Join(targetRosettaX87Dir, "libRuntimeRosettax87"),
|
||||
}
|
||||
|
||||
for resourceName, destPath := range rosettaFilesToCopy {
|
||||
log.Debugf("Processing rosetta resource: %s to %s", resourceName, destPath)
|
||||
resource, err := fyne.LoadResourceFromPath(resourceName)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
|
||||
if _, err := os.Stat(filepath.Join(paths.EpochPath, "rosettax87")); err == nil {
|
||||
log.Debugf("rosettax87 path already exists, skipping copy")
|
||||
} else {
|
||||
log.Debugf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
|
||||
if err := os.RemoveAll(targetRosettaX87Dir); err != nil {
|
||||
log.Debugf("Warning: could not remove existing rosettax87 folder '%s': %v", targetRosettaX87Dir, err)
|
||||
}
|
||||
if err := os.MkdirAll(targetRosettaX87Dir, 0755); err != nil {
|
||||
errMsg := fmt.Sprintf("failed to create directory %s: %v", targetRosettaX87Dir, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
@@ -114,40 +101,58 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
return
|
||||
}
|
||||
|
||||
destinationFile, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
rosettaFilesToCopy := map[string]string{
|
||||
"rosettax87/rosettax87": filepath.Join(targetRosettaX87Dir, "rosettax87"),
|
||||
"rosettax87/libRuntimeRosettax87": filepath.Join(targetRosettaX87Dir, "libRuntimeRosettax87"),
|
||||
}
|
||||
|
||||
_, err = io.Copy(destinationFile, bytes.NewReader(resource.Content()))
|
||||
if err != nil {
|
||||
destinationFile.Close()
|
||||
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
destinationFile.Close()
|
||||
|
||||
if filepath.Base(destPath) == "rosettax87" {
|
||||
log.Debugf("Setting execute permission for %s", destPath)
|
||||
if err := os.Chmod(destPath, 0755); err != nil {
|
||||
errMsg := fmt.Sprintf("failed to set execute permission for %s: %v", destPath, err)
|
||||
for resourceName, destPath := range rosettaFilesToCopy {
|
||||
log.Debugf("Processing rosetta resource: %s to %s", resourceName, destPath)
|
||||
resource, err := fyne.LoadResourceFromPath(resourceName)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
|
||||
destinationFile, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(destinationFile, bytes.NewReader(resource.Content()))
|
||||
if err != nil {
|
||||
destinationFile.Close()
|
||||
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
destinationFile.Close()
|
||||
|
||||
if filepath.Base(destPath) == "rosettax87" {
|
||||
log.Debugf("Setting execute permission for %s", destPath)
|
||||
if err := os.Chmod(destPath, 0755); err != nil {
|
||||
errMsg := fmt.Sprintf("failed to set execute permission for %s: %v", destPath, err)
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
log.Debug(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Debugf("Successfully copied %s to %s", resourceName, destPath)
|
||||
}
|
||||
log.Debugf("Successfully copied %s to %s", resourceName, destPath)
|
||||
}
|
||||
|
||||
log.Debugf("Checking dlls.txt file at: %s", dllsTextFile)
|
||||
@@ -266,7 +271,7 @@ func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
if strings.Contains(err.Error(), "operation not permitted") {
|
||||
errMsg += "\n\nSolution: Open System Settings, go to Privacy & Security > App Management, and enable EpochSilicon."
|
||||
}
|
||||
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
|
||||
dialog.ShowError(fmt.Errorf("%s", errMsg), myWindow)
|
||||
paths.PatchesAppliedCrossOver = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
@@ -462,3 +467,46 @@ func isConfigSettingCorrect(configText, setting, expectedValue string) bool {
|
||||
currentValue := matches[1]
|
||||
return currentValue == expectedValue
|
||||
}
|
||||
|
||||
func BuildRosetta() (string, string, error) {
|
||||
tmpDir, err := os.MkdirTemp("", "rosettax87")
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to create temporary directory: %v", err)
|
||||
}
|
||||
|
||||
clonedDir := filepath.Join(tmpDir, "rosettax87")
|
||||
|
||||
_, err = git.PlainClone(clonedDir, &git.CloneOptions{
|
||||
URL: "https://github.com/fputs/rosettax87",
|
||||
Progress: log.Writer,
|
||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
||||
SingleBranch: true,
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to clone repository: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("cmake", "-B", "build")
|
||||
cmd.Dir = clonedDir
|
||||
cmd.Stdout = log.Writer
|
||||
cmd.Stderr = log.Writer
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to create build files: %v", err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("cmake", "--build", "build")
|
||||
cmd.Dir = clonedDir
|
||||
cmd.Stdout = log.Writer
|
||||
cmd.Stderr = log.Writer
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to build rosettax87: %v", err)
|
||||
}
|
||||
|
||||
buildDir := filepath.Join(clonedDir, "build")
|
||||
rosettax87Path := filepath.Join(buildDir, "rosettax87")
|
||||
librosettaPath := filepath.Join(buildDir, "libRuntimeRosettax87")
|
||||
|
||||
return rosettax87Path, librosettaPath, nil
|
||||
}
|
||||
|
15
pkg/patching/patching_test.go
Normal file
15
pkg/patching/patching_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package patching
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildRosetta(t *testing.T) {
|
||||
rp, lp, err := BuildRosetta()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println("exe path:", rp)
|
||||
fmt.Println("lib path:", lp)
|
||||
}
|
Reference in New Issue
Block a user