summaryrefslogtreecommitdiff
path: root/lua_scripts
diff options
context:
space:
mode:
authorMika Westerberg <ext-mika.1.westerberg@nokia.com>2009-01-26 16:15:05 +0200
committerLauri Leukkunen <lle@rahina.org>2009-02-10 08:38:10 +0200
commit4cce31b57d50b667b03c34d37b42eb99254368f8 (patch)
treed494fd43ebdcb2b6bfd2de6d40e88c997d89fd07 /lua_scripts
parent11c9ef3f390169ca53f0dd7c3e9b1d584d561987 (diff)
Argv&envp mangling rules are now generated only once per session.
- There is new lua script: create_argvmods_rules.lua which is used to create explicit rules based rules created by argvenvp_xxx.lua. - Separated mangling rules for misc binaries to be in file argvenvp_misc.lua - Rules are generated by sb2 script and placed under $SBOX_SESSION_DIR/argvmods/*. Signed-off-by: Lauri Aarnio <Lauri.Aarnio@iki.fi>
Diffstat (limited to 'lua_scripts')
-rw-r--r--lua_scripts/argvenvp.lua63
-rw-r--r--lua_scripts/argvenvp_gcc.lua3
-rw-r--r--lua_scripts/argvenvp_misc.lua18
-rw-r--r--lua_scripts/create_argvmods_rules.lua85
4 files changed, 148 insertions, 21 deletions
diff --git a/lua_scripts/argvenvp.lua b/lua_scripts/argvenvp.lua
index a5480f9..8337540 100644
--- a/lua_scripts/argvenvp.lua
+++ b/lua_scripts/argvenvp.lua
@@ -4,21 +4,17 @@
--
-- Licensed under MIT license
-argvmods = {}
-
--- only map gcc & friends if a cross compiler has been defined,
--- and it has not been disabled by the mapping rules:
-if (enable_cross_gcc_toolchain == true) then
- local gcc_rule_file_path = session_dir .. "/gcc-conf.lua"
-
- if (sb.path_exists(gcc_rule_file_path)) then
- -- this generates gcc related argv/envp manglings
- do_file(session_dir .. "/lua_scripts/argvenvp_gcc.lua")
- end
-end
-
--- regular mangling rules go here
--- syntax is of the form:
+--
+-- argv&envp mangling rules are separated into two files
+-- argvenvp_misc.lua - rules for misc binaries
+-- argvenvp_gcc.lua - rules for gcc
+--
+-- With these rules, script create_argvmods_rules.lua generates
+-- the actual rules that are loaded into sb2. Generated files
+-- are placed under SBOX_SESSION_DIR/argvmods and they are named
+-- like argvmods_xxx.lua.
+--
+-- Syntax is of the form:
--
-- rule = {
-- name = "binary-name",
@@ -39,12 +35,37 @@ end
-- * new_filename should probably be replaced by integrating argv/envp
-- mangling with the path mapping machinery.
-dpkg_architecture = {
- name = "dpkg-architecture",
- path_prefixes = {"/usr/bin/"},
- remove = {"-f"}
-}
-argvmods[dpkg_architecture.name] = dpkg_architecture
+argvmods = {}
+
+-- only map gcc & friends if a cross compiler has been defined,
+-- and it has not been disabled by the mapping rules:
+if (enable_cross_gcc_toolchain == true) then
+ local gcc_argvmods_file_path =
+ session_dir .. "/argvmods/argvmods_gcc.lua"
+
+ if sb.path_exists(gcc_argvmods_file_path) then
+ -- load in autimatically generated argvmods for gcc
+ do_file(gcc_argvmods_file_path)
+ if debug_messages_enabled then
+ sb.log("debug", string.format(
+ "loaded argvmods for gcc from '%s'",
+ gcc_argvmods_file_path))
+ end
+ end
+end
+
+--
+-- Always load argvmods for misc binaries.
+--
+local misc_argvmods_file_path = session_dir .. "/argvmods/argvmods_misc.lua"
+if sb.path_exists(misc_argvmods_file_path) then
+ do_file(misc_argvmods_file_path)
+ if debug_messages_enabled then
+ sb.log("debug", string.format(
+ "loaded argvmods for misc binaries from '%s'",
+ misc_argvmods_file_path))
+ end
+end
-- ------------------------------------
-- Exec preprocessing.
diff --git a/lua_scripts/argvenvp_gcc.lua b/lua_scripts/argvenvp_gcc.lua
index 4603cac..26ee3bd 100644
--- a/lua_scripts/argvenvp_gcc.lua
+++ b/lua_scripts/argvenvp_gcc.lua
@@ -3,6 +3,9 @@
-- Here is the necessary plumbing to generate gcc related
-- argv/envp manglings
+--
+-- See syntax from argvenvp.lua.
+--
gcc_compilers = {
"cc",
diff --git a/lua_scripts/argvenvp_misc.lua b/lua_scripts/argvenvp_misc.lua
new file mode 100644
index 0000000..c9e58c2
--- /dev/null
+++ b/lua_scripts/argvenvp_misc.lua
@@ -0,0 +1,18 @@
+--
+-- Copyright (c) 2009 Nokia Corporation.
+-- Licensed under MIT license
+--
+
+--
+-- Here is the necessary plumbing to generate argv&envp mangling
+-- for miscellaneous binaries.
+--
+-- See syntax from argvenvp.lua.
+--
+
+dpkg_architecture = {
+ name = "dpkg-architecture",
+ path_prefixes = {"/usr/bin/"},
+ remove = {"-f"},
+}
+argvmods[dpkg_architecture.name] = dpkg_architecture
diff --git a/lua_scripts/create_argvmods_rules.lua b/lua_scripts/create_argvmods_rules.lua
new file mode 100644
index 0000000..8301236
--- /dev/null
+++ b/lua_scripts/create_argvmods_rules.lua
@@ -0,0 +1,85 @@
+--
+-- Copyright (c) 2009 Nokia Corporation.
+--
+-- Licensed under MIT licence
+--
+-- This script reads in argvmods_xxx.lua file (xxx being here
+-- gcc or misc) and writes out lua table containing generated
+-- argvmods rules.
+--
+argvmods = {}
+
+local argvmods_source_file = session_dir .. "/lua_scripts/" ..
+ os.getenv("SBOX_ARGVMODS_SOURCE_FILE")
+do_file(argvmods_source_file)
+
+local allowed_rulenames = {
+ "name",
+ "path_prefixes",
+ "add_head",
+ "add_tail",
+ "remove",
+ "new_filename",
+ "disable_mapping",
+ "drivers",
+}
+
+print("--")
+print("-- Generator: create_argvmods_rules.lua")
+print("-- Source file: " .. argvmods_source_file)
+print("-- Automatically generated rules. Do not modify:")
+print("--")
+
+local count = 0
+for binary_name, rule in pairs(argvmods) do
+ print(string.format("argvmods[\"%s\"] = {", binary_name))
+ for name, value in pairs(rule) do
+ --
+ -- Check that rulename is valid.
+ --
+ local found = 0
+ for i = 1, #allowed_rulenames do
+ if name == allowed_rulenames[i] then
+ found = 1
+ break
+ end
+ end
+ if found == 0 then
+ io.stderr:write(string.format(
+ "invalid rulename '%s'\n", name))
+ end
+ io.write(string.format("\t%s = ", name))
+ if type(value) == "string" then
+ io.write(string.format("\"%s\"", value))
+ elseif type(value) == "number" then
+ io.write(string.format("%d", value))
+ elseif type(value) == "table" then
+ if #value == 0 then
+ io.write("{}")
+ else
+ io.write("{\n")
+ for i = 1, #value do
+ assert(type(value[i]) == "string")
+
+ io.write(
+ string.format("\t\t\"%s\",\n",
+ value[i]))
+ end
+ io.write("\t}");
+ end
+ else
+ io.stderr:write(string.format(
+ "unsupported type '%s' in argvmod rule\n",
+ type(value)))
+ assert(false)
+ end
+ io.write(",\n")
+ end
+ print("}")
+ count = count + 1
+end
+
+print("--")
+print(string.format("-- Total %d rule(s).", count))
+print("-- End of rules created by argvmods expander.")
+print("--")