Skip to content

Commit

Permalink
fix(ll-builder): format output information
Browse files Browse the repository at this point in the history
-

Log:
  • Loading branch information
kamiyadm authored and black-desk committed Jan 16, 2024
1 parent cd6bd12 commit cefb8cf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
22 changes: 13 additions & 9 deletions src/linglong/builder/depend_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ DependFetcher::~DependFetcher() = default;
void DependFetcher::printProgress(const uint &progress, const QString &speed)
{
printer.printReplacedText(QString("%1%2%3%4 (%5\% %6/s)")
.arg(ref.appId, -20)
.arg(ref.version, -15)
.arg(ref.module, -15)
.arg("downloading")
.arg(progress)
.arg(speed));
.arg(ref.appId, -20)
.arg(ref.version, -15)
.arg(ref.module, -15)
.arg("downloading")
.arg(progress)
.arg(speed),
2);
}

linglong::util::Error DependFetcher::fetch(const QString &subPath, const QString &targetPath)
Expand All @@ -79,7 +80,8 @@ linglong::util::Error DependFetcher::fetch(const QString &subPath, const QString
.arg(ref.appId, -20)
.arg(ref.version, -15)
.arg(ref.module, -15)
.arg("..."));
.arg("..."),
2);
auto ret = ostree.pull(ref, true);
if (!ret.has_value()) {
return WrapError(NewError(ret.error().code(), ret.error().message()),
Expand All @@ -95,7 +97,8 @@ linglong::util::Error DependFetcher::fetch(const QString &subPath, const QString
.arg(ref.appId, -20)
.arg(ref.version, -15)
.arg(ref.module, -15)
.arg("checkout"));
.arg("checkout"),
2);
auto ret = ostree.checkout(ref, subPath, targetPath);
if (!ret.has_value()) {
return WrapError(NewError(ret.error().code(), ret.error().message()),
Expand All @@ -106,7 +109,8 @@ linglong::util::Error DependFetcher::fetch(const QString &subPath, const QString
.arg(ref.appId, -20)
.arg(ref.version, -15)
.arg(ref.module, -15)
.arg("complete\n"));
.arg("complete\n"),
2);
}
// for app,lib. if the dependType match runtime, should be submitted together.
if (dd_ptr->dependType == DependTypeRuntime) {
Expand Down
24 changes: 20 additions & 4 deletions src/linglong/builder/linglong_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,27 @@ linglong::util::Error LinglongBuilder::build()

project->generateBuildScript();
project->configFilePath = projectConfigPath;

linglong::builder::BuilderConfig::instance()->setProjectName(project->package->id);

printer.printMessage("[Build Target]");
printer.printMessage(project->package->id, 2);
printer.printMessage("[Project Info]");
printer.printMessage(QString("Packge Name: %1").arg(project->package->name), 2);
printer.printMessage(QString("Version: %1").arg(project->package->version), 2);
printer.printMessage(QString("Packge Type: %1").arg(project->package->kind), 2);
printer.printMessage(QString("Build Arch: %1").arg(project->config().targetArch()), 2);

printer.printMessage("[Current Repo]");
printer.printMessage(QString("Name: %1").arg(BuilderConfig::instance()->remoteRepoName), 2);
printer.printMessage(QString("Url: %1").arg(BuilderConfig::instance()->remoteRepoEndpoint), 2);

if (!project->package || project->package->kind.isEmpty()) {
return NewError(-1, "unknown package kind");
}

SourceFetcher sf(project->source, printer, project.get());
if (project->source) {
printer.printMessage(QString("fetching source code from: %1").arg(project->source->url));
printer.printMessage("[Processing Source]");
auto err = sf.fetch();
if (err) {
return NewError(-1, "fetch source failed");
Expand All @@ -529,6 +540,10 @@ linglong::util::Error LinglongBuilder::build()
util::ensureDir(project->config().cacheAbsoluteFilePath(
{ "overlayfs", "up", project->config().targetInstallPath("") }));

printer.printMessage("[Processing Dependency]");
printer.printMessage(
QString("%1%2%3%4").arg("Package", -20).arg("Version", -15).arg("Module", -15).arg("Status"),
2);
package::Ref baseRef("");

QString hostBasePath;
Expand Down Expand Up @@ -705,16 +720,17 @@ linglong::util::Error LinglongBuilder::build()
r->hooks = r->hooks.value_or(ocppi::runtime::config::types::Hooks{});
r->hooks->prestart = { { std::nullopt, std::nullopt, "/usr/sbin/ldconfig", std::nullopt } };

printer.printMessage("[Start Build]");
if (startContainer(container, *r)) {
return NewError(-1, "build task failed in container");
}

printer.printMessage("[Commit Content]");
auto result = commitBuildOutput(project.get(), anno["overlayfs"]);
if (!result.has_value()) {
return NewError(result.error().code(), result.error().message());
}

printer.printMessage(QString("build %1 success").arg(project->package->id));
printer.printMessage(QString("Build %1 success").arg(project->package->id));
return Success();
}

Expand Down
29 changes: 19 additions & 10 deletions src/linglong/builder/source_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ util::Error SourceFetcherPrivate::fetchGitRepo()
if (!QDir::setCurrent(sourceTargetPath())) {
return NewError(-1, QString("change to %1 failed").arg(sourceTargetPath()));
}

QSharedPointer<QByteArray> output = QSharedPointer<QByteArray>::create();
q->printer.printMessage(QString("git clone --recurse-submodules %1 %2").arg(source->url).arg(sourceTargetPath()));
q->printer.printMessage(
QString("git clone --recurse-submodules %1 %2").arg(source->url).arg(sourceTargetPath()),
2);
auto err = util::Exec("git",
{
"clone",
Expand All @@ -194,7 +196,9 @@ util::Error SourceFetcherPrivate::fetchGitRepo()

QDir::setCurrent(sourceTargetPath());

q->printer.printMessage(QString("git checkout -b %1 %2").arg(source->version).arg(source->commit));
q->printer.printMessage(
QString("git checkout -b %1 %2").arg(source->version).arg(source->commit),
2);
err = util::Exec("git",
{
"checkout",
Expand All @@ -204,17 +208,17 @@ util::Error SourceFetcherPrivate::fetchGitRepo()
},
-1,
output);

if (!output->isEmpty()) {
q->printer.printMessage(QString(output->constData()));
}

if (err) {
q->printer.printMessage("git checkout failed. " + err.message());
q->printer.printMessage("git checkout failed. " + err.message(), 2);
output->clear();
}

q->printer.printMessage(QString("git reset --hard %1").arg(source->commit));
q->printer.printMessage(QString("git reset --hard %1").arg(source->commit), 2);
err = util::Exec("git",
{
"reset",
Expand All @@ -225,7 +229,7 @@ util::Error SourceFetcherPrivate::fetchGitRepo()
output);

if (!output->isEmpty()) {
q->printer.printMessage(QString(output->constData()));
q->printer.printMessage(QString(output->constData()), 2);
}

return WrapError(err, "git reset failed");
Expand All @@ -235,9 +239,9 @@ util::Error SourceFetcherPrivate::handleLocalPatch()
{
Q_Q(SourceFetcher);
// apply local patch
q->printer.printMessage("finding local patch");
q->printer.printReplacedText("Finding local patch ...", 2);
if (source->patch.isEmpty()) {
q->printer.printMessage("nothing to patch");
q->printer.printReplacedText("Nothing to patch\n", 2);
return Success();
}

Expand All @@ -246,12 +250,13 @@ util::Error SourceFetcherPrivate::handleLocalPatch()
qWarning() << QString("this patch is empty, check it");
continue;
}
q->printer.printMessage(QString("applying patch: %1").arg(localPatch));
q->printer.printReplacedText(QString("Applying %1 ...").arg(localPatch), 2);
if (auto err =
util::Exec("patch",
{ "-p1", "-i", project->config().absoluteFilePath({ localPatch }) })) {
return NewError(err, "patch failed");
}
q->printer.printReplacedText(QString("Applying %1 done\n").arg(localPatch), 2);
}

return Success();
Expand Down Expand Up @@ -288,8 +293,10 @@ linglong::util::Error SourceFetcher::fetch()
util::Error err;

if (d->source->kind == "git") {
printer.printMessage(QString("Source: %1").arg(d->source->url), 2);
err = d->fetchGitRepo();
} else if (d->source->kind == "archive") {
printer.printMessage(QString("Source: %1").arg(d->source->url), 2);
QString s;
std::tie(s, err) = d->fetchArchiveFile();
if (err) {
Expand All @@ -298,7 +305,9 @@ linglong::util::Error SourceFetcher::fetch()
err = d->extractFile(s, d->sourceTargetPath());
} else if (d->source->kind == "local") {
err = d->handleLocalSource();
printer.printMessage(QString("Source: %1").arg(sourceRoot()), 2);
} else if (d->source->kind == "file") {
printer.printMessage(QString("Source: %1").arg(d->source->url), 2);
QString s;
std::tie(s, err) = d->fetchArchiveFile();
if (err) {
Expand Down

0 comments on commit cefb8cf

Please sign in to comment.