summaryrefslogtreecommitdiff
path: root/config/builder.go
blob: 112f181ac63a431ace3bd7058dd77c722735689f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package config

import (
	"phabricator.wikimedia.org/source/blubber/build"
)

// BuilderConfig contains configuration for the definition of an arbitrary
// build command.
//
type BuilderConfig struct {
	Builder []string `yaml:"builder"`
}

// Merge takes another BuilderConfig and merges its fields into this one's,
// overwriting the builder command.
//
func (bc *BuilderConfig) Merge(bc2 BuilderConfig) {
	if len(bc2.Builder) > 0 {
		bc.Builder = bc2.Builder
	}
}

// InstructionsForPhase injects instructions into the build related to
// builder commands.
//
// PhasePostInstall
//
// Runs build command provided for the builder
//
func (bc BuilderConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
	switch phase {
	case build.PhasePostInstall:
		if len(bc.Builder) == 0 {
			return []build.Instruction{}
		}

		run := build.Run{Command: bc.Builder[0]}

		if len(bc.Builder) > 1 {
			run.Arguments = bc.Builder[1:]
		}

		return []build.Instruction{run}
	}

	return []build.Instruction{}
}