aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-17 08:53:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-07-17 08:53:19 +0200
commit5c77690306d5430379bd6046ad2c0f4775cfce93 (patch)
treeef6286500fc4d5749d80106b87a819d844319476
parent724a88eb4c5ebdddb6d334beec53105f679c154a (diff)
Handle executables (permissions, extensions) in in::rule
-rw-r--r--build2/in/rule.cxx22
-rw-r--r--tests/in/testscript17
2 files changed, 37 insertions, 2 deletions
diff --git a/build2/in/rule.cxx b/build2/in/rule.cxx
index 1495c64..de43e4d 100644
--- a/build2/in/rule.cxx
+++ b/build2/in/rule.cxx
@@ -55,7 +55,10 @@ namespace build2
// Derive the file name.
//
- t.derive_path ();
+ // If this is an executable with an uspecified extension, then default
+ // to no extension (i.e., a shell script).
+ //
+ t.derive_path (t.is_a<exe> () ? "" : nullptr);
// Inject dependency on the output directory.
//
@@ -306,8 +309,23 @@ namespace build2
what = "open"; whom = &ip;
ifdstream ifs (ip, fdopen_mode::in, ifdstream::badbit);
+ // See fdopen() for details (umask, etc).
+ //
+ permissions prm (permissions::ru | permissions::wu |
+ permissions::rg | permissions::wg |
+ permissions::ro | permissions::wo);
+
+ if (t.is_a<exe> ())
+ prm |= permissions::xu | permissions::xg | permissions::xo;
+
+ // Remove the existing file to make sure permissions take effect.
+ //
+ rmfile (tp, 3 /* verbosity */);
+
what = "open"; whom = &tp;
- ofdstream ofs (tp);
+ ofdstream ofs (fdopen (tp,
+ fdopen_mode::out | fdopen_mode::create,
+ prm));
auto_rmfile arm (tp);
string s; // Reuse the buffer.
diff --git a/tests/in/testscript b/tests/in/testscript
index 4cf4ebf..3b1442a 100644
--- a/tests/in/testscript
+++ b/tests/in/testscript
@@ -94,3 +94,20 @@ $* <<EOI 2>>EOE != 0
EOI
test.in:2: error: undefined variable 'bar'
EOE
+
+: executable
+:
+: Test creation of executables (permissions, extensions).
+:
+if ($test.target == $build.host && $build.host.class != 'windows')
+{
+ cat <<EOI >=hello.in;
+ #!/bin/sh
+ echo 'Hello, $name$!'
+ EOI
+ $* <<EOI &hello &hello.d;
+ exe{hello}: in{hello}
+ exe{hello}: name = 'World'
+ EOI
+ $~/hello >'Hello, World!'
+}