This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.go
84 lines (69 loc) · 2.38 KB
/
install.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2018 Schibsted
package buildbuild
import (
"errors"
"strings"
)
var (
BadSymlinkFormat = errors.New("Bad symlink format, need symlink[dst:target]")
)
var InstallCommands = map[string]string{
"conf": "install_conf", // Installs the file with 644 permissions, intended for configuration files.
"scripts": "install_script", // Installs the file with 755 permissions, intended for executable scripts.
"python": "install_py", // Runs the py_compile module on the source file(s) during installation.
"php": "install_php", // Runs the php linter on the file during installation and fails if the file doesn't pass linting.
}
type InstallDesc struct {
GeneralDesc
Installs map[string][]string
Symlinks [][2]string
}
func (tmpl *InstallDesc) NewFromTemplate(bd, tname string, flavors []string) Descriptor {
return &InstallDesc{
GeneralDesc: *tmpl.GeneralDesc.NewFromTemplate(bd, tname, flavors),
Installs: make(map[string][]string),
}
}
func (id *InstallDesc) Parse(ops *GlobalOps, realsrcdir string, args map[string][]string) Descriptor {
extra := []string{"symlink"}
for inst := range InstallCommands {
if len(args[inst]) > 0 {
id.Installs[inst] = append(id.Installs[inst], ops.GlobDir(realsrcdir, args[inst])...)
}
extra = append(extra, inst)
}
desc := id.GenericParse(id, ops, realsrcdir, args, extra)
// Symlinks the tgt to the src, given as tgt:src in the arguments.
// Any relative path should be from the installation directory.
for _, sym := range args["symlink"] {
syms := strings.SplitN(sym, ":", 2)
if len(syms) < 2 {
panic(&ParseError{BadSymlinkFormat, sym, id.Builddesc})
}
id.Symlinks = append(id.Symlinks, [2]string{syms[0], syms[1]})
}
return desc
}
func (id *InstallDesc) Finalize(ops *GlobalOps) {
destdir := id.Destdir
if destdir == "" {
destdir = id.TargetName
}
opts := map[string]bool{"all": true}
for inst, command := range InstallCommands {
for _, src := range id.Installs[inst] {
id.AddTarget(src, command, []string{src}, destdir, id.Srcdir, nil, opts)
}
}
opts = map[string]bool{"all": true, "emptysrcs": true}
for _, syms := range id.Symlinks {
id.AddTarget(syms[0], "symlink", nil, destdir, destdir, []string{"target=" + syms[1]}, opts)
}
id.GeneralDesc.Finalize(ops)
}
var ToolInstallTemplate = InstallDesc{
GeneralDesc: GeneralDesc{
Destdir: "dest_tool",
},
}
var InstallTemplate = InstallDesc{}