-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
646 lines (592 loc) · 19.4 KB
/
main.go
File metadata and controls
646 lines (592 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
package main
import (
"context"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"time"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/spf13/cobra"
)
type Dependency struct {
Name string
Command string
Optional bool
Status string
Version string
Description string
Platform string // "all", "windows", "macos", "linux", "android", "ios"
Category string // "core", "mobile", "web", "performance", "compatibility"
Severity string // "critical", "warning", "info"
IssueLink string // Link to related GitHub issue
}
type Config struct {
Verbose bool
JSON bool
Categories []string
Timeout time.Duration
OutputFile string
}
var config Config
func main() {
rootCmd := &cobra.Command{
Use: "fyne-doctor",
Short: "Fyne Environment Check Tool",
Long: `Fyne Doctor is a comprehensive tool for checking your Fyne development environment.
It detects dependencies, identifies common issues, and provides installation guidance
based on the latest Fyne GitHub Issues and documentation.`,
}
doctorCmd := &cobra.Command{
Use: "doctor",
Short: "Check Fyne development environment",
Long: `Run a comprehensive check of your Fyne development environment.
This includes checking for required dependencies, detecting common issues,
and providing platform-specific installation guidance.`,
Run: runDoctor,
}
// Add flags
doctorCmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "Enable verbose output")
doctorCmd.Flags().BoolVarP(&config.JSON, "json", "j", false, "Output results in JSON format")
doctorCmd.Flags().StringSliceVarP(&config.Categories, "categories", "c", []string{}, "Filter by categories (core,mobile,web,performance,compatibility)")
doctorCmd.Flags().DurationVarP(&config.Timeout, "timeout", "t", 10*time.Second, "Command execution timeout")
doctorCmd.Flags().StringVarP(&config.OutputFile, "output", "o", "", "Save output to file")
rootCmd.AddCommand(doctorCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func runDoctor(cmd *cobra.Command, args []string) {
fmt.Println(" Fyne Doctor")
fmt.Println()
// Fyne version (we simulate if fyne CLI not installed)
fyneVersion := getFyneVersion()
fmt.Printf("# Fyne\nVersion | %s\n\n", fyneVersion)
// System info
printSystemInfo()
// Dependencies
deps := getDependencies()
for i := range deps {
// Only check dependencies for current platform
if deps[i].Platform == "all" || deps[i].Platform == runtime.GOOS {
status, version := checkDependency(deps[i].Command)
deps[i].Status = status
deps[i].Version = version
} else {
deps[i].Status = "N/A"
deps[i].Version = "Not applicable"
}
}
printDependencyTable(deps)
// Diagnosis
success := true
missingDeps := []string{}
for _, d := range deps {
if d.Platform == "all" || d.Platform == runtime.GOOS {
if d.Status != "Installed" && !d.Optional {
success = false
missingDeps = append(missingDeps, d.Name)
}
}
}
fmt.Println("\n# Diagnosis")
if success {
fmt.Println(" SUCCESS Your system is ready for Fyne development!")
} else {
fmt.Println(" FAILURE Some required dependencies are missing or not properly installed.")
fmt.Printf("Missing dependencies: %s\n", strings.Join(missingDeps, ", "))
printInstallationTips()
}
// Check for common issues based on GitHub Issues
checkCommonIssues(deps)
}
// getFyneVersion simulates fyne version if CLI not installed
func getFyneVersion() string {
if _, err := exec.LookPath("fyne"); err != nil {
return "Not installed"
}
out, err := exec.Command("fyne", "version").CombinedOutput()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(out))
}
// getDependencies returns platform-specific dependencies based on Fyne documentation and GitHub Issues
func getDependencies() []Dependency {
baseDeps := []Dependency{
{
Name: "Go",
Command: "go version",
Optional: false,
Description: "Go programming language (minimum version 1.12)",
Platform: "all",
Category: "core",
Severity: "critical",
},
{
Name: "Fyne CLI",
Command: "fyne version",
Optional: false,
Description: "Fyne command line tools",
Platform: "all",
Category: "core",
Severity: "critical",
},
{
Name: "Fyne-cross",
Command: "fyne-cross --version",
Optional: true,
Description: "Cross-platform build tool for Fyne",
Platform: "all",
Category: "core",
Severity: "info",
},
{
Name: "Fyne Setup",
Command: "setup --version || echo 'Not installed'",
Optional: true,
Description: "Official Fyne environment setup tool (GUI)",
Platform: "all",
Category: "core",
Severity: "info",
IssueLink: "https://github.com/fyne-io/setup",
},
}
// Platform-specific dependencies
switch runtime.GOOS {
case "windows":
baseDeps = append(baseDeps, []Dependency{
{
Name: "C Compiler (MSYS2)",
Command: "gcc --version",
Optional: false,
Description: "C compiler for Windows (MSYS2/MingW-w64 recommended)",
Platform: "windows",
Category: "core",
Severity: "critical",
},
{
Name: "MSYS2",
Command: "pacman --version",
Optional: false,
Description: "MSYS2 package manager",
Platform: "windows",
Category: "core",
Severity: "critical",
},
}...)
case "darwin": // macOS
baseDeps = append(baseDeps, []Dependency{
{
Name: "Xcode CLI Tools",
Command: "xcode-select -p",
Optional: false,
Description: "Xcode command line tools",
Platform: "macos",
Category: "core",
Severity: "critical",
},
{
Name: "C Compiler",
Command: "clang --version",
Optional: false,
Description: "Clang compiler (comes with Xcode)",
Platform: "macos",
Category: "core",
Severity: "critical",
},
}...)
case "linux":
baseDeps = append(baseDeps, []Dependency{
{
Name: "C Compiler",
Command: "gcc --version",
Optional: false,
Description: "GCC compiler",
Platform: "linux",
Category: "core",
Severity: "critical",
},
{
Name: "pkg-config",
Command: "pkg-config --version",
Optional: false,
Description: "Package configuration tool",
Platform: "linux",
Category: "core",
Severity: "critical",
},
{
Name: "Mesa GL",
Command: "pkg-config --exists gl && echo 'Found'",
Optional: false,
Description: "Mesa OpenGL library",
Platform: "linux",
Category: "core",
Severity: "critical",
},
{
Name: "X11 Development",
Command: "pkg-config --exists x11 && echo 'Found'",
Optional: false,
Description: "X11 development libraries",
Platform: "linux",
Category: "core",
Severity: "critical",
},
{
Name: "Wayland Support",
Command: "pkg-config --exists wayland-client && echo 'Found'",
Optional: true,
Description: "Wayland client library (for Wayland support)",
Platform: "linux",
Category: "compatibility",
Severity: "warning",
IssueLink: "https://github.com/fyne-io/fyne/issues/5908",
},
}...)
}
// Mobile development dependencies (based on GitHub Issues)
baseDeps = append(baseDeps, []Dependency{
{
Name: "Android SDK",
Command: "echo $ANDROID_HOME",
Optional: true,
Description: "Android SDK for mobile development",
Platform: "all",
Category: "mobile",
Severity: "info",
},
{
Name: "Android NDK",
Command: "echo $ANDROID_NDK_HOME",
Optional: true,
Description: "Android NDK for mobile development",
Platform: "all",
Category: "mobile",
Severity: "info",
},
{
Name: "Android Studio",
Command: "which studio || which android-studio",
Optional: true,
Description: "Android Studio IDE (recommended for mobile dev)",
Platform: "all",
Category: "mobile",
Severity: "info",
},
{
Name: "iOS Simulator",
Command: "xcrun simctl list devices",
Optional: true,
Description: "iOS Simulator for iOS development",
Platform: "darwin",
Category: "mobile",
Severity: "info",
},
}...)
// Web development dependencies
baseDeps = append(baseDeps, []Dependency{
{
Name: "WebAssembly Support",
Command: "go version | grep -q 'go1.16' && echo 'Supported' || echo 'Requires Go 1.16+'",
Optional: true,
Description: "WebAssembly support for web builds",
Platform: "all",
Category: "web",
Severity: "info",
},
{
Name: "Node.js",
Command: "node --version",
Optional: true,
Description: "Node.js for web development tools",
Platform: "all",
Category: "web",
Severity: "info",
},
}...)
// Performance and compatibility checks
baseDeps = append(baseDeps, []Dependency{
{
Name: "GPU Acceleration",
Command: "glxinfo | grep 'direct rendering' || echo 'Not available'",
Optional: true,
Description: "GPU acceleration support (Linux)",
Platform: "linux",
Category: "performance",
Severity: "warning",
},
{
Name: "Display Server",
Command: "echo $XDG_SESSION_TYPE",
Optional: true,
Description: "Current display server (X11/Wayland)",
Platform: "linux",
Category: "compatibility",
Severity: "info",
},
}...)
return baseDeps
}
// executeCommandWithTimeout executes a command with a timeout
func executeCommandWithTimeout(cmd string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
var c *exec.Cmd
if runtime.GOOS == "windows" {
c = exec.CommandContext(ctx, "cmd", "/C", cmd)
} else {
c = exec.CommandContext(ctx, "sh", "-c", cmd)
}
out, err := c.CombinedOutput()
if err != nil {
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("command timed out after %v", timeout)
}
return "", err
}
return strings.TrimSpace(string(out)), nil
}
func checkDependency(cmd string) (status string, version string) {
// Handle environment variable checks
if strings.HasPrefix(cmd, "echo $") {
envVar := strings.TrimPrefix(cmd, "echo $")
value := os.Getenv(envVar)
if value == "" {
return "Missing", ""
}
return "Installed", value
}
// Handle pkg-config checks
if strings.Contains(cmd, "pkg-config --exists") {
_, err := executeCommandWithTimeout(cmd, 5*time.Second)
if err != nil {
log.Printf("Warning: pkg-config check failed for '%s': %v", cmd, err)
return "Missing", ""
}
return "Installed", "Found"
}
// Handle which command checks
if strings.HasPrefix(cmd, "which ") {
_, err := executeCommandWithTimeout(cmd, 5*time.Second)
if err != nil {
log.Printf("Warning: which command failed for '%s': %v", cmd, err)
return "Missing", ""
}
return "Installed", "Found"
}
// Handle complex command chains
if strings.Contains(cmd, "||") || strings.Contains(cmd, "&&") {
result, err := executeCommandWithTimeout(cmd, 10*time.Second)
if err != nil {
log.Printf("Warning: complex command failed for '%s': %v", cmd, err)
return "Error", ""
}
if result == "" {
return "Missing", ""
}
return "Installed", result
}
// Regular command checks
firstCmd := strings.Fields(cmd)[0]
if _, err := exec.LookPath(firstCmd); err != nil {
return "Missing", ""
}
result, err := executeCommandWithTimeout(cmd, 10*time.Second)
if err != nil {
log.Printf("Warning: command execution failed for '%s': %v", cmd, err)
return "Error", ""
}
return "Installed", result
}
func printDependencyTable(deps []Dependency) {
// Group dependencies by category
categories := make(map[string][]Dependency)
for _, d := range deps {
if d.Platform == "all" || d.Platform == runtime.GOOS {
categories[d.Category] = append(categories[d.Category], d)
}
}
// Define category order and display names
categoryOrder := []string{"core", "mobile", "web", "performance", "compatibility"}
categoryNames := map[string]string{
"core": "Core Dependencies",
"mobile": "Mobile Development",
"web": "Web Development",
"performance": "Performance",
"compatibility": "Compatibility",
}
for _, cat := range categoryOrder {
if deps, exists := categories[cat]; exists && len(deps) > 0 {
fmt.Printf("\n## %s\n", categoryNames[cat])
fmt.Println("┌─────────────────────────────┬────────────┬────────────┬─────────────┬─────────────────────────────────────┐")
fmt.Println("| Dependency | Optional | Status | Version | Description |")
fmt.Println("├─────────────────────────────┼────────────┼────────────┼─────────────┼─────────────────────────────────────┤")
for _, d := range deps {
opt := ""
if d.Optional {
opt = "*"
}
// Truncate long descriptions
desc := d.Description
if len(desc) > 35 {
desc = desc[:32] + "..."
}
fmt.Printf("| %-27s | %-10s | %-10s | %-11s | %-35s |\n",
d.Name, opt, d.Status, d.Version, desc)
}
fmt.Println("└─────────────────────────────┴────────────┴────────────┴─────────────┴─────────────────────────────────────┘")
}
}
}
// printSystemInfo prints OS, Go version, CPU, Memory
func printSystemInfo() {
fmt.Println("# System")
cpuInfo, _ := cpu.Info()
memInfo, _ := mem.VirtualMemory()
fmt.Println("┌───────────────────────────┐")
fmt.Printf("| OS | %s\n", runtime.GOOS)
fmt.Printf("| Architecture | %s\n", runtime.GOARCH)
if len(cpuInfo) > 0 {
fmt.Printf("| CPU | %s @ %.0fMHz\n", cpuInfo[0].ModelName, cpuInfo[0].Mhz)
}
fmt.Printf("| Memory | %.2f GB\n", float64(memInfo.Total)/1024/1024/1024)
fmt.Println("└───────────────────────────┘")
fmt.Println()
}
// printInstallationTips provides platform-specific installation instructions
func printInstallationTips() {
fmt.Println("\n# Installation Tips")
fmt.Println("Based on your platform, here are the recommended installation steps:")
fmt.Println()
switch runtime.GOOS {
case "windows":
fmt.Println("Windows:")
fmt.Println("1. Install Go from https://golang.org/dl/")
fmt.Println("2. Install MSYS2 from https://www.msys2.org/")
fmt.Println("3. Open MSYS2 MinGW 64-bit terminal and run:")
fmt.Println(" pacman -Syu")
fmt.Println(" pacman -S git mingw-w64-x86_64-toolchain")
fmt.Println("4. Add C:\\msys64\\mingw64\\bin to your PATH")
fmt.Println("5. Install Fyne CLI: go install fyne.io/fyne/v2/cmd/fyne@latest")
case "darwin": // macOS
fmt.Println("macOS:")
fmt.Println("1. Install Go from https://golang.org/dl/")
fmt.Println("2. Install Xcode from Mac App Store")
fmt.Println("3. Install Xcode CLI tools: xcode-select --install")
fmt.Println("4. Install Fyne CLI: go install fyne.io/fyne/v2/cmd/fyne@latest")
case "linux":
fmt.Println("Linux:")
fmt.Println("For Debian/Ubuntu:")
fmt.Println(" sudo apt-get install golang gcc libgl1-mesa-dev xorg-dev pkg-config")
fmt.Println()
fmt.Println("For Fedora:")
fmt.Println(" sudo dnf install golang gcc libXcursor-devel libXrandr-devel mesa-libGL-devel libXi-devel libXinerama-devel libXxf86vm-devel")
fmt.Println()
fmt.Println("For Arch Linux:")
fmt.Println(" sudo pacman -S go xorg-server-devel libxcursor libxrandr libxinerama libxi")
fmt.Println()
fmt.Println("Then install Fyne CLI: go install fyne.io/fyne/v2/cmd/fyne@latest")
}
fmt.Println()
fmt.Println("For mobile development:")
fmt.Println("- Android: Install Android Studio and NDK")
fmt.Println("- iOS: Requires macOS with Xcode and Apple Developer account")
fmt.Println()
fmt.Println("For cross-platform builds:")
fmt.Println(" go install github.com/fyne-io/fyne-cross@latest")
fmt.Println()
fmt.Println("For GUI environment setup:")
fmt.Println(" go install fyne.io/setup@latest")
fmt.Println(" $(go env GOPATH)/bin/setup")
}
// checkCommonIssues checks for common problems based on GitHub Issues
func checkCommonIssues(deps []Dependency) {
fmt.Println("\n# Common Issues Check")
issues := []string{}
warnings := []string{}
// Check for Wayland issues
displayServer := os.Getenv("XDG_SESSION_TYPE")
if displayServer == "wayland" {
waylandSupport := false
for _, d := range deps {
if d.Name == "Wayland Support" && d.Status == "Installed" {
waylandSupport = true
break
}
}
if !waylandSupport {
issues = append(issues, "Running on Wayland but Wayland support may be incomplete")
fmt.Println("⚠️ WARNING: You're running on Wayland. Some Fyne apps may have issues.")
fmt.Println(" Related issue: https://github.com/fyne-io/fyne/issues/5908")
}
}
// Check for mobile development issues
androidSDK := false
androidNDK := false
for _, d := range deps {
if d.Name == "Android SDK" && d.Status == "Installed" {
androidSDK = true
}
if d.Name == "Android NDK" && d.Status == "Installed" {
androidNDK = true
}
}
if androidSDK && !androidNDK {
warnings = append(warnings, "Android SDK found but NDK missing - mobile builds may fail")
}
// Check for performance issues
gpuAccel := false
for _, d := range deps {
if d.Name == "GPU Acceleration" && d.Status == "Installed" {
gpuAccel = true
break
}
}
if !gpuAccel && runtime.GOOS == "linux" {
warnings = append(warnings, "GPU acceleration not available - performance may be reduced")
}
// Check for web development issues
goVersion := ""
for _, d := range deps {
if d.Name == "Go" && d.Status == "Installed" {
goVersion = d.Version
break
}
}
if goVersion != "" && !strings.Contains(goVersion, "go1.16") {
warnings = append(warnings, "Go version < 1.16 - WebAssembly builds not supported")
}
// Display results
if len(issues) == 0 && len(warnings) == 0 {
fmt.Println("✅ No common issues detected!")
} else {
if len(issues) > 0 {
fmt.Println("\n🚨 Issues found:")
for _, issue := range issues {
fmt.Printf(" • %s\n", issue)
}
}
if len(warnings) > 0 {
fmt.Println("\n⚠️ Warnings:")
for _, warning := range warnings {
fmt.Printf(" • %s\n", warning)
}
}
}
// Display GitHub Issues summary
fmt.Println("\n# GitHub Issues Summary")
fmt.Println("Based on recent Fyne GitHub Issues, common problems include:")
fmt.Println("• Mobile web builds: Paste functionality issues (#5916)")
fmt.Println("• Android: NewMultiLineEntry scrolling problems (#5915)")
fmt.Println("• Mobile: Grid container performance issues (#5914)")
fmt.Println("• Wayland: App crashes on some systems (#5908)")
fmt.Println("• X11: Display wake-up crashes (#5899)")
fmt.Println("• Windows: UI position issues after minimize/restore (#5898)")
fmt.Println("\nFor more details, visit: https://github.com/fyne-io/fyne/issues")
}