Skip to content

Commit ef52a88

Browse files
committed
Fix build dependencies.
1 parent 6fb2ca4 commit ef52a88

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

pkg/plugins/builder/builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ func (b *Builder) Build(ctx context.Context) error {
9999
_ = b.Close()
100100
}
101101
}()
102-
log.Printf("[INFO] Temporary folder: %s", b.env.wd)
102+
log.Printf("[DEBUG] Temporary folder: %s", b.env.wd)
103103

104104
// Write files to dir and generate go mod.
105105
log.Printf("[INFO] Creating project files and fetching dependencies")
106+
b.env.SetEnv("CGO_ENABLE", "0")
106107
err = b.env.CreateModFile(ctx, b.BuildOptions)
107108
if err != nil {
108109
return err
@@ -112,7 +113,7 @@ func (b *Builder) Build(ctx context.Context) error {
112113
buildVer := b.getBuildVersion(b.LaunchrVersion)
113114
for _, p := range b.Plugins {
114115
if p.Version == "" {
115-
p.Version = b.env.getPkgVersion(p.Package)
116+
p.Version = b.env.GetPkgVersion(p.Package)
116117
}
117118
}
118119

@@ -202,7 +203,7 @@ func (b *Builder) getBuildVersion(version *launchr.AppVersion) *launchr.AppVersi
202203
bv.Name = b.PkgName
203204

204205
// Get version from the fetched go.mod module
205-
bv.Version = b.env.getPkgVersion(b.CorePkg.Package)
206+
bv.Version = b.env.GetPkgVersion(b.CorePkg.Package)
206207

207208
bv.OS = os.Getenv("GOOS")
208209
bv.Arch = os.Getenv("GOARCH")

pkg/plugins/builder/environment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func envFromOs() envVars {
2020
osenv := os.Environ()
2121
env := make(envVars, 0, 8)
2222
for _, v := range osenv {
23-
if strings.HasPrefix(v, "GO") || strings.HasPrefix(v, "HOME=") {
23+
if strings.HasPrefix(v, "GO") ||
24+
strings.HasPrefix(v, "HOME=") ||
25+
strings.HasPrefix(v, "PATH=") {
2426
env = append(env, v)
2527
}
2628
}
@@ -201,7 +203,7 @@ func (env *buildEnvironment) parseGoMod() error {
201203
return nil
202204
}
203205

204-
func (env *buildEnvironment) getPkgVersion(pkg string) string {
206+
func (env *buildEnvironment) GetPkgVersion(pkg string) string {
205207
var vrep *modfile.Replace
206208
for _, rep := range env.gomod.Replace {
207209
if strings.HasPrefix(pkg, rep.Old.Path) {
@@ -223,3 +225,7 @@ func (env *buildEnvironment) getPkgVersion(pkg string) string {
223225
}
224226
return v
225227
}
228+
229+
func (env *buildEnvironment) SetEnv(k string, v string) {
230+
env.env.Set(k, v)
231+
}

pkg/plugins/builder/plugin.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,34 @@ func (p *Plugin) InitApp(*launchr.App) error {
3939
func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
4040
// Flag options.
4141
var (
42-
name string
43-
out string
44-
timeout int
45-
plugins []string
46-
replace []string
47-
debug bool
42+
name string
43+
out string
44+
timeoutStr string
45+
plugins []string
46+
replace []string
47+
debug bool
4848
)
4949

5050
var buildCmd = &cobra.Command{
5151
Use: "build",
5252
RunE: func(cmd *cobra.Command, args []string) error {
5353
// Don't show usage help on a runtime error.
5454
cmd.SilenceUsage = true
55+
56+
// Set build timeout.
5557
ctx := cmd.Context()
58+
timeout, err := time.ParseDuration(timeoutStr)
59+
if err != nil {
60+
return err
61+
}
5662
if timeout != 0 {
5763
// Execute build.
5864
var cancel context.CancelFunc
59-
ctx, cancel = context.WithTimeout(ctx, time.Second*time.Duration(timeout))
65+
ctx, cancel = context.WithTimeout(ctx, timeout)
6066
defer cancel()
6167
}
68+
69+
// Parse dependencies definition.
6270
allplugs, err := parsePlugins(plugins)
6371
if err != nil {
6472
return err
@@ -68,6 +76,7 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
6876
return err
6977
}
7078

79+
// Set output path if it's not defined.
7180
if len(out) == 0 && len(name) > 0 {
7281
out = "./" + name
7382
}
@@ -85,9 +94,10 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
8594
return Execute(ctx, opts)
8695
},
8796
}
97+
// Command flags.
8898
buildCmd.Flags().StringVarP(&name, "name", "n", "launchr", `Result application name`)
8999
buildCmd.Flags().StringVarP(&out, "output", "o", "", `Build output file, by default application name is used`)
90-
buildCmd.Flags().IntVarP(&timeout, "timeout", "t", 120, `Build timeout in seconds`)
100+
buildCmd.Flags().StringVarP(&timeoutStr, "timeout", "t", "120s", `Build timeout duration, example: 0, 100ms, 1h23m`)
91101
buildCmd.Flags().StringSliceVarP(&plugins, "plugin", "p", nil, `Include PLUGIN into the build with an optional version`)
92102
buildCmd.Flags().StringSliceVarP(&replace, "replace", "r", nil, `Replace go dependency, see "go mod edit -replace"`)
93103
buildCmd.Flags().BoolVarP(&debug, "debug", "d", false, `Include debug flags into the build to support go debugging with "delve". If not specified, debugging info is trimmed`)

0 commit comments

Comments
 (0)