Don't copy libraries that are already in prime. #580

Merged
merged 4 commits into from Jun 24, 2016
@@ -0,0 +1,10 @@
+name: rpath-test
+version: 1
+summary: summary
+description: description
+confinement: strict
+
+parts:
+ rpath-test:
+ plugin: make
+ source: src/
@@ -0,0 +1,19 @@
+all: main
+
+libfoo.so: foo.h foo.cpp
+ @g++ -fPIC -c foo.cpp
+ @g++ -shared foo.o -o libfoo.so
+ @mkdir -p lib
+ @mv libfoo.so lib/
+
+main: libfoo.so
+ @g++ main.cpp -o binary -Wl,-rpath=\$$ORIGIN/lib -Llib -lfoo
+
+install: main
+ @mkdir -p $(DESTDIR)/lib
+ @cp binary $(DESTDIR)/
+ @cp lib/* $(DESTDIR)/lib/
+
+clean:
+ @rm *.o binary
+ @rm -rf lib
@@ -0,0 +1,6 @@
+#include "foo.h"
+
+std::string foo()
+{
+ return "hello world";
+}
@@ -0,0 +1,3 @@
+#include <string>
+
+std::string foo();
@@ -0,0 +1,8 @@
+#include <iostream>
+#include "foo.h"
+
+int main()
+{
+ std::cout << foo() << std::endl;
+ return 0;
+}
@@ -0,0 +1,43 @@
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
+#
+# Copyright (C) 2016 Canonical Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+import os
+
+import integration_tests
+
+from testtools.matchers import (
+ DirExists,
+ FileExists,
+ Not,
+)
+
+
+class RpathTestCase(integration_tests.TestCase):
+
+ def test_origin_rpath(self):
+ project_dir = 'rpath-test'
+ self.run_snapcraft('prime', project_dir)
+
+ primedir = os.path.join(project_dir, 'prime')
+ self.assertThat(os.path.join(primedir, 'binary'), FileExists())
+ self.assertThat(
+ os.path.join(primedir, 'lib', 'libfoo.so'), FileExists())
+
+ # Assert that the $ORIGIN rpath did not result in the library being pulled
+ # in twice.
+ self.assertThat(
+ os.path.join(primedir, os.path.abspath(primedir).lstrip('/')),
+ Not(DirExists()))
@@ -391,6 +391,7 @@ def prime(self, force=False):
# potentially override the `stage` or `snap` filtering.
part_dependencies = set()
staged_dependencies = set()
+ primed_dependencies = set()
system_dependencies = set()
for file_path in dependencies:
if file_path.startswith(self.installdir):
@@ -399,6 +400,9 @@ def prime(self, force=False):
elif file_path.startswith(self.stagedir):
staged_dependencies.add(
os.path.relpath(file_path, self.stagedir))
+ elif file_path.startswith(self.snapdir):
+ primed_dependencies.add(
+ os.path.relpath(file_path, self.snapdir))
else:
system_dependencies.add(file_path.lstrip('/'))