Skip to content

Commit

Permalink
autotools v1 plugin: set correct file permissions for scripts
Browse files Browse the repository at this point in the history
The autogen.sh and bootstrap scripts had overeager permissions set
when they were found not to be executable.

The code has also been simplified.

LP: #1951645

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens committed Nov 26, 2021
1 parent 6382398 commit 08a3477
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
45 changes: 19 additions & 26 deletions snapcraft/plugins/v1/autotools.py
Expand Up @@ -40,7 +40,7 @@
"""

import os
import stat
from pathlib import Path

from snapcraft.plugins.v1 import make

Expand Down Expand Up @@ -88,32 +88,25 @@ def enable_cross_compilation(self):
pass

def build(self):
if not os.path.exists(os.path.join(self.builddir, "configure")):
generated = False
scripts = ["autogen.sh", "bootstrap"]
for script in scripts:
path = os.path.join(self.builddir, script)
if not os.path.exists(path) or os.path.isdir(path):
continue
# Make sure it's executable
if not os.access(path, os.X_OK):
os.chmod(
path,
stat.S_IRUSR
| stat.S_IWUSR
| stat.S_IXUSR
| stat.S_IRGRP
| stat.S_IWGRP
| stat.S_IXGRP
| stat.S_IROTH
| stat.S_IWOTH
| stat.S_IXOTH,
)
self.run(["env", "NOCONFIGURE=1", "./{}".format(script)])
generated = True
break
if not generated:
configure_script = Path(self.builddir) / "configure"
if not configure_script.exists():
potential_scripts = [
Path(self.builddir) / s for s in ["autogen.sh", "bootstrap"]
]
existing_scripts = [
s for s in potential_scripts if s.exists() and s.is_file()
]

# If there are not alternative configure scripts, run autoreconf.
if not existing_scripts:
self.run(["autoreconf", "-i"])
else:
# Pick the first one.
script = existing_scripts[0]
# Make sure it's executable.
if not os.access(script, os.X_OK):
script.chmod(0o755)
self.run(["env", "NOCONFIGURE=1", script])

configure_command = ["./configure"]

Expand Down
23 changes: 15 additions & 8 deletions tests/unit/plugins/v1/test_autotools.py
Expand Up @@ -16,8 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import pathlib
import stat
from pathlib import Path
from unittest import mock

import pytest
Expand Down Expand Up @@ -258,12 +258,13 @@ def test_build_autogen_with_destdir(self, run_mock):
self.assertThat(run_mock.call_count, Equals(4))
run_mock.assert_has_calls(
[
mock.call(["env", "NOCONFIGURE=1", "./autogen.sh"]),
mock.call(
["env", "NOCONFIGURE=1", Path(plugin.builddir) / "autogen.sh"]
),
mock.call(["./configure", "--prefix="]),
mock.call(["make", "-j2"], env=None),
mock.call(
["make", "install", "DESTDIR={}".format(plugin.installdir)],
env=None,
["make", "install", f"DESTDIR={plugin.installdir}"], env=None,
),
]
)
Expand All @@ -275,7 +276,9 @@ def test_build_bootstrap_with_destdir(self, run_mock):
self.assertThat(run_mock.call_count, Equals(4))
run_mock.assert_has_calls(
[
mock.call(["env", "NOCONFIGURE=1", "./bootstrap"]),
mock.call(
["env", "NOCONFIGURE=1", Path(plugin.builddir) / "bootstrap"]
),
mock.call(["./configure", "--prefix="]),
mock.call(["make", "-j2"], env=None),
mock.call(
Expand All @@ -292,7 +295,9 @@ def test_build_bootstrap_and_autogen_with_destdir(self, run_mock):
self.assertThat(run_mock.call_count, Equals(4))
run_mock.assert_has_calls(
[
mock.call(["env", "NOCONFIGURE=1", "./autogen.sh"]),
mock.call(
["env", "NOCONFIGURE=1", Path(plugin.builddir) / "autogen.sh"]
),
mock.call(["./configure", "--prefix="]),
mock.call(["make", "-j2"], env=None),
mock.call(
Expand All @@ -310,7 +315,9 @@ def test_build_autogen_with_prefix(self, run_mock):
self.assertThat(run_mock.call_count, Equals(4))
run_mock.assert_has_calls(
[
mock.call(["env", "NOCONFIGURE=1", "./autogen.sh"]),
mock.call(
["env", "NOCONFIGURE=1", Path(plugin.builddir) / "autogen.sh"]
),
mock.call(["./configure", "--prefix={}".format(plugin.installdir)]),
mock.call(["make", "-j2"], env=None),
mock.call(["make", "install"], env=None),
Expand Down Expand Up @@ -443,7 +450,7 @@ def test_cross_compile(mock_run, monkeypatch, project, options, deb_arch, triple

plugin = autotools.AutotoolsPlugin("test-part", options, project)
plugin.enable_cross_compilation()
configure_file = pathlib.Path(plugin.builddir) / "configure"
configure_file = Path(plugin.builddir) / "configure"
configure_file.parent.mkdir(parents=True)
configure_file.touch()

Expand Down

0 comments on commit 08a3477

Please sign in to comment.