shithub: mc

Download patch

ref: 5bc9a99994e20a7d5ea6bc298e4b37bf7db2e48d
parent: f8152dae21873cf42f2d65bdf657a717c2240a25
author: Ori Bernstein <ori@eigenstate.org>
date: Fri May 13 15:31:35 EDT 2016

Switch to using lib{}.use.

    Does 3 things;

        1) Teaches the compiler about how to load libfoo.use, falling
           back to 'foo'
        2) teaches muse how to generate packages named 'pkg' in fille
           'libthing.use'
        3) teaches mbld how to look up and resolve libfoo.use named
           usefiles.

    Eventually a fallback will be implemented.

--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -359,6 +359,8 @@
 	cmd = [][:]
 	std.slpush(&cmd, std.sldup(opt_muse))
 	std.slpush(&cmd, std.sldup("-o"))
+	std.slpush(&cmd, std.fmt("lib{}.use", lib))
+	std.slpush(&cmd, std.sldup("-p"))
 	std.slpush(&cmd, std.sldup(lib))
 	for f in files
 		if std.hassuffix(f, ".myr")
@@ -449,7 +451,7 @@
 		std.slfree(p)
 	;;
 
-	p = std.pathjoin([opt_instbase, config.Libpath, lib][:])
+	p = std.pathjoin([opt_instbase, config.Libpath, sl][:])
 	if std.fexists(p)
 		-> `std.Some p
 	;;
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -360,38 +360,40 @@
 }
 
 const openlib = {lib, incs
-	var path
+	var path, libname
 
 	for p in incs
+		libname = std.fmt("lib{}.use", lib)
+		path = std.pathjoin([p, libname][:])
+		std.slfree(libname)
+		if std.fisreg(path)
+			goto found
+		;;
+		std.slfree(path)
+
 		path = std.pathjoin([p, lib][:])
-		if !std.fisreg(path)
-			std.slfree(path)
-			continue
+		if std.fisreg(path)
+			goto found
 		;;
-		match  bio.open(path, bio.Rd)
-		| `std.Ok file:
-			std.slfree(path)
-			-> file
-		| `std.Fail m:
-			std.fput(std.Err, "could not open {}: {}\n", path, m)
-			goto error
-		;;
+		std.slfree(path)
 	;;
-	path = std.pathjoin([opt_instbase, config.Libpath, lib][:])
+
+	libname = std.fmt("lib{}.use", lib)
+	path = std.pathjoin([opt_instbase, config.Libpath, libname][:])
+	std.slfree(libname)
+:found
 	match  bio.open(path, bio.Rd)
 	| `std.Ok file:
 		std.slfree(path)
 		-> file
-	| `std.Fail m:	/* nothing */
+	| `std.Fail m:
 	;;
 	std.fput(std.Err, "could not find library {}\n", lib)
-
-:error
 	std.fput(std.Err, "search path is:\n")
 	for p in incs
 		std.fput(std.Err, "\t{}\n", p)
 	;;
-	std.fput(std.Err, "\t{}\n", path)
+	std.fput(std.Err, "\t{}\n", config.Libpath)
 	std.exit(1)
 }
 
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -23,7 +23,7 @@
 }
 
 const movetargs = {b, rm
-	var libarchive
+	var libarchive, libuse
 	var pfx
 
 	for tn in b.all
@@ -34,10 +34,12 @@
 			;;
 		| `Lib lt:
 			if lt.install && !lt.istest
-				movefile(b, rm, lt.dir, lt.name, config.Libpath, 0o644)
+				libuse = std.fmt("lib{}.use", lt.name)
+				movefile(b, rm, lt.dir, libuse, config.Libpath, 0o644)
 				libarchive = std.fmt("lib{}.a", lt.name)
 				movefile(b, rm, lt.dir, libarchive, config.Libpath, 0o644)
 				std.slfree(libarchive)
+				std.slfree(libuse)
 			;;
 		| `Data dt:
 			for blob in dt.blobs
@@ -75,13 +77,14 @@
 			std.put("\t\tno such file {}\n", file)
 		;;
 	else
-		std.put("\t{} => {}\n", file, path)
 		std.remove(path)
 		match std.slurp(file)
-		| `std.Fail m:	std.fatal("Could not open {} for reading\n", file)
+		| `std.Fail m:	std.fatal("could not open {} for reading\n", file)
 		| `std.Ok buf:
-			if !std.blat(path, buf, perm)
-				std.put("Could not write {}\n", file)
+			if std.blat(path, buf, perm)
+				std.put("\t{} => {}\n", file, path)
+			else
+				std.put("could not write {}\n", file)
 			;;
 		;;
 	;;
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -18,6 +18,7 @@
 /* FIXME: move into one place...? */
 Node *file;
 char *outfile;
+char *pkgname;
 int show;
 char debugopt[128];
 char **incpaths;
@@ -27,7 +28,7 @@
 
 static void usage(char *prog)
 {
-	printf("%s [-hIdos] [-o outfile] [-m] inputs\n", prog);
+	printf("%s [-hIdos] [-o outfile] [-p pkgname] [-m] inputs\n", prog);
 	printf("\t-h\tprint this help\n");
 	printf("\t\tThe outfile must be the same name as each package merged.\n");
 	printf("\t-I path\tAdd 'path' to use search path\n");
@@ -55,7 +56,7 @@
 	size_t i;
 	FILE *f;
 
-	optinit(&ctx, "sd:hmo:I:l:", argv, argc);
+	optinit(&ctx, "sd:hmo:p:I:l:", argv, argc);
 	while (!optdone(&ctx)) {
 		switch (optnext(&ctx)) {
 		case 'h':
@@ -62,6 +63,9 @@
 			usage(argv[0]);
 			exit(0);
 			break;
+		case 'p':
+			pkgname = ctx.optarg;
+			break;
 		case 'o':
 			outfile = ctx.optarg;
 			break;
@@ -90,11 +94,13 @@
 		fprintf(stderr, "output file needed when merging usefiles.\n");
 		exit(1);
 	}
+	if (!pkgname)
+		pkgname = outfile;
 
 	/* read and parse the file */
 	file = mkfile("internal");
 	file->file.globls = mkstab(0);
-	updatens(file->file.globls, outfile);
+	updatens(file->file.globls, pkgname);
 	tyinit(file->file.globls);
 	for (i = 0; i < ctx.nargs; i++)
 		mergeuse(ctx.args[i]);
--- a/parse/use.c
+++ b/parse/use.c
@@ -1042,6 +1042,16 @@
 		/* nonlocal (barename) uses are always searched on the include path */
 	} else {
 		for (i = 0; i < nincpaths; i++) {
+			snprintf(buf, sizeof buf, "lib%s.use", use->use.name);
+			t = strjoin(incpaths[i], "/");
+			p = strjoin(t, buf);
+			fd = fopen(p, "r");
+			if (fd) {
+				free(t);
+				break;
+			}
+			free(p);
+
 			t = strjoin(incpaths[i], "/");
 			p = strjoin(t, use->use.name);
 			fd = fopen(p, "r");