Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BrowsingPath to Boss.json #166

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/compiler/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func buildSearchPath(dep *models.Dependency) string {
if pac, e := models.LoadPackageOther(filepath.Join(env.GetModulesDir(), dep.GetName(), consts.FilePackage)); e == nil {
searchPath += ";" + filepath.Join(env.GetModulesDir(), dep.GetName(), pac.MainSrc)
for _, lib := range pac.GetParsedDependencies() {
searchPath += buildSearchPath(&lib)
searchPath += ";" + buildSearchPath(&lib)
}
}
}
Expand Down
42 changes: 33 additions & 9 deletions core/installer/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
Expand Down Expand Up @@ -43,7 +44,7 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
}
deps := pkg.GetParsedDependencies()

makeCache(deps)
//makeCache(deps)

ensureModules(rootLock, pkg, deps, lockedVersion)

Expand All @@ -52,13 +53,6 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
return deps
}

func makeCache(deps []models.Dependency) {
msg.Info("Building cache files...")
for _, dep := range deps {
GetDependency(dep)
}
}

func processOthers(rootLock models.PackageLock, lockedVersion bool) []models.Dependency {
infos, e := ioutil.ReadDir(env.GetModulesDir())
var lenProcessedInitial = len(processed)
Expand Down Expand Up @@ -106,8 +100,38 @@ func ensureModules(rootLock models.PackageLock, pkg *models.Package, deps []mode
msg.Info("Installing modules")
for _, dep := range deps {
msg.Info("Processing dependency %s", dep.GetName())

installed, exists := rootLock.Installed[strings.ToLower(dep.GetURL())]

if lockedVersion && exists {
depv := strings.Replace(strings.Replace(dep.GetVersion(), "^", "", -1), "~", "", -1)
requiredVersion, err := semver.NewVersion(depv)

if err != nil {
msg.Warn(" Error '%s' on get required version. Updating...", err)

} else {
installedVersion, err := semver.NewVersion(installed.Version)

if err != nil {
msg.Warn(" Error '%s' on get installed version. Updating...", err)
} else {
if !installedVersion.LessThan(requiredVersion) {
msg.Info("Dependency %s already installed", dep.GetName())
continue
} else {
msg.Info("Dependency %s needs to update", dep.GetName())
}
}
}

}
//git fetch only when necessary
GetDependency(dep)

repository := gitWrapper.GetRepository(dep)
hasMatch, bestMatch := getVersion(rootLock, dep, repository, lockedVersion)
hasMatch, bestMatch := getVersion(rootLock, dep, repository, false)

var referenceName plumbing.ReferenceName

worktree, _ := repository.Worktree()
Expand Down
1 change: 1 addition & 0 deletions models/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Package struct {
Version string `json:"version"`
Homepage string `json:"homepage"`
MainSrc string `json:"mainsrc"`
BrowsingPath string `json:"browsingpath"`
Projects []string `json:"projects"`
Scripts interface{} `json:"scripts,omitempty"`
Dependencies interface{} `json:"dependencies"`
Expand Down
11 changes: 11 additions & 0 deletions utils/librarypath/dproj_itil.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ func createTagOtherUnitFiles(node *etree.Element) *etree.Element {
return child
}

func updateGlobalBrowsingPath(pkg *models.Package) {
var isLazarus = isLazarus()
var projectNames = GetProjectNames(pkg)
for i, projectName := range projectNames {
if !isLazarus {
updateGlobalBrowsingByProject(projectName, i == 0)
}
}

}

func updateLibraryPathProject(dprojName string) {
doc := etree.NewDocument()
info, err := os.Stat(dprojName)
Expand Down
4 changes: 4 additions & 0 deletions utils/librarypath/global_util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ import (
func updateGlobalLibraryPath() {
msg.Warn("updateGlobalLibraryPath not implemented on this platform")
}

func updateGlobalBrowsingByProject(dprojName string, setReadOnly bool) {
msg.Warn("updateGlobalBrowsingByProject not implemented on this platform")
}
44 changes: 44 additions & 0 deletions utils/librarypath/global_util_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package librarypath

import (
"path"
"path/filepath"
"strings"

"github.com/hashload/boss/consts"
Expand All @@ -16,6 +18,7 @@ import (
)

const SearchPathRegistry = "Search Path"
const BrowsingPathRegistry = "Browsing Path"

func updateGlobalLibraryPath() {
ideVersion := bossRegistry.GetCurrentDelphiVersion()
Expand Down Expand Up @@ -57,3 +60,44 @@ func updateGlobalLibraryPath() {
}

}

func updateGlobalBrowsingByProject(dprojName string, setReadOnly bool) {
ideVersion := bossRegistry.GetCurrentDelphiVersion()
if ideVersion == "" {
msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath)
}
library, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library`, registry.ALL_ACCESS)

if err != nil {
msg.Err(`Registry path` + consts.RegistryBasePath + ideVersion + `\Library not exists`)
return
}

libraryInfo, err := library.Stat()
if err != nil {
msg.Err(err.Error())
return
}
platforms, err := library.ReadSubKeyNames(int(libraryInfo.SubKeyCount))
if err != nil {
msg.Err("No platform found for delphi " + ideVersion)
return
}

for _, platform := range platforms {
delphiPlatform, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library\`+platform, registry.ALL_ACCESS)
utils.HandleError(err)
paths, _, err := delphiPlatform.GetStringValue(BrowsingPathRegistry)
if err != nil {
msg.Debug("Failed to update library path from platform %s with delphi %s", platform, ideVersion)
continue
}

splitPaths := strings.Split(paths, ";")
rootPath := filepath.Join(env.GetCurrentDir(), path.Dir(dprojName))
newSplitPaths := GetNewBrowsingPaths(splitPaths, false, rootPath, setReadOnly)
newPaths := strings.Join(newSplitPaths, ";")
err = delphiPlatform.SetStringValue(BrowsingPathRegistry, newPaths)
utils.HandleError(err)
}
}
72 changes: 72 additions & 0 deletions utils/librarypath/librarypath.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package librarypath

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/hashload/boss/consts"
"github.com/hashload/boss/env"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
)

Expand All @@ -18,6 +21,7 @@ func UpdateLibraryPath(pkg *models.Package) {
updateGlobalLibraryPath()
} else {
updateDprojLibraryPath(pkg)
updateGlobalBrowsingPath(pkg)
}

}
Expand All @@ -40,6 +44,46 @@ func cleanPath(paths []string, fullPath bool) []string {
return processedPaths
}

func GetNewBrowsingPaths(paths []string, fullPath bool, rootPath string, setReadOnly bool) []string {
paths = cleanPath(paths, fullPath)
var path = env.GetModulesDir()

matches, _ := ioutil.ReadDir(path)

for _, value := range matches {

var packagePath = filepath.Join(path, value.Name(), consts.FilePackage)
if _, err := os.Stat(packagePath); !os.IsNotExist(err) {

other, _ := models.LoadPackageOther(packagePath)
if other.BrowsingPath != "" {
dir := filepath.Join(path, value.Name(), other.BrowsingPath)
paths = getNewBrowsingPathsFromDir(dir, paths, fullPath, rootPath)

if setReadOnly {
readonlybat := filepath.Join(dir, "readonly.bat")
readFileStr := fmt.Sprintf(`attrib +r "%s" /s /d`, filepath.Join(dir, "*"))
err = ioutil.WriteFile(readonlybat, []byte(readFileStr), os.ModePerm)
if err != nil {
msg.Warn(" - error on create build file")
}

cmd := exec.Command(readonlybat)

if _, err := cmd.Output(); err != nil {
msg.Err(" - Failed to set readonly property to folder", dir, " - ", err)
} else {
os.Remove(readonlybat)
}
}

}

}
}
return paths
}

func GetNewPaths(paths []string, fullPath bool, rootPath string) []string {
paths = cleanPath(paths, fullPath)
var path = env.GetModulesDir()
Expand Down Expand Up @@ -99,6 +143,34 @@ func cleanEmpty(paths []string) []string {
return paths
}

func getNewBrowsingPathsFromDir(path string, paths []string, fullPath bool, rootPath string) []string {
_, e := os.Stat(path)
if os.IsNotExist(e) {
return paths
}

_ = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
matched, _ := regexp.MatchString(consts.RegexArtifacts, info.Name())
if matched {
dir, _ := filepath.Split(path)

if !fullPath {
dir, _ = filepath.Rel(rootPath, dir)
}
if !utils.Contains(paths, dir) {
paths = append(paths, dir)
}
// add ..\ prefixed path -> @MeroFuruya fix #146
//prefixedPath := "..\\" + dir
//if !utils.Contains(paths, prefixedPath) {
// paths = append(paths, prefixedPath)
//}
}
return nil
})
return cleanEmpty(paths)
}

func getNewPathsFromDir(path string, paths []string, fullPath bool, rootPath string) []string {
_, e := os.Stat(path)
if os.IsNotExist(e) {
Expand Down
Loading