Skip to content

proposal: runtime: add GetEntryInfo function #68583

Description

@timandy

Proposal Details

Some time we want to get the entry info like module name. entry file path, dpendent modules and so on.
before go1.23 these infos can be get from runtime.firstmoduledata, but after go1.23 runtime.firstmoduledata can not be access.

before go1.23

// get path of the entry file, may be a /xx/xx_test.go or /xx/main.go
func getEntryFilePath() string {
	mainFile := getMainFile()
	if !isTestMode(mainFile) {
		return mainFile
	}
	firstModule := unsafe.Pointer(&firstmoduledata)
	fileTab := *(*[]byte)(reflection.Add(firstModule, filetabField.Offset))
	lastFiles := getLastFiles(fileTab)
	for _, file := range lastFiles {
		if isTestFile(file) {
			return file
		}
	}
	panic("can not found entry file path")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions