Skip to content
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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

feat: add llgo get #1038

wants to merge 28 commits into from

Conversation

seri037
Copy link

@seri037 seri037 commented Mar 24, 2025

  • add mod package to sync and query llpkgstore.json
  • complete logic of llgo get

@seri037 seri037 marked this pull request as draft March 24, 2025 10:03
return nil
}

func (m *metadataMgr) buildVersionsHash() error {
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 720cc2e

} 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
Copy link
Contributor

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").

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 44 to 53
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)
Copy link
Contributor

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.

Copy link
Author

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.

@seri037 seri037 marked this pull request as ready for review March 27, 2025 08:19
@seri037
Copy link
Author

seri037 commented Mar 27, 2025

need review @visualfc @aofei

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
Copy link
Member

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.

Copy link
Author

@seri037 seri037 Mar 28, 2025

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.

Copy link
Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated line update

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 5729a26

Comment on lines +16 to +17
type cache[T any] struct {
data T // stores cached data
Copy link
Contributor

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?

Copy link
Author

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

)

// llgo get
var Cmd = &base.Command{
UsageLine: "llgo get [-t -u -v] [build flags] [packages]",
UsageLine: "llgo get [clibs/packages]",
Copy link
Member

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 中。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 0041c77

return filepath.Join(userCacheDir, "llgo")
}

func LLPkgCache() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有使用到的函数在这个 PR 本身不需要定义

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at b56a73a

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 3b07d0c


for _, m := range modules {
// Extract the name/path and version from the first argument
name, version := parse(m)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name, version := parse(m)
name, version, _ := strings.Cut(m, "@")

And remove parse as it is no longer needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 326f1e8

// If not set, LLGOCACHE defaults to {UserCacheDir}/llgo/
userCacheDir, err := os.UserCacheDir()
if err != nil {
panic("Can not get user cache dir: " + err.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 801690b


cmd := exec.Command("go", args...)
cmd.Stderr = os.Stderr
_, err := cmd.Output()
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at 5449ef3

)

var (
remoteMetadataURL = "https://llpkg.goplus.org/llpkgstore.json" // change only for testing
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done at b5004f6

@xushiwei
Copy link
Member

xushiwei commented Apr 1, 2025

Don't need a cache package. Just use a cache missing mechanism.


flags := []string{}
flagEndIndex := -1
for idx, arg := range args {
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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():

args := flag.Args()

@seri037
Copy link
Author

seri037 commented Apr 1, 2025

Don't need a cache package. Just use a cache missing mechanism.

does it means that we should modify the function metadata.update(), and integrate all func. in cache.go to the metadata.go? Is it ok to mix file loading, file updating and file parsing functions all in one go file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants