Now generates Makefiles!

This commit is contained in:
Joshua Bussdieker
2012-03-01 17:00:50 -08:00
parent 3102c3bab5
commit b4d148ed9a
2 changed files with 59 additions and 15 deletions
+9
View File
@@ -1,6 +1,7 @@
package main
import "os"
import "path/filepath"
import "github.com/moovweb/gvm/gpkg/pkg"
import "github.com/moovweb/gvm/gpkg/pkgs"
import "github.com/moovweb/gvm/gpkg/gopkgs"
@@ -16,11 +17,19 @@ func main() {
os.Exit(1)
}
gvm_go_name := os.Getenv("gvm_go_name")
if gvm_go_name == "" {
println("ERROR: No Go version selected")
os.Exit(1)
}
if len(os.Args) > 1 {
if os.Args[1] == "list" {
println()
pkgs.List(gvm_root)
gopkgs.List(gvm_root)
} else if os.Args[1] == "listall" {
pkg.List(filepath.Join(gvm_root, "gos", gvm_go_name, "src", "pkg"))
} else if os.Args[1] == "install" {
pkg.Install()
} else {
+50 -15
View File
@@ -1,12 +1,15 @@
package pkg
import "os"
//import "path"
import "strings"
import "go/parser"
import "go/token"
import "path/filepath"
import "io/ioutil"
var root string
var go_packages []string
func readFile(imports map[string]string, filename string) map[string]string {
fset := token.NewFileSet()
@@ -31,36 +34,57 @@ func checkIt(f *os.FileInfo) bool {
return false
}
func DebugPackages(path string) {
func checkName(name string) bool {
for _, cur_name := range go_packages {
if "\"" + cur_name + "\"" == name {
return true
}
}
return false
}
func DebugPackages(path string, level int) {
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, path, checkIt, 0)
if err != nil {
println("ERROR: Couldn't parse files" + err.String())
}
pkg_name := ""
for _, pkg := range pkgs {
pkg_name := ""
if len(path) > len(root) {
pkg_name = path[len(root)+1:] + "/" + pkg.Name
pkg_name = path[len(root)+1:]
} else {
pkg_name = pkg.Name
}
println(" Package:", pkg_name)
}
imports := make(map[string]string)
file := fset.Files()
for f := range file {
imports = readFile(imports, f.Name())
//println(f.Name())
imp_list := ""
if level > 0 {
imports := make(map[string]string)
file := fset.Files()
for f := range file {
imports = readFile(imports, f.Name())
}
for _, str := range imports {
if checkName(str) == false {
imp_list += str[1:len(str)-1] + " "
}
}
}
for _, str := range imports {
println(" import", str)
if pkg_name != "" {
println(pkg_name + ": " + imp_list)
//println(" make -f Makefile.gvm -C " + pkg_name)
println(" goinstall -nuke " + pkg_name)
}
}
func ParseDir(path string) {
func ParseDir(path string, level int) {
pkgfolder, err := os.Open(path)
if err != nil {
println("ERROR: Failed to open pkg dir", path)
@@ -72,23 +96,34 @@ func ParseDir(path string) {
os.Exit(1)
}
DebugPackages(path)
DebugPackages(path, level)
for _, pkgfile := range dirs {
if pkgfile.IsDirectory() {
if pkgfile.Name != "test" && pkgfile.Name != "_obj" && pkgfile.Name != "_bin" {
ParseDir(filepath.Join(path, pkgfile.Name))
ParseDir(filepath.Join(path, pkgfile.Name), level)
}
}
}
}
func List(path string) {
root = path
ParseDir(path, 0)
}
func Install() {
data, err := ioutil.ReadFile("go.list")
if err != nil {
println("ERROR: Failed to read Go default package list")
}
go_packages = strings.Split(string(data), "\n")
wd, err := os.Getwd()
root = wd
if err != nil {
println("ERROR: Couldn't read current directory")
}
ParseDir(root)
ParseDir(root, 1)
println()
}