| namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
| static int _repoman_add(const options& opts) { | static int _repoman_add(const options& opts) { | ||||
| auto pkg_id = dds::pkg_id::parse(opts.repoman.add.pkg_id_str); | |||||
| auto rpkg = any_remote_pkg::from_url(neo::url::parse(opts.repoman.add.url_str)); | |||||
| auto rpkg = any_remote_pkg::from_url(neo::url::parse(opts.repoman.add.url_str)); | |||||
| auto temp_sdist = get_package_sdist(rpkg); | |||||
| dds::pkg_listing add_info{ | dds::pkg_listing add_info{ | ||||
| .ident = pkg_id, | |||||
| .ident = temp_sdist.sdist.manifest.id, | |||||
| .deps = temp_sdist.sdist.manifest.dependencies, | |||||
| .description = opts.repoman.add.description, | .description = opts.repoman.add.description, | ||||
| .remote_pkg = rpkg, | .remote_pkg = rpkg, | ||||
| }; | }; | ||||
| auto temp_sdist = get_package_sdist(add_info); | |||||
| add_info.deps = temp_sdist.sdist.manifest.dependencies; | |||||
| auto repo = repo_manager::open(opts.repoman.repo_dir); | auto repo = repo_manager::open(opts.repoman.repo_dir); | ||||
| repo.add_pkg(add_info, opts.repoman.add.url_str); | repo.add_pkg(add_info, opts.repoman.add.url_str); | ||||
| dds::capture_exception(); | dds::capture_exception(); | ||||
| } | } | ||||
| }, | }, | ||||
| [](user_error<errc::invalid_pkg_id>, | |||||
| semver::invalid_version err, | |||||
| dds::e_invalid_pkg_id_str idstr) -> int { | |||||
| dds_log(error, | |||||
| "Package ID string '{}' is invalid, because '{}' is not a valid semantic " | |||||
| "version string", | |||||
| idstr.value, | |||||
| err.string()); | |||||
| write_error_marker("invalid-pkg-id-str-version"); | |||||
| throw; | |||||
| }, | |||||
| [](user_error<errc::invalid_pkg_id>, dds::e_invalid_pkg_id_str idstr) -> int { | |||||
| dds_log(error, "Invalid package ID string '{}'", idstr.value); | |||||
| write_error_marker("invalid-pkg-id-str"); | |||||
| throw; | |||||
| }, | |||||
| [](dds::e_sqlite3_error_exc, | [](dds::e_sqlite3_error_exc, | ||||
| boost::leaf::match<neo::sqlite3::errc, neo::sqlite3::errc::constraint_unique>, | boost::leaf::match<neo::sqlite3::errc, neo::sqlite3::errc::constraint_unique>, | ||||
| dds::pkg_id pkid) { | dds::pkg_id pkid) { |
| void setup_repoman_add_cmd(argument_parser& repoman_add_cmd) { | void setup_repoman_add_cmd(argument_parser& repoman_add_cmd) { | ||||
| repoman_add_cmd.add_argument(repoman_repo_dir_arg.dup()); | repoman_add_cmd.add_argument(repoman_repo_dir_arg.dup()); | ||||
| repoman_add_cmd.add_argument({ | |||||
| .help = "The package ID of the package to add", | |||||
| .valname = "<pkg-id>", | |||||
| .required = true, | |||||
| .action = put_into(opts.repoman.add.pkg_id_str), | |||||
| }); | |||||
| repoman_add_cmd.add_argument({ | repoman_add_cmd.add_argument({ | ||||
| .help = "URL to add to the repository", | .help = "URL to add to the repository", | ||||
| .valname = "<url>", | .valname = "<url>", |
| /// Options for 'dds repoman add' | /// Options for 'dds repoman add' | ||||
| struct { | struct { | ||||
| std::string pkg_id_str; | |||||
| std::string url_str; | std::string url_str; | ||||
| std::string description; | std::string description; | ||||
| } add; | } add; |
| using namespace dds; | using namespace dds; | ||||
| namespace { | |||||
| temporary_sdist do_pull_sdist(const any_remote_pkg& rpkg) { | |||||
| temporary_sdist dds::get_package_sdist(const any_remote_pkg& rpkg) { | |||||
| auto tmpdir = dds::temporary_dir::create(); | auto tmpdir = dds::temporary_dir::create(); | ||||
| rpkg.get_sdist(tmpdir.path()); | rpkg.get_sdist(tmpdir.path()); | ||||
| return {sd_tmp_dir, sd}; | return {sd_tmp_dir, sd}; | ||||
| } | } | ||||
| } // namespace | |||||
| temporary_sdist dds::get_package_sdist(const pkg_listing& pkg) { | temporary_sdist dds::get_package_sdist(const pkg_listing& pkg) { | ||||
| auto tsd = do_pull_sdist(pkg.remote_pkg); | |||||
| auto tsd = get_package_sdist(pkg.remote_pkg); | |||||
| if (!(tsd.sdist.manifest.id == pkg.ident)) { | if (!(tsd.sdist.manifest.id == pkg.ident)) { | ||||
| throw_external_error<errc::sdist_ident_mismatch>( | throw_external_error<errc::sdist_ident_mismatch>( | ||||
| "The package name@version in the generated source distribution does not match the name " | "The package name@version in the generated source distribution does not match the name " |
| class pkg_cache; | class pkg_cache; | ||||
| class pkg_db; | class pkg_db; | ||||
| struct pkg_listing; | struct pkg_listing; | ||||
| class any_remote_pkg; | |||||
| temporary_sdist get_package_sdist(const any_remote_pkg&); | |||||
| temporary_sdist get_package_sdist(const pkg_listing&); | temporary_sdist get_package_sdist(const pkg_listing&); | ||||
| void get_all(const std::vector<pkg_id>& pkgs, dds::pkg_cache& repo, const pkg_db& cat); | void get_all(const std::vector<pkg_id>& pkgs, dds::pkg_cache& repo, const pkg_db& cat); |
| return tmp_path | return tmp_path | ||||
| def test_error_bad_pkg_id(dds: DDSWrapper, tmp_repo: Path) -> None: | |||||
| with expect_error_marker('invalid-pkg-id-str-version'): | |||||
| dds.run(['repoman', 'add', tmp_repo, 'foo@bar', 'http://example.com']) | |||||
| with expect_error_marker('invalid-pkg-id-str'): | |||||
| dds.run(['repoman', 'add', tmp_repo, 'foo', 'http://example.com']) | |||||
| def test_add_simple(dds: DDSWrapper, tmp_repo: Path) -> None: | def test_add_simple(dds: DDSWrapper, tmp_repo: Path) -> None: | ||||
| dds.run(['repoman', 'add', tmp_repo, 'neo-fun@0.6.0', 'git+https://github.com/vector-of-bool/neo-fun.git#0.6.0']) | |||||
| dds.run(['repoman', 'add', tmp_repo, 'git+https://github.com/vector-of-bool/neo-fun.git#0.6.0']) | |||||
| with expect_error_marker('dup-pkg-add'): | with expect_error_marker('dup-pkg-add'): | ||||
| dds.run( | |||||
| ['repoman', 'add', tmp_repo, 'neo-fun@0.6.0', 'git+https://github.com/vector-of-bool/neo-fun.git#0.6.0']) | |||||
| dds.run(['repoman', 'add', tmp_repo, 'git+https://github.com/vector-of-bool/neo-fun.git#0.6.0']) | |||||
| def test_add_github(dds: DDSWrapper, tmp_repo: Path) -> None: | def test_add_github(dds: DDSWrapper, tmp_repo: Path) -> None: | ||||
| dds.run(['repoman', 'add', tmp_repo, 'neo-fun@0.6.0', 'github:vector-of-bool/neo-fun/0.6.0']) | |||||
| dds.run(['repoman', 'add', tmp_repo, 'github:vector-of-bool/neo-fun/0.6.0']) | |||||
| with expect_error_marker('dup-pkg-add'): | with expect_error_marker('dup-pkg-add'): | ||||
| dds.run(['repoman', 'add', tmp_repo, 'neo-fun@0.6.0', 'github:vector-of-bool/neo-fun/0.6.0']) | |||||
| dds.run(['repoman', 'add', tmp_repo, 'github:vector-of-bool/neo-fun/0.6.0']) | |||||
| def test_add_invalid(dds: DDSWrapper, tmp_repo: Path) -> None: | def test_add_invalid(dds: DDSWrapper, tmp_repo: Path) -> None: | ||||
| with expect_error_marker('repoman-add-invalid-pkg-url'): | with expect_error_marker('repoman-add-invalid-pkg-url'): | ||||
| dds.run(['repoman', 'add', tmp_repo, 'foo@1.2.3', 'invalid://google.com/lolwut']) | |||||
| dds.run(['repoman', 'add', tmp_repo, 'invalid://google.com/lolwut']) | |||||
| def test_error_double_remove(tmp_repo: Path, dds: DDSWrapper) -> None: | def test_error_double_remove(tmp_repo: Path, dds: DDSWrapper) -> None: | ||||
| dds.run([ | dds.run([ | ||||
| 'repoman', '-ltrace', 'add', tmp_repo, 'neo-fun@0.4.0', | |||||
| 'repoman', '-ltrace', 'add', tmp_repo, | |||||
| 'https://github.com/vector-of-bool/neo-fun/archive/0.4.0.tar.gz?__dds_strpcmp=1' | 'https://github.com/vector-of-bool/neo-fun/archive/0.4.0.tar.gz?__dds_strpcmp=1' | ||||
| ]) | ]) | ||||
| dds.run(['repoman', 'remove', tmp_repo, 'neo-fun@0.4.0']) | dds.run(['repoman', 'remove', tmp_repo, 'neo-fun@0.4.0']) | ||||
| def test_pkg_http(http_repo: RepoServer, tmp_project: Project) -> None: | def test_pkg_http(http_repo: RepoServer, tmp_project: Project) -> None: | ||||
| tmp_project.dds.run([ | tmp_project.dds.run([ | ||||
| 'repoman', '-ltrace', 'add', http_repo.server.root, 'neo-fun@0.4.0', | |||||
| 'repoman', '-ltrace', 'add', http_repo.server.root, | |||||
| 'https://github.com/vector-of-bool/neo-fun/archive/0.4.0.tar.gz?__dds_strpcmp=1' | 'https://github.com/vector-of-bool/neo-fun/archive/0.4.0.tar.gz?__dds_strpcmp=1' | ||||
| ]) | ]) | ||||
| tmp_project.dds.repo_add(http_repo.url) | tmp_project.dds.repo_add(http_repo.url) |