Beispiel #1
0
func main() {
	flag.Parse()

	if *outputDir == "" {
		log.Fatal("You must provide a non-empty --output_dir")
	}

	ext := golang.Extractor{
		BuildContext: bc,
		Corpus:       *corpus,
		LocalPath:    *localPath,
	}
	if cleanup, err := setupCampfire(&ext); err != nil {
		log.Fatalf("Error enabling campfire support: %v", err)
	} else {
		defer cleanup()
	}
	locate := ext.Locate
	if *byDir {
		locate = ext.ImportDir
	}
	for _, path := range flag.Args() {
		pkg, err := locate(path)
		if err == nil {
			maybeLog("Found %q in %s", pkg.Path, pkg.BuildPackage.Dir)
		} else {
			maybeFatal("Error locating %q: %v", path, err)
		}
	}

	if err := ext.Extract(); err != nil {
		maybeFatal("Error in extraction: %v", err)
	}

	pack, err := indexpack.CreateOrOpen(context.Background(), *outputDir,
		indexpack.UnitType((*apb.CompilationUnit)(nil)))
	if err != nil {
		log.Fatalf("Unable to open %q: %v", *outputDir, err)
	}

	maybeLog("Writing %d package(s) to %q", len(ext.Packages), pack.Root())
	for _, pkg := range ext.Packages {
		maybeLog("Package %q:\n\t// %s", pkg.Path, pkg.BuildPackage.Doc)
		uf, err := pkg.Store(context.Background(), pack)
		if err != nil {
			maybeFatal("Error writing %q: %v", pkg.Path, err)
		} else {
			maybeLog("Output: %v\n", strings.Join(uf, ", "))
		}
	}
}
Beispiel #2
0
// setupCampfire modifies the build configurations to support the Kythe
// campfire build environment.  It adds entries to GOPATH for generated files
// in campfire-out and third_party packages, and the working directory so that
// "kythe/..." import paths will work.
//
// On success, returns a function to clean up leftover state, which the caller
// should defer so it occurs before exit.
func setupCampfire(ext *golang.Extractor) (func(), error) {
	if !*campfireMode {
		return func() {}, nil
	}

	maybeLog("Enabling campfire compatibility mode")
	tp, err := ioutil.ReadDir("third_party/go")
	if err != nil {
		return nil, err
	}
	goPath := os.ExpandEnv(":$PWD:campfire-out/gen/go")
	for _, elt := range tp {
		if elt.IsDir() {
			goPath += filepath.Join(":third_party/go", elt.Name())
		}
	}
	ext.BuildContext.GOPATH += goPath
	ext.AltInstallPath = "campfire-out/go"
	if err := os.Symlink(".", "src"); err != nil {
		if os.IsExist(err) {
			return func() {}, nil
		}
		return nil, err
	}
	return func() { os.Remove("src") }, nil
}