Giter Club home page Giter Club logo

Comments (8)

xhd2015 avatar xhd2015 commented on May 25, 2024

This may needs an extra layer of work before build: importing dependencies.

Maybe related to this project: https://github.com/xhd2015/go-inspect

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

Process overview:
image

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

Kwonledge of packages.Load:

import "golang.org/x/tools/go/packages"

func TestPackageLoad(t *testing.T) {
	fset := token.NewFileSet()
	cfg := &packages.Config{
		Mode: packages.NeedImports,
		Fset: fset,
	}

	pkgs, err := packages.Load(cfg, "./cmd/xgo")
	if err != nil {
		return err
	}
        t.Logf(pkgs)
}
mode fields
NeedImports add imports are resolved, but resolved package does not contain other info
NeedFiles the GoFiles and IgnoredFiles will be set

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

Since go1.16, go build adds a -overlay flag, that was primarily added to support editors loading unsaved files: golang/go#39958.

But we can utilize it to include extra files without modifying any project files.

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

For the vendoring case, can we just use this replace:

replace github.com/xhd2015/xgo/runtime => ./local_created_runtime

We can manually parse the vendor/modules.txt, and recover the minimal go.mod for each module.
See here: https://github.com/golang/go/blob/334ce510046ad30b1be466634cf313aad3040892/src/cmd/go/internal/modload/vendor.go#L40

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

We can manually parse the vendor/modules.txt, and recover the minimal go.mod for each module.

To make it work in vendor mode, the key point is to use an alternate -modfile to allow go modify the go.mod, bypassing the vendoring check.

Because when turning -mod=vendor into -mod=mod -overlay overlay.json, if go.mod appears in overlay.json, go complains:

go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay

The solution becomes:

 -mod=mod -modfile go-tmp.mod

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

We are currently encounter a subtle bug while running tests:

  • after trap_without_dep passed, future tests with stdlib, like func_list would fail
    • complaining about net/http.Get not trapped,
    • It's just that net, net/http are missing, but os, io, io/ioutil are still fine
  • If run tests with -a, that problem goes away.

This may be related to build cache.

from xgo.

xhd2015 avatar xhd2015 commented on May 25, 2024

More edge scenarios need to be verified:

  • what if the go.mod already contains github.com/xhd2015/xgo/runtime, directly or indirectly.
  • when multiple args were used, what if some imports the dependency, while others not?

This leads to a more sophisticated solution:

  1. check if go.mod contains the dependency directly or indirectly,
  • go list -m -json github.com/xhd2015/xgo/runtime , or
  • go list -m -json -mod=vendor github.com/xhd2015/xgo/runtime
  1. for vendor mode, should also check if the pkg github.com/xhd2015/xgo/runtime/pkg is missing, if missing then the whole runtime should be imported and replacing the current runtime

The process is splitted into 2 phases:

  • load dependency
  • update each package's import to include the trace package
    image

image

from xgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.