Add getSourceRoot for artifacts

This commit is contained in:
crazywhalecc 2026-02-03 10:59:16 +08:00
parent 6688819605
commit a2409d9c0f
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
5 changed files with 33 additions and 7 deletions

View File

@ -436,7 +436,7 @@ trait unix
*/ */
private function makeVars(PackageInstaller $installer): array private function makeVars(PackageInstaller $installer): array
{ {
$config = (new SPCConfigUtil(['libs_only_deps' => true]))->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages())); $config = new SPCConfigUtil(['libs_only_deps' => true])->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages()));
$static = ApplicationContext::get(ToolchainInterface::class)->isStatic() ? '-all-static' : ''; $static = ApplicationContext::get(ToolchainInterface::class)->isStatic() ? '-all-static' : '';
$pie = SystemTarget::getTargetOS() === 'Linux' ? '-pie' : ''; $pie = SystemTarget::getTargetOS() === 'Linux' ? '-pie' : '';

View File

@ -268,6 +268,19 @@ class Artifact
return FileSystem::convertPath(SOURCE_PATH . '/' . $path); return FileSystem::convertPath(SOURCE_PATH . '/' . $path);
} }
/**
* Get source build root directory.
* It's only worked when 'source-root' is defined in artifact config.
* Normally it's equal to source dir.
*/
public function getSourceRoot(): string
{
if (isset($this->config['metadata']['source-root'])) {
return $this->getSourceDir() . '/' . ltrim($this->config['metadata']['source-root'], '/');
}
return $this->getSourceDir();
}
/** /**
* Get binary extraction directory and mode. * Get binary extraction directory and mode.
* *

View File

@ -212,6 +212,19 @@ abstract class Package
throw new SPCInternalException("Source directory for package {$this->name} is not available because the source artifact is missing."); throw new SPCInternalException("Source directory for package {$this->name} is not available because the source artifact is missing.");
} }
/**
* Get source build root directory.
* It's only worked when 'source-root' is defined in artifact config.
* Normally it's equal to source dir.
*/
public function getSourceRoot(): string
{
if (($artifact = $this->getArtifact()) && $artifact->hasSource()) {
return $artifact->getSourceRoot();
}
throw new SPCInternalException("Source root for package {$this->name} is not available because the source artifact is missing.");
}
/** /**
* Check if the package has a binary available for current OS and architecture. * Check if the package has a binary available for current OS and architecture.
*/ */

View File

@ -169,7 +169,7 @@ class UnixAutoconfExecutor extends Executor
*/ */
private function initShell(): void private function initShell(): void
{ {
$this->shell = shell()->cd($this->package->getSourceDir())->initializeEnv($this->package)->appendEnv([ $this->shell = shell()->cd($this->package->getSourceRoot())->initializeEnv($this->package)->appendEnv([
'CFLAGS' => "-I{$this->package->getIncludeDir()}", 'CFLAGS' => "-I{$this->package->getIncludeDir()}",
'CXXFLAGS' => "-I{$this->package->getIncludeDir()}", 'CXXFLAGS' => "-I{$this->package->getIncludeDir()}",
'LDFLAGS' => "-L{$this->package->getLibDir()}", 'LDFLAGS' => "-L{$this->package->getLibDir()}",
@ -185,12 +185,12 @@ class UnixAutoconfExecutor extends Executor
$callable(); $callable();
return $this; return $this;
} catch (SPCException $e) { } catch (SPCException $e) {
if (file_exists("{$this->package->getSourceDir()}/config.log")) { if (file_exists("{$this->package->getSourceRoot()}/config.log")) {
logger()->debug("Config log file found: {$this->package->getSourceDir()}/config.log"); logger()->debug("Config log file found: {$this->package->getSourceRoot()}/config.log");
$log_file = "lib.{$this->package->getName()}.console.log"; $log_file = "lib.{$this->package->getName()}.console.log";
logger()->debug('Saved config log file to: ' . SPC_LOGS_DIR . "/{$log_file}"); logger()->debug('Saved config log file to: ' . SPC_LOGS_DIR . "/{$log_file}");
$e->addExtraLogFile("{$this->package->getName()} library config.log", $log_file); $e->addExtraLogFile("{$this->package->getName()} library config.log", $log_file);
copy("{$this->package->getSourceDir()}/config.log", SPC_LOGS_DIR . "/{$log_file}"); copy("{$this->package->getSourceRoot()}/config.log", SPC_LOGS_DIR . "/{$log_file}");
} }
throw $e; throw $e;
} }

View File

@ -233,7 +233,7 @@ class UnixCMakeExecutor extends Executor
private function initBuildDir(): void private function initBuildDir(): void
{ {
if ($this->build_dir === null) { if ($this->build_dir === null) {
$this->build_dir = "{$this->package->getSourceDir()}/build"; $this->build_dir = "{$this->package->getSourceRoot()}/build";
} }
} }
@ -295,7 +295,7 @@ CMAKE;
*/ */
private function initShell(): void private function initShell(): void
{ {
$this->shell = shell()->cd($this->package->getSourceDir())->initializeEnv($this->package)->appendEnv([ $this->shell = shell()->cd($this->package->getSourceRoot())->initializeEnv($this->package)->appendEnv([
'CFLAGS' => "-I{$this->package->getIncludeDir()}", 'CFLAGS' => "-I{$this->package->getIncludeDir()}",
'CXXFLAGS' => "-I{$this->package->getIncludeDir()}", 'CXXFLAGS' => "-I{$this->package->getIncludeDir()}",
'LDFLAGS' => "-L{$this->package->getLibDir()}", 'LDFLAGS' => "-L{$this->package->getLibDir()}",