-
Notifications
You must be signed in to change notification settings - Fork 46
[WIP]feat: support llpkg for building #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MeteorsLiu
wants to merge
5
commits into
goplus:main
Choose a base branch
from
MeteorsLiu:support-llpkg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,910
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e6b75a
feat: support llpkg for building
MeteorsLiu 0995de0
feat: support nested zip
MeteorsLiu 22f243d
chore: add comments and fix cache check
MeteorsLiu 5a9e896
test: optimize tests
MeteorsLiu 05b1a1b
fix(llpkg/installer): remove unused args for DownloadFile
MeteorsLiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package llpkg | ||
|
|
||
| import "github.com/goplus/llgo/internal/llpkg/installer" | ||
|
|
||
| // LLPkgConfig represents the configuration structure parsed from llpkg.cfg files. | ||
| type LLPkgConfig struct { | ||
| Upstream UpstreamConfig `json:"upstream"` | ||
| } | ||
|
|
||
| // UpstreamConfig defines the upstream configuration containing installer settings and package metadata. | ||
| type UpstreamConfig struct { | ||
| Installer InstallerConfig `json:"installer"` | ||
| Package installer.Package `json:"package"` | ||
| } | ||
|
|
||
| // InstallerConfig specifies the installer type and its configuration options. | ||
| // "name" field must match supported installers (e.g., "conan"). | ||
| // "config" holds installer-specific parameters (optional). | ||
| type InstallerConfig struct { | ||
| Name string `json:"name"` | ||
| Config map[string]string `json:"config,omitempty"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package llpkg | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/goplus/llgo/internal/llpkg/installer" | ||
| ) | ||
|
|
||
| func TestLLPkgConfig(t *testing.T) { | ||
| config := LLPkgConfig{ | ||
| Upstream: UpstreamConfig{ | ||
| Installer: InstallerConfig{ | ||
| Name: "conan", | ||
| Config: map[string]string{ | ||
| "profile": "default", | ||
| }, | ||
| }, | ||
| Package: installer.Package{ | ||
| Name: "libxslt", | ||
| Version: "v1.0.3", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| if config.Upstream.Installer.Name != "conan" { | ||
| t.Errorf("expected installer name 'conan', got %s", config.Upstream.Installer.Name) | ||
| } | ||
|
|
||
| if config.Upstream.Package.Name != "libxslt" { | ||
| t.Errorf("expected package name 'libxslt', got %s", config.Upstream.Package.Name) | ||
| } | ||
|
|
||
| if config.Upstream.Package.Version != "v1.0.3" { | ||
| t.Errorf("expected package version 'v1.0.3', got %s", config.Upstream.Package.Version) | ||
| } | ||
|
|
||
| if config.Upstream.Installer.Config["profile"] != "default" { | ||
| t.Errorf("expected config profile 'default', got %s", config.Upstream.Installer.Config["profile"]) | ||
| } | ||
| } | ||
|
|
||
| func TestUpstreamConfig(t *testing.T) { | ||
| upstream := UpstreamConfig{ | ||
| Installer: InstallerConfig{ | ||
| Name: "ghrelease", | ||
| Config: nil, | ||
| }, | ||
| Package: installer.Package{ | ||
| Name: "testpkg", | ||
| Version: "v2.0.0", | ||
| }, | ||
| } | ||
|
|
||
| if upstream.Installer.Name != "ghrelease" { | ||
| t.Errorf("expected installer name 'ghrelease', got %s", upstream.Installer.Name) | ||
| } | ||
|
|
||
| if upstream.Installer.Config != nil { | ||
| t.Errorf("expected nil config, got %v", upstream.Installer.Config) | ||
| } | ||
|
|
||
| if upstream.Package.Name != "testpkg" { | ||
| t.Errorf("expected package name 'testpkg', got %s", upstream.Package.Name) | ||
| } | ||
|
|
||
| if upstream.Package.Version != "v2.0.0" { | ||
| t.Errorf("expected package version 'v2.0.0', got %s", upstream.Package.Version) | ||
| } | ||
|
|
||
| upstream.Package.SetModuleVersion("v1.0.0") | ||
|
|
||
| if upstream.Package.ModuleVersion() != "v1.0.0" { | ||
| t.Errorf("expected package version 'v1.0.0', got %s", upstream.Package.ModuleVersion()) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallerConfig(t *testing.T) { | ||
| config := InstallerConfig{ | ||
| Name: "conan", | ||
| Config: map[string]string{ | ||
| "profile": "default", | ||
| "settings": "os=Linux", | ||
| }, | ||
| } | ||
|
|
||
| if config.Name != "conan" { | ||
| t.Errorf("expected name 'conan', got %s", config.Name) | ||
| } | ||
|
|
||
| if len(config.Config) != 2 { | ||
| t.Errorf("expected 2 config items, got %d", len(config.Config)) | ||
| } | ||
|
|
||
| if config.Config["profile"] != "default" { | ||
| t.Errorf("expected profile 'default', got %s", config.Config["profile"]) | ||
| } | ||
|
|
||
| if config.Config["settings"] != "os=Linux" { | ||
| t.Errorf("expected settings 'os=Linux', got %s", config.Config["settings"]) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallerConfig_EmptyConfig(t *testing.T) { | ||
| config := InstallerConfig{ | ||
| Name: "simple", | ||
| Config: map[string]string{}, | ||
| } | ||
|
|
||
| if config.Name != "simple" { | ||
| t.Errorf("expected name 'simple', got %s", config.Name) | ||
| } | ||
|
|
||
| if len(config.Config) != 0 { | ||
| t.Errorf("expected empty config, got %v", config.Config) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package installer | ||
|
|
||
| import ( | ||
| "archive/zip" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| // wrapDownloadError wraps an error with a descriptive message for download failures. | ||
| // It returns nil if the input error is nil, otherwise returns a wrapped error with context. | ||
| func wrapDownloadError(err error) error { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("failed to download llpkg binary files: %w", err) | ||
| } | ||
|
|
||
| // Unzip extracts a zip file to the specified output directory. | ||
| // It creates the output directory if it doesn't exist, handles nested directories, | ||
| // and recursively unzips any nested zip files found within the archive. | ||
| func Unzip(zipFilePath, outputDir string) error { | ||
| // make sure path exists | ||
| if err := os.MkdirAll(outputDir, 0700); err != nil { | ||
| return err | ||
| } | ||
| r, err := zip.OpenReader(zipFilePath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer r.Close() | ||
| decompress := func(file *zip.File) error { | ||
| path := filepath.Join(outputDir, file.Name) | ||
|
|
||
| if file.FileInfo().IsDir() { | ||
| return os.MkdirAll(path, 0700) | ||
| } | ||
|
|
||
| fs, err := file.Open() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer fs.Close() | ||
|
|
||
| w, err := os.Create(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if _, err := io.Copy(w, fs); err != nil { | ||
| w.Close() | ||
| return err | ||
| } | ||
| if err := w.Close(); err != nil { | ||
| return err | ||
| } | ||
| // if this is a nested zip, unzip it. | ||
| if strings.HasSuffix(path, ".zip") { | ||
| if err := Unzip(path, outputDir); err != nil { | ||
| return err | ||
| } | ||
| os.Remove(path) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| for _, file := range r.File { | ||
| if err = decompress(file); err != nil { | ||
| break | ||
| } | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| // DownloadFile downloads a file from the given URL and saves it to a temporary file. | ||
| // It returns the path to the downloaded temporary file. | ||
| // The caller is responsible for cleaning up the temporary file when no longer needed. | ||
| func DownloadFile(url string) (fileName string, err error) { | ||
| resp, err := http.Get(url) | ||
| if err != nil { | ||
| return "", wrapDownloadError(err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusOK { | ||
| return "", fmt.Errorf("failed to download llpkg binary files: status %s", resp.Status) | ||
| } | ||
|
|
||
| tempFile, err := os.CreateTemp("", "download*.temp") | ||
| if err != nil { | ||
| return "", wrapDownloadError(err) | ||
| } | ||
| defer tempFile.Close() | ||
|
|
||
| _, err = io.Copy(tempFile, resp.Body) | ||
|
|
||
| return tempFile.Name(), wrapDownloadError(err) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the generated
symbol.mapfile might be misunderstood as a build artifact, especially since we haven't established where debug outputs should go yet.