[feature] add gen-ide-env cmd.

This commit is contained in:
chengsiyuan 2024-11-20 17:52:51 +08:00
parent fff4825cf5
commit 2b21e934e7
3 changed files with 83 additions and 2 deletions

View File

@ -15,11 +15,15 @@ SylixOS Uploader is a command-line tool designed for uploading SylixOS projects
- Generate structured YAML configuration files for SylixOS projects, ensuring easier management and deployment.
3. Versioning:
3. Generate-Ide-Env-Example:
- Generate environment variables on linux from IDE projects.
4. Versioning:
- Injects Git version information into the build, including the latest tag, commit hash, and dirty state (if there are uncommitted changes).
4. Flexible Build Options:
5. Flexible Build Options:
- Default: Build only for the local platform.
- Optionally: Cross-compile for multiple platforms (Linux, Windows, macOS, SylixOS).
@ -39,6 +43,12 @@ sylixos-uploader upload --path ~/sylixos-workspace/base-project --device 10.13.1
sylixos-uploader gen-yaml --path ~/sylixos-workspace/base-project
```
### Generate IDE ENV Example
```bash
source <(sylixos-uploader gen-ide-env --workspace ~/sylixos-workspace)
```
### YAML File Example
```yaml

67
cmd/gen_ide_env.go Normal file
View File

@ -0,0 +1,67 @@
package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"
"sylixos-uploader/detector"
"github.com/spf13/cobra"
)
var genIdeEnvCmd = &cobra.Command{
Use: "gen-ide-env",
Short: "usage: source <(sylixos-uploader gen-ide-env --workspace <path>)",
Long: `usage: source <(sylixos-uploader gen-ide-env --workspace <path>)
Generate environment variables from IDE projects.`,
Run: func(cmd *cobra.Command, args []string) {
// 遍历根目录下的第一级子目录
if WorkSpacePath == "" {
WorkSpacePath = "."
}
err := filepath.Walk(WorkSpacePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// 只处理第一级子目录
if info.IsDir() && path != WorkSpacePath {
relativePath, err := filepath.Rel(WorkSpacePath, path)
if err != nil {
return err
}
// 替换路径中的特殊字符,确保变量名合法
envVarNameOrgin := strings.ReplaceAll(relativePath, string(os.PathSeparator), "_")
envVarName := strings.ReplaceAll(envVarNameOrgin, "-", "_")
s := detector.NewSylixOSPrj(path)
if s.IsSylixOSPrj() {
// 输出结果
fmt.Printf("export WORKSPACE_%s=%s\n", envVarName, path)
if strings.Contains(relativePath, "-") {
fmt.Printf("echo \"you have to change \\$(WORKSPACE_%s) to \\$(WORKSPACE_%s) in all config.mk\"\n", envVarNameOrgin, envVarName)
}
}
// 阻止深入子目录
return filepath.SkipDir
}
return nil
})
if err != nil {
fmt.Printf("Error: %v\n", err)
}
},
}
func init() {
RootCmd.AddCommand(genIdeEnvCmd)
// Adding flags with long names
genIdeEnvCmd.Flags().StringVar(&WorkSpacePath, "workspace", "", "Workspace path")
}

View File

@ -28,6 +28,7 @@ Konwn-Behavior:
2. On Remote device, ELF executable or shared object file will be chmod to 0755.
3. On Remote device, konwn executable script (e.g. .sh, .py, .lua, etc) will be chmod to 0755.
4. Generate upload yaml file from real evo project.
5. Generate environment variables on linux from IDE projects.
Upload-Example:
sylixos-uploader upload --path ~/sylixos-workspace/base-project --device 10.13.16.250 --method ftp
@ -35,6 +36,9 @@ Upload-Example:
Generate-Yaml-Example:
sylixos-uploader gen-yaml --path ~/sylixos-workspace/base-project
Generate-Ide-Env-Example:
source <(sylixos-uploader gen-ide-env --workspace ~/sylixos-workspace)
Yaml-file-Demo:
"
base-settings: