8000 Merge pull request #486 from symfony-cli/composer-tweaks · symfony-cli/symfony-cli@b5d89ad · GitHub
[go: up one dir, main page]

Skip to content

Commit b5d89ad

Browse files
authored
Merge pull request #486 from symfony-cli/composer-tweaks
Add more debug logs
2 parents 73c6d77 + bd0da75 commit b5d89ad

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

local/php/composer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ func Composer(dir string, args, env []string, stdout, stderr, logger io.Writer,
8484
error: errors.Wrap(err, "unable to find composer, get it at https://getcomposer.org/download/"),
8585
}
8686
}
87+
fmt.Fprintf(logger, " (running %s %s)\n\n", path, strings.TrimSpace(strings.Join(args, " ")))
8788
}
8889

8990
e.Args = append([]string{"php", path}, args...)
90-
fmt.Fprintf(logger, " (running %s %s)\n\n", path, strings.TrimSpace(strings.Join(args, " ")))
9191
ret := e.Execute(false)
9292
if ret != 0 {
9393
return ComposerResult{
@@ -135,19 +135,21 @@ func composerVersion() int {
135135
return DefaultComposerVersion
136136
}
137137

138-
func findComposer(extraBin string) (string, error) {
138+
func findComposer(extraBin string, logger zerolog.Logger) (string, error) {
139139
// Special support for OS specific things. They need to run before the
140140
// PATH detection because most of them adds shell wrappers that we
141141
// can't run via PHP.
142142
if pharPath := findComposerSystemSpecific(); pharPath != "" {
143143
return pharPath, nil
144144
}
145145
for _, file := range []string{extraBin, "composer", "composer.phar"} {
146+
logger.Debug().Str("source", "Composer").Msgf(`Looking for Composer in the PATH as "%s"`, file)
146147
if pharPath, _ := LookPath(file); pharPath != "" {
147148
// On Windows, we don't want the .bat, but the real composer phar/PHP file
148149
if strings.HasSuffix(pharPath, ".bat") {
149150
pharPath = pharPath[:len(pharPath)-4] + ".phar"
150151
}
152+
logger.Debug().Str("source", "Composer").Msgf(`Found Composer as "%s"`, pharPath)
151153
return pharPath, nil
152154
}
153155
}

local/php/executor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,21 @@ func (e *Executor) findComposer(extraBin string) (string, error) {
289289
if scriptDir, err := e.DetectScriptDir(); err == nil {
290290
for _, file := range []string{extraBin, "composer.phar", "composer"} {
291291
path := filepath.Join(scriptDir, file)
292+
e.Logger.Debug().Str("source", "Composer").Msgf(`Looking for Composer under "%s"`, path)
292293
d, err := os.Stat(path)
293294
if err != nil {
294295
continue
295296
}
296297
if m := d.Mode(); !m.IsDir() {
297298
// Yep!
299+
e.Logger.Debug().Str("source", "Composer").Msgf(`Found Composer as "%s"`, path)
298300
return path, nil
299301
}
300302
}
301303
}
302304

303305
// fallback to default composer detection
304-
return findComposer(extraBin)
306+
return findComposer(extraBin, e.Logger)
305307
}
306308

307309
// Execute executes the right version of PHP depending on the configuration

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ package main
2323

2424
import (
2525
"fmt"
26-
"io"
2726
"os"
2827
"time"
2928

30-
"github.com/rs/zerolog"
3129
"github.com/symfony-cli/console"
3230
"github.com/symfony-cli/symfony-cli/commands"
3331
"github.com/symfony-cli/symfony-cli/local/php"
@@ -52,6 +50,10 @@ func getCliExtraEnv() []string {
5250
}
5351

5452
func main() {
53+
if os.Getenv("SC_DEBUG") == "1" {
54+
terminal.SetLogLevel(5)
55+
}
56+
5557
args := os.Args
5658
name := console.CurrentBinaryName()
5759
// called via "php"?
@@ -84,7 +86,7 @@ func main() {
8486
}
8587
// called via "symfony composer"?
8688
if len(args) >= 2 && args[1] == "composer" {
87-
res := php.Composer("", args[2:], getCliExtraEnv(), os.Stdout, os.Stderr, io.Discard, zerolog.Nop())
89+
res := php.Composer("", args[2:], getCliExtraEnv(), os.Stdout, os.Stderr, os.Stderr, terminal.Logger)
8890
terminal.Eprintln(res.Error())
8991
os.Exit(res.ExitCode())
9092
}

0 commit comments

Comments
 (0)
0