blob: 18008da23dbcccc7e6d27420c56395738dfd61f7 [file] [log] [blame]
Dan Willemsen0043c0e2016-09-18 20:27:41 -07001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Microfactory is a tool to incrementally compile a go program. It's similar
16// to `go install`, but doesn't require a GOPATH. A package->path mapping can
17// be specified as command line options:
18//
19// -pkg-path android/soong=build/soong
20// -pkg-path github.com/google/blueprint=build/blueprint
21//
22// The paths can be relative to the current working directory, or an absolute
23// path. Both packages and paths are compared with full directory names, so the
24// android/soong-test package wouldn't be mapped in the above case.
25//
26// Microfactory will ignore *_test.go files, and limits *_darwin.go and
27// *_linux.go files to MacOS and Linux respectively. It does not support build
28// tags or any other suffixes.
29//
30// Builds are incremental by package. All input files are hashed, and if the
31// hash of an input or dependency changes, the package is rebuilt.
32//
33// It also exposes the -trimpath option from go's compiler so that embedded
34// path names (such as in log.Llongfile) are relative paths instead of absolute
35// paths.
36//
37// If you don't have a previously built version of Microfactory, when used with
38// -s <microfactory_src_dir> -b <microfactory_bin_file>, Microfactory can
39// rebuild itself as necessary. Combined with a shell script like soong_ui.bash
40// that uses `go run` to run Microfactory for the first time, go programs can be
41// quickly bootstrapped entirely from source (and a standard go distribution).
42package main
43
44import (
45 "bytes"
46 "crypto/sha1"
47 "flag"
48 "fmt"
49 "go/ast"
50 "go/parser"
51 "go/token"
52 "io"
53 "io/ioutil"
54 "os"
55 "os/exec"
56 "path/filepath"
57 "runtime"
58 "sort"
59 "strconv"
60 "strings"
61 "sync"
62 "syscall"
Dan Willemsencae59bc2017-07-13 14:27:31 -070063 "time"
Dan Willemsen0043c0e2016-09-18 20:27:41 -070064)
65
66var (
67 race = false
68 verbose = false
69
70 goToolDir = filepath.Join(runtime.GOROOT(), "pkg", "tool", runtime.GOOS+"_"+runtime.GOARCH)
Dan Willemsenfde85342017-02-22 22:03:04 -080071 goVersion = findGoVersion()
Dan Willemsen0043c0e2016-09-18 20:27:41 -070072)
73
Dan Willemsenfde85342017-02-22 22:03:04 -080074func findGoVersion() string {
75 if version, err := ioutil.ReadFile(filepath.Join(runtime.GOROOT(), "VERSION")); err == nil {
76 return string(version)
77 }
78
79 cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "version")
80 if version, err := cmd.Output(); err == nil {
81 return string(version)
82 } else {
83 panic(fmt.Sprintf("Unable to discover go version: %v", err))
84 }
85}
86
Dan Willemsen0043c0e2016-09-18 20:27:41 -070087type GoPackage struct {
88 Name string
89
90 // Inputs
Jeff Gaston1ae73a62017-03-31 14:08:00 -070091 directDeps []*GoPackage // specified directly by the module
92 allDeps []*GoPackage // direct dependencies and transitive dependencies
93 files []string
Dan Willemsen0043c0e2016-09-18 20:27:41 -070094
95 // Outputs
96 pkgDir string
97 output string
98 hashResult []byte
99
100 // Status
101 mutex sync.Mutex
102 compiled bool
103 failed error
104 rebuilt bool
105}
106
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700107// LinkedHashMap<string, GoPackage>
108type linkedDepSet struct {
109 packageSet map[string](*GoPackage)
110 packageList []*GoPackage
111}
112
113func newDepSet() *linkedDepSet {
114 return &linkedDepSet{packageSet: make(map[string]*GoPackage)}
115}
116func (s *linkedDepSet) tryGetByName(name string) (*GoPackage, bool) {
117 pkg, contained := s.packageSet[name]
118 return pkg, contained
119}
120func (s *linkedDepSet) getByName(name string) *GoPackage {
121 pkg, _ := s.tryGetByName(name)
122 return pkg
123}
124func (s *linkedDepSet) add(name string, goPackage *GoPackage) {
125 s.packageSet[name] = goPackage
126 s.packageList = append(s.packageList, goPackage)
127}
128func (s *linkedDepSet) ignore(name string) {
129 s.packageSet[name] = nil
130}
131
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700132// FindDeps searches all applicable go files in `path`, parses all of them
133// for import dependencies that exist in pkgMap, then recursively does the
134// same for all of those dependencies.
135func (p *GoPackage) FindDeps(path string, pkgMap *pkgPathMapping) error {
Dan Willemsencae59bc2017-07-13 14:27:31 -0700136 defer un(trace("findDeps"))
137
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700138 depSet := newDepSet()
139 err := p.findDeps(path, pkgMap, depSet)
140 if err != nil {
141 return err
142 }
143 p.allDeps = depSet.packageList
144 return nil
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700145}
146
147// findDeps is the recursive version of FindDeps. allPackages is the map of
148// all locally defined packages so that the same dependency of two different
149// packages is only resolved once.
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700150func (p *GoPackage) findDeps(path string, pkgMap *pkgPathMapping, allPackages *linkedDepSet) error {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700151 // If this ever becomes too slow, we can look at reading the files once instead of twice
152 // But that just complicates things today, and we're already really fast.
153 foundPkgs, err := parser.ParseDir(token.NewFileSet(), path, func(fi os.FileInfo) bool {
154 name := fi.Name()
155 if fi.IsDir() || strings.HasSuffix(name, "_test.go") || name[0] == '.' || name[0] == '_' {
156 return false
157 }
158 if runtime.GOOS != "darwin" && strings.HasSuffix(name, "_darwin.go") {
159 return false
160 }
161 if runtime.GOOS != "linux" && strings.HasSuffix(name, "_linux.go") {
162 return false
163 }
164 return true
165 }, parser.ImportsOnly)
166 if err != nil {
167 return fmt.Errorf("Error parsing directory %q: %v", path, err)
168 }
169
170 var foundPkg *ast.Package
171 // foundPkgs is a map[string]*ast.Package, but we only want one package
172 if len(foundPkgs) != 1 {
173 return fmt.Errorf("Expected one package in %q, got %d", path, len(foundPkgs))
174 }
175 // Extract the first (and only) entry from the map.
176 for _, pkg := range foundPkgs {
177 foundPkg = pkg
178 }
179
180 var deps []string
181 localDeps := make(map[string]bool)
182
183 for filename, astFile := range foundPkg.Files {
184 p.files = append(p.files, filename)
185
186 for _, importSpec := range astFile.Imports {
187 name, err := strconv.Unquote(importSpec.Path.Value)
188 if err != nil {
189 return fmt.Errorf("%s: invalid quoted string: <%s> %v", filename, importSpec.Path.Value, err)
190 }
191
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700192 if pkg, ok := allPackages.tryGetByName(name); ok {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700193 if pkg != nil {
194 if _, ok := localDeps[name]; !ok {
195 deps = append(deps, name)
196 localDeps[name] = true
197 }
198 }
199 continue
200 }
201
202 var pkgPath string
203 if path, ok, err := pkgMap.Path(name); err != nil {
204 return err
205 } else if !ok {
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700206 // Probably in the stdlib, but if not, then the compiler will fail with a reasonable error message
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700207 // Mark it as such so that we don't try to decode its path again.
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700208 allPackages.ignore(name)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700209 continue
210 } else {
211 pkgPath = path
212 }
213
214 pkg := &GoPackage{
215 Name: name,
216 }
217 deps = append(deps, name)
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700218 allPackages.add(name, pkg)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700219 localDeps[name] = true
220
221 if err := pkg.findDeps(pkgPath, pkgMap, allPackages); err != nil {
222 return err
223 }
224 }
225 }
226
227 sort.Strings(p.files)
228
229 if verbose {
230 fmt.Fprintf(os.Stderr, "Package %q depends on %v\n", p.Name, deps)
231 }
232
233 for _, dep := range deps {
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700234 p.directDeps = append(p.directDeps, allPackages.getByName(dep))
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700235 }
236
237 return nil
238}
239
240func (p *GoPackage) Compile(outDir, trimPath string) error {
241 p.mutex.Lock()
242 defer p.mutex.Unlock()
243 if p.compiled {
244 return p.failed
245 }
246 p.compiled = true
247
248 // Build all dependencies in parallel, then fail if any of them failed.
249 var wg sync.WaitGroup
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700250 for _, dep := range p.directDeps {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700251 wg.Add(1)
252 go func(dep *GoPackage) {
253 defer wg.Done()
254 dep.Compile(outDir, trimPath)
255 }(dep)
256 }
257 wg.Wait()
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700258 for _, dep := range p.directDeps {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700259 if dep.failed != nil {
260 p.failed = dep.failed
261 return p.failed
262 }
263 }
264
Dan Willemsencae59bc2017-07-13 14:27:31 -0700265 endTrace := trace("check compile %s", p.Name)
266
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700267 p.pkgDir = filepath.Join(outDir, p.Name)
268 p.output = filepath.Join(p.pkgDir, p.Name) + ".a"
269 shaFile := p.output + ".hash"
270
271 hash := sha1.New()
Dan Willemsenfde85342017-02-22 22:03:04 -0800272 fmt.Fprintln(hash, runtime.GOOS, runtime.GOARCH, goVersion)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700273
274 cmd := exec.Command(filepath.Join(goToolDir, "compile"),
275 "-o", p.output,
276 "-p", p.Name,
277 "-complete", "-pack", "-nolocalimports")
278 if race {
279 cmd.Args = append(cmd.Args, "-race")
280 fmt.Fprintln(hash, "-race")
281 }
282 if trimPath != "" {
283 cmd.Args = append(cmd.Args, "-trimpath", trimPath)
284 fmt.Fprintln(hash, trimPath)
285 }
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700286 for _, dep := range p.directDeps {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700287 cmd.Args = append(cmd.Args, "-I", dep.pkgDir)
288 hash.Write(dep.hashResult)
289 }
290 for _, filename := range p.files {
291 cmd.Args = append(cmd.Args, filename)
292 fmt.Fprintln(hash, filename)
293
294 // Hash the contents of the input files
295 f, err := os.Open(filename)
296 if err != nil {
297 f.Close()
298 err = fmt.Errorf("%s: %v", filename, err)
299 p.failed = err
300 return err
301 }
302 _, err = io.Copy(hash, f)
303 if err != nil {
304 f.Close()
305 err = fmt.Errorf("%s: %v", filename, err)
306 p.failed = err
307 return err
308 }
309 f.Close()
310 }
311 p.hashResult = hash.Sum(nil)
312
313 var rebuild bool
314 if _, err := os.Stat(p.output); err != nil {
315 rebuild = true
316 }
317 if !rebuild {
318 if oldSha, err := ioutil.ReadFile(shaFile); err == nil {
319 rebuild = !bytes.Equal(oldSha, p.hashResult)
320 } else {
321 rebuild = true
322 }
323 }
324
Dan Willemsencae59bc2017-07-13 14:27:31 -0700325 endTrace()
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700326 if !rebuild {
327 return nil
328 }
Dan Willemsencae59bc2017-07-13 14:27:31 -0700329 defer un(trace("compile %s", p.Name))
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700330
331 err := os.RemoveAll(p.pkgDir)
332 if err != nil {
333 err = fmt.Errorf("%s: %v", p.Name, err)
334 p.failed = err
335 return err
336 }
337
338 err = os.MkdirAll(filepath.Dir(p.output), 0777)
339 if err != nil {
340 err = fmt.Errorf("%s: %v", p.Name, err)
341 p.failed = err
342 return err
343 }
344
345 cmd.Stdin = nil
346 cmd.Stdout = os.Stdout
347 cmd.Stderr = os.Stderr
348 if verbose {
349 fmt.Fprintln(os.Stderr, cmd.Args)
350 }
351 err = cmd.Run()
352 if err != nil {
353 err = fmt.Errorf("%s: %v", p.Name, err)
354 p.failed = err
355 return err
356 }
357
358 err = ioutil.WriteFile(shaFile, p.hashResult, 0666)
359 if err != nil {
360 err = fmt.Errorf("%s: %v", p.Name, err)
361 p.failed = err
362 return err
363 }
364
365 p.rebuilt = true
366
367 return nil
368}
369
370func (p *GoPackage) Link(out string) error {
371 if p.Name != "main" {
372 return fmt.Errorf("Can only link main package")
373 }
Dan Willemsencae59bc2017-07-13 14:27:31 -0700374 endTrace := trace("check link %s", p.Name)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700375
376 shaFile := filepath.Join(filepath.Dir(out), "."+filepath.Base(out)+"_hash")
377
378 if !p.rebuilt {
379 if _, err := os.Stat(out); err != nil {
380 p.rebuilt = true
381 } else if oldSha, err := ioutil.ReadFile(shaFile); err != nil {
382 p.rebuilt = true
383 } else {
384 p.rebuilt = !bytes.Equal(oldSha, p.hashResult)
385 }
386 }
Dan Willemsencae59bc2017-07-13 14:27:31 -0700387 endTrace()
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700388 if !p.rebuilt {
389 return nil
390 }
Dan Willemsencae59bc2017-07-13 14:27:31 -0700391 defer un(trace("link %s", p.Name))
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700392
393 err := os.Remove(shaFile)
394 if err != nil && !os.IsNotExist(err) {
395 return err
396 }
397 err = os.Remove(out)
398 if err != nil && !os.IsNotExist(err) {
399 return err
400 }
401
402 cmd := exec.Command(filepath.Join(goToolDir, "link"), "-o", out)
403 if race {
404 cmd.Args = append(cmd.Args, "-race")
405 }
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700406 for _, dep := range p.allDeps {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700407 cmd.Args = append(cmd.Args, "-L", dep.pkgDir)
408 }
409 cmd.Args = append(cmd.Args, p.output)
410 cmd.Stdin = nil
411 cmd.Stdout = os.Stdout
412 cmd.Stderr = os.Stderr
413 if verbose {
414 fmt.Fprintln(os.Stderr, cmd.Args)
415 }
416 err = cmd.Run()
417 if err != nil {
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700418 return fmt.Errorf("command %s failed with error %v", cmd.Args, err)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700419 }
420
421 return ioutil.WriteFile(shaFile, p.hashResult, 0666)
422}
423
424// rebuildMicrofactory checks to see if microfactory itself needs to be rebuilt,
Dan Willemsencae59bc2017-07-13 14:27:31 -0700425// and if does, it will launch a new copy and return true. Otherwise it will return
426// false to continue executing.
427func rebuildMicrofactory(mybin, mysrc string, pkgMap *pkgPathMapping) bool {
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700428 intermediates := filepath.Join(filepath.Dir(mybin), "."+filepath.Base(mybin)+"_intermediates")
429
430 err := os.MkdirAll(intermediates, 0777)
431 if err != nil {
432 fmt.Fprintln(os.Stderr, "Failed to create intermediates directory: %v", err)
433 os.Exit(1)
434 }
435
436 pkg := &GoPackage{
437 Name: "main",
438 }
439
440 if err := pkg.FindDeps(mysrc, pkgMap); err != nil {
441 fmt.Fprintln(os.Stderr, err)
442 os.Exit(1)
443 }
444
445 if err := pkg.Compile(intermediates, mysrc); err != nil {
446 fmt.Fprintln(os.Stderr, err)
447 os.Exit(1)
448 }
449
450 if err := pkg.Link(mybin); err != nil {
451 fmt.Fprintln(os.Stderr, err)
452 os.Exit(1)
453 }
454
455 if !pkg.rebuilt {
Dan Willemsencae59bc2017-07-13 14:27:31 -0700456 return false
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700457 }
458
459 cmd := exec.Command(mybin, os.Args[1:]...)
460 cmd.Stdin = os.Stdin
461 cmd.Stdout = os.Stdout
462 cmd.Stderr = os.Stderr
463 if err := cmd.Run(); err == nil {
Dan Willemsencae59bc2017-07-13 14:27:31 -0700464 return true
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700465 } else if e, ok := err.(*exec.ExitError); ok {
466 os.Exit(e.ProcessState.Sys().(syscall.WaitStatus).ExitStatus())
467 }
468 os.Exit(1)
Dan Willemsencae59bc2017-07-13 14:27:31 -0700469 return true
470}
471
472var traceFile *os.File
473
474func trace(format string, a ...interface{}) func() {
475 if traceFile == nil {
476 return func() {}
477 }
478 s := strings.TrimSpace(fmt.Sprintf(format, a...))
479 fmt.Fprintf(traceFile, "%d B %s\n", time.Now().UnixNano()/1000, s)
480 return func() {
481 fmt.Fprintf(traceFile, "%d E %s\n", time.Now().UnixNano()/1000, s)
482 }
483}
484
485func un(f func()) {
486 f()
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700487}
488
489func main() {
490 var output, mysrc, mybin, trimPath string
491 var pkgMap pkgPathMapping
492
493 flags := flag.NewFlagSet("", flag.ExitOnError)
494 flags.BoolVar(&race, "race", false, "enable data race detection.")
495 flags.BoolVar(&verbose, "v", false, "Verbose")
496 flags.StringVar(&output, "o", "", "Output file")
497 flags.StringVar(&mysrc, "s", "", "Microfactory source directory (for rebuilding microfactory if necessary)")
498 flags.StringVar(&mybin, "b", "", "Microfactory binary location")
499 flags.StringVar(&trimPath, "trimpath", "", "remove prefix from recorded source file paths")
500 flags.Var(&pkgMap, "pkg-path", "Mapping of package prefixes to file paths")
501 err := flags.Parse(os.Args[1:])
502
503 if err == flag.ErrHelp || flags.NArg() != 1 || output == "" {
504 fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "-o out/binary <main-package>")
505 flags.PrintDefaults()
506 os.Exit(1)
507 }
508
Dan Willemsencae59bc2017-07-13 14:27:31 -0700509 tracePath := filepath.Join(filepath.Dir(output), "."+filepath.Base(output)+".trace")
510 traceFile, err = os.OpenFile(tracePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
511 if err != nil {
512 traceFile = nil
513 }
514 if executable, err := os.Executable(); err == nil {
515 defer un(trace("microfactory %s", executable))
516 } else {
517 defer un(trace("microfactory <unknown>"))
518 }
519
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700520 if mybin != "" && mysrc != "" {
Dan Willemsencae59bc2017-07-13 14:27:31 -0700521 if rebuildMicrofactory(mybin, mysrc, &pkgMap) {
522 return
523 }
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700524 }
525
526 mainPackage := &GoPackage{
527 Name: "main",
528 }
529
530 if path, ok, err := pkgMap.Path(flags.Arg(0)); err != nil {
531 fmt.Fprintln(os.Stderr, "Error finding main path:", err)
532 os.Exit(1)
533 } else if !ok {
534 fmt.Fprintln(os.Stderr, "Cannot find path for", flags.Arg(0))
535 } else {
536 if err := mainPackage.FindDeps(path, &pkgMap); err != nil {
537 fmt.Fprintln(os.Stderr, err)
538 os.Exit(1)
539 }
540 }
541
542 intermediates := filepath.Join(filepath.Dir(output), "."+filepath.Base(output)+"_intermediates")
543
544 err = os.MkdirAll(intermediates, 0777)
545 if err != nil {
546 fmt.Fprintln(os.Stderr, "Failed to create intermediates directory: %ve", err)
547 os.Exit(1)
548 }
549
550 err = mainPackage.Compile(intermediates, trimPath)
551 if err != nil {
552 fmt.Fprintln(os.Stderr, "Failed to compile:", err)
553 os.Exit(1)
554 }
555
556 err = mainPackage.Link(output)
557 if err != nil {
Jeff Gaston1ae73a62017-03-31 14:08:00 -0700558 fmt.Fprintln(os.Stderr, "microfactory.go failed to link:", err)
Dan Willemsen0043c0e2016-09-18 20:27:41 -0700559 os.Exit(1)
560 }
561}
562
563// pkgPathMapping can be used with flag.Var to parse -pkg-path arguments of
564// <package-prefix>=<path-prefix> mappings.
565type pkgPathMapping struct {
566 pkgs []string
567
568 paths map[string]string
569}
570
571func (pkgPathMapping) String() string {
572 return "<package-prefix>=<path-prefix>"
573}
574
575func (p *pkgPathMapping) Set(value string) error {
576 equalPos := strings.Index(value, "=")
577 if equalPos == -1 {
578 return fmt.Errorf("Argument must be in the form of: %q", p.String())
579 }
580
581 pkgPrefix := strings.TrimSuffix(value[:equalPos], "/")
582 pathPrefix := strings.TrimSuffix(value[equalPos+1:], "/")
583
584 if p.paths == nil {
585 p.paths = make(map[string]string)
586 }
587 if _, ok := p.paths[pkgPrefix]; ok {
588 return fmt.Errorf("Duplicate package prefix: %q", pkgPrefix)
589 }
590
591 p.pkgs = append(p.pkgs, pkgPrefix)
592 p.paths[pkgPrefix] = pathPrefix
593
594 return nil
595}
596
597// Path takes a package name, applies the path mappings and returns the resulting path.
598//
599// If the package isn't mapped, we'll return false to prevent compilation attempts.
600func (p *pkgPathMapping) Path(pkg string) (string, bool, error) {
601 if p.paths == nil {
602 return "", false, fmt.Errorf("No package mappings")
603 }
604
605 for _, pkgPrefix := range p.pkgs {
606 if pkg == pkgPrefix {
607 return p.paths[pkgPrefix], true, nil
608 } else if strings.HasPrefix(pkg, pkgPrefix+"/") {
609 return filepath.Join(p.paths[pkgPrefix], strings.TrimPrefix(pkg, pkgPrefix+"/")), true, nil
610 }
611 }
612
613 return "", false, nil
614}