aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-11-02 16:56:35 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-11-02 20:38:57 +0300
commita1d00de1408b36b6b68d18d1c1e1fba7df1add49 (patch)
treec6add78f6380f9325648be5698da10c311ed2e9b /libbuild2
parent809123f03100ee9ed90d31424304c22ba28e842c (diff)
Set executable bit for ad hoc buildscript rule executable target on POSIX
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/adhoc-rule-buildscript.cxx22
-rw-r--r--libbuild2/dist/operation.cxx2
-rw-r--r--libbuild2/filesystem.cxx26
-rw-r--r--libbuild2/filesystem.hxx10
-rw-r--r--libbuild2/version/utility.cxx3
5 files changed, 61 insertions, 2 deletions
diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx
index ed53c95..3dbe817 100644
--- a/libbuild2/adhoc-rule-buildscript.cxx
+++ b/libbuild2/adhoc-rule-buildscript.cxx
@@ -10,6 +10,7 @@
#include <libbuild2/target.hxx>
#include <libbuild2/context.hxx>
#include <libbuild2/algorithm.hxx>
+#include <libbuild2/filesystem.hxx> // path_perms()
#include <libbuild2/diagnostics.hxx>
#include <libbuild2/parser.hxx> // attributes
@@ -553,7 +554,28 @@ namespace build2
p.execute (*rs, *bs, e, script, r);
if (!ctx.dry_run)
+ {
+ // If this is an executable, let's be helpful to the user and set
+ // the executable bit on POSIX.
+ //
+#ifndef _WIN32
+ auto chmod = [] (const path& p)
+ {
+ path_perms (p,
+ (path_perms (p) |
+ permissions::xu |
+ permissions::xg |
+ permissions::xo));
+ };
+
+ for (const target* m (&t); m != nullptr; m = m->adhoc_member)
+ {
+ if (auto* p = m->is_a<exe> ())
+ chmod (p->path ());
+ }
+#endif
dd.check_mtime (tp);
+ }
}
}
diff --git a/libbuild2/dist/operation.cxx b/libbuild2/dist/operation.cxx
index 21d5283..2fa953d 100644
--- a/libbuild2/dist/operation.cxx
+++ b/libbuild2/dist/operation.cxx
@@ -649,7 +649,7 @@ namespace build2
//
args.push_back ("-m");
args.push_back (
- (path_permissions (t.path ()) & permissions::xu) == permissions::xu
+ (path_perms (t.path ()) & permissions::xu) == permissions::xu
? "755"
: "644");
diff --git a/libbuild2/filesystem.cxx b/libbuild2/filesystem.cxx
index 0072408..fbe145c 100644
--- a/libbuild2/filesystem.cxx
+++ b/libbuild2/filesystem.cxx
@@ -297,4 +297,30 @@ namespace build2
//
return rmdir (ctx, d, verbosity);
}
+
+ permissions
+ path_perms (const path& p)
+ {
+ try
+ {
+ return path_permissions (p);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to obtain path " << p << " permissions: " << e << endf;
+ }
+ }
+
+ void
+ path_perms (const path& p, permissions f)
+ {
+ try
+ {
+ path_permissions (p, f);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to set path " << p << " permissions: " << e;
+ }
+ }
}
diff --git a/libbuild2/filesystem.hxx b/libbuild2/filesystem.hxx
index 5169964..26544bc 100644
--- a/libbuild2/filesystem.hxx
+++ b/libbuild2/filesystem.hxx
@@ -179,6 +179,16 @@ namespace build2
LIBBUILD2_SYMEXPORT fs_status<rmdir_status>
rmdir_buildignore (context&,
const dir_path&, const path&, uint16_t verbosity = 1);
+
+ // Get/set a path permissions.
+ //
+ using permissions = butl::permissions;
+
+ LIBBUILD2_SYMEXPORT permissions
+ path_perms (const path&);
+
+ LIBBUILD2_SYMEXPORT void
+ path_perms (const path&, permissions);
}
#include <libbuild2/filesystem.ixx>
diff --git a/libbuild2/version/utility.cxx b/libbuild2/version/utility.cxx
index 4b958c6..5e2375d 100644
--- a/libbuild2/version/utility.cxx
+++ b/libbuild2/version/utility.cxx
@@ -7,6 +7,7 @@
#include <libbutl/manifest-serializer.mxx>
#include <libbuild2/context.hxx>
+#include <libbuild2/filesystem.hxx> // path_perms()
#include <libbuild2/diagnostics.hxx>
using namespace butl;
@@ -27,7 +28,7 @@ namespace build2
{
try
{
- permissions perm (path_permissions (in));
+ permissions perm (path_perms (in));
ifdstream ifs (in);
manifest_parser p (ifs, in.string ());