Hi Stephen,

On Thu, Apr 3, 2014 at 12:16 PM, stevek <[email protected]> wrote:

>
> Hi all,
>
> I recently tried tup in a reasonably complex scenario. Building consists
> of:
>
> * building a custom generation tool
> * running the tool to generate headers
> * compiling the source (a mix of generated & "original" files)
> * inter project dependencies
> * multiple build variants
>
> I was pleasantly surprised that tup does a pretty good job of it! It
> leaves the source tree pristine and although the errors are quite terse,
> it's good to be strict.
>
> On the bad side, I wasted a bit of time trying to get things to work using
> the builtin syntax before abandoning it and outputting rules directly.
>
> Interestingly, as soon as I used the run command, my tupfiles were almost
> empty. I suspect this will be the case for a lot of people since for cross
> platform development, the rules/config is stored somewhere else and
> makefiles/tupfiles etc are generated from them. In the case of tup, is
> there any need to have Tupfiles at all? I didn't have any luck getting tup
> to generate tupfiles on the fly, but that's exactly what would be wonderful
> - the equivalent of "run" except that it outputs pairs of (source folder,
> tup rule generator).
>
>
Have you tried the Lua parser instead of using a run script? Personally I
have found that using a python run-script doesn't scale very well for large
projects, though for a small one you might not notice. See the first patch
for what that might look like - it should generate the same rules as your
python script.

Also I'd suggest using a single group at the root of your project, rather
than one per directory. For example, rather than have a
myproj/source/util/<AutoGen> and a myproj/source/base/<AutoGen>, you could
just have a myproj/<AutoGen>. The second patch adds on to the Lua script to
use just a single <AutoGen> and a single <Libs> group. Note you could do
this with the python script, too.

With the rules in the Lua setup, you can experiment with a Tupdefault.lua
file, so you don't need to put one in each directory.

-Mike

-- 
-- 
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 068e5336570f8d8d1eeaeecc73e202972416c43e Mon Sep 17 00:00:00 2001
From: Mike Shal <[email protected]>
Date: Thu, 10 Apr 2014 23:12:17 -0400
Subject: [PATCH 1/2] Part 1 - use lua instead

---
 Tuprules.lua            | 43 +++++++++++++++++++++++++++++++++++++++++++
 exe1/Tupfile            |  1 -
 exe1/Tupfile.lua        |  1 +
 exe2/Tupfile            |  1 -
 exe2/Tupfile.lua        |  1 +
 source/base/Tupfile     |  2 --
 source/base/Tupfile.lua |  1 +
 source/util/Tupfile     |  1 -
 source/util/Tupfile.lua |  1 +
 9 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 Tuprules.lua
 delete mode 100644 exe1/Tupfile
 create mode 100644 exe1/Tupfile.lua
 delete mode 100644 exe2/Tupfile
 create mode 100644 exe2/Tupfile.lua
 delete mode 100644 source/base/Tupfile
 create mode 100644 source/base/Tupfile.lua
 delete mode 100644 source/util/Tupfile
 create mode 100644 source/util/Tupfile.lua

diff --git a/Tuprules.lua b/Tuprules.lua
new file mode 100644
index 0000000..db90894
--- /dev/null
+++ b/Tuprules.lua
@@ -0,0 +1,43 @@
+my_root = tup.getcwd()
+generate_bin = my_root .. '/bin/generate'
+
+function gen_header_rules()
+	inputs = {'*.h'}
+	inputs.extra_inputs = {generate_bin}
+	outputs = {'_Auto/%B.inl', '<AutoGen>'}
+	command = generate_bin .. ' %f'
+	tup.foreach_rule(inputs, command, outputs)
+end
+
+function gen_cc_rules(deps)
+	inputs = {'*.cpp'}
+	include_flags = ""
+	inputs.extra_inputs = {'<AutoGen>'}
+	if deps then
+		for k, v in ipairs(deps) do
+			inputs.extra_inputs += v .. "/<AutoGen>"
+			include_flags = include_flags .. " -I" .. v
+		end
+	end
+	command = '^ CC %f^ @(CXX) @(CXXFLAGS) $(include_flags) -c %f -o %o'
+	tup.foreach_rule(inputs, command, '%B.o')
+end
+
+function gen_rules(project_type, deps)
+	gen_header_rules()
+	gen_cc_rules(deps)
+
+	if project_type == 'lib' then
+		outputs = {my_root .. '/bin/lib%d.a'}
+		outputs.extra_outputs = {'<Built>'}
+		tup.rule('*.o', '^ AR %o^ @(AR) %o %f', outputs)
+	elseif project_type == 'exe' then
+		linkflags = '-L' .. my_root .. '/bin'
+		inputs = {'*.o'}
+		for k, v in ipairs(deps) do
+			inputs.extra_inputs += v .. '/<Built>'
+			linkflags = linkflags .. ' -l' .. (v:gsub('.*/', ''))
+		end
+		tup.rule(inputs, '^ LINK %o^ @(LINK) -o %o %f $(linkflags)', my_root .. '/bin/%d')
+	end
+end
diff --git a/exe1/Tupfile b/exe1/Tupfile
deleted file mode 100644
index 0373bf6..0000000
--- a/exe1/Tupfile
+++ /dev/null
@@ -1 +0,0 @@
-run ../bin/list-tup-rules exe ../source/base
diff --git a/exe1/Tupfile.lua b/exe1/Tupfile.lua
new file mode 100644
index 0000000..fe0b050
--- /dev/null
+++ b/exe1/Tupfile.lua
@@ -0,0 +1 @@
+gen_rules('exe', {'../source/base'})
diff --git a/exe2/Tupfile b/exe2/Tupfile
deleted file mode 100644
index ded6cb1..0000000
--- a/exe2/Tupfile
+++ /dev/null
@@ -1 +0,0 @@
-run ../bin/list-tup-rules exe ../source/base ../source/util
diff --git a/exe2/Tupfile.lua b/exe2/Tupfile.lua
new file mode 100644
index 0000000..562bc16
--- /dev/null
+++ b/exe2/Tupfile.lua
@@ -0,0 +1 @@
+gen_rules('exe', {'../source/base', '../source/util'})
diff --git a/source/base/Tupfile b/source/base/Tupfile
deleted file mode 100644
index 9147668..0000000
--- a/source/base/Tupfile
+++ /dev/null
@@ -1,2 +0,0 @@
-run ../../bin/list-tup-rules lib
-
diff --git a/source/base/Tupfile.lua b/source/base/Tupfile.lua
new file mode 100644
index 0000000..7a0ffca
--- /dev/null
+++ b/source/base/Tupfile.lua
@@ -0,0 +1 @@
+gen_rules('lib')
diff --git a/source/util/Tupfile b/source/util/Tupfile
deleted file mode 100644
index 725cec6..0000000
--- a/source/util/Tupfile
+++ /dev/null
@@ -1 +0,0 @@
-run ../../bin/list-tup-rules lib
diff --git a/source/util/Tupfile.lua b/source/util/Tupfile.lua
new file mode 100644
index 0000000..7a0ffca
--- /dev/null
+++ b/source/util/Tupfile.lua
@@ -0,0 +1 @@
+gen_rules('lib')
-- 
1.8.1.5

From 143e8bfead1ed225c1183ce06e06d776ae3583ff Mon Sep 17 00:00:00 2001
From: Mike Shal <[email protected]>
Date: Thu, 10 Apr 2014 23:21:15 -0400
Subject: [PATCH 2/2] single group at root

---
 Tuprules.lua | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Tuprules.lua b/Tuprules.lua
index db90894..b9d0160 100644
--- a/Tuprules.lua
+++ b/Tuprules.lua
@@ -1,10 +1,12 @@
 my_root = tup.getcwd()
+autogen_group = my_root .. '/<AutoGen>'
+libs_group = my_root .. '/<Libs>'
 generate_bin = my_root .. '/bin/generate'
 
 function gen_header_rules()
 	inputs = {'*.h'}
 	inputs.extra_inputs = {generate_bin}
-	outputs = {'_Auto/%B.inl', '<AutoGen>'}
+	outputs = {'_Auto/%B.inl', autogen_group}
 	command = generate_bin .. ' %f'
 	tup.foreach_rule(inputs, command, outputs)
 end
@@ -12,10 +14,9 @@ end
 function gen_cc_rules(deps)
 	inputs = {'*.cpp'}
 	include_flags = ""
-	inputs.extra_inputs = {'<AutoGen>'}
+	inputs.extra_inputs = {autogen_group}
 	if deps then
 		for k, v in ipairs(deps) do
-			inputs.extra_inputs += v .. "/<AutoGen>"
 			include_flags = include_flags .. " -I" .. v
 		end
 	end
@@ -29,13 +30,13 @@ function gen_rules(project_type, deps)
 
 	if project_type == 'lib' then
 		outputs = {my_root .. '/bin/lib%d.a'}
-		outputs.extra_outputs = {'<Built>'}
+		outputs.extra_outputs = {libs_group}
 		tup.rule('*.o', '^ AR %o^ @(AR) %o %f', outputs)
 	elseif project_type == 'exe' then
 		linkflags = '-L' .. my_root .. '/bin'
 		inputs = {'*.o'}
+		inputs.extra_inputs = {libs_group}
 		for k, v in ipairs(deps) do
-			inputs.extra_inputs += v .. '/<Built>'
 			linkflags = linkflags .. ' -l' .. (v:gsub('.*/', ''))
 		end
 		tup.rule(inputs, '^ LINK %o^ @(LINK) -o %o %f $(linkflags)', my_root .. '/bin/%d')
-- 
1.8.1.5

Reply via email to