-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneration.go
180 lines (149 loc) · 4.11 KB
/
generation.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright (C) 2017, 2018 Damon Revoe. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
package main
import (
"bufio"
"os"
"os/exec"
"path"
"regexp"
"strings"
)
type configureHelpParser struct {
optRegexp *regexp.Regexp
classifier optClassifier
ignoredFeatOrPkg map[string]struct{}
}
func createConfigureHelpParser() configureHelpParser {
return configureHelpParser{
regexp.MustCompile(`^--([^\s\[=]+)([^\s]*)\s*(.*)$`),
createOptClassifier(),
map[string]struct{}{
"FEATURE": {},
"PACKAGE": {},
"aix-soname": {},
"dependency-tracking": {},
"fast-install": {},
"gnu-ld": {},
"libtool-lock": {},
"option-checking": {},
"pkgconfigdir": {},
"silent-rules": {},
"sysroot": {},
}}
}
func (helpParser *configureHelpParser) parseOptions(packageDir string) (
[]optDescription, error) {
configureHelpCmd := exec.Command("./configure", "--help")
configureHelpCmd.Dir = packageDir
configureHelpStdout, err := configureHelpCmd.StdoutPipe()
if err != nil {
return nil, err
}
if err = configureHelpCmd.Start(); err != nil {
return nil, err
}
helpScanner := bufio.NewScanner(configureHelpStdout)
var options []optDescription
var currentOption *optDescription
for helpScanner.Scan() {
helpLine := strings.TrimRight(helpScanner.Text(), " ")
if helpLine == "" || !strings.HasPrefix(helpLine, " ") {
if currentOption != nil {
options = append(options, *currentOption)
currentOption = nil
}
continue
}
helpLine = strings.TrimLeft(helpLine, " ")
if strings.HasPrefix(helpLine, "-") {
if currentOption != nil {
options = append(options, *currentOption)
currentOption = nil
}
} else {
if currentOption != nil {
if currentOption.description != "" {
currentOption.description += " "
}
currentOption.description += helpLine
}
continue
}
parts := helpParser.optRegexp.FindStringSubmatch(helpLine)
if len(parts) < 4 {
continue
}
opt, arg, descr := parts[1], parts[2], parts[3]
key := helpParser.classifier.classify(opt)
if key.optType != optOther {
_, present := helpParser.ignoredFeatOrPkg[key.optName]
if present {
continue
}
}
currentOption = &optDescription{key, descr, "--" + opt + arg}
}
if err := helpScanner.Err(); err != nil {
return nil, err
}
if err = configureHelpCmd.Wait(); err != nil {
return nil, err
}
return options, nil
}
func generateAndBootstrapPackages(ws *workspace, pi *packageIndex,
selection packageDefinitionList, conftab *Conftab) error {
pkgRootDir := ws.generatedPkgRootDir()
type packageAndGenerator struct {
pd *packageDefinition
packageDir string
generator func() (bool, error)
}
var packagesAndGenerators []packageAndGenerator
for _, pd := range selection {
packageDir := path.Join(pkgRootDir, pd.PackageName)
generator, err := pd.getPackageGeneratorFunc(packageDir)
if err != nil {
return err
}
packagesAndGenerators = append(packagesAndGenerators,
packageAndGenerator{pd, packageDir, generator})
}
var packagesToBootstrap []packageAndGenerator
// Generate autoconf and automake sources for the selected packages.
for _, pg := range packagesAndGenerators {
changed, err := pg.generator()
if err != nil {
return err
}
_, err = os.Stat(path.Join(pg.packageDir, "configure"))
if changed || os.IsNotExist(err) {
packagesToBootstrap = append(packagesToBootstrap, pg)
}
}
if !flags.noBootstrap {
// Bootstrap the selected packages.
for _, pg := range packagesToBootstrap {
err := bootstrapPackage(pg.packageDir, pg.pd)
if err != nil {
return err
}
}
helpParser := createConfigureHelpParser()
for _, pg := range packagesAndGenerators {
options, err := helpParser.parseOptions(pg.packageDir)
if err != nil {
return err
}
for _, opt := range options {
if opt.key.optType != optOther {
conftab.addOption(
pg.pd.PackageName, &opt)
}
}
}
}
return generateWorkspaceFiles(ws, pi, selection, conftab)
}