VOOZH about

URL: https://deepwiki.com/rudderlabs/rudder-php-sdk/6.1-build-system-and-makefile

⇱ Build System and Makefile | rudderlabs/rudder-php-sdk | DeepWiki


Loading...
Menu

Build System and Makefile

The RudderStack PHP SDK utilizes a standard Makefile to orchestrate its build, test, and release lifecycles. This system manages Composer-based dependencies, enforces coding standards through linting, executes the PHPUnit test suite, and automates version synchronization across the codebase.

Dependency Lifecycle and Composer Integration

The SDK manages its dependencies via Composer. The build system is designed to be self-contained, downloading composer.phar locally if it is not already present in the environment.

Dependency Flow

The following diagram illustrates how the Makefile interacts with the filesystem and Composer to establish the development environment.

Build System Dependency Flow


Implementation Details:

  • Composer Download: The composer.phar target uses curl to fetch the installer from the official source Makefile12-13
  • Vendor Installation: The vendor target executes the installation and explicitly ensures that development tools like phplint and php_codesniffer are present Makefile6-11
  • Autoloading: The SDK uses PSR-4 autoloading, mapping the Rudder\ namespace to the lib/ directory and Rudder\Test\ to the test/ directory composer.json39-44

Sources:


Makefile Target Reference

The Makefile defines several high-level targets for development, testing, and CI/CD integration.

TargetDescriptionImplementation
bootstrapSets up the local environment (macOS/Homebrew focus).Executes scripts/bootstrap.sh Makefile1-2
dependenciesEnsures vendor/ is populated.Depends on the vendor target Makefile4
testsRuns the full PHPUnit suite with coverage.Generates Clover XML and JUnit logs in build/logs/ Makefile15-19
lintRuns local code style checks.Executes phplint and phpcs Makefile20-23
lint-ciRuns linting with machine-readable output.Generates JUnit and Checkstyle reports for CI pipelines Makefile24-28
releaseSynchronizes version numbers.Updates lib/Version.php and composer.json Makefile29-33
exampleRuns the main demonstration app.Executes php -f examples/App.php Makefile34-35
smoke-testRuns a basic sanity integration test.Executes php -f examples/sanity-test/Sanity.php Makefile37-38
cleanResets the repository state.Removes composer.phar, vendor/, composer.lock, and build/ Makefile40-45

Environment Bootstrapping

The bootstrap target is primarily intended for macOS users. It checks for Homebrew, installs PHP if missing, and installs the pcov extension via PECL to enable high-performance code coverage scripts/bootstrap.sh1-21

Sources:


Release Tagging Mechanism

The release target is a critical utility for maintainers to ensure version consistency across different metadata files. It requires a VERSION environment variable (e.g., VERSION=2.1.0 make release).

Release Data Flow


Logic Breakdown:

  1. PHP Version File: The target uses printf to overwrite ./lib/Version.php, declaring a global variable $RUDDER_VERSION containing the new version string Makefile31
  2. Composer Metadata: It uses a node one-liner to parse composer.json, update the version key, and write the formatted JSON back to disk Makefile32 This ensures that when the package is published to Packagist, the metadata matches the internal SDK version.

Sources:


Linting and Quality Enforcement

The SDK enforces PSR-12 coding standards and performs syntax linting to ensure compatibility across supported PHP versions (7.4 and 8.0+).

  • Syntax Linting: Managed by overtrue/phplint. It is configured via .phplint.yml to exclude the vendor directory and process 10 jobs in parallel Makefile21 .phplint.yml1-7
  • Code Style: Managed by squizlabs/php_codesniffer (phpcs). The lint-ci target specifically formats these results into checkstyle format for integration with CI tools like SonarCloud Makefile27
  • Validation: The tests target also executes composer validate to ensure the composer.json file remains valid and follows schema requirements Makefile18

Sources: