Remove pkg6dev module and related code

- Deleted `pkg6dev` crate, including all related files (`src`, `Cargo.toml`, `Cargo.lock`, and `README.md`).
- Removed error handling, CLI logic, and publishing functionality from the project.
- Migrated relevant high-level APIs to `libips`, ensuring consistency with existing modules.
- Updated `libips` with a new `api` module to encapsulate `forge/pkgdev` integration logic.
- Simplified repository structure to exclude now-unused components and dependencies.
This commit is contained in:
Till Wegmueller 2025-08-30 21:59:52 +02:00
parent 77f02fdfbd
commit a156a3f863
No known key found for this signature in database
9 changed files with 0 additions and 847 deletions

14
Cargo.lock generated
View file

@ -1573,20 +1573,6 @@ dependencies = [
name = "pkg6depotd" name = "pkg6depotd"
version = "0.5.1" version = "0.5.1"
[[package]]
name = "pkg6dev"
version = "0.5.1"
dependencies = [
"anyhow",
"clap",
"libips",
"miette",
"thiserror 2.0.15",
"tracing",
"tracing-subscriber",
"userland",
]
[[package]] [[package]]
name = "pkg6repo" name = "pkg6repo"
version = "0.5.1" version = "0.5.1"

View file

@ -3,7 +3,6 @@
members = [ members = [
"libips", "libips",
"pkg6depotd", "pkg6depotd",
"pkg6dev",
"pkg6repo", "pkg6repo",
"userland", "userland",
"specfile", "specfile",

1
pkg6dev/.gitignore vendored
View file

@ -1 +0,0 @@
/target

5
pkg6dev/Cargo.lock generated
View file

@ -1,5 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "pkg6dev"
version = "0.0.1-placeholder"

View file

@ -1,22 +0,0 @@
[package]
name = "pkg6dev"
version.workspace = true
authors.workspace = true
edition.workspace = true
license-file.workspace = true
description = "Helper tool for IPS package development"
repository.workspace = true
readme.workspace = true
keywords.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libips = {path = "../libips", version = "*"}
userland = {path = "../userland", version = "*"}
clap = {version = "4", features = [ "derive" ] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
miette = { version = "7", features = ["fancy"] }
thiserror = "2"
anyhow = "1.0"

View file

@ -1,149 +0,0 @@
Mozilla Public License
Version 2.0
1. Definitions
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributors Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
1.5. “Incompatible With Secondary Licenses”
means
that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
1.6. “Executable Form”
means any form of the work other than Source Code Form.
1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
1.8. “License”
means this document.
1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
1.10. “Modifications”
means any of the following:
any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
any new file in Source Code Form that contains any Covered Software.
1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
1.13. “Source Code Form”
means the form of the work preferred for making modifications.
1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this License. For legal entities, “You” includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
for any code that a Contributor has removed from Covered Software; or
for infringements caused by: (i) Your and any other third partys modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
under Patent Claims infringed by Covered Software in the absence of its Contributions.
This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients rights in the Source Code Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
3.4. Notices
You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an “as is” basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such partys negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a partys ability to bring cross-claims or counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.

View file

@ -1,3 +0,0 @@
# IPS Packaging utility.
Work in progress

View file

@ -1,147 +0,0 @@
use libips::actions::ActionError;
use libips::repository;
use miette::Diagnostic;
use std::path::PathBuf;
use thiserror::Error;
/// Result type for pkg6dev operations
pub type Result<T> = std::result::Result<T, Pkg6DevError>;
/// Errors that can occur in pkg6dev operations
#[derive(Debug, Error, Diagnostic)]
pub enum Pkg6DevError {
#[error("I/O error: {0}")]
#[diagnostic(
code(ips::pkg6dev::io_error),
help("Check system resources and permissions")
)]
IoError(#[from] std::io::Error),
#[error("action error: {0}")]
#[diagnostic(
code(ips::pkg6dev::action_error),
help("Check the action format and try again")
)]
ActionError(#[from] ActionError),
#[error("repository error: {0}")]
#[diagnostic(transparent)]
RepositoryError(#[from] repository::RepositoryError),
#[error("userland error: {0}")]
#[diagnostic(
code(ips::pkg6dev::userland_error),
help("Check the userland component and try again")
)]
UserlandError(String),
// Component-related errors
#[error("component path error: {path} is not a valid component path")]
#[diagnostic(
code(ips::pkg6dev::component_path_error),
help("Ensure the component path exists and is a directory")
)]
ComponentPathError { path: PathBuf },
#[error("manifest not found: {path}")]
#[diagnostic(
code(ips::pkg6dev::manifest_not_found),
help("Ensure the manifest file exists at the specified path")
)]
ManifestNotFoundError { path: PathBuf },
#[error("replacement format error: {value} is not in the format 'key:value'")]
#[diagnostic(
code(ips::pkg6dev::replacement_format_error),
help("Replacements must be in the format 'key:value'")
)]
ReplacementFormatError { value: String },
// Makefile-related errors
#[error("makefile parse error: {message}")]
#[diagnostic(
code(ips::pkg6dev::makefile_parse_error),
help("Check the Makefile syntax and try again")
)]
MakefileParseError { message: String },
#[error("component info error: {message}")]
#[diagnostic(
code(ips::pkg6dev::component_info_error),
help("Check the component information and try again")
)]
ComponentInfoError { message: String },
// Package publishing errors
#[error("manifest file not found: {path}")]
#[diagnostic(
code(ips::pkg6dev::manifest_file_not_found),
help("Ensure the manifest file exists at the specified path")
)]
ManifestFileNotFoundError { path: PathBuf },
#[error("prototype directory not found: {path}")]
#[diagnostic(
code(ips::pkg6dev::prototype_dir_not_found),
help("Ensure the prototype directory exists at the specified path")
)]
PrototypeDirNotFoundError { path: PathBuf },
#[error("publisher not found: {publisher}")]
#[diagnostic(
code(ips::pkg6dev::publisher_not_found),
help("Add the publisher to the repository using pkg6repo add-publisher")
)]
PublisherNotFoundError { publisher: String },
#[error("no default publisher set")]
#[diagnostic(
code(ips::pkg6dev::no_default_publisher),
help("Specify a publisher using the --publisher option or set a default publisher")
)]
NoDefaultPublisherError,
#[error("file not found in prototype directory: {path}")]
#[diagnostic(
code(ips::pkg6dev::file_not_found_in_prototype),
help("Ensure the file exists in the prototype directory")
)]
FileNotFoundInPrototypeError { path: PathBuf },
// Logging environment error
#[error("logging environment setup error: {0}")]
#[diagnostic(
code(ips::pkg6dev::logging_env_error),
help("Check your logging environment configuration and try again")
)]
LoggingEnvError(String),
// Generic custom error (for backward compatibility)
#[error("{0}")]
#[diagnostic(
code(ips::pkg6dev::custom_error),
help("See error message for details")
)]
Custom(String),
}
/// Convert a string to a Pkg6DevError::Custom
impl From<String> for Pkg6DevError {
fn from(s: String) -> Self {
Pkg6DevError::Custom(s)
}
}
/// Convert a &str to a Pkg6DevError::Custom
impl From<&str> for Pkg6DevError {
fn from(s: &str) -> Self {
Pkg6DevError::Custom(s.to_string())
}
}
/// Convert an anyhow::Error to a Pkg6DevError::UserlandError
impl From<anyhow::Error> for Pkg6DevError {
fn from(e: anyhow::Error) -> Self {
Pkg6DevError::UserlandError(e.to_string())
}
}

View file

@ -1,505 +0,0 @@
mod error;
use clap::{Parser, Subcommand};
use libips::actions::{ActionError, File, Manifest};
use libips::repository::{FileBackend, ReadableRepository, WritableRepository};
use error::{Pkg6DevError, Result};
use std::collections::HashMap;
use std::fs::{OpenOptions, read_dir};
use std::io::Write;
use std::path::{Path, PathBuf};
use tracing::{debug, info, warn};
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::{EnvFilter, fmt};
use userland::repology::find_newest_version;
use userland::{Component, Makefile};
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
struct App {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
DiffComponent {
component: String,
#[clap(short)]
replacements: Option<Vec<String>>,
/// Place the file actions missing in the manifests but present in sample-manifest into this file
#[clap(short = 'm')]
output_manifest: Option<PathBuf>,
},
ShowComponent {
component: String,
},
/// Publish a package to a repository
Publish {
/// Path to the manifest file
#[clap(short = 'm', long)]
manifest_path: PathBuf,
/// Path to the prototype directory containing the files to publish
#[clap(short = 'p', long)]
prototype_dir: PathBuf,
/// Path to the repository
#[clap(short = 'r', long)]
repo_path: PathBuf,
/// Publisher name (defaults to "test" if not specified)
#[clap(short = 'u', long)]
publisher: Option<String>,
},
}
fn main() -> Result<()> {
// Initialize the tracing subscriber with the default log level as debug and no decorations
// Parse the environment filter first, handling any errors with our custom error type
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.from_env()
.map_err(|e| {
Pkg6DevError::LoggingEnvError(format!("Failed to parse environment filter: {}", e))
})?;
fmt::Subscriber::builder()
.with_max_level(tracing::Level::DEBUG)
.with_env_filter(env_filter)
.without_time()
.with_target(false)
.with_ansi(false)
.with_writer(std::io::stderr)
.init();
let cli = App::parse();
match &cli.command {
Commands::ShowComponent { component } => show_component_info(component),
Commands::DiffComponent {
component,
replacements,
output_manifest,
} => diff_component(component, replacements, output_manifest),
Commands::Publish {
manifest_path,
prototype_dir,
repo_path,
publisher,
} => publish_package(manifest_path, prototype_dir, repo_path, publisher),
}
}
fn parse_triplet_replacements(replacements: &[String]) -> HashMap<String, String> {
let mut map = HashMap::new();
for pair in replacements
.iter()
.map(|str| {
str.split_once(':')
.map(|s| (s.0.to_owned(), s.1.to_owned()))
.unwrap_or((String::new(), String::new()))
})
.collect::<Vec<(String, String)>>()
{
map.insert(pair.0, pair.1);
}
map
}
fn diff_component(
component_path: impl AsRef<Path>,
replacements: &Option<Vec<String>>,
output_manifest: &Option<PathBuf>,
) -> Result<()> {
// Validate component path
let component_path_ref = component_path.as_ref();
if !component_path_ref.exists() || !component_path_ref.is_dir() {
return Err(Pkg6DevError::ComponentPathError {
path: component_path_ref.to_path_buf(),
});
}
// Process replacements
let replacements = if let Some(replacements) = replacements {
// Validate replacement format
for replacement in replacements {
if !replacement.contains(':') {
return Err(Pkg6DevError::ReplacementFormatError {
value: replacement.clone(),
});
}
}
let map = parse_triplet_replacements(replacements);
Some(map)
} else {
None
};
// Read directory contents
let files = read_dir(&component_path).map_err(|e| Pkg6DevError::IoError(e))?;
// Filter for manifest files
let manifest_files: Vec<String> = files
.filter_map(std::result::Result::ok)
.filter(|d| {
if let Some(e) = d.path().extension() {
e == "p5m"
} else {
false
}
})
.map(|e| e.path().into_os_string().into_string().unwrap())
.collect();
// Check for the sample manifest
let sample_manifest_file = &component_path_ref.join("manifests/sample-manifest.p5m");
if !sample_manifest_file.exists() {
return Err(Pkg6DevError::ManifestNotFoundError {
path: sample_manifest_file.to_path_buf(),
});
}
// Parse manifests
// Use std::result::Result here to avoid confusion with our custom Result type
let manifests_res: std::result::Result<Vec<Manifest>, ActionError> =
manifest_files.iter().map(Manifest::parse_file).collect();
// Parse sample manifest
let sample_manifest = Manifest::parse_file(sample_manifest_file)?;
// Unwrap manifests result
let manifests: Vec<Manifest> = manifests_res?;
// Find missing files
let missing_files =
find_files_missing_in_manifests(&sample_manifest, manifests.clone(), &replacements)?;
// Print missing files
for f in missing_files.clone() {
debug!("file {} is missing in the manifests", f.path);
}
// Find removed files
let removed_files =
find_removed_files(&sample_manifest, manifests, &component_path, &replacements)?;
// Print removed files
for f in removed_files {
debug!(
"file path={} has been removed from the sample-manifest",
f.path
);
}
// Write output manifest if requested
if let Some(output_manifest) = output_manifest {
let mut f = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(output_manifest)
.map_err(|e| Pkg6DevError::IoError(e))?;
for action in missing_files {
writeln!(&mut f, "file path={}", action.path).map_err(|e| Pkg6DevError::IoError(e))?;
}
}
Ok(())
}
fn show_component_info<P: AsRef<Path>>(component_path: P) -> Result<()> {
// Validate component path
let component_path_ref = component_path.as_ref();
if !component_path_ref.exists() || !component_path_ref.is_dir() {
return Err(Pkg6DevError::ComponentPathError {
path: component_path_ref.to_path_buf(),
});
}
// Get a Makefile path
let makefile_path = component_path_ref.join("Makefile");
if !makefile_path.exists() {
return Err(Pkg6DevError::MakefileParseError {
message: format!("Makefile not found at {}", makefile_path.display()),
});
}
// Parse Makefile
// We'll wrap the anyhow errors with our more specific error types
let initial_makefile = Makefile::parse_single_file(&makefile_path).map_err(|e| {
Pkg6DevError::MakefileParseError {
message: format!("Failed to parse Makefile: {}", e),
}
})?;
let makefile = initial_makefile
.parse_all()
.map_err(|e| Pkg6DevError::MakefileParseError {
message: format!("Failed to parse all Makefiles: {}", e),
})?;
let mut name = String::new();
// Get component information
let component =
Component::new_from_makefile(&makefile).map_err(|e| Pkg6DevError::ComponentInfoError {
message: format!("Failed to get component information: {}", e),
})?;
// Display component information
if let Some(var) = makefile.get("COMPONENT_NAME") {
info!("Name: {}", var.replace('\n', "\n\t"));
if let Some(component_name) = makefile.get_first_value_of_variable_by_name("COMPONENT_NAME")
{
name = component_name;
}
}
if let Some(var) = makefile.get("COMPONENT_VERSION") {
info!("Version: {}", var.replace('\n', "\n\t"));
let latest_version = find_newest_version(&name);
if latest_version.is_ok() {
info!(
"Latest Version: {}",
latest_version.map_err(|e| Pkg6DevError::ComponentInfoError {
message: format!("Failed to get latest version: {}", e),
})?
);
} else {
warn!(
"Could not get latest version info: {}",
latest_version.unwrap_err()
)
}
}
if let Some(var) = makefile.get("BUILD_BITS") {
info!("Build bits: {}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("COMPONENT_BUILD_ACTION") {
info!("Build action: {}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("COMPONENT_PROJECT_URL") {
info!("Project URl: {}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("COMPONENT_ARCHIVE_URL") {
info!("Source URl: {}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("COMPONENT_ARCHIVE_HASH") {
info!("Source Archive File Hash: {}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("REQUIRED_PACKAGES") {
info!("Dependencies:\n\t{}", var.replace('\n', "\n\t"));
}
if let Some(var) = makefile.get("COMPONENT_INSTALL_ACTION") {
info!("Install Action:\n\t{}", var);
}
info!("Component: {:?}", component);
Ok(())
}
// Show all files that have been removed in the sample-manifest
fn find_removed_files<P: AsRef<Path>>(
sample_manifest: &Manifest,
manifests: Vec<Manifest>,
component_path: P,
replacements: &Option<HashMap<String, String>>,
) -> Result<Vec<File>> {
let f_map = make_file_map(sample_manifest.files.clone());
let all_files: Vec<File> = manifests.iter().flat_map(|m| m.files.clone()).collect();
let mut removed_files: Vec<File> = Vec::new();
for f in all_files {
match f.get_original_path() {
Some(path) => {
if !f_map.contains_key(replace_func(path.clone(), replacements).as_str())
&& !component_path.as_ref().join(path).exists()
{
removed_files.push(f)
}
}
None => {
if !f_map.contains_key(replace_func(f.path.clone(), replacements).as_str()) {
removed_files.push(f)
}
}
}
}
Ok(removed_files)
}
// Show all files missing in the manifests that are in sample_manifest
fn find_files_missing_in_manifests(
sample_manifest: &Manifest,
manifests: Vec<Manifest>,
replacements: &Option<HashMap<String, String>>,
) -> Result<Vec<File>> {
let all_files: Vec<File> = manifests.iter().flat_map(|m| m.files.clone()).collect();
let f_map = make_file_map(all_files);
let mut missing_files: Vec<File> = Vec::new();
for f in sample_manifest.files.clone() {
match f.get_original_path() {
Some(path) => {
if !f_map.contains_key(replace_func(path, replacements).as_str()) {
missing_files.push(f)
}
}
None => {
if !f_map.contains_key(replace_func(f.path.clone(), replacements).as_str()) {
missing_files.push(f)
}
}
}
}
Ok(missing_files)
}
fn replace_func(orig: String, replacements: &Option<HashMap<String, String>>) -> String {
if let Some(replacements) = replacements {
let mut replacement = orig.clone();
for (i, (from, to)) in replacements.iter().enumerate() {
let from: &str = &format!("$({})", from);
if i == 0 {
replacement = orig.replace(from, to);
} else {
replacement = replacement.replace(from, to);
}
}
replacement
} else {
orig
}
}
fn make_file_map(files: Vec<File>) -> HashMap<String, File> {
files
.iter()
.map(|f| {
let orig_path_opt = f.get_original_path();
if orig_path_opt.is_none() {
return (f.path.clone(), f.clone());
}
(orig_path_opt.unwrap(), f.clone())
})
.collect()
}
/// Publish a package to a repository
///
/// This function:
/// 1. Opens the repository at the specified path
/// 2. Parses manifest file
/// 3. Uses the FileBackend's publish_files method to publish the files from the prototype directory
fn publish_package(
manifest_path: &PathBuf,
prototype_dir: &PathBuf,
repo_path: &PathBuf,
publisher: &Option<String>,
) -> Result<()> {
// Check if the manifest file exists
if !manifest_path.exists() {
return Err(Pkg6DevError::ManifestFileNotFoundError {
path: manifest_path.clone(),
});
}
// Check if the prototype directory exists
if !prototype_dir.exists() {
return Err(Pkg6DevError::PrototypeDirNotFoundError {
path: prototype_dir.clone(),
});
}
// Parse the manifest file
info!("Parsing manifest file: {}", manifest_path.display());
let manifest = Manifest::parse_file(manifest_path)?;
// Open the repository
info!("Opening repository at: {}", repo_path.display());
let repo = match FileBackend::open(repo_path) {
Ok(repo) => repo,
Err(_) => {
info!("Repository does not exist, creating a new one...");
// Create a new repository with version 4
FileBackend::create(repo_path, libips::repository::RepositoryVersion::V4)?
}
};
// Determine which publisher to use
let publisher_name = if let Some(pub_name) = publisher {
// Use the explicitly specified publisher
if !repo.config.publishers.contains(pub_name) {
return Err(Pkg6DevError::PublisherNotFoundError {
publisher: pub_name.clone(),
});
}
pub_name.clone()
} else {
// Use the default publisher
match &repo.config.default_publisher {
Some(default_pub) => default_pub.clone(),
None => return Err(Pkg6DevError::NoDefaultPublisherError),
}
};
// Begin a transaction
info!("Beginning transaction for publisher: {}", publisher_name);
let mut transaction = repo.begin_transaction()?;
// Set the publisher for the transaction
transaction.set_publisher(&publisher_name);
// Add files from the prototype directory to the transaction
info!(
"Adding files from prototype directory: {}",
prototype_dir.display()
);
for file_action in manifest.files.iter() {
// Construct the full path to the file in the prototype directory
let file_path = prototype_dir.join(&file_action.path);
// Check if the file exists
if !file_path.exists() {
return Err(Pkg6DevError::FileNotFoundInPrototypeError {
path: file_path.clone(),
});
}
// Add the file to the transaction
debug!("Adding file: {}", file_action.path);
transaction.add_file(file_action.clone(), &file_path)?;
}
// Update the manifest in the transaction
info!("Updating manifest in the transaction...");
transaction.update_manifest(manifest);
// Commit the transaction
info!("Committing transaction...");
transaction.commit()?;
// Regenerate catalog and search index
info!("Regenerating catalog and search index...");
repo.rebuild(Some(&publisher_name), false, false)?;
info!("Package published successfully!");
Ok(())
}