Add license installer for build mode

This commit is contained in:
crazywhalecc
2024-07-08 12:55:41 +08:00
committed by Jerry Ma
parent 386e9adf44
commit eec8ee03bf
2 changed files with 35 additions and 6 deletions

View File

@@ -217,6 +217,7 @@ abstract class LibraryBase
}
$this->getBuilder()->emitPatchPoint('before-library[ ' . static::NAME . ']-build');
$this->build();
$this->installLicense();
$this->getBuilder()->emitPatchPoint('after-library[ ' . static::NAME . ']-build');
return LIB_STATUS_OK;
}
@@ -311,4 +312,26 @@ abstract class LibraryBase
{
return str_replace('-', '_', static::NAME);
}
/**
* Install license files in buildroot directory
*/
protected function installLicense(): void
{
FileSystem::createDir(BUILD_ROOT_PATH . '/source-licenses/' . $this->getName());
$source = Config::getLib($this->getName(), 'source');
$license_files = Config::getSource($source)['license'] ?? [];
if (is_assoc_array($license_files)) {
$license_files = [$license_files];
}
foreach ($license_files as $index => $license) {
if ($license['type'] === 'text') {
FileSystem::writeFile(BUILD_ROOT_PATH . '/source-licenses/' . $this->getName() . "/{$index}.txt", $license['text']);
continue;
}
if ($license['type'] === 'file') {
copy($this->source_dir . '/' . $license['path'], BUILD_ROOT_PATH . '/source-licenses/' . $this->getName() . "/{$index}.txt");
}
}
}
}