Example #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)
}
Example #2
0
func TestListInterfaces(t *testing.T) {
	src, err := buildutils.SrcDir(SelfPackage)
	require.NoError(t, err)
	list, err := ListInterfacesFromFile(path.Join(src, SelfFile))
	require.NoError(t, err)
	assert.EqualValues(t, []string{"FirstInterface", "SecondInterface"}, list)
}
Example #3
0
func walkProtoProjectsFromCurrent(walkFn walkProjectFunc) error {
	root, err := os.Getwd()
	if err != nil {
		return err
	}
	importPath, err := buildutils.ImportPath(root)
	if err != nil {
		return err
	}
	state := make(map[string]int)
	if *dependOnBootstrapProject && importPath != *bootstrapProject {
		bootstrapRoot, err := buildutils.SrcDir(*bootstrapProject)
		if err != nil {
			return err
		}
		err = walkProtoProjectsCustom(bootstrapRoot, *bootstrapProject, state, walkFn)
		if err != nil {
			return err
		}
	}
	return walkProtoProjectsCustom(root, importPath, state, walkFn)
}