From a1d00de1408b36b6b68d18d1c1e1fba7df1add49 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 2 Nov 2020 16:56:35 +0300 Subject: Set executable bit for ad hoc buildscript rule executable target on POSIX --- libbuild2/adhoc-rule-buildscript.cxx | 22 ++++++++++++++++++++++ libbuild2/dist/operation.cxx | 2 +- libbuild2/filesystem.cxx | 26 ++++++++++++++++++++++++++ libbuild2/filesystem.hxx | 10 ++++++++++ libbuild2/version/utility.cxx | 3 ++- 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 #include #include +#include // path_perms() #include #include // 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 ()) + 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_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 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 #include +#include // path_perms() #include 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 ()); -- cgit v1.1