Skip to content

Commit abd6c2f

Browse files
committed
Add PackageInstaller::isPackageInstalled() API
1 parent df6c27c commit abd6c2f

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/StaticPHP/Package/PackageInstaller.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function setDownload(bool $download = true): static
108108
*/
109109
public function run(bool $interactive = true, bool $disable_delay_msg = false): void
110110
{
111-
// resolve input, make dependency graph
112-
$this->resolvePackages();
111+
if (empty($this->packages)) {
112+
// resolve input, make dependency graph
113+
$this->resolvePackages();
114+
}
113115

114116
if ($interactive && !$disable_delay_msg) {
115117
// show install or build options in terminal with beautiful output
@@ -148,7 +150,10 @@ public function run(bool $interactive = true, bool $disable_delay_msg = false):
148150
}
149151
$builder = ApplicationContext::get(PackageBuilder::class);
150152
foreach ($this->packages as $package) {
151-
if ($this->isBuildPackage($package) || $package instanceof LibraryPackage && $package->hasStage('build')) {
153+
if (
154+
$this->isBuildPackage($package) ||
155+
$package instanceof LibraryPackage && $package->hasStage('build') && !$package->getArtifact()->shouldUseBinary()
156+
) {
152157
if ($interactive) {
153158
InteractiveTerm::indicateProgress('Building package: ' . ConsoleColor::yellow($package->getName()));
154159
}
@@ -213,6 +218,31 @@ public function isPackageResolved(string $package_name): bool
213218
return isset($this->packages[$package_name]);
214219
}
215220

221+
public function isPackageInstalled(Package|string $package_name): bool
222+
{
223+
if (empty($this->packages)) {
224+
$this->resolvePackages();
225+
}
226+
if (is_string($package_name)) {
227+
$package = $this->getPackage($package_name);
228+
if ($package === null) {
229+
throw new WrongUsageException("Package '{$package_name}' is not resolved.");
230+
}
231+
} else {
232+
$package = $package_name;
233+
}
234+
235+
// check if package is built/installed
236+
if ($this->isBuildPackage($package)) {
237+
return $package->isInstalled();
238+
}
239+
if ($package instanceof LibraryPackage && $package->getArtifact()->shouldUseBinary()) {
240+
$artifact = $package->getArtifact();
241+
return $artifact->isBinaryExtracted();
242+
}
243+
return false;
244+
}
245+
216246
/**
217247
* Returns the download status of all artifacts for the resolved packages.
218248
*

src/StaticPHP/Util/SPCConfigUtil.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,15 @@ private function getLibsString(array $packages, bool $use_short_libs = true): st
225225
// convert all static-libs to short names
226226
$libs = array_reverse(PackageConfig::get($package, 'static-libs', []));
227227
foreach ($libs as $lib) {
228-
// check file existence
229-
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
230-
throw new WrongUsageException("Library file '{$lib}' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
228+
if (FileSystem::isRelativePath($lib)) {
229+
// check file existence
230+
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
231+
throw new WrongUsageException("Library file '{$lib}' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
232+
}
233+
$lib_names[] = $this->getShortLibName($lib);
234+
} else {
235+
$lib_names[] = $lib;
231236
}
232-
$lib_names[] = $this->getShortLibName($lib);
233237
}
234238
// add frameworks for macOS
235239
if (SystemTarget::getTargetOS() === 'Darwin') {

0 commit comments

Comments
 (0)