// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package packages

import (
	
	

	
)

// determineRootDirs returns a mapping from absolute directories that could
// contain code to their corresponding import path prefixes.
func ( *golistState) () (map[string]string, error) {
	,  := .getEnv()
	if  != nil {
		return nil, 
	}
	if ["GOMOD"] != "" {
		.rootsOnce.Do(func() {
			.rootDirs, .rootDirsError = .determineRootDirsModules()
		})
	} else {
		.rootsOnce.Do(func() {
			.rootDirs, .rootDirsError = .determineRootDirsGOPATH()
		})
	}
	return .rootDirs, .rootDirsError
}

func ( *golistState) () (map[string]string, error) {
	// List all of the modules--the first will be the directory for the main
	// module. Any replaced modules will also need to be treated as roots.
	// Editing files in the module cache isn't a great idea, so we don't
	// plan to ever support that.
	,  := .invokeGo("list", "-m", "-json", "all")
	if  != nil {
		// 'go list all' will fail if we're outside of a module and
		// GO111MODULE=on. Try falling back without 'all'.
		var  error
		,  = .invokeGo("list", "-m", "-json")
		if  != nil {
			return nil, 
		}
	}
	 := map[string]string{}
	 := map[string]string{}
	var  int
	for  := json.NewDecoder(); .More(); {
		 := new(gocommand.ModuleJSON)
		if  := .Decode();  != nil {
			return nil, 
		}
		if .Dir != "" && .Path != "" {
			// This is a valid module; add it to the map.
			,  := .cfg.abs(.Dir)
			if  != nil {
				return nil, 
			}
			[] = .Path
			// The first result is the main module.
			if  == 0 || .Replace != nil && .Replace.Path != "" {
				[] = .Path
			}
		}
		++
	}
	return , nil
}

func ( *golistState) () (map[string]string, error) {
	 := map[string]string{}
	for ,  := range filepath.SplitList(.mustGetEnv()["GOPATH"]) {
		,  := filepath.Abs()
		if  != nil {
			return nil, 
		}
		[filepath.Join(, "src")] = ""
	}
	return , nil
}