summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-05-30 10:22:06 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-05-30 10:22:06 +0000
commit0988b8076c91248953feb595f993c0ab80a8cd33 (patch)
treea7be0f8cb6d0fa6f7b747fb62cfa103035385b12
parent5a29d98c43fdb637947af893b8604b5d6adcd113 (diff)
parentcfd49d9342a197308f0e7bdd19f6a8ece8516481 (diff)
downloaddefinitions-0988b8076c91248953feb595f993c0ab80a8cd33.tar.gz
Merge remote-tracking branch 'origin/richarddale/qmake_build_system'
-rw-r--r--morphlib/buildsystem.py57
-rw-r--r--morphlib/buildsystem_tests.py51
-rwxr-xr-xtests.build/build-system-cmake.script59
-rw-r--r--tests.build/build-system-cmake.stdout8
-rwxr-xr-xtests.build/build-system-qmake.script67
-rw-r--r--tests.build/build-system-qmake.stdout8
6 files changed, 250 insertions, 0 deletions
diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py
index a6645eb2..90cc15c2 100644
--- a/morphlib/buildsystem.py
+++ b/morphlib/buildsystem.py
@@ -197,12 +197,69 @@ class CPANBuildSystem(BuildSystem):
return any(x in file_list for x in indicators)
+class CMakeBuildSystem(BuildSystem):
+
+ '''The cmake build system.'''
+
+ name = 'cmake'
+
+ def __init__(self):
+ BuildSystem.__init__(self)
+ self.configure_commands = [
+ 'cmake -DCMAKE_INSTALL_PREFIX=/usr'
+ ]
+ self.build_commands = [
+ 'make',
+ ]
+ self.test_commands = [
+ ]
+ self.install_commands = [
+ 'make DESTDIR="$DESTDIR" install',
+ ]
+
+ def used_by_project(self, file_list):
+ indicators = [
+ 'CMakeLists.txt',
+ ]
+
+ return any(x in file_list for x in indicators)
+
+class QMakeBuildSystem(BuildSystem):
+
+ '''The Qt build system.'''
+
+ name = 'qmake'
+
+ def __init__(self):
+ BuildSystem.__init__(self)
+ self.configure_commands = [
+ 'qmake -makefile '
+ ]
+ self.build_commands = [
+ 'make',
+ ]
+ self.test_commands = [
+ ]
+ self.install_commands = [
+ 'make INSTALL_ROOT="$DESTDIR" install',
+ ]
+
+ def used_by_project(self, file_list):
+ indicator = '.pro'
+
+ for x in file_list:
+ if x.endswith(indicator):
+ return True
+
+ return False
build_systems = [
ManualBuildSystem(),
AutotoolsBuildSystem(),
PythonDistutilsBuildSystem(),
CPANBuildSystem(),
+ CMakeBuildSystem(),
+ QMakeBuildSystem(),
DummyBuildSystem(),
]
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py
index d1095037..f5505ddd 100644
--- a/morphlib/buildsystem_tests.py
+++ b/morphlib/buildsystem_tests.py
@@ -28,6 +28,8 @@ def touch(pathname):
manual_project = []
autotools_project = ['configure.in']
+qmake_project = ['foo.pro']
+cmake_project = ['CMakeLists.txt']
class BuildSystemTests(unittest.TestCase):
@@ -64,6 +66,12 @@ class ManualBuildSystemTests(unittest.TestCase):
def test_does_not_autodetect_autotools(self):
self.assertFalse(self.bs.used_by_project(autotools_project))
+ def test_does_not_autodetect_qmake(self):
+ self.assertFalse(self.bs.used_by_project(qmake_project))
+
+ def test_does_not_autodetect_cmake(self):
+ self.assertFalse(self.bs.used_by_project(cmake_project))
+
class DummyBuildSystemTests(unittest.TestCase):
@@ -76,6 +84,12 @@ class DummyBuildSystemTests(unittest.TestCase):
def test_does_not_autodetect_autotools(self):
self.assertFalse(self.bs.used_by_project(autotools_project))
+ def test_does_not_autodetect_cmake(self):
+ self.assertFalse(self.bs.used_by_project(cmake_project))
+
+ def test_does_not_autodetect_qmake(self):
+ self.assertFalse(self.bs.used_by_project(qmake_project))
+
class AutotoolsBuildSystemTests(unittest.TestCase):
@@ -88,6 +102,27 @@ class AutotoolsBuildSystemTests(unittest.TestCase):
def test_autodetects_autotools(self):
self.assertTrue(self.bs.used_by_project(autotools_project))
+class CMakeBuildSystemTests(unittest.TestCase):
+
+ def setUp(self):
+ self.bs = morphlib.buildsystem.CMakeBuildSystem()
+
+ def test_does_not_autodetect_empty(self):
+ self.assertFalse(self.bs.used_by_project(manual_project))
+
+ def test_autodetects_cmake(self):
+ self.assertTrue(self.bs.used_by_project(cmake_project))
+
+class QMakeBuildSystemTests(unittest.TestCase):
+
+ def setUp(self):
+ self.bs = morphlib.buildsystem.QMakeBuildSystem()
+
+ def test_does_not_autodetect_empty(self):
+ self.assertFalse(self.bs.used_by_project(manual_project))
+
+ def test_autodetects_qmake(self):
+ self.assertTrue(self.bs.used_by_project(qmake_project))
class DetectBuildSystemTests(unittest.TestCase):
@@ -99,6 +134,14 @@ class DetectBuildSystemTests(unittest.TestCase):
bs = morphlib.buildsystem.detect_build_system(autotools_project)
self.assertEqual(type(bs), morphlib.buildsystem.AutotoolsBuildSystem)
+ def test_autodetects_cmake(self):
+ bs = morphlib.buildsystem.detect_build_system(cmake_project)
+ self.assertEqual(type(bs), morphlib.buildsystem.CMakeBuildSystem)
+
+ def test_autodetects_qmake(self):
+ bs = morphlib.buildsystem.detect_build_system(qmake_project)
+ self.assertEqual(type(bs), morphlib.buildsystem.QMakeBuildSystem)
+
class LookupBuildSystemTests(unittest.TestCase):
@@ -116,6 +159,14 @@ class LookupBuildSystemTests(unittest.TestCase):
self.assertEqual(type(self.lookup('autotools')),
morphlib.buildsystem.AutotoolsBuildSystem)
+ def test_looks_up_cmake(self):
+ self.assertEqual(type(self.lookup('cmake')),
+ morphlib.buildsystem.CMakeBuildSystem)
+
+ def test_looks_up_qmake(self):
+ self.assertEqual(type(self.lookup('qmake')),
+ morphlib.buildsystem.QMakeBuildSystem)
+
def test_looks_up_dummy(self):
self.assertEqual(type(self.lookup('dummy')),
morphlib.buildsystem.DummyBuildSystem)
diff --git a/tests.build/build-system-cmake.script b/tests.build/build-system-cmake.script
new file mode 100755
index 00000000..00b9ed23
--- /dev/null
+++ b/tests.build/build-system-cmake.script
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright (C) 2011-2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+## Convert the hello-chunk project to something cmake-like, then
+## build it.
+
+set -eu
+
+chunkrepo="$DATADIR/chunk-repo"
+cd "$chunkrepo"
+
+git checkout --quiet farrokh
+
+cat <<'EOF' >CMakeLists.txt
+cmake_minimum_required(VERSION 2.8)
+project(hello)
+
+set(hello_SOURCES hello.c)
+add_executable(hello ${hello_SOURCES})
+install(TARGETS hello RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
+EOF
+
+git add CMakeLists.txt
+
+cat <<EOF > hello.morph
+{
+ "name": "hello",
+ "kind": "chunk",
+ "build-system": "cmake",
+ "install-commands": ["make DESTDIR=\"\$DESTDIR\" install"]
+}
+EOF
+git add hello.morph
+git commit --quiet -m "Convert hello to a cmake project"
+
+"$SRCDIR/scripts/test-morph" build-morphology \
+ test:morphs-repo master hello-system
+
+for chunk in "$DATADIR/cache/artifacts/"*.chunk.*
+do
+ echo "$chunk:" | sed 's/[^.]*//'
+ tar -tf "$chunk" | LC_ALL=C sort | sed '/^\.\/./s:^\./::'
+ echo
+done
diff --git a/tests.build/build-system-cmake.stdout b/tests.build/build-system-cmake.stdout
new file mode 100644
index 00000000..ccf80a86
--- /dev/null
+++ b/tests.build/build-system-cmake.stdout
@@ -0,0 +1,8 @@
+.chunk.hello:
+./
+baserock/
+baserock/hello.meta
+usr/
+usr/bin/
+usr/bin/hello
+
diff --git a/tests.build/build-system-qmake.script b/tests.build/build-system-qmake.script
new file mode 100755
index 00000000..d9e21fba
--- /dev/null
+++ b/tests.build/build-system-qmake.script
@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# Copyright (C) 2011-2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+## Convert the hello-chunk project to something qmake-like, then
+## build it.
+
+set -eu
+
+if ! command -v qmake > /dev/null ; then
+ # There is no qmake, so skip this test.
+ cat "$SRCDIR/tests.build/build-system-qmake.stdout"
+ exit 0
+fi
+
+chunkrepo="$DATADIR/chunk-repo"
+cd "$chunkrepo"
+
+git checkout --quiet farrokh
+
+cat <<'EOF' >hello.pro
+TEMPLATE = app
+TARGET = hello
+DEPENDPATH += .
+INCLUDEPATH += .
+
+SOURCES += hello.c
+hello.path = /usr/bin
+hello.files = hello
+INSTALLS += hello
+EOF
+git add hello.pro
+
+cat <<EOF > hello.morph
+{
+ "name": "hello",
+ "kind": "chunk",
+ "build-system": "qmake",
+ "install-commands": ["make INSTALL_ROOT=\"\$DESTDIR\" install"]
+}
+EOF
+git add hello.morph
+git commit --quiet -m "Convert hello to an qmake project"
+
+"$SRCDIR/scripts/test-morph" build-morphology \
+ test:morphs-repo master hello-system
+
+for chunk in "$DATADIR/cache/artifacts/"*.chunk.*
+do
+ echo "$chunk:" | sed 's/[^.]*//'
+ tar -tf "$chunk" | LC_ALL=C sort | sed '/^\.\/./s:^\./::'
+ echo
+done
diff --git a/tests.build/build-system-qmake.stdout b/tests.build/build-system-qmake.stdout
new file mode 100644
index 00000000..ccf80a86
--- /dev/null
+++ b/tests.build/build-system-qmake.stdout
@@ -0,0 +1,8 @@
+.chunk.hello:
+./
+baserock/
+baserock/hello.meta
+usr/
+usr/bin/
+usr/bin/hello
+