Skip to content

Commit

Permalink
fixing code style
Browse files Browse the repository at this point in the history
  • Loading branch information
shimib committed Jan 31, 2024
1 parent b5ac289 commit 63f154c
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions build/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newCargoModule(srcPath string, containingBuild *Build) (*CargoModule, error
}

// Read module name
name, version, err := getModuleNameByDirWithVersion(srcPath, containingBuild.logger)
name, version, err := getModuleNameByDirWithVersion(srcPath)
if err != nil {
return nil, err
}
Expand All @@ -53,8 +53,7 @@ func getProjectRoot() (string, error) {
return utils.FindFileInDirAndParents(wd, cargoModuleFile)
}

func getModuleNameByDirWithVersion(projectDir string, log utils.Log) (string, string, error) {

func getModuleNameByDirWithVersion(projectDir string) (string, string, error) {
var values map[string]map[string]string

_, err := toml.DecodeFile(path.Join(projectDir, cargoModuleFile), &values)
Expand Down Expand Up @@ -165,7 +164,6 @@ func populateCrate(packageId, zipPath string) (zipDependency entities.Dependency
}

var deplineRegex = regexp.MustCompile(`([0-9]+)(\S+) v(\S+)( \(.*\))?`)
var depNoDepthlineRegex = regexp.MustCompile(`(\S+) v(\S+)( \(.*\))?`)

func graphToMap(output string) map[string][]string {
var stack Stack
Expand All @@ -188,12 +186,13 @@ func graphToMap(output string) map[string][]string {
}
nameAndVersion := match[2] + ":" + match[3]

if depth == prevDepth {
switch {
case depth == prevDepth:
// no need to change parent or if 0, no need to store at all
} else if depth > prevDepth {
case depth > prevDepth:
stack.Push(currParent)
currParent = prevLineName
} else {
default:
diff := prevDepth - depth // how many parents to pop
for i := 0; i < diff; i++ {
currParent, _ = stack.Pop()
Expand Down Expand Up @@ -223,16 +222,15 @@ func getCargoHome(log utils.Log) (cargoHome string, err error) {
return "", err
}
cargoHome = path.Dir(path.Dir(cargo))
} else {
if !path.IsAbs(cargoHome) {
// for relative path, prepend current directory to it
wd, err := os.Getwd()
if err != nil {
return wd, err
}
cargoHome = filepath.Join(wd, cargoHome)
} else if !path.IsAbs(cargoHome) {
// for relative path, prepend current directory to it
wd, err := os.Getwd()
if err != nil {
return wd, err
}
cargoHome = filepath.Join(wd, cargoHome)
}

log.Debug("Cargo home location:", cargoHome)

return
Expand Down

0 comments on commit 63f154c

Please sign in to comment.