Skip to content

Commit e1014a0

Browse files
jld3103pchampio
authored andcommitted
Fix 'strip' not available on windows/darwin (#49)
* Fix 'strip' not available on windows/darwin * Add documentation for engine file * Fix output directory path
1 parent 9b42aa6 commit e1014a0

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

cmd/build.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,12 @@ func buildInDocker(targetOS string, vmArguments []string) {
285285
if runtime.GOOS != "windows" {
286286
chownStr = fmt.Sprintf(" && chown %s:%s ./ -R", u.Uid, u.Gid)
287287
}
288-
args = append(args, "bash", "-c", fmt.Sprintf("%s%s", strings.Join(buildCommand(targetOS, vmArguments, "build/outputs/"+targetOS+"/"+build.OutputBinaryName(pubspec.GetPubSpec().Name, targetOS)), " "), chownStr))
288+
stripStr := ""
289+
if targetOS == "linux" {
290+
outputEngineFile := filepath.Join("/app", build.BuildPath, "build", "outputs", targetOS, build.EngineFile(targetOS))
291+
stripStr = fmt.Sprintf("strip -s %s && ", outputEngineFile)
292+
}
293+
args = append(args, "bash", "-c", fmt.Sprintf("%s%s%s", stripStr, strings.Join(buildCommand(targetOS, vmArguments, "build/outputs/"+targetOS+"/"+build.OutputBinaryName(pubspec.GetPubSpec().Name, targetOS)), " "), chownStr))
289294
dockerRunCmd := exec.Command(build.DockerBin, args...)
290295
dockerRunCmd.Stderr = os.Stderr
291296
dockerRunCmd.Stdout = os.Stdout
@@ -383,32 +388,15 @@ func buildNormal(targetOS string, vmArguments []string) {
383388
}
384389
}
385390

386-
var engineFile string
387-
switch targetOS {
388-
case "darwin":
389-
engineFile = "FlutterEmbedder.framework"
390-
case "linux":
391-
engineFile = "libflutter_engine.so"
392-
case "windows":
393-
engineFile = "flutter_engine.dll"
394-
}
395-
396-
outputEngineFile := filepath.Join(build.OutputDirectoryPath(targetOS), engineFile)
391+
outputEngineFile := filepath.Join(build.OutputDirectoryPath(targetOS), build.EngineFile(targetOS))
397392
err = copy.Copy(
398-
filepath.Join(engineCachePath, engineFile),
393+
filepath.Join(engineCachePath, build.EngineFile(targetOS)),
399394
outputEngineFile,
400395
)
401396
if err != nil {
402-
log.Errorf("Failed to copy %s: %v", engineFile, err)
397+
log.Errorf("Failed to copy %s: %v", build.EngineFile(targetOS), err)
403398
os.Exit(1)
404399
}
405-
if !buildDebug && targetOS == "linux" {
406-
err = exec.Command("strip", "-s", outputEngineFile).Run()
407-
if err != nil {
408-
log.Errorf("Failed to strip %s: %v", outputEngineFile, err)
409-
os.Exit(1)
410-
}
411-
}
412400

413401
err = copy.Copy(
414402
filepath.Join(engineCachePath, "artifacts", "icudtl.dat"),
@@ -489,6 +477,14 @@ func buildNormal(targetOS string, vmArguments []string) {
489477
return
490478
}
491479

480+
if !buildDebug && targetOS == "linux" {
481+
err = exec.Command("strip", "-s", outputEngineFile).Run()
482+
if err != nil {
483+
log.Errorf("Failed to strip %s: %v", outputEngineFile, err)
484+
os.Exit(1)
485+
}
486+
}
487+
492488
buildCommandString := buildCommand(targetOS, vmArguments, build.OutputBinaryPath(pubspec.GetPubSpec().Name, targetOS))
493489
cmdGoBuild := exec.Command(buildCommandString[0], buildCommandString[1:]...)
494490
cmdGoBuild.Dir = filepath.Join(wd, build.BuildPath)

internal/build/build.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,20 @@ func OutputBinaryPath(projectName string, targetOS string) string {
5454
outputBinaryPath := filepath.Join(OutputDirectoryPath(targetOS), OutputBinaryName(projectName, targetOS))
5555
return outputBinaryPath
5656
}
57+
58+
// EngineFile returns the name of the engine file from flutter for the
59+
// specified platform.
60+
func EngineFile(targetOS string) string {
61+
switch targetOS {
62+
case "darwin":
63+
return "FlutterEmbedder.framework"
64+
case "linux":
65+
return "libflutter_engine.so"
66+
case "windows":
67+
return "flutter_engine.dll"
68+
default:
69+
log.Errorf("%s has no implemented engine file", targetOS)
70+
os.Exit(1)
71+
return ""
72+
}
73+
}

0 commit comments

Comments
 (0)