diff --git a/docs/configuration/command.md b/docs/configuration/command.md index ae40826..080e4cb 100644 --- a/docs/configuration/command.md +++ b/docs/configuration/command.md @@ -263,7 +263,7 @@ list | `[]` ### build.env -Type | Required +Type | Default ---|--- map | `{}` @@ -288,9 +288,33 @@ map | `{}` In this case, VERSION is specified to change version used in build steps. +### build.directory + +Type | Default +---|--- +string | (each package home) + +`build.directory` can be specified a path of working directory to build a package. + +=== "Case 1" + + ```yaml hl_lines="7" + http: + - name: nkf + description: Netword Kanji Filter + url: https://free.nchc.org.tw/osdn//nkf/70406/nkf-2.1.5.tar.gz + command: + build: + directory: nkf-2.1.5 + steps: + - make + link: + - from: '*/nkf' + ``` + ### snippet -Type | Required +Type | Default ---|--- string | `""` @@ -316,7 +340,7 @@ string | `""` ### if -Type | Required +Type | Default ---|--- string | `""` diff --git a/pkg/config/command.go b/pkg/config/command.go index 17a159f..847b5cb 100644 --- a/pkg/config/command.go +++ b/pkg/config/command.go @@ -29,8 +29,9 @@ type Command struct { // Build is type Build struct { - Steps []string `yaml:"steps" validate:"required"` - Env map[string]string `yaml:"env"` + Steps []string `yaml:"steps" validate:"required"` + Env map[string]string `yaml:"env"` + Directory string `yaml:"directory"` } // Link is @@ -162,10 +163,15 @@ func (c Command) buildRequired() bool { } func (c Command) build(pkg Package) error { + wd, _ := os.Getwd() + log.Printf("[DEBUG] Current working directory: %s", wd) + + dir := filepath.Join(pkg.GetHome(), c.Build.Directory) + p := shellwords.NewParser() p.ParseEnv = true p.ParseBacktick = true - p.Dir = pkg.GetHome() + p.Dir = dir var errs errors.Errors for _, step := range c.Build.Steps { @@ -191,8 +197,8 @@ func (c Command) build(pkg Package) error { cmd.Stdout = &stdout cmd.Stdout = os.Stdout // TODO: remove cmd.Stderr = &stderr - log.Printf("[INFO] cd %s\n", pkg.GetHome()) - cmd.Dir = pkg.GetHome() + log.Printf("[DEBUG] change dir to: %s\n", dir) + cmd.Dir = dir if err := cmd.Run(); err != nil { errs.Append(err) if stderr.String() != "" {