lib/vdl/build: don't implicitly add 'src' to VDLPATH dirs

Addresses https://github.com/vanadium/issues/issues/145.

MultiPart: 1/6
Change-Id: Iea0b40362a4b66989b16a1a8b58c952d5e62498a
diff --git a/cmd/vdl/doc.go b/cmd/vdl/doc.go
index 7307617..098e9ed 100644
--- a/cmd/vdl/doc.go
+++ b/cmd/vdl/doc.go
@@ -60,18 +60,18 @@
       "src->dst[,s2->d2...]" : Generate output using translation rules
    Assume your source tree is organized as follows:
       VDLPATH=/home/vdl
-         /home/vdl/src/test_base/base1.vdl
-         /home/vdl/src/test_base/base2.vdl
+         /home/vdl/test_base/base1.vdl
+         /home/vdl/test_base/base2.vdl
    Here's example output under the different modes:
       --go-out-dir=""
-         /home/vdl/src/test_base/base1.vdl.go
-         /home/vdl/src/test_base/base2.vdl.go
+         /home/vdl/test_base/base1.vdl.go
+         /home/vdl/test_base/base2.vdl.go
       --go-out-dir="/tmp/foo"
          /tmp/foo/test_base/base1.vdl.go
          /tmp/foo/test_base/base2.vdl.go
-      --go-out-dir="vdl/src->foo/bar/src"
-         /home/foo/bar/src/test_base/base1.vdl.go
-         /home/foo/bar/src/test_base/base2.vdl.go
+      --go-out-dir="vdl->foo/bar"
+         /home/foo/bar/test_base/base1.vdl.go
+         /home/foo/bar/test_base/base2.vdl.go
    When the src->dst form is used, src must match the suffix of the path just
    before the package path, and dst is the replacement for src.  Use commas to
    separate multiple rules; the first rule matching src is used.  The special
@@ -130,18 +130,18 @@
       "src->dst[,s2->d2...]" : Generate output using translation rules
    Assume your source tree is organized as follows:
       VDLPATH=/home/vdl
-         /home/vdl/src/test_base/base1.vdl
-         /home/vdl/src/test_base/base2.vdl
+         /home/vdl/test_base/base1.vdl
+         /home/vdl/test_base/base2.vdl
    Here's example output under the different modes:
       --go-out-dir=""
-         /home/vdl/src/test_base/base1.vdl.go
-         /home/vdl/src/test_base/base2.vdl.go
+         /home/vdl/test_base/base1.vdl.go
+         /home/vdl/test_base/base2.vdl.go
       --go-out-dir="/tmp/foo"
          /tmp/foo/test_base/base1.vdl.go
          /tmp/foo/test_base/base2.vdl.go
-      --go-out-dir="vdl/src->foo/bar/src"
-         /home/foo/bar/src/test_base/base1.vdl.go
-         /home/foo/bar/src/test_base/base2.vdl.go
+      --go-out-dir="vdl->foo/bar"
+         /home/foo/bar/test_base/base1.vdl.go
+         /home/foo/bar/test_base/base2.vdl.go
    When the src->dst form is used, src must match the suffix of the path just
    before the package path, and dst is the replacement for src.  Use commas to
    separate multiple rules; the first rule matching src is used.  The special
@@ -234,6 +234,10 @@
 such paths are ignored in wildcard matches, and return errors if specified
 explicitly.
 
+Note that whereas GOPATH requires *.go source files and packages to appear under
+a "src" directory, VDLPATH requires *.vdl source files and packages to appear
+directly under the VDLPATH directories.
+
  Run "vdl help vdlpath" to see docs on VDLPATH.
  Run "go help packages" to see the standard go package docs.
 
@@ -242,26 +246,25 @@
 The VDLPATH environment variable is used to resolve import statements. It must
 be set to compile and generate vdl packages.
 
-The format is a colon-separated list of directories, where each directory must
-have a "src/" directory that holds vdl source code.  The path below 'src'
-determines the import path.  If VDLPATH specifies multiple directories, imports
-are resolved by picking the first directory with a matching import name.
+The format is a colon-separated list of directories containing vdl source code.
+These directories are searched recursively for VDL source files.  The path below
+the directory determines the import path.  If VDLPATH specifies multiple
+directories, imports are resolved by picking the first directory with a matching
+import name.
 
 An example:
 
    VDPATH=/home/user/vdlA:/home/user/vdlB
 
-   /home/user/vdlA/
-      src/
-         foo/                 (import "foo" refers here)
-            foo1.vdl
-   /home/user/vdlB/
-      src/
-         foo/                 (this package is ignored)
-            foo2.vdl
-         bar/
-            baz/              (import "bar/baz" refers here)
-               baz.vdl
+   /home/user/vdlA
+       foo/                 (import "foo" refers here)
+           foo1.vdl
+   /home/user/vdlB
+       foo/                 (this package is ignored)
+          foo2.vdl
+       bar/
+          baz/              (import "bar/baz" refers here)
+             baz.vdl
 
 Vdl vdlroot - Description of VDLROOT environment variable
 
diff --git a/cmd/vdl/main.go b/cmd/vdl/main.go
index 50c4c22..57973c3 100644
--- a/cmd/vdl/main.go
+++ b/cmd/vdl/main.go
@@ -100,6 +100,10 @@
 such paths are ignored in wildcard matches, and return errors if specified
 explicitly.
 
+Note that whereas GOPATH requires *.go source files and packages to appear
+under a "src" directory, VDLPATH requires *.vdl source files and packages to
+appear directly under the VDLPATH directories.
+
  Run "vdl help vdlpath" to see docs on VDLPATH.
  Run "go help packages" to see the standard go package docs.
 `,
@@ -112,26 +116,25 @@
 The VDLPATH environment variable is used to resolve import statements.
 It must be set to compile and generate vdl packages.
 
-The format is a colon-separated list of directories, where each directory must
-have a "src/" directory that holds vdl source code.  The path below 'src'
-determines the import path.  If VDLPATH specifies multiple directories, imports
-are resolved by picking the first directory with a matching import name.
+The format is a colon-separated list of directories containing vdl source code.
+These directories are searched recursively for VDL source files.  The path
+below the directory determines the import path.  If VDLPATH specifies multiple
+directories, imports are resolved by picking the first directory with a
+matching import name.
 
 An example:
 
    VDPATH=/home/user/vdlA:/home/user/vdlB
 
-   /home/user/vdlA/
-      src/
-         foo/                 (import "foo" refers here)
-            foo1.vdl
-   /home/user/vdlB/
-      src/
-         foo/                 (this package is ignored)
-            foo2.vdl
-         bar/
-            baz/              (import "bar/baz" refers here)
-               baz.vdl
+   /home/user/vdlA
+       foo/                 (import "foo" refers here)
+           foo1.vdl
+   /home/user/vdlB
+       foo/                 (this package is ignored)
+          foo2.vdl
+       bar/
+          baz/              (import "bar/baz" refers here)
+             baz.vdl
 `,
 }
 
@@ -388,18 +391,18 @@
    "src->dst[,s2->d2...]" : Generate output using translation rules
 Assume your source tree is organized as follows:
    VDLPATH=/home/vdl
-      /home/vdl/src/test_base/base1.vdl
-      /home/vdl/src/test_base/base2.vdl
+      /home/vdl/test_base/base1.vdl
+      /home/vdl/test_base/base2.vdl
 Here's example output under the different modes:
    --go-out-dir=""
-      /home/vdl/src/test_base/base1.vdl.go
-      /home/vdl/src/test_base/base2.vdl.go
+      /home/vdl/test_base/base1.vdl.go
+      /home/vdl/test_base/base2.vdl.go
    --go-out-dir="/tmp/foo"
       /tmp/foo/test_base/base1.vdl.go
       /tmp/foo/test_base/base2.vdl.go
-   --go-out-dir="vdl/src->foo/bar/src"
-      /home/foo/bar/src/test_base/base1.vdl.go
-      /home/foo/bar/src/test_base/base2.vdl.go
+   --go-out-dir="vdl->foo/bar"
+      /home/foo/bar/test_base/base1.vdl.go
+      /home/foo/bar/test_base/base2.vdl.go
 When the src->dst form is used, src must match the suffix of the path just
 before the package path, and dst is the replacement for src.  Use commas to
 separate multiple rules; the first rule matching src is used.  The special dst
diff --git a/lib/vdl/build/build.go b/lib/vdl/build/build.go
index 4bc5ce2..967c77f 100644
--- a/lib/vdl/build/build.go
+++ b/lib/vdl/build/build.go
@@ -298,10 +298,9 @@
 	var srcDirs []string
 	for _, dir := range filepath.SplitList(os.Getenv("VDLPATH")) {
 		if dir != "" {
-			src := filepath.Join(dir, "src")
-			abs, err := filepath.Abs(src)
+			abs, err := filepath.Abs(dir)
 			if err != nil {
-				errs.Errorf("VDLPATH src dir %q can't be made absolute (%v)", src, err)
+				errs.Errorf("VDLPATH src dir %q can't be made absolute (%v)", dir, err)
 				continue // keep going to collect all errors
 			}
 			srcDirs = append(srcDirs, abs)
diff --git a/lib/vdl/build/build_test.go b/lib/vdl/build/build_test.go
index e437bdb..f3c4414 100644
--- a/lib/vdl/build/build_test.go
+++ b/lib/vdl/build/build_test.go
@@ -37,7 +37,7 @@
 // TODO(toddw): Put a full VDLPATH tree under ../testdata and only use that.
 const (
 	defaultVDLRoot = "../../../../../v23/vdlroot"
-	defaultVDLPath = "../../../../../../.."
+	defaultVDLPath = "../../../../../.."
 )
 
 func setEnvironment(t *testing.T, vdlroot, vdlpath string) bool {
@@ -93,8 +93,8 @@
 		got := build.SrcDirs(errs)
 		vdltest.ExpectResult(t, errs, name, test.ErrRE)
 		// Every result will have our valid VDLPATH srcdir.
-		vdlpathsrc := filepath.Join(abs(defaultVDLPath), "src")
-		want := append(test.Want, vdlpathsrc)
+		vdlpath := abs(defaultVDLPath)
+		want := append(test.Want, vdlpath)
 		if !reflect.DeepEqual(got, want) {
 			t.Errorf("SrcDirs(%s) got %v, want %v", name, got, want)
 		}
@@ -116,24 +116,24 @@
 	}{
 		{"", nil},
 		// Test absolute paths.
-		{"/a", []string{"/a/src"}},
-		{"/a/b", []string{"/a/b/src"}},
-		{"/a:/b", []string{"/a/src", "/b/src"}},
-		{"/a/1:/b/2", []string{"/a/1/src", "/b/2/src"}},
-		{"/a/1:/b/2:/c/3", []string{"/a/1/src", "/b/2/src", "/c/3/src"}},
-		{":::/a/1::::/b/2::::/c/3:::", []string{"/a/1/src", "/b/2/src", "/c/3/src"}},
+		{"/a", []string{"/a"}},
+		{"/a/b", []string{"/a/b"}},
+		{"/a:/b", []string{"/a", "/b"}},
+		{"/a/1:/b/2", []string{"/a/1", "/b/2"}},
+		{"/a/1:/b/2:/c/3", []string{"/a/1", "/b/2", "/c/3"}},
+		{":::/a/1::::/b/2::::/c/3:::", []string{"/a/1", "/b/2", "/c/3"}},
 		// Test relative paths.
-		{"a", []string{abs("a/src")}},
-		{"a/b", []string{abs("a/b/src")}},
-		{"a:b", []string{abs("a/src"), abs("b/src")}},
-		{"a/1:b/2", []string{abs("a/1/src"), abs("b/2/src")}},
-		{"a/1:b/2:c/3", []string{abs("a/1/src"), abs("b/2/src"), abs("c/3/src")}},
-		{":::a/1::::b/2::::c/3:::", []string{abs("a/1/src"), abs("b/2/src"), abs("c/3/src")}},
+		{"a", []string{abs("a")}},
+		{"a/b", []string{abs("a/b")}},
+		{"a:b", []string{abs("a"), abs("b")}},
+		{"a/1:b/2", []string{abs("a/1"), abs("b/2")}},
+		{"a/1:b/2:c/3", []string{abs("a/1"), abs("b/2"), abs("c/3")}},
+		{":::a/1::::b/2::::c/3:::", []string{abs("a/1"), abs("b/2"), abs("c/3")}},
 		// Test mixed absolute / relative paths.
-		{"a:/b", []string{abs("a/src"), "/b/src"}},
-		{"/a/1:b/2", []string{"/a/1/src", abs("b/2/src")}},
-		{"/a/1:b/2:/c/3", []string{"/a/1/src", abs("b/2/src"), "/c/3/src"}},
-		{":::/a/1::::b/2::::/c/3:::", []string{"/a/1/src", abs("b/2/src"), "/c/3/src"}},
+		{"a:/b", []string{abs("a"), "/b"}},
+		{"/a/1:b/2", []string{"/a/1", abs("b/2")}},
+		{"/a/1:b/2:/c/3", []string{"/a/1", abs("b/2"), "/c/3"}},
+		{":::/a/1::::b/2::::/c/3:::", []string{"/a/1", abs("b/2"), "/c/3"}},
 	}
 	for _, test := range tests {
 		if !setEnvironment(t, defaultVDLRoot, test.VDLPath) {