diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb3b88..666a359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ This update introduces minor bug fixes & improvements - Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the output path of a specific build configuration +### Changed + - Refactor phpmake template to support dynamic build targets + ### Fixed - ncc will now correctly handle package execution where the main unit is not defined in the package instead of throwing an exception. diff --git a/src/ncc/Classes/PhpExtension/Templates/Makefile.tpl b/src/ncc/Classes/PhpExtension/Templates/Makefile.tpl index e7d3a5c..583d192 100644 --- a/src/ncc/Classes/PhpExtension/Templates/Makefile.tpl +++ b/src/ncc/Classes/PhpExtension/Templates/Makefile.tpl @@ -1,23 +1,21 @@ # Variables -CONFIG ?= release +DEFAULT_CONFIGURATION ?= %TPL_DEFAULT_BUILD_CONFIGURATION% LOG_LEVEL = debug -OUTDIR = build/$(CONFIG) -PACKAGE = $(OUTDIR)/%ASSEMBLY.PACKAGE%.ncc # Default Target -all: build +all: %TPL_BUILD_NAMES% # Build Steps -build: - ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL) +%TPL_BUILDS% -install: build - ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL) +install: %TPL_DEFAULT_BUILD_CONFIGURATION% + ncc package install --package=%TPL_DEFAULT_BUILD_PATH% --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL) -test: build +test: %TPL_DEFAULT_BUILD_CONFIGURATION% + [ -f phpunit.xml ] || { echo "phpunit.xml not found"; exit 1; } phpunit clean: rm -rf build -.PHONY: all build install test clean \ No newline at end of file +.PHONY: all install test clean %TPL_BUILD_NAMES% \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php b/src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php index 5723fed..ed58a62 100644 --- a/src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php +++ b/src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php @@ -42,20 +42,37 @@ class MakefileTemplate } /** - * Writes the Makefile to the project directory + * Writes the Makefile template for the given project. * - * @param ProjectManager $project_manager - * @return void - * @throws IOException - * @throws PathNotFoundException + * @param ProjectManager $project_manager The project manager containing project configurations. + * @throws IOException If there is an error reading or writing files. + * @throws PathNotFoundException If a required file path is not found. */ private static function writeMakefileTemplate(ProjectManager $project_manager): void { + $makefile_template = IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'Makefile.tpl'); + $builds = []; + + foreach($project_manager->getProjectConfiguration()->getBuild()->getBuildConfigurations() as $build_name) + { + $builds[$build_name] = str_replace('%TPL_BUILD_NAME%', $build_name, IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'make_build.tpl')); + } + + $default_build = $project_manager->getProjectConfiguration()->getBuild()->getDefaultConfiguration(); + $makefile_template = str_replace('%TPL_DEFAULT_BUILD_CONFIGURATION%', $default_build, $makefile_template); + $makefile_template = str_replace('%TPL_DEFAULT_BUILD_PATH%', $project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($default_build)->getOutput(), $makefile_template); + $makefile_template = str_replace('%TPL_BUILD_NAMES%', implode(' ', array_keys($builds)), $makefile_template); + + $build_template = ''; + foreach($builds as $name => $template) + { + $build_template .= $template . PHP_EOL; + } + + $makefile_template = str_replace('%TPL_BUILDS%', $build_template, $makefile_template); IO::fwrite( $project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'Makefile', - ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(), - IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'Makefile.tpl') - ) + ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(), $makefile_template) ); } } \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/Templates/make_build.tpl b/src/ncc/Classes/PhpExtension/Templates/make_build.tpl new file mode 100644 index 0000000..9080587 --- /dev/null +++ b/src/ncc/Classes/PhpExtension/Templates/make_build.tpl @@ -0,0 +1,2 @@ +%TPL_BUILD_NAME%: + ncc build --config=%TPL_BUILD_NAME% --log-level $(LOG_LEVEL) \ No newline at end of file