Skip to content

Commit e843d8d

Browse files
Uilian Riesuilianries
Uilian Ries
authored andcommitted
WIP: macchina-io#70 Conan support
- Created Conan recipe to build and deploy macchin.io as package - Include package validation that start the service Signed-off-by: Uilian Ries <[email protected]>
1 parent a603a55 commit e843d8d

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ matrix:
3131
- make -s -j2 hosttools DEFAULT_TARGET=shared_release
3232
- export PATH=$PATH:`pwd`/ti-am335x-sdk/linux-devkit/sysroots/i686-arago-linux/usr/bin; POCO_CONFIG=Arago make -s -j2 DEFAULT_TARGET=shared_release V8_NOSNAPSHOT=1
3333

34+
- env: TEST_NAME="conan (host)" CONAN_GCC_VERSIONS=4.8
35+
os: linux
36+
sudo: required
37+
language: python
38+
python: "3.6"
39+
install:
40+
- pip install -U conan
41+
- pip install conan_package_tools
42+
- conan user
43+
script:
44+
- python build.py
45+
3446
# QA jobs for code analytics and metrics
3547
# static code analysis with cppcheck (we can add --enable=all later)
3648
- env: TEST_NAME="cppcheck"

build.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import copy
2+
from conan.packager import ConanMultiPackager, os, re
3+
from conans import tools
4+
5+
6+
def get_name_version_from_recipe():
7+
with open("conanfile.py", "r") as conanfile:
8+
contents = conanfile.read()
9+
name = re.search(r'name\s*=\s*"(\S*)"', contents).groups()[0]
10+
version = re.search(r'version\s*=\s*"(\S*)"', contents).groups()[0]
11+
return name, version
12+
13+
def get_default_vars():
14+
username = os.getenv("CONAN_USERNAME", "macchinaio")
15+
channel = os.getenv("CONAN_CHANNEL", "testing")
16+
_, version = get_name_version_from_recipe()
17+
return username, channel, version
18+
19+
def is_ci_running():
20+
return os.getenv("APPVEYOR_REPO_NAME","") or os.getenv("TRAVIS_REPO_SLUG","")
21+
22+
def get_ci_vars():
23+
reponame_a = os.getenv("APPVEYOR_REPO_NAME","")
24+
repobranch_a = os.getenv("APPVEYOR_REPO_BRANCH","")
25+
26+
reponame_t = os.getenv("TRAVIS_REPO_SLUG","")
27+
repobranch_t = os.getenv("TRAVIS_BRANCH","")
28+
29+
username, _ = reponame_a.split("/") if reponame_a else reponame_t.split("/")
30+
channel, version = repobranch_a.split("/") if repobranch_a else repobranch_t.split("/")
31+
return username, channel, version
32+
33+
def get_env_vars():
34+
return get_ci_vars() if is_ci_running() else get_default_vars()
35+
36+
if __name__ == "__main__":
37+
name, _ = get_name_version_from_recipe()
38+
username, channel, version = get_env_vars()
39+
reference = "{0}/{1}".format(name, version)
40+
upload = "https://api.bintray.com/conan/{0}/conan".format(username)
41+
42+
builder = ConanMultiPackager(args="--build missing", username=username, channel=channel, archs=['x86_64'],
43+
reference=reference, upload=upload, upload_only_when_stable=True)
44+
builder.add_common_builds(pure_c=False)
45+
builder.run()

conanfile.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Conan recipe for Macchina.io project.
2+
3+
This recipe exports all necessary sources, build the project and create a
4+
package with all artifacts.
5+
6+
"""
7+
8+
import os
9+
from conans import ConanFile, AutoToolsBuildEnvironment, tools
10+
11+
12+
class MacchinaioConan(ConanFile):
13+
name = "macchina.io"
14+
version = "0.7.0"
15+
generators = "cmake"
16+
license = "https://github.com/macchina-io/macchina.io/blob/master/LICENSE"
17+
url = "https://github.com/macchina-io/macchina.io"
18+
author = "Gunter Obiltschnig <[email protected]>"
19+
description = "macchina.io is a toolkit for building IoT edge and fog device applications in JavaScript and C++"
20+
settings = "os", "compiler", "build_type", "arch"
21+
options = {"with_V8_snapshot": [True, False]}
22+
default_options = "with_V8_snapshot=True"
23+
exports = "LICENSE"
24+
exports_sources = "devices/*", "launcher/*", "platform/*", "protocols/*", "samples/*", "server/*", "services/*", "tools/*", "webui/*", "Makefile"
25+
requires = "OpenSSL/1.0.2@conan/stable"
26+
27+
def build(self):
28+
build_args = []
29+
build_args.append("-s")
30+
build_args.append("DEFAULT_TARGET=shared_%s" % self.settings.build_type.value.lower())
31+
build_args.append("V8_SNAPSHOT=1" if self.options.with_V8_snapshot else "V8_NOSNAPSHOT=1")
32+
install_args = ["install"]
33+
install_args.extend(build_args)
34+
install_args.append("INSTALLDIR=%s" % self.package_folder)
35+
env_build = AutoToolsBuildEnvironment(self)
36+
with tools.environment_append(env_build.vars):
37+
env_build.make(args=build_args)
38+
env_build.make(args=install_args)
39+
os.rename(os.path.join(self.package_folder, "etc"), os.path.join(self.package_folder, "res"))
40+
41+
def package(self):
42+
self.copy("LICENSE", dst=".", src=".")
43+
44+
def package_info(self):
45+
self.cpp_info.libs = tools.collect_libs(self)
46+
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
47+
if self.settings.os == "Linux":
48+
self.env_info.LD_LIBRARY_PATH.append(os.path.join(self.package_folder, "lib"))
49+
elif self.settings.os == "Macos":
50+
self.env_info.DYLD_LIBRARY_PATH.append(os.path.join(self.package_folder, "lib"))

test_package/conanfile.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Conan recipe for Macchina.io test package.
2+
3+
This test summons the macchina.io process, and check by a HTTP resquest on
4+
port 22080.
5+
6+
"""
7+
8+
import os
9+
import signal
10+
import subprocess
11+
import tempfile
12+
import time
13+
import sys
14+
from conans import ConanFile, RunEnvironment, tools
15+
16+
if (sys.version_info > (3, 0)):
17+
import http.client
18+
httplib = http.client
19+
else:
20+
import httplib
21+
22+
class MacchinaioTestConan(ConanFile):
23+
settings = "os", "compiler", "arch", "build_type"
24+
generators = "cmake"
25+
26+
def imports(self):
27+
self.copy(pattern="*", dst="bin", src="bin")
28+
29+
def test(self):
30+
config_file = os.path.join(self.deps_cpp_info["macchina.io"].res_paths[0], "macchina.properties")
31+
bundles_dir = os.path.join(self.deps_cpp_info["macchina.io"].lib_paths[0], "bundles")
32+
codecache_dir = os.path.join(os.getcwd(), "bin", "codeCache")
33+
_, pid_file = tempfile.mkstemp(prefix="macchinaio-pid")
34+
35+
build_vars = RunEnvironment(self).vars
36+
build_vars["LD_LIBRARY_PATH"].append(codecache_dir)
37+
with tools.environment_append(build_vars):
38+
self.run("%s/bin/macchina --daemon -B%s -c%s --pidfile=%s" % (os.getcwd(), bundles_dir, config_file, pid_file))
39+
time.sleep(10)
40+
try:
41+
conn = httplib.HTTPConnection("localhost:22080")
42+
conn.request("GET","/macchina/login")
43+
res = conn.getresponse()
44+
assert(res.status == 200)
45+
finally:
46+
with open(pid_file) as f:
47+
pid = int(f.read())
48+
os.kill(pid, signal.SIGKILL)

0 commit comments

Comments
 (0)