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

TMP: Attempt to extract nogo into a separate action #3840

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ func compileArchive(
}
if coverMode != "" && nogoPath != "" {
// Compile original source files, not coverage instrumented, for nogo
_, goSrcsNogo, _, err = cgo2(goenv, goSrcsNogo, cgoSrcsNogo, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSrcs, hSrcs, packagePath, packageName, cc, cppFlags, cFlags, cxxFlags, objcFlags, objcxxFlags, ldFlags, cgoExportHPath)
_, _, _, err = cgo2(goenv, goSrcsNogo, cgoSrcsNogo, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSrcs, hSrcs, packagePath, packageName, cc, cppFlags, cFlags, cxxFlags, objcFlags, objcxxFlags, ldFlags, cgoExportHPath)
if err != nil {
return err
}
} else {
goSrcsNogo = goSrcs
//goSrcsNogo = goSrcs
}

gcFlags = append(gcFlags, createTrimPath(gcFlags, srcDir))
Expand All @@ -375,38 +375,7 @@ func compileArchive(
gcFlags = append(gcFlags, createTrimPath(gcFlags, "."))
}

// Check that the filtered sources don't import anything outside of
// the standard library and the direct dependencies.
imports, err := checkImports(srcs.goSrcs, deps, packageListPath, importPath, recompileInternalDeps)
if err != nil {
return err
}
if compilingWithCgo {
// cgo generated code imports some extra packages.
imports["runtime/cgo"] = nil
imports["syscall"] = nil
imports["unsafe"] = nil
}
if coverMode != "" {
if coverMode == "atomic" {
imports["sync/atomic"] = nil
}
const coverdataPath = "github.com/bazelbuild/rules_go/go/tools/coverdata"
var coverdata *archive
for i := range deps {
if deps[i].importPath == coverdataPath {
coverdata = &deps[i]
break
}
}
if coverdata == nil {
return errors.New("coverage requested but coverdata dependency not provided")
}
imports[coverdataPath] = coverdata
}

// Build an importcfg file for the compiler.
importcfgPath, err := buildImportcfgFileForCompile(imports, goenv.installSuffix, filepath.Dir(outLinkObj))
importcfgPath, err := checkImportsAndBuildImportcfg(srcs, deps, packageListPath, importPath, recompileInternalDeps, goenv.installSuffix, coverMode, compilingWithCgo, filepath.Dir(outLinkObj))
if err != nil {
return err
}
Expand Down Expand Up @@ -535,6 +504,41 @@ func compileArchive(
return nil
}

func checkImportsAndBuildImportcfg(srcs archiveSrcs, deps []archive, packageListPath string, importPath string, recompileInternalDeps []string, installSuffix string, coverMode string, compilingWithCgo bool, outDir string) (string, error) {
// Check that the filtered sources don't import anything outside of
// the standard library and the direct dependencies.
imports, err := checkImports(srcs.goSrcs, deps, packageListPath, importPath, recompileInternalDeps)
if err != nil {
return "", err
}
if compilingWithCgo {
// cgo generated code imports some extra packages.
imports["runtime/cgo"] = nil
imports["syscall"] = nil
imports["unsafe"] = nil
}
if coverMode != "" {
if coverMode == "atomic" {
imports["sync/atomic"] = nil
}
const coverdataPath = "github.com/bazelbuild/rules_go/go/tools/coverdata"
var coverdata *archive
for i := range deps {
if deps[i].importPath == coverdataPath {
coverdata = &deps[i]
break
}
}
if coverdata == nil {
return "", errors.New("coverage requested but coverdata dependency not provided")
}
imports[coverdataPath] = coverdata
}

// Build an importcfg file for the compiler.
return buildImportcfgFileForCompile(imports, installSuffix, outDir)
}

func compileGo(goenv *env, srcs []string, packagePath, importcfgPath, embedcfgPath, asmHdrPath, symabisPath string, gcFlags []string, pgoprofile, outLinkobjPath, outInterfacePath string) error {
args := goenv.goTool("compile")
args = append(args, "-p", packagePath, "-importcfg", importcfgPath, "-pack")
Expand Down
Loading