Skip to content

Commit

Permalink
Add build.directory
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed May 28, 2022
1 parent 4b34e4c commit 3d7beda
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
30 changes: 27 additions & 3 deletions docs/configuration/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ list | `[]`

### build.env

Type | Required
Type | Default
---|---
map | `{}`

Expand All @@ -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 | `""`

Expand All @@ -316,7 +340,7 @@ string | `""`

### if

Type | Required
Type | Default
---|---
string | `""`

Expand Down
16 changes: 11 additions & 5 deletions pkg/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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() != "" {
Expand Down

0 comments on commit 3d7beda

Please sign in to comment.