Refactor phpmake template to support dynamic build targets
This commit is contained in:
parent
c40c7ce8fe
commit
77c668f7b6
4 changed files with 38 additions and 18 deletions
|
@ -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
|
- 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
|
output path of a specific build configuration
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Refactor phpmake template to support dynamic build targets
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- ncc will now correctly handle package execution where the main unit is not defined in the package instead of
|
- ncc will now correctly handle package execution where the main unit is not defined in the package instead of
|
||||||
throwing an exception.
|
throwing an exception.
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
# Variables
|
# Variables
|
||||||
CONFIG ?= release
|
DEFAULT_CONFIGURATION ?= %TPL_DEFAULT_BUILD_CONFIGURATION%
|
||||||
LOG_LEVEL = debug
|
LOG_LEVEL = debug
|
||||||
OUTDIR = build/$(CONFIG)
|
|
||||||
PACKAGE = $(OUTDIR)/%ASSEMBLY.PACKAGE%.ncc
|
|
||||||
|
|
||||||
# Default Target
|
# Default Target
|
||||||
all: build
|
all: %TPL_BUILD_NAMES%
|
||||||
|
|
||||||
# Build Steps
|
# Build Steps
|
||||||
build:
|
%TPL_BUILDS%
|
||||||
ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL)
|
|
||||||
|
|
||||||
install: build
|
install: %TPL_DEFAULT_BUILD_CONFIGURATION%
|
||||||
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
|
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
|
phpunit
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
.PHONY: all build install test clean
|
.PHONY: all install test clean %TPL_BUILD_NAMES%
|
|
@ -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
|
* @param ProjectManager $project_manager The project manager containing project configurations.
|
||||||
* @return void
|
* @throws IOException If there is an error reading or writing files.
|
||||||
* @throws IOException
|
* @throws PathNotFoundException If a required file path is not found.
|
||||||
* @throws PathNotFoundException
|
|
||||||
*/
|
*/
|
||||||
private static function writeMakefileTemplate(ProjectManager $project_manager): void
|
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(
|
IO::fwrite(
|
||||||
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'Makefile',
|
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'Makefile',
|
||||||
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
|
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(), $makefile_template)
|
||||||
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'Makefile.tpl')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
2
src/ncc/Classes/PhpExtension/Templates/make_build.tpl
Normal file
2
src/ncc/Classes/PhpExtension/Templates/make_build.tpl
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
%TPL_BUILD_NAME%:
|
||||||
|
ncc build --config=%TPL_BUILD_NAME% --log-level $(LOG_LEVEL)
|
Loading…
Add table
Reference in a new issue