Skip to content

Commit 98f5e1d

Browse files
Florent Teuberdfeyer
authored andcommitted
TASK: Add localroot options to support remote debug session
1 parent b1cdb0a commit 98f5e1d

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package config
88
type Config struct {
99
Context string
1010
Framework string
11+
LocalRoot string
1112
Verbose bool
1213
VeryVerbose bool
1314
Debug bool

flowpathmapper/flowpathmapper.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828

2929
var (
3030
regexpPhpFile = regexp.MustCompile(`(?://)?(/[^ ]*\.php)`)
31-
regexpFilename = regexp.MustCompile(`filename=["]?file://(\S+)/Data/Temporary/([^/]*(/SubContext[^/]*)?)/Cache/Code/Flow_Object_Classes/([^"]*)\.php`)
31+
regexpFilename = regexp.MustCompile(`filename=["]?file://(\S+)/Data/Temporary/.+?/Cache/Code/Flow_Object_Classes/([^"]*)\.php`)
3232
regexpPathAndFilename = regexp.MustCompile(`(?m)^# PathAndFilename: (.*)$`)
3333
regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/[^/]*/(.*?)/Classes/(.*).php`)
3434
regexpDot = regexp.MustCompile(`[\./]`)
@@ -92,15 +92,20 @@ func (p *PathMapper) doTextPathMapping(message []byte) []byte {
9292

9393
func (p *PathMapper) getCachePath(base, filename string) string {
9494
cachePath := strings.Replace(cachePathPattern, "@base@", base, 1)
95-
contextPath := strings.Replace(p.config.Context, "/", "/SubContext", 1)
96-
cachePath = strings.Replace(cachePath, "@context@", contextPath, 1)
95+
context := p.config.Context
96+
if strings.Contains(context, "/") {
97+
contextParts := strings.Split(context, "/")
98+
contextParts[1] = "SubContext" + contextParts[1]
99+
context = strings.Join(contextParts, "/")
100+
}
101+
cachePath = strings.Replace(cachePath, "@context@", context, 1)
97102
return strings.Replace(cachePath, "@filename@", filename, 1)
98103
}
99104

100105
func (p *PathMapper) doXMLPathMapping(b []byte) []byte {
101106
var processedMapping = map[string]string{}
102107
for _, match := range regexpFilename.FindAllStringSubmatch(string(b), -1) {
103-
path := p.getCachePath(match[1], match[4])
108+
path := p.getCachePath(match[1], match[2])
104109
if _, ok := processedMapping[path]; ok == false {
105110
if originalPath, exist := p.pathMapping.Get(path); exist {
106111
if p.config.VeryVerbose {
@@ -109,7 +114,7 @@ func (p *PathMapper) doXMLPathMapping(b []byte) []byte {
109114
processedMapping[path] = originalPath
110115
p.logger.Debug("doXMLPathMapping mapping exist %s >>> %s", path, originalPath)
111116
} else {
112-
originalPath = p.readOriginalPathFromCache(path)
117+
originalPath = p.readOriginalPathFromCache(path, match[1])
113118
processedMapping[path] = originalPath
114119
p.logger.Debug("doXMLPathMapping missing mapping %s >>> %s", path, originalPath)
115120
}
@@ -135,7 +140,11 @@ func (p *PathMapper) mapPath(originalPath string) string {
135140
p.logger.Debug("Path %s is a Flow Package file", originalPath)
136141
cachePath := p.getCachePath(p.buildClassNameFromPath(originalPath))
137142
realPath := p.getRealFilename(cachePath)
138-
if _, err := os.Stat(realPath); err == nil {
143+
var err error
144+
if len(p.config.LocalRoot) == 0 {
145+
_, err = os.Stat(realPath)
146+
}
147+
if err == nil {
139148
return p.setPathMapping(realPath, originalPath)
140149
}
141150
}
@@ -155,13 +164,20 @@ func (p *PathMapper) setPathMapping(path string, originalPath string) string {
155164
return path
156165
}
157166

158-
func (p *PathMapper) readOriginalPathFromCache(path string) string {
159-
dat, err := ioutil.ReadFile(path)
167+
func (p *PathMapper) readOriginalPathFromCache(path, basePath string) string {
168+
localPath := path
169+
if len(p.config.LocalRoot) > 0 {
170+
localPath = strings.Replace(path, basePath, p.config.LocalRoot, 1)
171+
}
172+
dat, err := ioutil.ReadFile(localPath)
160173
errorhandler.PanicHandling(err, p.logger)
161174
match := regexpPathAndFilename.FindStringSubmatch(string(dat))
162-
p.logger.Debug("readOriginalPathFromCache %s", path)
175+
p.logger.Debug("readOriginalPathFromCache %s", localPath)
163176
if len(match) == 2 {
164177
originalPath := match[1]
178+
if len(p.config.LocalRoot) > 0 {
179+
originalPath = strings.Replace(strings.Replace(originalPath, "\\", "/", -1), p.config.LocalRoot, basePath, 1)
180+
}
165181
if p.config.VeryVerbose {
166182
p.logger.Info("Umpa Lumpa need to work harder, need to reverse this one\n>>> %s\n>>> %s\n", p.logger.Colorize(fmt.Sprintf(h, path), "yellow"), p.logger.Colorize(fmt.Sprintf(h, originalPath), "green"))
167183
}

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"net"
2323
"os"
24+
"strings"
2425
)
2526

2627
func main() {
@@ -47,6 +48,11 @@ func main() {
4748
Value: "Development",
4849
Usage: "The context to run as",
4950
},
51+
cli.StringFlag{
52+
Name: "localroot, r",
53+
Value: "",
54+
Usage: "Local project root for remote debugging",
55+
},
5056
cli.StringFlag{
5157
Name: "framework",
5258
Value: "flow",
@@ -70,6 +76,7 @@ func main() {
7076
c := &config.Config{
7177
Context: cli.String("context"),
7278
Framework: cli.String("framework"),
79+
LocalRoot: strings.TrimRight(cli.String("localroot"), "/"),
7380
Verbose: cli.Bool("verbose") || cli.Bool("vv"),
7481
VeryVerbose: cli.Bool("vv"),
7582
Debug: cli.Bool("debug"),
@@ -81,6 +88,7 @@ func main() {
8188

8289
laddr, raddr, listener := setupNetworkConnection(cli.String("xdebug"), cli.String("ide"), log)
8390

91+
log.Info("special version [wy/ft]\n")
8492
log.Info("Debugger from %v\nIDE from %v\n", laddr, raddr)
8593

8694
pathMapping := &pathmapping.PathMapping{}

0 commit comments

Comments
 (0)