Пример #1
0
// getGeneratedFiles returns a list of all automatically generated files in the repo. These include
// docs, deep_copy, and conversions
//
// It would be 'better' to call this for every commit but that takes
// a whole lot of time for almost always the same information, and if
// our results are slightly wrong, who cares? Instead look for the
// generated files once and if someone changed what files are generated
// we'll size slightly wrong. No biggie.
func (s *SizeMunger) getGeneratedFiles(obj *github.MungeObject) {
	if s.genFiles != nil {
		return
	}
	files := sets.NewString()
	prefixes := []string{}
	s.genFiles = &files
	s.genPrefixes = &prefixes

	file := s.generatedFilesFile
	if len(file) == 0 {
		glog.Infof("No --generated-files-config= supplied, applying no labels")
		return
	}
	fp, err := os.Open(file)
	if err != nil {
		glog.Errorf("Unable to open %q: %v", file, err)
		return
	}

	defer fp.Close()
	scanner := bufio.NewScanner(fp)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "#") || line == "" {
			continue
		}
		fields := strings.Fields(line)
		if len(fields) != 2 {
			glog.Errorf("Invalid line in generated docs config %s: %q", file, line)
			continue
		}
		eType := fields[0]
		file := fields[1]
		if eType == "prefix" {
			prefixes = append(prefixes, file)
		} else if eType == "path" {
			files.Insert(file)
		} else if eType == "paths-from-repo" {
			docs, err := obj.GetFileContents(file, "")
			if err != nil {
				continue
			}
			docSlice := strings.Split(docs, "\n")
			files.Insert(docSlice...)
		} else {
			glog.Errorf("Invalid line in generated docs config, unknown type: %s, %q", eType, line)
			continue
		}
	}
	if scanner.Err() != nil {
		glog.Errorf("Error scanning %s: %v", file, err)
		return
	}
	s.genFiles = &files
	s.genPrefixes = &prefixes

	return
}
Пример #2
0
// getGeneratedFiles returns a list of all automatically generated files in the repo. These include
// docs, deep_copy, and conversions
//
// It would be 'better' to call this for every commit but that takes
// a whole lot of time for almost always the same information, and if
// our results are slightly wrong, who cares? Instead look for the
// generated files once and if someone changed what files are generated
// we'll size slightly wrong. No biggie.
func (s *SizeMunger) getGeneratedFiles(obj *github.MungeObject) {
	if s.genFilePaths != nil {
		return
	}
	if s.genFilePrefixes != nil {
		return
	}
	if s.genFileNames != nil {
		return
	}
	if s.genPathPrefixes != nil {
		return
	}

	// Don't write into s yet, since this might fail, and these are indicators
	// to not repeat this function.
	paths := sets.NewString()
	filePrefixes := sets.NewString()
	fileNames := sets.NewString()
	pathPrefixes := sets.NewString()

	file := s.GeneratedFilesFile
	if len(file) == 0 {
		glog.Infof("No --generated-files-config= supplied, applying no labels")
		return
	}

	contents, err := obj.GetFileContents(file, "")
	if err != nil {
		glog.Errorf("Failed to read generated-files-config %q: %v", file, err)
	}

	lines := strings.Split(contents, "\n")
	for i, line := range lines {
		line := strings.TrimSpace(line)
		if strings.HasPrefix(line, "#") || line == "" {
			continue
		}
		fields := strings.Fields(line)
		if len(fields) != 2 {
			glog.Errorf("Invalid line %d in generated docs config %s: %q", i, file, line)
			continue
		}
		key := fields[0]
		val := fields[1]
		if key == "prefix" || key == "path-prefix" {
			pathPrefixes.Insert(val)
		} else if key == "file-prefix" {
			filePrefixes.Insert(val)
		} else if key == "file-name" {
			fileNames.Insert(val)
		} else if key == "path" {
			paths.Insert(val)
		} else if key == "paths-from-repo" {
			docs, err := obj.GetFileContents(val, "")
			if err != nil {
				continue
			}
			docSlice := strings.Split(docs, "\n")
			paths.Insert(docSlice...)
		} else {
			glog.Errorf("Invalid line %d in generated docs config, unknown key: %s, %q", i, key, line)
			continue
		}
	}

	// Save the results so we don't repeat this function.
	s.genFilePaths = paths
	s.genFilePrefixes = filePrefixes
	s.genFileNames = fileNames
	s.genPathPrefixes = pathPrefixes

	return
}