Add option to force package build from source

This commit is contained in:
netkas 2024-09-20 17:04:30 -04:00
parent be70823a79
commit dda710119c
4 changed files with 54 additions and 26 deletions

View file

@ -168,6 +168,11 @@
$options[InstallPackageOptions::SKIP_DEPENDENCIES->value] = true; $options[InstallPackageOptions::SKIP_DEPENDENCIES->value] = true;
} }
if(isset($args['build-source']))
{
$options[InstallPackageOptions::BUILD_SOURCE->value] = true;
}
if($authentication !== null) if($authentication !== null)
{ {
$entry = (new CredentialManager())->getVault()?->getEntry($authentication); $entry = (new CredentialManager())->getVault()?->getEntry($authentication);
@ -560,6 +565,7 @@
new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified ncc package but skips the installation of dependencies'), new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified ncc package but skips the installation of dependencies'),
new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified ncc package, reinstall if already installed'), new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified ncc package, reinstall if already installed'),
new CliHelpSection(['install', '--prefer-static', '--static'], 'Installs a static version of the package from the remote repository if available'), new CliHelpSection(['install', '--prefer-static', '--static'], 'Installs a static version of the package from the remote repository if available'),
new CliHelpSection(['install', '--build-source'], 'Forces ncc to build the packages from source rather than trying to use a pre-built binary'),
new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified ncc package'), new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified ncc package'),
new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified ncc package version'), new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified ncc package version'),
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'), new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),

View file

@ -30,7 +30,7 @@
* @warning This will cause the package to fail to import of * @warning This will cause the package to fail to import of
* the dependencies are not met * the dependencies are not met
*/ */
case SKIP_DEPENDENCIES = 'skip_dependencies'; case SKIP_DEPENDENCIES = 'skip-dependencies';
/** /**
* Reinstall all packages if they are already installed, * Reinstall all packages if they are already installed,
@ -42,5 +42,11 @@
* Installs a static version of the package if it's available * Installs a static version of the package if it's available
* otherwise it will install non-static version * otherwise it will install non-static version
*/ */
case PREFER_STATIC = 'prefer_static'; case PREFER_STATIC = 'prefer-static';
/**
* Forces ncc to build packages from source rather than trying to obtain
* a pre-built version of the package
*/
case BUILD_SOURCE = 'build-source';
} }

View file

@ -521,7 +521,7 @@
)); ));
/** @noinspection SlowArrayOperationsInLoopInspection */ /** @noinspection SlowArrayOperationsInLoopInspection */
$installed_packages = array_merge($installed_packages, $this->install($dependency->getSource(), $authentication)); $installed_packages = array_merge($installed_packages, $this->install($dependency->getSource(), $authentication, $options));
} }
} }
@ -550,6 +550,15 @@
Console::out(sprintf('Fetching package %s/%s=%s from %s', $input->getVendor(), $input->getPackage(), $input->getVersion(), $input->getRepository())); Console::out(sprintf('Fetching package %s/%s=%s from %s', $input->getVendor(), $input->getPackage(), $input->getVersion(), $input->getRepository()));
if(isset($options[InstallPackageOptions::BUILD_SOURCE->value]))
{
Console::outVerbose(sprintf(
'Forcing ncc to build package %s/%s=%s from source',
$input->getVendor(), $input->getPackage(), $input->getVersion()
));
}
else
{
try try
{ {
Console::outVerbose(sprintf( Console::outVerbose(sprintf(
@ -580,6 +589,7 @@
// This is a warning because we can still attempt to build from source // This is a warning because we can still attempt to build from source
unset($results, $package_path); unset($results, $package_path);
} }
}
if(!isset($package_path)) if(!isset($package_path))
{ {
@ -848,7 +858,7 @@
} }
default: default:
throw new NotSupportedException(sprintf('Cannot build from source %s, the project type %s is not supported', $archive, $project_detection->getProjectType())); throw new NotSupportedException(sprintf('Cannot build from source %s, the project type %s is not supported', $archive, $project_detection->getProjectType()->value));
} }
} }

View file

@ -96,6 +96,12 @@
$path = substr($path, 0, -1); $path = substr($path, 0, -1);
} }
if(is_file($path))
{
// We can assume the user is trying to load a project file
$path = dirname($path);
}
// Detect if the folder exists or not // Detect if the folder exists or not
if(!is_dir($path)) if(!is_dir($path))
{ {