Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently Snapcraft adds only a few standard paths to LD_LIBRARY_PATH. This commit expands that to include paths used by mesa packages. Also add an opencv example to exercise this. Signed-off-by: Kyle Fazzari <kyle@canonical.com> LP: #1531620
- Loading branch information
Showing
8 changed files
with
221 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: opencv-example | ||
version: 1.0 | ||
summary: Use OpenCV and OpenGL | ||
description: A simple OpenCV example | ||
|
||
binaries: | ||
example: | ||
exec: bin/example | ||
|
||
parts: | ||
example: | ||
plugin: cmake | ||
source: src | ||
stage-packages: [libopencv-dev] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
project(example) | ||
|
||
find_package(OpenCV REQUIRED) | ||
|
||
add_executable(example main.cpp) | ||
|
||
target_link_libraries(example ${OpenCV_LIBS}) | ||
|
||
install(TARGETS example RUNTIME DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <iostream> | ||
|
||
#include <opencv2/core/core.hpp> | ||
|
||
int main() | ||
{ | ||
cv::Mat matrix(2, 2, CV_8UC1); | ||
|
||
matrix.at<uint8_t>(cv::Point(0, 0)) = 1; | ||
matrix.at<uint8_t>(cv::Point(0, 1)) = 2; | ||
matrix.at<uint8_t>(cv::Point(1, 0)) = 3; | ||
matrix.at<uint8_t>(cv::Point(1, 1)) = 4; | ||
|
||
std::cout << matrix << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- 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 re | ||
import glob | ||
|
||
|
||
def determine_ld_library_path(root): | ||
# If more ld.so.conf files need to be supported, add them here. | ||
ld_config_globs = { | ||
'{}/usr/lib/*/mesa*/ld.so.conf'.format(root) | ||
} | ||
|
||
ld_library_paths = [] | ||
for this_glob in ld_config_globs: | ||
for ld_conf_file in glob.glob(this_glob): | ||
ld_library_paths.extend(_extract_ld_library_paths(ld_conf_file)) | ||
|
||
return [root + path for path in ld_library_paths] | ||
|
||
|
||
def _extract_ld_library_paths(ld_conf_file): | ||
# From the ldconfig manpage, paths can be colon-, space-, tab-, newline-, | ||
# or comma-separated. | ||
path_delimiters = re.compile(r'[:\s,]') | ||
comments = re.compile(r'#.*$') | ||
|
||
paths = [] | ||
with open(ld_conf_file, 'r') as f: | ||
for line in f: | ||
# Remove comments from line | ||
line = comments.sub('', line).strip() | ||
|
||
if line: | ||
paths.extend(path_delimiters.split(line)) | ||
|
||
return paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- 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 tempfile | ||
|
||
from snapcraft import ( | ||
libraries, | ||
tests, | ||
) | ||
|
||
|
||
class TestLdLibraryPathParser(tests.TestCase): | ||
|
||
def _write_conf_file(self, contents): | ||
tmp = tempfile.NamedTemporaryFile(delete=False, mode='w') | ||
self.addCleanup(os.remove, tmp.name) | ||
|
||
tmp.write(contents) | ||
tmp.close() | ||
|
||
return tmp.name | ||
|
||
def test_extract_ld_library_paths(self): | ||
file_path = self._write_conf_file("""# This is a comment | ||
/foo/bar | ||
/colon:/separated,/comma\t/tab /space # This is another comment | ||
/baz""") | ||
|
||
self.assertEqual(['/foo/bar', '/colon', '/separated', '/comma', | ||
'/tab', '/space', '/baz'], | ||
libraries._extract_ld_library_paths(file_path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters