mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Add PackageInstaller::isPackageInstalled() API
This commit is contained in:
parent
df6c27c98d
commit
abd6c2fa3a
@ -108,8 +108,10 @@ class PackageInstaller
|
|||||||
*/
|
*/
|
||||||
public function run(bool $interactive = true, bool $disable_delay_msg = false): void
|
public function run(bool $interactive = true, bool $disable_delay_msg = false): void
|
||||||
{
|
{
|
||||||
// resolve input, make dependency graph
|
if (empty($this->packages)) {
|
||||||
$this->resolvePackages();
|
// resolve input, make dependency graph
|
||||||
|
$this->resolvePackages();
|
||||||
|
}
|
||||||
|
|
||||||
if ($interactive && !$disable_delay_msg) {
|
if ($interactive && !$disable_delay_msg) {
|
||||||
// show install or build options in terminal with beautiful output
|
// show install or build options in terminal with beautiful output
|
||||||
@ -148,7 +150,10 @@ class PackageInstaller
|
|||||||
}
|
}
|
||||||
$builder = ApplicationContext::get(PackageBuilder::class);
|
$builder = ApplicationContext::get(PackageBuilder::class);
|
||||||
foreach ($this->packages as $package) {
|
foreach ($this->packages as $package) {
|
||||||
if ($this->isBuildPackage($package) || $package instanceof LibraryPackage && $package->hasStage('build')) {
|
if (
|
||||||
|
$this->isBuildPackage($package) ||
|
||||||
|
$package instanceof LibraryPackage && $package->hasStage('build') && !$package->getArtifact()->shouldUseBinary()
|
||||||
|
) {
|
||||||
if ($interactive) {
|
if ($interactive) {
|
||||||
InteractiveTerm::indicateProgress('Building package: ' . ConsoleColor::yellow($package->getName()));
|
InteractiveTerm::indicateProgress('Building package: ' . ConsoleColor::yellow($package->getName()));
|
||||||
}
|
}
|
||||||
@ -213,6 +218,31 @@ class PackageInstaller
|
|||||||
return isset($this->packages[$package_name]);
|
return isset($this->packages[$package_name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isPackageInstalled(Package|string $package_name): bool
|
||||||
|
{
|
||||||
|
if (empty($this->packages)) {
|
||||||
|
$this->resolvePackages();
|
||||||
|
}
|
||||||
|
if (is_string($package_name)) {
|
||||||
|
$package = $this->getPackage($package_name);
|
||||||
|
if ($package === null) {
|
||||||
|
throw new WrongUsageException("Package '{$package_name}' is not resolved.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$package = $package_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if package is built/installed
|
||||||
|
if ($this->isBuildPackage($package)) {
|
||||||
|
return $package->isInstalled();
|
||||||
|
}
|
||||||
|
if ($package instanceof LibraryPackage && $package->getArtifact()->shouldUseBinary()) {
|
||||||
|
$artifact = $package->getArtifact();
|
||||||
|
return $artifact->isBinaryExtracted();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the download status of all artifacts for the resolved packages.
|
* Returns the download status of all artifacts for the resolved packages.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -225,11 +225,15 @@ class SPCConfigUtil
|
|||||||
// convert all static-libs to short names
|
// convert all static-libs to short names
|
||||||
$libs = array_reverse(PackageConfig::get($package, 'static-libs', []));
|
$libs = array_reverse(PackageConfig::get($package, 'static-libs', []));
|
||||||
foreach ($libs as $lib) {
|
foreach ($libs as $lib) {
|
||||||
// check file existence
|
if (FileSystem::isRelativePath($lib)) {
|
||||||
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
|
// check file existence
|
||||||
throw new WrongUsageException("Library file '{$lib}' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
|
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
|
||||||
|
throw new WrongUsageException("Library file '{$lib}' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
|
||||||
|
}
|
||||||
|
$lib_names[] = $this->getShortLibName($lib);
|
||||||
|
} else {
|
||||||
|
$lib_names[] = $lib;
|
||||||
}
|
}
|
||||||
$lib_names[] = $this->getShortLibName($lib);
|
|
||||||
}
|
}
|
||||||
// add frameworks for macOS
|
// add frameworks for macOS
|
||||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user