"flag"
"fmt"
"io"
+ "io/ioutil"
"log"
"os"
"path"
objabi.Flagcount("h", "halt on error", &Debug['h'])
objabi.Flagcount("i", "debug line number stack", &Debug['i'])
objabi.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
+ objabi.Flagfn1("importcfg", "read import configuration from `file`", readImportCfg)
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
objabi.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
objabi.Flagcount("l", "disable inlining", &Debug['l'])
return f.Close()
}
-var importMap = map[string]string{}
+var (
+ importMap = map[string]string{}
+ packageFile map[string]string // nil means not in use
+)
func addImportMap(s string) {
if strings.Count(s, "=") != 1 {
importMap[source] = actual
}
+func readImportCfg(file string) {
+ packageFile = map[string]string{}
+ data, err := ioutil.ReadFile(file)
+ if err != nil {
+ log.Fatalf("-importcfg: %v", err)
+ }
+
+ for lineNum, line := range strings.Split(string(data), "\n") {
+ lineNum++ // 1-based
+ line = strings.TrimSpace(line)
+ if line == "" || strings.HasPrefix(line, "#") {
+ continue
+ }
+
+ var verb, args string
+ if i := strings.Index(line, " "); i < 0 {
+ verb = line
+ } else {
+ verb, args = line[:i], strings.TrimSpace(line[i+1:])
+ }
+ var before, after string
+ if i := strings.Index(args, "="); i >= 0 {
+ before, after = args[:i], args[i+1:]
+ }
+ switch verb {
+ default:
+ log.Fatalf("%s:%d: unknown directive %q", file, lineNum, verb)
+ case "importmap":
+ if before == "" || after == "" {
+ log.Fatalf(`%s:%d: invalid importmap: syntax is "importmap old=new"`, file, lineNum)
+ }
+ importMap[before] = after
+ case "packagefile":
+ if before == "" || after == "" {
+ log.Fatalf(`%s:%d: invalid packagefile: syntax is "packagefile path=filename"`, file, lineNum)
+ }
+ packageFile[before] = after
+ }
+ }
+}
+
func saveerrors() {
nsavederrors += nerrors
nerrors = 0
return "", false
}
+ if packageFile != nil {
+ file, ok = packageFile[name]
+ return file, ok
+ }
+
// try .a before .6. important for building libraries:
// if there is an array.6 in the array.a library,
// want to find all of array.a, not just array.6.
return "", false
}
+ if packageFile != nil {
+ file, ok = packageFile[name]
+ return file, ok
+ }
+
for _, dir := range idirs {
file = fmt.Sprintf("%s/%s.a", dir, name)
if _, err := os.Stat(file); err == nil {
}
// assume files move (get installed) so don't record the full path
- // (e.g., for file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a")
- Ctxt.AddImport(file[len(file)-len(path_)-len(pkgSuffix):])
+ if packageFile != nil {
+ // If using a packageFile map, assume path_ can be recorded directly.
+ Ctxt.AddImport(path_)
+ } else {
+ // For file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a".
+ Ctxt.AddImport(file[len(file)-len(path_)-len(pkgSuffix):])
+ }
// In the importfile, if we find:
// $$\n (textual format): not supported anymore