Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from serpent-os/add-path-types
Browse files Browse the repository at this point in the history
Add path types
  • Loading branch information
ermo committed Aug 15, 2022
2 parents 2374519 + 440643a commit 2438ec5
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 89 deletions.
32 changes: 32 additions & 0 deletions nano-path-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name : nano
version : 6.4
release : 3
homepage : https://www.nano-editor.org/dist/v6
upstreams :
- https://www.nano-editor.org/dist/v6/nano-6.4.tar.xz : 4199ae8ca78a7796de56de1a41b821dc47912c0307e9816b56cc317df34661c0
summary : GNU Text Editor
description : |
GNU nano is a small and friendly text editor.
Besides basic text editing, nano offers features like undo/redo,
syntax coloring, interactive search-and-replace, auto-indentation,
line numbers, word completion, file locking, backup files,
and internationalization support.
license :
- GPL-3.0-or-later
builddeps :
- make
- file-devel
- ncurses-devel
- zlib-devel
setup : |
%configure
build : |
%make
install : |
%make_install
packages :
- "%(name)-sharedoc":
paths:
- "/usr/share/doc"
toolchain : gnu
49 changes: 26 additions & 23 deletions source/boulder/controller.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import std.algorithm : filter;
import std.exception : enforce;
import std.experimental.logger;
import std.file : exists, rmdirRecurse, thisExePath;
import std.format : format;
import std.parallelism : totalCPUs;
import std.path : absolutePath, baseName, buildNormalizedPath, dirName, buildNormalizedPath;
import std.range : take;
import std.string : format;

/**
* This is the main entry point for all build commands which will be dispatched
Expand Down Expand Up @@ -65,18 +65,19 @@ public final class Controller : StageContext
{
if (!mossBinary.exists)
{
fatalf("Cannot find `moss` at: %s", _mossBinary);
fatal(format!"Cannot find `moss` at: %s"(_mossBinary));
}
if (!containerBinary.exists)
{
fatalf("Cannot find `moss-container` at: %s", _containerBinary);
fatal(format!"Cannot find `moss-container` at: %s"(_containerBinary));
}

tracef("moss: %s", _mossBinary);
tracef("moss-container: %s", _containerBinary);
trace(format!"moss: %s"(_mossBinary));
trace(format!"moss-container: %s"(_containerBinary));
}
else
{
trace(format!"moss: %s"(_mossBinary));
warning("RUNNING BOULDER WITHOUT CONFINEMENT");
}

Expand Down Expand Up @@ -154,13 +155,26 @@ public final class Controller : StageContext
void build(in string filename)
{
auto fi = File(filename, "r");
trace(format!"%s: Parsing recipe file %s"(__FUNCTION__, filename));
recipe = new Spec(fi);
recipe.parse();

trace(format!"%s: Constructing BuildJob from parsed recipe %s"(__FUNCTION__, filename));
_job = new BuildJob(recipe, filename);

scope (exit)
{
fi.close();
/* Unmount anything mounted on both error and normal exit */
foreach_reverse (ref m; mountPoints)
{
trace(format!"Unmounting %s"(m));
m.unmountFlags = UnmountFlags.Force | UnmountFlags.Detach;
auto err = m.unmount();
if (!err.isNull())
{
error(format!"Unmount failure: %s (%s)"(m.target, err.get.toString));
}
}
}

int stageIndex = 0;
Expand All @@ -177,15 +191,15 @@ public final class Controller : StageContext
auto stage = boulderStages[stageIndex];
enforce(stage.functor !is null);

tracef("Stage begin: %s", stage.name);
trace(format!"Stage begin: %s"(stage.name));
StageReturn result = StageReturn.Failure;
try
{
result = stage.functor(this);
}
catch (Exception e)
{
errorf("Exception: %s", e.message);
error(format!"Exception: %s"(e.message));
result = StageReturn.Failure;
}

Expand All @@ -198,29 +212,18 @@ public final class Controller : StageContext
final switch (result)
{
case StageReturn.Failure:
errorf("Stage failure: %s", stage.name);
error(format!"Stage failure: %s"(stage.name));
break build_loop;
case StageReturn.Success:
infof("Stage success: %s", stage.name);
info(format!"Stage success: %s"(stage.name));
++stageIndex;
break;
case StageReturn.Skipped:
tracef("Stage skipped: %s", stage.name);
trace(format!"Stage skipped: %s"(stage.name));
++stageIndex;
break;
}
}

/* Unmount anything mounted */
foreach_reverse (ref m; mountPoints)
{
m.unmountFlags = UnmountFlags.Force | UnmountFlags.Detach;
auto err = m.unmount();
if (!err.isNull())
{
errorf("Unmount failure: %s (%s)", m.target, err.get.toString);
}
}
}

/**
Expand Down Expand Up @@ -260,7 +263,7 @@ private:
{
fetcher.clear();
failFlag = true;
errorf("Download failure: %s (reason: %s)", f.sourceURI, failMsg);
error(format!"Download failure: %s (reason: %s)"(f.sourceURI, failMsg));
}

/**
Expand Down
14 changes: 13 additions & 1 deletion source/boulder/stages/build_package.d
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ static private StageReturn buildPackageConfined(scope StageContext context)
"-b", context.job.guestPaths.buildRoot,
join([context.job.guestPaths.recipe, context.job.name], "/")
];
/* '-d' was supplied to the boulder invocation, carry it on to mason */
if (globalLogLevel == LogLevel.trace)
{
args ~= "-d";
}
if (archCommand !is null)
{
args ~= archCommand;
}
trace(format!"%s: executeCommand(%s, %s, %s, \"/\")"(__FUNCTION__, context.containerBinary, args, environ));
auto result = executeCommand(context.containerBinary, args, environ, "/");
auto ret = result.match!((int err) => err != 0 ? StageReturn.Failure
: StageReturn.Success, (e) => StageReturn.Failure);
Expand All @@ -110,12 +116,18 @@ static private StageReturn buildPackageUnconfined(scope StageContext context)
"-u", "nobody", "--",
/* fakeroot pls! */
"fakeroot", "--",
/* Buidl with mason */
/* Build with mason */
"mason", "build", "-o", context.job.hostPaths.artefacts, "-b",
context.job.hostPaths.buildRoot, "-a", context.architecture,
/* Here be your recipe. */
join([context.job.unconfinedRecipe, context.job.name], "/")
];
/* '-d' was supplied to the boulder invocation, carry it on to mason */
if (globalLogLevel == LogLevel.trace)
{
args ~= "-d";
}
trace(format!"%s: executeCommand('runuser, %s, %s, \"/\"')"(__FUNCTION__, args, environ));
auto result = executeCommand("runuser", args, environ, "/");
auto ret = result.match!((int err) => err != 0 ? StageReturn.Failure
: StageReturn.Success, (e) => StageReturn.Failure);
Expand Down
53 changes: 31 additions & 22 deletions source/mason/build/builder.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@

module mason.build.builder;

import moss.format.source.spec;
import mason.build.context;
import core.sys.posix.sys.stat;
import mason.build.collector;
import mason.build.profile;
import mason.build.context;
import mason.build.emitter;
import mason.build.profile;
import mason.build.util;
import moss.deps.analysis.elves;
import moss.deps.analysis;
import moss.format.source.spec;
import std.algorithm : each, filter, canFind;
import moss.deps.analysis.elves;
import std.experimental.logger;
import std.path : dirName, baseName;
import std.string : startsWith, endsWith, format;
import std.experimental.logger;

import core.sys.posix.sys.stat;

/**
* As far as boulder is concerned, any directory mode 0755 is utterly uninteresting
Expand Down Expand Up @@ -71,6 +70,7 @@ public:
*/
this(string nativeArchitecture)
{
trace(__FUNCTION__);
if (buildContext.rootDir is null)
{
buildContext.rootDir = getBuildRoot();
Expand Down Expand Up @@ -236,6 +236,7 @@ private:
* Setup our boulder chains */
void setupChains()
{
trace(__FUNCTION__);
const auto boulderChains = [
/* Highest policy */
AnalysisChain("badFiles", [&dropBadPaths], 100),
Expand Down Expand Up @@ -396,6 +397,7 @@ private:
auto debugInfoPath = join([
instance.profiles[0].installRoot, debugInfoPathRelative
], "/");
trace("debugInfoPath: ", debugInfoPath);
auto debugInfoDir = debugInfoPath.dirName;
debugInfoDir.mkdirRecurse();

Expand Down Expand Up @@ -465,25 +467,27 @@ private:

if (code == 0)
{
tracef("strip: %s", fileInfo.path);
trace(format!"strip: %s"(fileInfo.path));
}

return AnalysisReturn.NextFunction;
}

/**
* Explicitly requested addition of some path, so add it now.
*/
* Explicitly requested addition of some path, so add it now.
*/
void collectPath(in string path, in string root)
{
import std.path : relativePath;
import std.string : format;

debug { trace(format!"%s: %s"(__FUNCTION__, path)); }
auto targetPath = path.relativePath(root);
if (targetPath[0] != '/')
{
targetPath = format!"/%s"(targetPath);
}
/// FIXME: care about type information
auto inf = FileInfo(targetPath, path);
inf.target = collector.packageTarget(targetPath);
analyser.addFile(inf);
Expand All @@ -497,6 +501,8 @@ private:
{
import std.file : dirEntries, DirEntry, SpanMode;

trace(__FUNCTION__);

/**
* Custom recursive dirEntries (DFS) style function which lets us
* detect empty directories and directories with special permissions
Expand Down Expand Up @@ -547,6 +553,7 @@ private:
import std.algorithm : map, each, joiner;
import std.array : array;

trace(__FUNCTION__);
string[] arches = ["base"];
arches ~= architectures;

Expand All @@ -569,46 +576,48 @@ private:
* PackageDefinition merged object. This comes from the spec and
* our base definitions.
*/
void addDefinition(PackageDefinition pd)
void addDefinition(PackageDefinition pkd)
{
import std.algorithm : each, uniq, sort;
import std.range : chain;
import std.array : array;

trace(format!"%s: '%s'"(__FUNCTION__, pkd.name));
/* Always insert paths as they're encountered */
pd = buildContext.spec.expand(pd);
void insertRule(const(string) name)
pkd = buildContext.spec.expand(pkd);

void insertRule(const(PathDefinition) pd)
{
collector.addRule(name, pd.name, inclusionPriority);
collector.addRule(pd, pkd.name, inclusionPriority);
++inclusionPriority;
}

pd.paths.each!((p) => insertRule(p));
pkd.paths.each!((pd) => insertRule(pd));

/* Insert new package if needed */
if (!(pd.name in packages))
if (!(pkd.name in packages))
{
packages[pd.name] = pd;
packages[pkd.name] = pkd;
return;
}

/* Merge rules */
auto oldPkg = &packages[pd.name];
oldPkg.runtimeDependencies = oldPkg.runtimeDependencies.chain(pd.runtimeDependencies)
auto oldPkg = &packages[pkd.name];
oldPkg.runtimeDependencies = oldPkg.runtimeDependencies.chain(pkd.runtimeDependencies)
.uniq.array;
oldPkg.paths = oldPkg.paths.chain(pd.paths).uniq.array;
oldPkg.paths = oldPkg.paths.chain(pkd.paths).uniq.array;

sort(oldPkg.runtimeDependencies);
sort(oldPkg.paths);

/* Merge details */
if (oldPkg.summary is null)
{
oldPkg.summary = pd.summary;
oldPkg.summary = pkd.summary;
}
if (oldPkg.description is null)
{
oldPkg.description = pd.description;
oldPkg.description = pkd.description;
}
}

Expand Down
Loading

0 comments on commit 2438ec5

Please sign in to comment.