shithub: mc

Download patch

ref: d7d976b9e1b50fc1fd761e560fe3990f2399db4f
parent: debe132462d524de672e982f5982cc5882d2490b
author: Ori Bernstein <[email protected]>
date: Tue Apr 14 20:23:48 EDT 2015

Walk up the directory tree to the project root.

    This necessitates some name changes in the mbld input files
    in order to know when to walking up the tree. is renamed to
    one of bld.proj or bld.sub, for project roots and subprojects.

        bld.proj:       The project file. This goes at the root
                        of the project heirarchy, and mbld walks
                        up the directory tree until it finds it.

                        A bldfile may call to a subbuild using
                        bld.proj, and all project-relative things
                        will be relative to the most recent bld.proj.

        bld.sub:        The subproject file. mbld includes these
                        from the parent directories.

    Dependencies can now be specified using @/, relative
    to the project directory, since the '@' symbol is now a
    word character.

--- a/mbld/bldfile
+++ b/mbld/bldfile
@@ -18,10 +18,10 @@
 	# Currently, mbld doesn't add all deps transitively.
 	# Until this gets fixed, we need to list all dependent
 	# libraries here explicitly.
-	lib ../libstd:sys
-	lib ../libstd:std
-	lib ../libbio:bio
-	lib ../libregex:regex
+	lib @/libstd:sys
+	lib @/libstd:std
+	lib @/libbio:bio
+	lib @/libregex:regex
 ;;
 
 gen config.myr {durable} =
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -52,7 +52,6 @@
 		;;
 	;;
 	if bld.opt_instroot.len > 0 && !std.sleq(bld.opt_instroot, "none")
-		std.put("instroot: %s\n", bld.opt_instroot)
 		libpath = std.pathcat(bld.opt_instroot, "lib/myr")
 		bld.opt_incpaths = std.slpush(bld.opt_incpaths, libpath)
 	;;
@@ -62,7 +61,7 @@
 	| `std.Fail f:	std.fatal(1, "Failed to compile use pattern regex\n")
 	;;
 
-	b = mkbuild()
+	b = mkbuild(bld.opt_bldfile)
 	if targname.len != 0
 		mt = [
 			.name=targname,
@@ -78,7 +77,7 @@
 			bld.buildlib(b, &mt)
 		;;
 	else
-		bld.load(b, bld.opt_bldfile)
+		bld.load(b)
 		/*bld.configure()*/
 		/* default: buildall */
 		if optctx.args.len == 0
@@ -99,18 +98,35 @@
 	;;
 }
 
-const mkbuild = {
+const mkbuild = {bldfile
 	var b
 
 	b = std.zalloc()
 	b.targs = std.mkht(std.strhash, std.streq)
 	b.gensrc = std.mkht(std.strhash, std.streq)
-	/*
-	b.basedir = std.sldup("/Users/orib/src/myr/mc")
-	*/
-	b.basedir = std.getcwd()
+	if !findbase(b, bldfile) || !std.chdir(b.basedir)
+		std.fatal(1, "could not find %s\n", bldfile)
+	;;
 	b.curdir = ""
 	-> b
+}
+
+const findbase = {b, file
+	var p, bld, dir
+
+	dir = std.getcwd()
+	while !std.sleq(dir, "/")
+		bld = std.pathcat(dir, file)
+		if std.fexists(bld)
+			b.basedir = dir
+			b.bldfile = bld
+			-> true
+		;;
+		p = std.pathcat(dir, "..")
+		std.slfree(dir)
+		dir = p
+	;;
+	-> false
 }
 
 const usage = {prog
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -38,7 +38,7 @@
 var opt_manpath	= ""
 var opt_destdir	= ""
 var opt_debug	= false
-var opt_bldfile = "bldfile"
+var opt_bldfile = "bld.proj"
 var opt_mc	= "6m"
 var opt_as	= "as"
 var opt_muse	= "muse"
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -6,7 +6,7 @@
 use "fsel.use"
 
 pkg bld =
-	const load	: (b : build#, path : byte[:]	-> bool)
+	const load	: (b : build# -> bool)
 ;;
 
 type parser = struct
@@ -22,23 +22,44 @@
 	subdirs	: byte[:][:]
 ;;
 
-const load = {b, path
-	-> loadall(b, path, "")
+const load = {b
+	-> loadall(b, b.bldfile, "")
 }
 
 
 const loadall = {b, path, dir
 	var p : parser#
-	var subpath, subbld, ok
+	var subpath, subbld, subproj, ok
+	var curbase
 
 	p = mkparser(path, dir, b.basedir)
 	ok = bld.parse(b, p, "")
 	for s in p.subdirs
 		subpath = std.pathcat(p.fdir, s)
-		subbld = std.pathcat(subpath, "bldfile")
-		loadall(b, subbld, subpath)
-		std.slfree(subpath)
+		subbld = std.pathcat(subpath, "bld.sub")
+		subproj = std.pathcat(subpath, "bld.proj")
+		/*
+		bld.sub is a subbuild. It doesn't change the
+		build root.
+		*/
+		if std.fexists(subbld)
+			loadall(b, subbld, subpath)
+		/*
+		bld.proj reroots the project -- @/
+		is relative to the most recent bld.proj
+		in the heirarchy.
+		*/
+		elif std.fexists(subproj)
+			curbase = b.basedir
+			b.basedir = subpath
+			loadall(b, subproj, subpath)
+			b.basedir = curbase
+		else
+			std.fatal(1, "could not open %s or %s \n", subbld, subproj)
+		;;
 		std.slfree(subbld)
+		std.slfree(subproj)
+		std.slfree(subpath)
 	;;
 	freeparser(p)
 	-> ok
@@ -450,8 +471,9 @@
 const wordchar = {c
 	-> std.isalnum(c) || \
 		c == '.' || c == '_' || c == '$' || c == '-' || \
-		c == '/' || c == ':' || c == '!' || c == '~' || \
-		c == '+'
+		c == '/' || c == '@' || c == '!' || c == '~' || \
+		c == '+' || c == '%' || c == '&' || c == '(' || \
+		c == ')' || c == '[' || c == ']' || c == ':'
 }
 
 const skipspace = {p
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -5,6 +5,7 @@
 		cmd	: byte[:][:]	/* command that we ran */
 		/* build state */
 		basedir	: byte[:]
+		bldfile	: byte[:]
 		curdir	: byte[:]
 		/* build params */
 		all	: byte[:][:]
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -114,7 +114,7 @@
 
 		std.put("Entering directory '%s'\n", dir)
 		if !std.chdir(p)
-			std.fatal(1, "could not cd into %s\n")
+			std.fatal(1, "could not cd into %s\n", p)
 		;;
 		b.curdir = dir
 		std.slfree(p)