gen.go: fix breakage due to changes in core

Changes:
src/vendor/golang_org moved to src/internal/x

Change-Id: I3791fd633534f15f5e2698ad01ae8d226128181e
Reviewed-on: https://go-review.googlesource.com/c/154438
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ross Light <light@google.com>
diff --git a/gen.go b/gen.go
index 40ae925..cf2640e 100644
--- a/gen.go
+++ b/gen.go
@@ -138,7 +138,7 @@
 	copyExported("golang.org/x/net/idna")
 
 	if updateCore {
-		copyVendored()
+		copyInternal()
 	}
 
 	if hasErrors {
@@ -236,9 +236,9 @@
 		p)
 }
 
-// copyVendored copies packages used by Go core into the vendored directory.
-func copyVendored() {
-	root := filepath.Join(build.Default.GOROOT, filepath.FromSlash("src/vendor/golang_org/x"))
+// copyInternal copies packages used by Go core into the internal directory.
+func copyInternal() {
+	root := filepath.Join(build.Default.GOROOT, filepath.FromSlash("src/internal/x"))
 
 	err := filepath.Walk(root, func(dir string, info os.FileInfo, err error) error {
 		if err != nil || !info.IsDir() || root == dir {
@@ -253,7 +253,7 @@
 			// Copy the vendored package if it exists in the export directory.
 			src = filepath.Join("internal", "export", filepath.Base(src))
 		}
-		copyPackage(src, dir, "golang.org", "golang_org")
+		copyPackage(src, dir, "golang.org", "internal")
 		return nil
 	})
 	if err != nil {
@@ -279,18 +279,22 @@
 			filepath.Dir(file) != dirSrc {
 			return nil
 		}
+		if strings.HasPrefix(base, "tables") {
+			if !strings.HasSuffix(base, gen.UnicodeVersion()+".go") {
+				return nil
+			}
+			base = "tables.go"
+		}
 		b, err := ioutil.ReadFile(file)
 		if err != nil || bytes.Contains(b, []byte("\n// +build ignore")) {
 			return err
 		}
 		// Fix paths.
 		b = bytes.Replace(b, []byte(search), []byte(replace), -1)
+		b = bytes.Replace(b, []byte("internal/export"), []byte(""), -1)
 		// Remove go:generate lines.
 		b = goGenRE.ReplaceAllLiteral(b, nil)
 		comment := "// Code generated by running \"go generate\" in golang.org/x/text. DO NOT EDIT.\n\n"
-		if *doCore {
-			comment = "// Code generated by running \"go run gen.go -core\" in golang.org/x/text. DO NOT EDIT.\n\n"
-		}
 		if !bytes.HasPrefix(b, []byte(comment)) {
 			b = append([]byte(comment), b...)
 		}