Skip to content

Commit 158a1a5

Browse files
Merge pull request #115 from lmbelo/master
Setting search paths relative to project path
2 parents 0869d68 + 03eedfa commit 158a1a5

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

utils/librarypath/dproj_itil.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package librarypath
33
import (
44
"io/ioutil"
55
"os"
6+
"path"
67
"path/filepath"
78
"regexp"
89
"strconv"
@@ -77,7 +78,7 @@ func processCompilerOptions(compilerOptions *etree.Element) {
7778
}
7879
value := otherUnitFiles.SelectAttr("Value")
7980
currentPaths := strings.Split(value.Value, ";")
80-
currentPaths = GetNewPaths(currentPaths, false)
81+
currentPaths = GetNewPaths(currentPaths, false, env.GetCurrentDir())
8182
value.Value = strings.Join(currentPaths, ";")
8283
}
8384

@@ -109,7 +110,11 @@ func updateLibraryPathProject(dprojName string) {
109110
if child == nil {
110111
child = createTagLibraryPath(children)
111112
}
112-
processCurrentPath(child)
113+
rootPath := filepath.Join(env.GetCurrentDir(), path.Dir(dprojName))
114+
if _, err := os.Stat(rootPath); os.IsNotExist(err) {
115+
rootPath = env.GetCurrentDir()
116+
}
117+
processCurrentPath(child, rootPath)
113118
}
114119
}
115120

@@ -170,10 +175,10 @@ func isLazarus() bool {
170175
return false
171176
}
172177

173-
func processCurrentPath(node *etree.Element) {
178+
func processCurrentPath(node *etree.Element, rootPath string) {
174179
currentPaths := strings.Split(node.Text(), ";")
175180

176-
currentPaths = GetNewPaths(currentPaths, false)
181+
currentPaths = GetNewPaths(currentPaths, false, rootPath)
177182

178183
node.SetText(strings.Join(currentPaths, ";"))
179184
}

utils/librarypath/global_util_win.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func updateGlobalLibraryPath() {
5050
}
5151

5252
splitPaths := strings.Split(paths, ";")
53-
newSplitPaths := GetNewPaths(splitPaths, true)
53+
newSplitPaths := GetNewPaths(splitPaths, true, env.GetCurrentDir())
5454
newPaths := strings.Join(newSplitPaths, ";")
5555
err = delphiPlatform.SetStringValue(SearchPathRegistry, newPaths)
5656
utils.HandleError(err)

utils/librarypath/librarypath.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func cleanPath(paths []string, fullPath bool) []string {
4040
return processedPaths
4141
}
4242

43-
func GetNewPaths(paths []string, fullPath bool) []string {
43+
func GetNewPaths(paths []string, fullPath bool, rootPath string) []string {
4444
paths = cleanPath(paths, fullPath)
4545
var path = env.GetModulesDir()
4646

@@ -52,28 +52,28 @@ func GetNewPaths(paths []string, fullPath bool) []string {
5252
if _, err := os.Stat(packagePath); !os.IsNotExist(err) {
5353

5454
other, _ := models.LoadPackageOther(packagePath)
55-
paths = getNewPathsFromDir(filepath.Join(path, value.Name(), other.MainSrc), paths, fullPath)
55+
paths = getNewPathsFromDir(filepath.Join(path, value.Name(), other.MainSrc), paths, fullPath, rootPath)
5656

5757
} else {
58-
paths = getNewPathsFromDir(filepath.Join(path, value.Name()), paths, fullPath)
58+
paths = getNewPathsFromDir(filepath.Join(path, value.Name()), paths, fullPath, rootPath)
5959
}
6060
}
6161
return paths
6262
}
6363

64-
func getDefaultPath(fullPath bool) []string {
64+
func getDefaultPath(fullPath bool, rootPath string) []string {
6565
var paths []string
6666

6767
if !fullPath {
6868
fullPath := filepath.Join(env.GetCurrentDir(), consts.FolderDependencies, consts.DcpFolder)
6969

70-
dir, err := filepath.Rel(env.GetCurrentDir(), fullPath)
70+
dir, err := filepath.Rel(rootPath, fullPath)
7171
if err == nil {
7272
paths = append(paths, dir)
7373
}
7474

7575
fullPath = filepath.Join(env.GetCurrentDir(), consts.FolderDependencies, consts.DcuFolder)
76-
dir, err = filepath.Rel(env.GetCurrentDir(), fullPath)
76+
dir, err = filepath.Rel(rootPath, fullPath)
7777
if err == nil {
7878
paths = append(paths, dir)
7979
}
@@ -99,7 +99,7 @@ func cleanEmpty(paths []string) []string {
9999
return paths
100100
}
101101

102-
func getNewPathsFromDir(path string, paths []string, fullPath bool) []string {
102+
func getNewPathsFromDir(path string, paths []string, fullPath bool, rootPath string) []string {
103103
_, e := os.Stat(path)
104104
if os.IsNotExist(e) {
105105
return paths
@@ -110,7 +110,7 @@ func getNewPathsFromDir(path string, paths []string, fullPath bool) []string {
110110
if matched {
111111
dir, _ := filepath.Split(path)
112112
if !fullPath {
113-
dir, _ = filepath.Rel(env.GetCurrentDir(), dir)
113+
dir, _ = filepath.Rel(rootPath, dir)
114114
}
115115
if !utils.Contains(paths, dir) {
116116
paths = append(paths, dir)
@@ -119,7 +119,7 @@ func getNewPathsFromDir(path string, paths []string, fullPath bool) []string {
119119
return nil
120120
})
121121

122-
for _, path := range getDefaultPath(fullPath) {
122+
for _, path := range getDefaultPath(fullPath, rootPath) {
123123
if !utils.Contains(paths, path) {
124124
paths = append(paths, path)
125125
}

0 commit comments

Comments
 (0)