示例#1
0
func walkProtoProjectsCustom(
	root, importPath string, state map[string]int, walkFn walkProjectFunc) error {

	if s, ok := state[importPath]; ok {
		switch s {
		case notDone:
			state[importPath] = doing
		case doing:
			return fmt.Errorf("cyclic dependency detected at %q", importPath)
		case done:
			return nil
		}
	} else {
		state[importPath] = doing
	}
	defer func() { state[importPath] = done }()

	cfg, err := config.ParseProject(root)
	if err != nil {
		return err
	}
	for _, dep := range cfg.Dependencies {
		depPath, err := buildutils.SrcDir(dep)
		if err != nil {
			return err
		}
		err = walkProtoProjectsCustom(depPath, dep, state, walkFn)
		if err != nil {
			return err
		}
	}
	return walkFn(root, importPath, cfg)
}
示例#2
0
func Generate() error {
	currentProject, err := os.Getwd()
	if err != nil {
		return err
	}
	cfg, err := config.ParseProject(currentProject)
	if err != nil {
		return err
	}
	pathContext, err := newProtocPathContext(currentProject, cfg)
	if err != nil {
		return err
	}

	generator, err := newGenerator(pathContext)
	if err != nil {
		return err
	}

	err = walkProtoProjectsFromCurrent(generator.walkImportProjects)
	if err != nil {
		return err
	}

	err = walkProtoPackages(pathContext.ProtoRoot(), generator.walkGenProtos)
	if err != nil {
		return err
	}
	for _, imp := range cfg.Local.Import {
		err = walkProtoPackagesCustom(imp.Prefix, imp.Path, generator.walkGenProtos)
		if err != nil {
			return err
		}
	}
	return nil
}