diff --git a/src/StaticPHP/Package/PackageInstaller.php b/src/StaticPHP/Package/PackageInstaller.php index 34e24621..c6aa3421 100644 --- a/src/StaticPHP/Package/PackageInstaller.php +++ b/src/StaticPHP/Package/PackageInstaller.php @@ -108,8 +108,10 @@ class PackageInstaller */ public function run(bool $interactive = true, bool $disable_delay_msg = false): void { - // resolve input, make dependency graph - $this->resolvePackages(); + if (empty($this->packages)) { + // resolve input, make dependency graph + $this->resolvePackages(); + } if ($interactive && !$disable_delay_msg) { // show install or build options in terminal with beautiful output @@ -148,7 +150,10 @@ class PackageInstaller } $builder = ApplicationContext::get(PackageBuilder::class); 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) { InteractiveTerm::indicateProgress('Building package: ' . ConsoleColor::yellow($package->getName())); } @@ -213,6 +218,31 @@ class PackageInstaller 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. * diff --git a/src/StaticPHP/Util/SPCConfigUtil.php b/src/StaticPHP/Util/SPCConfigUtil.php index 317258d0..c525f8c7 100644 --- a/src/StaticPHP/Util/SPCConfigUtil.php +++ b/src/StaticPHP/Util/SPCConfigUtil.php @@ -225,11 +225,15 @@ class SPCConfigUtil // convert all static-libs to short names $libs = array_reverse(PackageConfig::get($package, 'static-libs', [])); foreach ($libs as $lib) { - // check file existence - 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."); + if (FileSystem::isRelativePath($lib)) { + // check file existence + 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 if (SystemTarget::getTargetOS() === 'Darwin') {