Skip to content

Commit

Permalink
feat: add list and remove commands to builder
Browse files Browse the repository at this point in the history
builder添加应用列表和删除应用的命令, 便于开发者清理构建缓存
  • Loading branch information
myml authored and dengbo11 committed Dec 4, 2024
1 parent c7528ab commit abde9d1
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 182 deletions.
23 changes: 23 additions & 0 deletions apps/ll-builder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ You can report bugs to the linyaps team under this project: https://github.com/O
->group(hiddenGroup);
buildRun->add_flag("--debug", debugMode, _("Run in debug mode (enable develop module)"));

auto buildList = commandParser.add_subcommand("list", _("List builded linyaps app"));
buildList->usage(_("Usage: ll-builder list [OPTIONS]"));
std::vector<std::string> removeList;
auto buildRemove = commandParser.add_subcommand("remove", _("Remove builded linyaps app"));
buildRemove->usage(_("Usage: ll-builder remove [OPTIONS] [APP...]"));
buildRemove->add_option("APP", removeList);

// build export
bool layerMode = false;
std::string iconFile;
Expand Down Expand Up @@ -816,6 +823,22 @@ You can report bugs to the linyaps team under this project: https://github.com/O
return 0;
}

if (buildList->parsed()) {
auto ret = linglong::builder::cmdListApp(repo);
if (!ret.has_value()) {
return -1;
}
return 0;
}

if (buildRemove->parsed()) {
auto ret = linglong::builder::cmdRemoveApp(repo, removeList);
if (!ret.has_value()) {
return -1;
}
return 0;
}

std::cout << commandParser.help("", CLI::AppFormatMode::All);

return 0;
Expand Down
57 changes: 56 additions & 1 deletion libs/linglong/src/linglong/builder/linglong_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
#include <QUrl>
#include <QUuid>

#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <optional>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -271,7 +273,7 @@ utils::error::Result<package::Reference> pullDependency(const package::FuzzyRefe

auto tmpTask = service::PackageTask::createTemporaryTask();
auto partChanged = [&ref, module](const uint fetched, const uint requested) {
auto percentage = (uint)((((double)fetched) / requested) * 100);
auto percentage = (uint)((((double)fetched) / requested) * 100);
auto progress = QString("(%1/%2 %3%)").arg(fetched).arg(requested).arg(percentage);
printReplacedText(QString("%1%2%3%4 %5")
.arg(ref->id, -25) // NOLINT
Expand Down Expand Up @@ -400,6 +402,59 @@ utils::error::Result<void> installModule(QStringList installRules,

} // namespace

utils::error::Result<void> cmdListApp(repo::OSTreeRepo &repo)
{
LINGLONG_TRACE("cmd list app");
auto list = repo.listLocal();
if (!list.has_value()) {
return LINGLONG_ERR("list local pkg", list);
}
std::vector<std::string> refs;
for (const auto &item : *list) {
auto ref = package::Reference::fromPackageInfo(item);
if (!ref.has_value()) {
continue;
}
refs.push_back(ref->toString().toStdString());
}
std::sort(refs.begin(), refs.end());
auto it = std::unique(refs.begin(), refs.end());
refs.erase(it, refs.end());
for (const auto &ref : refs) {
std::cout << ref << std::endl;
}
return LINGLONG_OK;
}

utils::error::Result<void> cmdRemoveApp(repo::OSTreeRepo &repo, std::vector<std::string> refs)
{
LINGLONG_TRACE("cmd remove app");
for (const auto &ref : refs) {
auto r = package::Reference::parse(QString::fromStdString(ref));
if (!r.has_value()) {
std::cerr << ref << ": " << r.error().message().toStdString() << std::endl;
continue;
}
auto modules = repo.getModuleList(*r);
for (const auto &module : modules) {
auto v = repo.remove(*r, module);
if (!v.has_value()) {
std::cerr << ref << ": " << v.error().message().toStdString() << std::endl;
continue;
}
}
}
auto v = repo.prune();
if (!v.has_value()) {
std::cerr << v.error().message().toStdString();
}
v = repo.mergeModules();
if (!v.has_value()) {
std::cerr << v.error().message().toStdString();
}
return LINGLONG_OK;
}

Builder::Builder(const api::types::v1::BuilderProject &project,
const QDir &workingDir,
repo::OSTreeRepo &repo,
Expand Down
17 changes: 10 additions & 7 deletions libs/linglong/src/linglong/builder/linglong_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ struct BuilderBuildOptions
{
// 兼容选项,在制作runtime时构建全量develop, 以兼容旧版本linglong-builder使用
// TODO 后续版本删除该选项
bool fullDevelop {false};
bool skipFetchSource {false};
bool skipPullDepend {false};
bool skipRunContainer {false};
bool skipCommitOutput {false};
bool skipCheckOutput {false};
bool skipStripSymbols {false};
bool fullDevelop{ false };
bool skipFetchSource{ false };
bool skipPullDepend{ false };
bool skipRunContainer{ false };
bool skipCommitOutput{ false };
bool skipCheckOutput{ false };
bool skipStripSymbols{ false };
};

utils::error::Result<void> cmdListApp(repo::OSTreeRepo &repo);
utils::error::Result<void> cmdRemoveApp(repo::OSTreeRepo &repo, std::vector<std::string> refs);

class Builder
{
public:
Expand Down
84 changes: 50 additions & 34 deletions po/en_GB.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-23 17:02+0800\n"
"POT-Creation-Date: 2024-11-27 18:02+0800\n"
"PO-Revision-Date: 2024-11-23 17:05+0800\n"
"Last-Translator: deepiner, 2024\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -350,7 +350,7 @@ msgid "Usage: ll-cli repo SUBCOMMAND [OPTIONS]"
msgstr "Usage: ll-cli repo SUBCOMMAND [OPTIONS]"

#. add repo sub command add
#: ../apps/ll-cli/src/main.cpp:449 ../apps/ll-builder/src/main.cpp:334
#: ../apps/ll-cli/src/main.cpp:449 ../apps/ll-builder/src/main.cpp:341
msgid "Add a new repository"
msgstr "Add a new repository"

Expand All @@ -360,15 +360,15 @@ msgstr "Usage: ll-cli repo add [OPTIONS] NAME URL"

#: ../apps/ll-cli/src/main.cpp:451 ../apps/ll-cli/src/main.cpp:461
#: ../apps/ll-cli/src/main.cpp:471 ../apps/ll-cli/src/main.cpp:478
#: ../apps/ll-cli/src/main.cpp:489 ../apps/ll-builder/src/main.cpp:336
#: ../apps/ll-builder/src/main.cpp:346 ../apps/ll-builder/src/main.cpp:353
#: ../apps/ll-builder/src/main.cpp:364
#: ../apps/ll-cli/src/main.cpp:489 ../apps/ll-builder/src/main.cpp:343
#: ../apps/ll-builder/src/main.cpp:353 ../apps/ll-builder/src/main.cpp:360
#: ../apps/ll-builder/src/main.cpp:371
msgid "Specify the repo name"
msgstr "Specify the repo name"

#: ../apps/ll-cli/src/main.cpp:454 ../apps/ll-cli/src/main.cpp:464
#: ../apps/ll-cli/src/main.cpp:481 ../apps/ll-builder/src/main.cpp:339
#: ../apps/ll-builder/src/main.cpp:356
#: ../apps/ll-cli/src/main.cpp:481 ../apps/ll-builder/src/main.cpp:346
#: ../apps/ll-builder/src/main.cpp:363
msgid "Url of the repository"
msgstr "Url of the repository"

Expand All @@ -377,7 +377,7 @@ msgid "Modify repository URL"
msgstr "Modify repository URL"

#. add repo sub command remove
#: ../apps/ll-cli/src/main.cpp:469 ../apps/ll-builder/src/main.cpp:344
#: ../apps/ll-cli/src/main.cpp:469 ../apps/ll-builder/src/main.cpp:351
msgid "Remove a repository"
msgstr "Remove a repository"

Expand All @@ -386,15 +386,15 @@ msgid "Usage: ll-cli repo remove [OPTIONS] NAME"
msgstr "Usage: ll-cli repo remove [OPTIONS] NAME"

#. add repo sub command update
#: ../apps/ll-cli/src/main.cpp:476 ../apps/ll-builder/src/main.cpp:351
#: ../apps/ll-cli/src/main.cpp:476 ../apps/ll-builder/src/main.cpp:358
msgid "Update the repository URL"
msgstr "Update the repository URL"

#: ../apps/ll-cli/src/main.cpp:477
msgid "Usage: ll-cli repo update [OPTIONS] NAME URL"
msgstr "Usage: ll-cli repo update [OPTIONS] NAME URL"

#: ../apps/ll-cli/src/main.cpp:487 ../apps/ll-builder/src/main.cpp:362
#: ../apps/ll-cli/src/main.cpp:487 ../apps/ll-builder/src/main.cpp:369
msgid "Set a default repository name"
msgstr "Set a default repository name"

Expand All @@ -403,7 +403,7 @@ msgid "Usage: ll-cli repo set-default [OPTIONS] NAME"
msgstr "Usage: ll-cli repo set-default [OPTIONS] NAME"

#. add repo sub command show
#: ../apps/ll-cli/src/main.cpp:494 ../apps/ll-builder/src/main.cpp:369
#: ../apps/ll-cli/src/main.cpp:494 ../apps/ll-builder/src/main.cpp:376
msgid "Show repository information"
msgstr "Show repository information"

Expand Down Expand Up @@ -496,7 +496,7 @@ msgid "Usage: ll-builder build [OPTIONS] [COMMAND...]"
msgstr "Usage: ll-builder build [OPTIONS] [COMMAND...]"

#: ../apps/ll-builder/src/main.cpp:214 ../apps/ll-builder/src/main.cpp:257
#: ../apps/ll-builder/src/main.cpp:284 ../apps/ll-builder/src/main.cpp:297
#: ../apps/ll-builder/src/main.cpp:291 ../apps/ll-builder/src/main.cpp:304
msgid "File path of the linglong.yaml"
msgstr "File path of the linglong.yaml"

Expand Down Expand Up @@ -569,95 +569,111 @@ msgstr "Enter the container to execute command instead of running application"
msgid "Run in debug mode (enable develop module)"
msgstr "Run in debug mode (enable develop module)"

#: ../apps/ll-builder/src/main.cpp:279
msgid "List builded linyaps app"
msgstr "List builded linyaps app"

#: ../apps/ll-builder/src/main.cpp:280
msgid "Usage: ll-builder list [OPTIONS]"
msgstr "Usage: ll-builder list [OPTIONS]"

#: ../apps/ll-builder/src/main.cpp:282
msgid "Remove builded linyaps app"
msgstr "Remove builded linyaps app"

#: ../apps/ll-builder/src/main.cpp:283
msgid "Usage: ll-builder remove [OPTIONS] [APP...]"
msgstr "Usage: ll-builder remove [OPTIONS] [APP...]"

#: ../apps/ll-builder/src/main.cpp:289
msgid "Export to linyaps layer or uab"
msgstr "Export to linyaps layer or uab"

#: ../apps/ll-builder/src/main.cpp:283
#: ../apps/ll-builder/src/main.cpp:290
msgid "Usage: ll-builder export [OPTIONS]"
msgstr "Usage: ll-builder export [OPTIONS]"

#: ../apps/ll-builder/src/main.cpp:288
#: ../apps/ll-builder/src/main.cpp:295
msgid "Uab icon (optional)"
msgstr "Uab icon (optional)"

#: ../apps/ll-builder/src/main.cpp:291
#: ../apps/ll-builder/src/main.cpp:298
msgid "Export to linyaps layer file"
msgstr "Export to linyaps layer file"

#: ../apps/ll-builder/src/main.cpp:295
#: ../apps/ll-builder/src/main.cpp:302
msgid "Push linyaps app to remote repo"
msgstr "Push linyaps app to remote repo"

#: ../apps/ll-builder/src/main.cpp:296
#: ../apps/ll-builder/src/main.cpp:303
msgid "Usage: ll-builder push [OPTIONS]"
msgstr "Usage: ll-builder push [OPTIONS]"

#: ../apps/ll-builder/src/main.cpp:301
#: ../apps/ll-builder/src/main.cpp:308
msgid "Remote repo url"
msgstr "Remote repo url"

#: ../apps/ll-builder/src/main.cpp:304
#: ../apps/ll-builder/src/main.cpp:311
msgid "Remote repo name"
msgstr "Remote repo name"

#: ../apps/ll-builder/src/main.cpp:307
#: ../apps/ll-builder/src/main.cpp:314
msgid "Push single module"
msgstr "Push single module"

#: ../apps/ll-builder/src/main.cpp:312
#: ../apps/ll-builder/src/main.cpp:319
msgid "Import linyaps layer to build repo"
msgstr "Import linyaps layer to build repo"

#: ../apps/ll-builder/src/main.cpp:313
#: ../apps/ll-builder/src/main.cpp:320
msgid "Usage: ll-builder import [OPTIONS] LAYER"
msgstr "Usage: ll-builder import [OPTIONS] LAYER"

#: ../apps/ll-builder/src/main.cpp:314 ../apps/ll-builder/src/main.cpp:323
#: ../apps/ll-builder/src/main.cpp:321 ../apps/ll-builder/src/main.cpp:330
msgid "Layer file path"
msgstr "Layer file path"

#: ../apps/ll-builder/src/main.cpp:321
#: ../apps/ll-builder/src/main.cpp:328
msgid "Extract linyaps layer to dir"
msgstr "Extract linyaps layer to dir"

#: ../apps/ll-builder/src/main.cpp:322
#: ../apps/ll-builder/src/main.cpp:329
msgid "Usage: ll-builder extract [OPTIONS] LAYER DIR"
msgstr "Usage: ll-builder extract [OPTIONS] LAYER DIR"

#: ../apps/ll-builder/src/main.cpp:326
#: ../apps/ll-builder/src/main.cpp:333
msgid "Destination directory"
msgstr "Destination directory"

#. add build repo
#: ../apps/ll-builder/src/main.cpp:329
#: ../apps/ll-builder/src/main.cpp:336
msgid "Display and manage repositories"
msgstr "Display and manage repositories"

#: ../apps/ll-builder/src/main.cpp:330
#: ../apps/ll-builder/src/main.cpp:337
msgid "Usage: ll-builder repo [OPTIONS] SUBCOMMAND"
msgstr "Usage: ll-builder repo [OPTIONS] SUBCOMMAND"

#: ../apps/ll-builder/src/main.cpp:335
#: ../apps/ll-builder/src/main.cpp:342
msgid "Usage: ll-builder repo add [OPTIONS] NAME URL"
msgstr "Usage: ll-builder repo add [OPTIONS] NAME URL"

#: ../apps/ll-builder/src/main.cpp:345
#: ../apps/ll-builder/src/main.cpp:352
msgid "Usage: ll-builder repo remove [OPTIONS] NAME"
msgstr "Usage: ll-builder repo remove [OPTIONS] NAME"

#: ../apps/ll-builder/src/main.cpp:352
#: ../apps/ll-builder/src/main.cpp:359
msgid "Usage: ll-builder repo update [OPTIONS] NAME URL"
msgstr "Usage: ll-builder repo update [OPTIONS] NAME URL"

#: ../apps/ll-builder/src/main.cpp:363
#: ../apps/ll-builder/src/main.cpp:370
msgid "Usage: ll-builder repo set-default [OPTIONS] NAME"
msgstr "Usage: ll-builder repo set-default [OPTIONS] NAME"

#: ../apps/ll-builder/src/main.cpp:370
#: ../apps/ll-builder/src/main.cpp:377
msgid "Usage: ll-builder repo show [OPTIONS]"
msgstr "Usage: ll-builder repo show [OPTIONS]"

#: ../apps/ll-builder/src/main.cpp:375
#: ../apps/ll-builder/src/main.cpp:382
msgid "linyaps build tool version "
msgstr "linyaps build tool version "
Loading

0 comments on commit abde9d1

Please sign in to comment.