func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error { targetFilePath := utils.NULLFile() importedLibraries := ctx.ImportedLibraries done := false for !done { commands := []types.Command{ &GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath}, &IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE}, &IncludesToIncludeFolders{}, } for _, command := range commands { err := runCommand(ctx, command) if err != nil { return i18n.WrapError(err) } } if len(ctx.IncludesJustFound) == 0 { done = true } else if len(ctx.ImportedLibraries) == len(importedLibraries) { err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) return i18n.WrapError(err) } importedLibraries = ctx.ImportedLibraries ctx.IncludesJustFound = []string{} } return nil }
func (s *IncludesFinderWithRegExp) Run(ctx *types.Context) error { source := *s.Source matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1) includes := []string{} for _, match := range matches { includes = append(includes, strings.TrimSpace(match[1])) } if len(includes) == 0 { include := findIncludesForOldCompilers(source) if include != "" { includes = append(includes, include) } } ctx.IncludesJustFound = includes ctx.Includes = utils.AppendIfNotPresent(ctx.Includes, includes...) return nil }