-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add llgo get
#1038
base: main
Are you sure you want to change the base?
feat: add llgo get
#1038
Conversation
compiler/internal/mod/metadata.go
Outdated
return nil | ||
} | ||
|
||
func (m *metadataMgr) buildVersionsHash() error { |
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 function name buildVersionsHash
might be misleading. What it actually builds is just a mapping. Using "Hash" to describe this mapping functionality could be misinterpreted as performing hash encryption on this JSON.
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.
done at 720cc2e
compiler/internal/mod/mod.go
Outdated
} else if major == "v0" || major == "v1" { | ||
return fmt.Sprintf("%s/%s", LLPkgPathPrefix, name), nil | ||
} else { | ||
return fmt.Sprintf("%s/%s/v%s", LLPkgPathPrefix, name, major), nil |
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.
duplicates the "v" prefix. Since semver.Major already returns values with "v" (e.g., "v2"), this creates paths with double "v" (like "/vv2").
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.
donne at fix: duplicated 'v' prefix of semver
compiler/internal/get/get.go
Outdated
isLLPkg, err := mod.IsLLPkg(actualModule) | ||
if err != nil { | ||
return err | ||
} else if !isLLPkg { | ||
// no more work | ||
return nil | ||
} | ||
|
||
// 3. Now we need to parse the llpkg.cfg file. | ||
cfgPath, err := mod.LLPkgCfgFilePath(actualModule) |
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.
Suggest optimizing the usage of mod.IsLLPkg
in Do method. Currently it calls mod.IsLLPkg
to check if it's an LLPkg, then calls LLPkgCfgFilePath to get the path. Since mod.IsLLPkg
internally calculates the config file path as well, suggest modifying mod.IsLLPkg
to:
func IsLLPkg(module string) (isLLPkg bool, cfgPath string, err error)
This would avoid calculating the config file path twice in the Do method.
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.
Using multiple return values can lead to misunderstandings. Instead, a direct approach is preferable since the performance difference can be insignificant.
feat: add version mappings querying func.
compiler/go.mod
Outdated
@@ -6,16 +6,15 @@ require ( | |||
github.com/goplus/gogen v1.16.9 | |||
github.com/goplus/llgo v0.9.9 | |||
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000 | |||
github.com/goplus/llpkgstore v0.0.0-20250318065259-1f6d7d1376ae |
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.
don't depend this repo.
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.
We integrate some llpkg-related functionalities (e.g. version query, binary download) into goplus/llpkgstore
because they're going to be used by other components, that is pkgsite
, GitHub Actions
. It can also reduce the redundancy in code.
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.
done at c066031
xtool/env/env.go
Outdated
@@ -61,6 +61,7 @@ func expandEnvWithCmd(s string) (string, bool) { | |||
|
|||
var out []byte | |||
var err error | |||
|
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.
unrelated line update
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.
done at 5729a26
type cache[T any] struct { | ||
data T // stores cached data |
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.
Given that the cache
currently has only one user, perhaps we could simplify the implementation by temporarily removing the generic design?
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.
sure cache
has only one user, but using generic design keeps extensibility. I don't think it a proper way to integrate type of metadata
directly into cache
compiler/cmd/internal/get/get.go
Outdated
) | ||
|
||
// llgo get | ||
var Cmd = &base.Command{ | ||
UsageLine: "llgo get [-t -u -v] [build flags] [packages]", | ||
UsageLine: "llgo get [clibs/packages]", |
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.
llgo get 原有的 flags 可以保留支持,传递到 go get 中。
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.
done at 0041c77
compiler/internal/env/env.go
Outdated
return filepath.Join(userCacheDir, "llgo") | ||
} | ||
|
||
func LLPkgCache() string { |
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.
没有使用到的函数在这个 PR 本身不需要定义
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.
done at b56a73a
compiler/internal/get/get.go
Outdated
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.
Consider moving from compiler/internal/get
to compiler/internal/modget
for better semantics.
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.
done at 3b07d0c
compiler/cmd/internal/get/get.go
Outdated
|
||
for _, m := range modules { | ||
// Extract the name/path and version from the first argument | ||
name, version := parse(m) |
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.
name, version := parse(m) | |
name, version, _ := strings.Cut(m, "@") |
And remove parse
as it is no longer needed.
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.
done at 326f1e8
compiler/internal/env/env.go
Outdated
// If not set, LLGOCACHE defaults to {UserCacheDir}/llgo/ | ||
userCacheDir, err := os.UserCacheDir() | ||
if err != nil { | ||
panic("Can not get user cache dir: " + err.Error()) |
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.
panic("Can not get user cache dir: " + err.Error()) | |
panic(fmt.Errorf("Can not get user cache dir: %w", err)) |
To preserve the original error in case an upper layer wants to recover from our panic, we use %w
for wrapping instead of string concatenation. (See https://pkg.go.dev/fmt#Errorf)
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.
done at 801690b
compiler/internal/get/get.go
Outdated
|
||
cmd := exec.Command("go", args...) | ||
cmd.Stderr = os.Stderr | ||
_, err := cmd.Output() |
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.
Is hiding stdout here intentional? If not, consider using cmd.Run()
instead, and setting cmd.Stdout = os.Stdout
above.
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.
done at 5449ef3
compiler/internal/mod/metadata.go
Outdated
) | ||
|
||
var ( | ||
remoteMetadataURL = "https://llpkg.goplus.org/llpkgstore.json" // change only for testing |
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.
Replace this with https://goplus.github.io/llpkg/llpkgstore.json
.
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.
done at b5004f6
Don't need a cache package. Just use a cache missing mechanism. |
|
||
flags := []string{} | ||
flagEndIndex := -1 | ||
for idx, arg := range args { |
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.
use flag.Parse to parse command line arguments.
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.
flag.Parse has been called in main()
. we process the args it parsed here
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.
I think the args
passed in here are already all non-flag arguments, since they come from flag.Args()
:
llgo/compiler/cmd/llgo/llgo.go
Line 59 in 3b9b716
args := flag.Args() |
does it means that we should modify the function |
mod
package to sync and queryllpkgstore.json
llgo get