@@ -3,7 +3,6 @@ package main
33import (
44 "fmt"
55 "log"
6- "net/url"
76 "os"
87 "os/exec"
98 "path/filepath"
@@ -56,63 +55,6 @@ Build behavior:
5655 fmt .Fprintf (os .Stderr , "Usage:\n \n %s\n " , os .Args [0 ])
5756}
5857
59- // Returns the import path of the package being built, or "" if it cannot be determined.
60- func getImportPath () (importpath string ) {
61- importpath = os .Getenv ("LGTM_INDEX_IMPORT_PATH" )
62- if importpath == "" {
63- repourl := os .Getenv ("SEMMLE_REPO_URL" )
64- if repourl == "" {
65- githubrepo := os .Getenv ("GITHUB_REPOSITORY" )
66- if githubrepo == "" {
67- log .Printf ("Unable to determine import path, as neither LGTM_INDEX_IMPORT_PATH nor GITHUB_REPOSITORY is set\n " )
68- return ""
69- } else {
70- importpath = "github.com/" + githubrepo
71- }
72- } else {
73- importpath = getImportPathFromRepoURL (repourl )
74- if importpath == "" {
75- log .Printf ("Failed to determine import path from SEMMLE_REPO_URL '%s'\n " , repourl )
76- return
77- }
78- }
79- }
80- log .Printf ("Import path is '%s'\n " , importpath )
81- return
82- }
83-
84- // Returns the import path of the package being built from `repourl`, or "" if it cannot be
85- // determined.
86- func getImportPathFromRepoURL (repourl string ) string {
87- // check for scp-like URL as in "git@github.com:github/codeql-go.git"
88- shorturl := regexp .MustCompile (`^([^@]+@)?([^:]+):([^/].*?)(\.git)?$` )
89- m := shorturl .FindStringSubmatch (repourl )
90- if m != nil {
91- return m [2 ] + "/" + m [3 ]
92- }
93-
94- // otherwise parse as proper URL
95- u , err := url .Parse (repourl )
96- if err != nil {
97- log .Fatalf ("Malformed repository URL '%s'\n " , repourl )
98- }
99-
100- if u .Scheme == "file" {
101- // we can't determine import paths from file paths
102- return ""
103- }
104-
105- if u .Hostname () == "" || u .Path == "" {
106- return ""
107- }
108-
109- host := u .Hostname ()
110- path := u .Path
111- // strip off leading slashes and trailing `.git` if present
112- path = regexp .MustCompile (`^/+|\.git$` ).ReplaceAllString (path , "" )
113- return host + "/" + path
114- }
115-
11658func restoreRepoLayout (fromDir string , dirEntries []string , scratchDirName string , toDir string ) {
11759 for _ , dirEntry := range dirEntries {
11860 if dirEntry != scratchDirName {
@@ -568,7 +510,7 @@ func installDependenciesAndBuild() {
568510 if len (workspaces ) == 1 {
569511 workspace := workspaces [0 ]
570512
571- importpath := getImportPath ()
513+ importpath := util . GetImportPath ()
572514 needGopath := getNeedGopath (workspace , importpath )
573515
574516 inLGTM := os .Getenv ("LGTM_SRC" ) != "" || os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != ""
0 commit comments