Skip to content

Commit

Permalink
Add more debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 6, 2024
1 parent 73c6d77 commit bd0da75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions local/php/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func Composer(dir string, args, env []string, stdout, stderr, logger io.Writer,
error: errors.Wrap(err, "unable to find composer, get it at https://getcomposer.org/download/"),
}
}
fmt.Fprintf(logger, " (running %s %s)\n\n", path, strings.TrimSpace(strings.Join(args, " ")))
}

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

func findComposer(extraBin string) (string, error) {
func findComposer(extraBin string, logger zerolog.Logger) (string, error) {
// Special support for OS specific things. They need to run before the
// PATH detection because most of them adds shell wrappers that we
// can't run via PHP.
if pharPath := findComposerSystemSpecific(); pharPath != "" {
return pharPath, nil
}
for _, file := range []string{extraBin, "composer", "composer.phar"} {
logger.Debug().Str("source", "Composer").Msgf(`Looking for Composer in the PATH as "%s"`, file)
if pharPath, _ := LookPath(file); pharPath != "" {
// On Windows, we don't want the .bat, but the real composer phar/PHP file
if strings.HasSuffix(pharPath, ".bat") {
pharPath = pharPath[:len(pharPath)-4] + ".phar"
}
logger.Debug().Str("source", "Composer").Msgf(`Found Composer as "%s"`, pharPath)
return pharPath, nil
}
}
Expand Down
4 changes: 3 additions & 1 deletion local/php/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,21 @@ func (e *Executor) findComposer(extraBin string) (string, error) {
if scriptDir, err := e.DetectScriptDir(); err == nil {
for _, file := range []string{extraBin, "composer.phar", "composer"} {
path := filepath.Join(scriptDir, file)
e.Logger.Debug().Str("source", "Composer").Msgf(`Looking for Composer under "%s"`, path)
d, err := os.Stat(path)
if err != nil {
continue
}
if m := d.Mode(); !m.IsDir() {
// Yep!
e.Logger.Debug().Str("source", "Composer").Msgf(`Found Composer as "%s"`, path)
return path, nil
}
}
}

// fallback to default composer detection
return findComposer(extraBin)
return findComposer(extraBin, e.Logger)
}

// Execute executes the right version of PHP depending on the configuration
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ package main

import (
"fmt"
"io"
"os"
"time"

"github.com/rs/zerolog"
"github.com/symfony-cli/console"
"github.com/symfony-cli/symfony-cli/commands"
"github.com/symfony-cli/symfony-cli/local/php"
Expand All @@ -52,6 +50,10 @@ func getCliExtraEnv() []string {
}

func main() {
if os.Getenv("SC_DEBUG") == "1" {
terminal.SetLogLevel(5)
}

args := os.Args
name := console.CurrentBinaryName()
// called via "php"?
Expand Down Expand Up @@ -84,7 +86,7 @@ func main() {
}
// called via "symfony composer"?
if len(args) >= 2 && args[1] == "composer" {
res := php.Composer("", args[2:], getCliExtraEnv(), os.Stdout, os.Stderr, io.Discard, zerolog.Nop())
res := php.Composer("", args[2:], getCliExtraEnv(), os.Stdout, os.Stderr, os.Stderr, terminal.Logger)
terminal.Eprintln(res.Error())
os.Exit(res.ExitCode())
}
Expand Down

0 comments on commit bd0da75

Please sign in to comment.