diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-08-08 14:45:56 -0700 |
---|---|---|
committer | Jeff Gaston <jeffrygaston@google.com> | 2017-10-30 15:00:19 -0700 |
commit | a12f22fb695d20abfdceea360ca0e37901bee631 (patch) | |
tree | 96b8d378b79a49aef880c08459486049bd4ddcf7 /context.go | |
parent | 5f763d05115af3b9dd7b27a1b5a7f9463ef8c617 (diff) | |
download | android_build_blueprint-a12f22fb695d20abfdceea360ca0e37901bee631.tar.gz android_build_blueprint-a12f22fb695d20abfdceea360ca0e37901bee631.tar.bz2 android_build_blueprint-a12f22fb695d20abfdceea360ca0e37901bee631.zip |
Move parseOne for readability
Bug: 64363847
Test: m -j
Change-Id: Ie3e973dadbff139def127b0bb05c57bafb79165b
Diffstat (limited to 'context.go')
-rw-r--r-- | context.go | 178 |
1 files changed, 89 insertions, 89 deletions
@@ -520,95 +520,6 @@ func (c *Context) SetAllowMissingDependencies(allowMissingDependencies bool) { c.allowMissingDependencies = allowMissingDependencies } -// parseOne parses a single Blueprints file from the given reader, creating Module -// objects for each of the module definitions encountered. If the Blueprints -// file contains an assignment to the "subdirs" variable, then the -// subdirectories listed are searched for Blueprints files returned in the -// subBlueprints return value. If the Blueprints file contains an assignment -// to the "build" variable, then the file listed are returned in the -// subBlueprints return value. -// -// rootDir specifies the path to the root directory of the source tree, while -// filename specifies the path to the Blueprints file. These paths are used for -// error reporting and for determining the module's directory. -func (c *Context) parseOne(rootDir, filename string, reader io.Reader, - scope *parser.Scope) (file *parser.File, subBlueprints []stringAndScope, errs []error) { - - relBlueprintsFile, err := filepath.Rel(rootDir, filename) - if err != nil { - return nil, nil, []error{err} - } - - scope = parser.NewScope(scope) - scope.Remove("subdirs") - scope.Remove("optional_subdirs") - scope.Remove("build") - file, errs = parser.ParseAndEval(filename, reader, scope) - if len(errs) > 0 { - for i, err := range errs { - if parseErr, ok := err.(*parser.ParseError); ok { - err = &BlueprintError{ - Err: parseErr.Err, - Pos: parseErr.Pos, - } - errs[i] = err - } - } - - // If there were any parse errors don't bother trying to interpret the - // result. - return nil, nil, errs - } - file.Name = relBlueprintsFile - - subdirs, subdirsPos, err := getLocalStringListFromScope(scope, "subdirs") - if err != nil { - errs = append(errs, err) - } - - optionalSubdirs, optionalSubdirsPos, err := getLocalStringListFromScope(scope, "optional_subdirs") - if err != nil { - errs = append(errs, err) - } - - build, buildPos, err := getLocalStringListFromScope(scope, "build") - if err != nil { - errs = append(errs, err) - } - - subBlueprintsName, _, err := getStringFromScope(scope, "subname") - if err != nil { - errs = append(errs, err) - } - - if subBlueprintsName == "" { - subBlueprintsName = "Blueprints" - } - - var blueprints []string - - newBlueprints, newErrs := c.findBuildBlueprints(filepath.Dir(filename), build, buildPos) - blueprints = append(blueprints, newBlueprints...) - errs = append(errs, newErrs...) - - newBlueprints, newErrs = c.findSubdirBlueprints(filepath.Dir(filename), subdirs, subdirsPos, - subBlueprintsName, false) - blueprints = append(blueprints, newBlueprints...) - errs = append(errs, newErrs...) - - newBlueprints, newErrs = c.findSubdirBlueprints(filepath.Dir(filename), optionalSubdirs, - optionalSubdirsPos, subBlueprintsName, true) - blueprints = append(blueprints, newBlueprints...) - errs = append(errs, newErrs...) - - subBlueprintsAndScope := make([]stringAndScope, len(blueprints)) - for i, b := range blueprints { - subBlueprintsAndScope[i] = stringAndScope{b, scope} - } - - return file, subBlueprintsAndScope, errs -} - type stringAndScope struct { string *parser.Scope @@ -845,6 +756,95 @@ func (c *Context) parseOneAsync(filename string, scope *parser.Scope, rootDir st } } +// parseOne parses a single Blueprints file from the given reader, creating Module +// objects for each of the module definitions encountered. If the Blueprints +// file contains an assignment to the "subdirs" variable, then the +// subdirectories listed are searched for Blueprints files returned in the +// subBlueprints return value. If the Blueprints file contains an assignment +// to the "build" variable, then the file listed are returned in the +// subBlueprints return value. +// +// rootDir specifies the path to the root directory of the source tree, while +// filename specifies the path to the Blueprints file. These paths are used for +// error reporting and for determining the module's directory. +func (c *Context) parseOne(rootDir, filename string, reader io.Reader, + scope *parser.Scope) (file *parser.File, subBlueprints []stringAndScope, errs []error) { + + relBlueprintsFile, err := filepath.Rel(rootDir, filename) + if err != nil { + return nil, nil, []error{err} + } + + scope = parser.NewScope(scope) + scope.Remove("subdirs") + scope.Remove("optional_subdirs") + scope.Remove("build") + file, errs = parser.ParseAndEval(filename, reader, scope) + if len(errs) > 0 { + for i, err := range errs { + if parseErr, ok := err.(*parser.ParseError); ok { + err = &BlueprintError{ + Err: parseErr.Err, + Pos: parseErr.Pos, + } + errs[i] = err + } + } + + // If there were any parse errors don't bother trying to interpret the + // result. + return nil, nil, errs + } + file.Name = relBlueprintsFile + + subdirs, subdirsPos, err := getLocalStringListFromScope(scope, "subdirs") + if err != nil { + errs = append(errs, err) + } + + optionalSubdirs, optionalSubdirsPos, err := getLocalStringListFromScope(scope, "optional_subdirs") + if err != nil { + errs = append(errs, err) + } + + build, buildPos, err := getLocalStringListFromScope(scope, "build") + if err != nil { + errs = append(errs, err) + } + + subBlueprintsName, _, err := getStringFromScope(scope, "subname") + if err != nil { + errs = append(errs, err) + } + + if subBlueprintsName == "" { + subBlueprintsName = "Blueprints" + } + + var blueprints []string + + newBlueprints, newErrs := c.findBuildBlueprints(filepath.Dir(filename), build, buildPos) + blueprints = append(blueprints, newBlueprints...) + errs = append(errs, newErrs...) + + newBlueprints, newErrs = c.findSubdirBlueprints(filepath.Dir(filename), subdirs, subdirsPos, + subBlueprintsName, false) + blueprints = append(blueprints, newBlueprints...) + errs = append(errs, newErrs...) + + newBlueprints, newErrs = c.findSubdirBlueprints(filepath.Dir(filename), optionalSubdirs, + optionalSubdirsPos, subBlueprintsName, true) + blueprints = append(blueprints, newBlueprints...) + errs = append(errs, newErrs...) + + subBlueprintsAndScope := make([]stringAndScope, len(blueprints)) + for i, b := range blueprints { + subBlueprintsAndScope[i] = stringAndScope{b, scope} + } + + return file, subBlueprintsAndScope, errs +} + func (c *Context) findBuildBlueprints(dir string, build []string, buildPos scanner.Position) ([]string, []error) { |