build: only limit run command to single package
This commit is contained in:
@@ -64,10 +64,6 @@ const (
|
|||||||
debugBuild = packages.DebugPackagesLoad
|
debugBuild = packages.DebugPackagesLoad
|
||||||
)
|
)
|
||||||
|
|
||||||
func needLLFile(mode Mode) bool {
|
|
||||||
return mode != ModeBuild
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
BinPath string
|
BinPath string
|
||||||
AppExt string // ".exe" on Windows, empty on Unix
|
AppExt string // ".exe" on Windows, empty on Unix
|
||||||
@@ -169,13 +165,13 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
initial, err := packages.LoadEx(dedup, sizes, cfg, patterns...)
|
initial, err := packages.LoadEx(dedup, sizes, cfg, patterns...)
|
||||||
check(err)
|
check(err)
|
||||||
mode := conf.Mode
|
mode := conf.Mode
|
||||||
switch mode {
|
if len(initial) > 1 {
|
||||||
case ModeBuild:
|
switch mode {
|
||||||
if len(initial) == 1 && len(initial[0].CompiledGoFiles) > 0 {
|
case ModeBuild:
|
||||||
mode = ModeInstall
|
if conf.OutFile != "" {
|
||||||
}
|
return nil, fmt.Errorf("cannot build multiple packages with -o")
|
||||||
case ModeRun:
|
}
|
||||||
if len(initial) > 1 {
|
case ModeRun:
|
||||||
return nil, fmt.Errorf("cannot run multiple packages")
|
return nil, fmt.Errorf("cannot run multiple packages")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +204,8 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
env := llvm.New("")
|
env := llvm.New("")
|
||||||
os.Setenv("PATH", env.BinDir()+":"+os.Getenv("PATH")) // TODO(xsw): check windows
|
os.Setenv("PATH", env.BinDir()+":"+os.Getenv("PATH")) // TODO(xsw): check windows
|
||||||
|
|
||||||
ctx := &context{env, cfg, progSSA, prog, dedup, patches, make(map[string]none), initial, mode, 0}
|
output := mode != ModeBuild || conf.OutFile != ""
|
||||||
|
ctx := &context{env, cfg, progSSA, prog, dedup, patches, make(map[string]none), initial, mode, 0, output}
|
||||||
pkgs, err := buildAllPkgs(ctx, initial, verbose)
|
pkgs, err := buildAllPkgs(ctx, initial, verbose)
|
||||||
check(err)
|
check(err)
|
||||||
if mode == ModeGen {
|
if mode == ModeGen {
|
||||||
@@ -227,7 +224,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
linkArgs = append(linkArgs, pkg.LinkArgs...)
|
linkArgs = append(linkArgs, pkg.LinkArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode != ModeBuild {
|
if ctx.output {
|
||||||
for _, pkg := range initial {
|
for _, pkg := range initial {
|
||||||
if pkg.Name == "main" {
|
if pkg.Name == "main" {
|
||||||
linkMainPkg(ctx, pkg, pkgs, linkArgs, conf, mode, verbose)
|
linkMainPkg(ctx, pkg, pkgs, linkArgs, conf, mode, verbose)
|
||||||
@@ -270,6 +267,7 @@ type context struct {
|
|||||||
initial []*packages.Package
|
initial []*packages.Package
|
||||||
mode Mode
|
mode Mode
|
||||||
nLibdir int
|
nLibdir int
|
||||||
|
output bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs []*aPackage, err error) {
|
func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs []*aPackage, err error) {
|
||||||
@@ -438,7 +436,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
|
|||||||
|
|
||||||
args = append(args, linkArgs...)
|
args = append(args, linkArgs...)
|
||||||
|
|
||||||
if needLLFile(mode) {
|
if ctx.output {
|
||||||
lpkg := aPkg.LPkg
|
lpkg := aPkg.LPkg
|
||||||
os.WriteFile(pkg.ExportFile, []byte(lpkg.String()), 0644)
|
os.WriteFile(pkg.ExportFile, []byte(lpkg.String()), 0644)
|
||||||
}
|
}
|
||||||
@@ -578,7 +576,7 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) (cgoLdflags []string,
|
|||||||
check(err)
|
check(err)
|
||||||
aPkg.LPkg = ret
|
aPkg.LPkg = ret
|
||||||
cgoLdflags, err = buildCgo(ctx, aPkg, aPkg.Package.Syntax, externs, verbose)
|
cgoLdflags, err = buildCgo(ctx, aPkg, aPkg.Package.Syntax, externs, verbose)
|
||||||
if needLLFile(ctx.mode) {
|
if ctx.output {
|
||||||
pkg.ExportFile += ".ll"
|
pkg.ExportFile += ".ll"
|
||||||
os.WriteFile(pkg.ExportFile, []byte(ret.String()), 0644)
|
os.WriteFile(pkg.ExportFile, []byte(ret.String()), 0644)
|
||||||
if debugBuild || verbose {
|
if debugBuild || verbose {
|
||||||
|
|||||||
Reference in New Issue
Block a user