Add option to force package build from source
This commit is contained in:
parent
be70823a79
commit
dda710119c
4 changed files with 54 additions and 26 deletions
|
@ -168,6 +168,11 @@
|
|||
$options[InstallPackageOptions::SKIP_DEPENDENCIES->value] = true;
|
||||
}
|
||||
|
||||
if(isset($args['build-source']))
|
||||
{
|
||||
$options[InstallPackageOptions::BUILD_SOURCE->value] = true;
|
||||
}
|
||||
|
||||
if($authentication !== null)
|
||||
{
|
||||
$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', '--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', '--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', '--version', '-v'], 'Uninstalls a specified ncc package version'),
|
||||
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* @warning This will cause the package to fail to import of
|
||||
* the dependencies are not met
|
||||
*/
|
||||
case SKIP_DEPENDENCIES = 'skip_dependencies';
|
||||
case SKIP_DEPENDENCIES = 'skip-dependencies';
|
||||
|
||||
/**
|
||||
* Reinstall all packages if they are already installed,
|
||||
|
@ -42,5 +42,11 @@
|
|||
* Installs a static version of the package if it's available
|
||||
* 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';
|
||||
}
|
|
@ -521,7 +521,7 @@
|
|||
));
|
||||
|
||||
/** @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,35 +550,45 @@
|
|||
|
||||
Console::out(sprintf('Fetching package %s/%s=%s from %s', $input->getVendor(), $input->getPackage(), $input->getVersion(), $input->getRepository()));
|
||||
|
||||
try
|
||||
if(isset($options[InstallPackageOptions::BUILD_SOURCE->value]))
|
||||
{
|
||||
Console::outVerbose(sprintf(
|
||||
'Attempting to fetch a pre-built ncc package for %s=%s from %s',
|
||||
$input->getPackage(), $input->getVersion(), $input->getRepository()
|
||||
'Forcing ncc to build package %s/%s=%s from source',
|
||||
$input->getVendor(), $input->getPackage(), $input->getVersion()
|
||||
));
|
||||
|
||||
// First try to fetch a pre-built package from the repository
|
||||
$results = $this->repository_manager->getRepository($input->getRepository())->fetchPackage(
|
||||
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication, $options
|
||||
);
|
||||
|
||||
$package_path = $this->downloadFile($results->getUrl(), PathFinder::getCachePath());
|
||||
}
|
||||
catch(Exception $e)
|
||||
else
|
||||
{
|
||||
Console::outVerbose(sprintf(
|
||||
'Failed to fetch a pre-built ncc package for %s=%s from %s: %s',
|
||||
$input->getPackage(), $input->getVersion(), $input->getRepository(), $e->getMessage()
|
||||
));
|
||||
|
||||
// Clean up the package file if it exists
|
||||
if(isset($package_path) && is_file($package_path))
|
||||
try
|
||||
{
|
||||
ShutdownHandler::declareTemporaryPath($package_path);
|
||||
}
|
||||
Console::outVerbose(sprintf(
|
||||
'Attempting to fetch a pre-built ncc package for %s=%s from %s',
|
||||
$input->getPackage(), $input->getVersion(), $input->getRepository()
|
||||
));
|
||||
|
||||
// This is a warning because we can still attempt to build from source
|
||||
unset($results, $package_path);
|
||||
// First try to fetch a pre-built package from the repository
|
||||
$results = $this->repository_manager->getRepository($input->getRepository())->fetchPackage(
|
||||
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication, $options
|
||||
);
|
||||
|
||||
$package_path = $this->downloadFile($results->getUrl(), PathFinder::getCachePath());
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
Console::outVerbose(sprintf(
|
||||
'Failed to fetch a pre-built ncc package for %s=%s from %s: %s',
|
||||
$input->getPackage(), $input->getVersion(), $input->getRepository(), $e->getMessage()
|
||||
));
|
||||
|
||||
// Clean up the package file if it exists
|
||||
if(isset($package_path) && is_file($package_path))
|
||||
{
|
||||
ShutdownHandler::declareTemporaryPath($package_path);
|
||||
}
|
||||
|
||||
// This is a warning because we can still attempt to build from source
|
||||
unset($results, $package_path);
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($package_path))
|
||||
|
@ -848,7 +858,7 @@
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,12 @@
|
|||
$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
|
||||
if(!is_dir($path))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue