diff --git a/src/ncc/CLI/Commands/PackageInspectorCommand.php b/src/ncc/CLI/Commands/PackageInspectorCommand.php index cecd13b..cc82db6 100644 --- a/src/ncc/CLI/Commands/PackageInspectorCommand.php +++ b/src/ncc/CLI/Commands/PackageInspectorCommand.php @@ -52,6 +52,19 @@ return 1; } + if(isset($args['info'])) + { + try + { + return self::displayInfo($args); + } + catch(Exception $e) + { + Console::outException(sprintf('Failed to display info: %s', $e->getMessage()), $e, 1); + return 1; + } + } + if(isset($args['headers'])) { try @@ -149,6 +162,31 @@ return 0; } + /** + * Prints out basic information about the package + * + * @param array $args + * @return int + */ + private static function displayInfo(array $args): int + { + $package_reader = new PackageReader($args['path'] ?? $args['p']); + + Console::out(sprintf('File Version: %s', $package_reader->getFileVersion())); + Console::out(sprintf('crc32: %s', $package_reader->getChecksum())); + Console::out(sprintf('sha256: %s', $package_reader->getChecksum('sha256'))); + Console::out(sprintf('Flags: %s', implode(', ', $package_reader->getFlags()))); + Console::out(sprintf('Package Offset: %s', $package_reader->getPackageOffset())); + Console::out(sprintf('Package Length: %s', $package_reader->getPackageLength())); + Console::out(sprintf('Header Offset: %s', $package_reader->getHeaderOffset())); + Console::out(sprintf('Header Length: %s', $package_reader->getHeaderLength())); + Console::out(sprintf('Data Offset: %s', $package_reader->getDataOffset())); + Console::out(sprintf('Data Length: %s', $package_reader->getDataLength())); + Console::out(sprintf('Directory Size: %d items', count($package_reader->getDirectory()))); + + return 0; + } + /** * Displays the assembly section * @@ -311,6 +349,7 @@ new CliHelpSection(['--path', '-p'], 'Required. Specifies the path to the binary package to inspect'), new CliHelpSection(['--json'], 'Prints out the information of the package in JSON format'), new CliHelpSection(['--pretty-json'], 'Prints out the information of the package in pretty JSON format'), + new CliHelpSection(['info'], 'Prints out basic information about the binary package'), new CliHelpSection(['headers'], 'Prints out the headers of the package'), new CliHelpSection(['metadata'], 'Prints out the metadata of the package'), new CliHelpSection(['assembly'], 'Prints out the assembly information of the package'), diff --git a/src/ncc/Classes/NccExtension/NccCompiler.php b/src/ncc/Classes/NccExtension/NccCompiler.php index c408b7c..84047af 100644 --- a/src/ncc/Classes/NccExtension/NccCompiler.php +++ b/src/ncc/Classes/NccExtension/NccCompiler.php @@ -37,6 +37,7 @@ use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; use ncc\Interfaces\CompilerInterface; + use ncc\Managers\PackageManager; use ncc\Managers\ProjectManager; use ncc\Objects\Package\Component; use ncc\Objects\Package\Metadata; @@ -192,9 +193,18 @@ $this->processResource($package_writer, $resource); } + $package_manager = new PackageManager(); + // Add the project dependencies foreach($this->project_manager->getProjectConfiguration()->getBuild()->getDependencies() as $dependency) { + if(isset($configuration->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES])) + { + $package_entry = $package_manager->getPackageLock()->getEntry($dependency->getName()); + $shadow_package = $package_entry->getShadowPackagePath($dependency->getVersion()); + // TODO: Add support for static dependencies + } + $package_writer->addDependencyConfiguration($dependency); } diff --git a/src/ncc/Classes/PackageReader.php b/src/ncc/Classes/PackageReader.php index 85db16d..7e0f1ca 100644 --- a/src/ncc/Classes/PackageReader.php +++ b/src/ncc/Classes/PackageReader.php @@ -654,6 +654,36 @@ return $this->data_length; } + /** + * Returns the checksum of the package + * + * @param string $hash + * @param bool $binary + * @return string + */ + public function getChecksum(string $hash='crc32b', bool $binary=false): string + { + $checksum = hash($hash, '', $binary); + + fseek($this->package_file, $this->package_offset); + $bytes_left = $this->package_length; + + while ($bytes_left > 0) + { + $buffer = fread($this->package_file, min(1024, $bytes_left)); + $buffer_length = strlen($buffer); + $bytes_left -= $buffer_length; + $checksum = hash($hash, ($checksum . $buffer), $binary); + + if ($buffer_length === 0) + { + break; + } + } + + return $checksum; + } + /** * @param string $path * @return void diff --git a/src/ncc/Enums/Options/BuildConfigurationOptions.php b/src/ncc/Enums/Options/BuildConfigurationOptions.php index c5a2300..7876e20 100644 --- a/src/ncc/Enums/Options/BuildConfigurationOptions.php +++ b/src/ncc/Enums/Options/BuildConfigurationOptions.php @@ -31,4 +31,6 @@ public const NCC_CONFIGURATION = 'ncc_configuration'; public const OUTPUT_FILE = 'output_file'; + + public const STATIC_DEPENDENCIES = 'static'; } \ No newline at end of file diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index 0d076ff..e7cac7f 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -518,8 +518,6 @@ $package_reader->getComponent($component_name)->getData([ComponentDecodeOptions::AS_FILE]), 0755 ); - - Console::inlineProgressBar(++$current_step, $total_steps); } diff --git a/src/ncc/Objects/PackageLock/PackageEntry.php b/src/ncc/Objects/PackageLock/PackageEntry.php index 73ee4b5..79ce074 100644 --- a/src/ncc/Objects/PackageLock/PackageEntry.php +++ b/src/ncc/Objects/PackageLock/PackageEntry.php @@ -101,6 +101,17 @@ return $this->getVersion($version)->getPath($this->name); } + /** + * Returns the path to where the shadow package is located + * + * @param string $version + * @return string + */ + public function getShadowPackagePath(string $version): string + { + return $this->getVersion($version)->getShadowPackagePath($this->name); + } + /** * Adds a new version entry to the package, if overwrite is true then * the entry will be overwritten if it exists, otherwise it will return diff --git a/src/ncc/Objects/PackageLock/VersionEntry.php b/src/ncc/Objects/PackageLock/VersionEntry.php index d3adeb9..0e4cbc4 100644 --- a/src/ncc/Objects/PackageLock/VersionEntry.php +++ b/src/ncc/Objects/PackageLock/VersionEntry.php @@ -25,6 +25,7 @@ namespace ncc\Objects\PackageLock; use InvalidArgumentException; + use ncc\Enums\FileDescriptor; use ncc\Exceptions\ConfigurationException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Objects\ProjectConfiguration\Dependency; @@ -222,6 +223,17 @@ return PathFinder::getPackagesPath() . DIRECTORY_SEPARATOR . sprintf('%s=%s', $package_name, $this->getVersion()); } + /** + * Returns the path where the shadow package is located + * + * @param string $package_name + * @return string + */ + public function getShadowPackagePath(string $package_name): string + { + return $this->getPath($package_name) . DIRECTORY_SEPARATOR . FileDescriptor::SHADOW_PACKAGE; + } + /** * Returns an array representation of the object *