compileFrankenPHP compiles FrankenPHP with the generated extension
(moduleDir string)
| 144 | |
| 145 | // compileFrankenPHP compiles FrankenPHP with the generated extension |
| 146 | func (s *IntegrationTestSuite) compileFrankenPHP(moduleDir string) (string, error) { |
| 147 | s.t.Helper() |
| 148 | |
| 149 | projectRoot, err := filepath.Abs(filepath.Join("..", "..")) |
| 150 | if err != nil { |
| 151 | return "", fmt.Errorf("failed to get project root: %w", err) |
| 152 | } |
| 153 | |
| 154 | cflags, err := exec.Command(s.phpConfigPath, "--includes").Output() |
| 155 | if err != nil { |
| 156 | return "", fmt.Errorf("failed to get PHP includes: %w", err) |
| 157 | } |
| 158 | |
| 159 | ldflags, err := exec.Command(s.phpConfigPath, "--ldflags").Output() |
| 160 | if err != nil { |
| 161 | return "", fmt.Errorf("failed to get PHP ldflags: %w", err) |
| 162 | } |
| 163 | |
| 164 | libs, err := exec.Command(s.phpConfigPath, "--libs").Output() |
| 165 | if err != nil { |
| 166 | return "", fmt.Errorf("failed to get PHP libs: %w", err) |
| 167 | } |
| 168 | |
| 169 | cgoCflags := strings.TrimSpace(string(cflags)) |
| 170 | cgoLdflags := strings.TrimSpace(string(ldflags)) + " " + strings.TrimSpace(string(libs)) |
| 171 | |
| 172 | outputBinary := filepath.Join(s.tempDir, "frankenphp") |
| 173 | |
| 174 | cmd := exec.Command( |
| 175 | s.xcaddyPath, |
| 176 | "build", |
| 177 | "--output", outputBinary, |
| 178 | "--with", "github.com/dunglas/frankenphp="+projectRoot, |
| 179 | "--with", "github.com/dunglas/frankenphp/caddy="+projectRoot+"/caddy", |
| 180 | "--with", testModuleName+"="+moduleDir, |
| 181 | ) |
| 182 | |
| 183 | cmd.Env = append(os.Environ(), |
| 184 | "CGO_ENABLED=1", |
| 185 | "CGO_CFLAGS="+cgoCflags, |
| 186 | "CGO_LDFLAGS="+cgoLdflags, |
| 187 | fmt.Sprintf("XCADDY_GO_BUILD_FLAGS=-ldflags='-w -s' -tags=nobadger,nomysql,nopgx,nowatcher"), |
| 188 | ) |
| 189 | |
| 190 | cmd.Dir = s.tempDir |
| 191 | |
| 192 | output, err := cmd.CombinedOutput() |
| 193 | if err != nil { |
| 194 | return "", fmt.Errorf("xcaddy build failed: %w\nOutput: %s", err, string(output)) |
| 195 | } |
| 196 | |
| 197 | s.frankenphpPath = outputBinary |
| 198 | return outputBinary, nil |
| 199 | } |
| 200 | |
| 201 | func (s *IntegrationTestSuite) runPHPCode(phpCode string) (string, error) { |
| 202 | s.t.Helper() |
no outgoing calls
no test coverage detected