Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the marked-up object compiler, moc, package to conan center #5832

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/moc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.9.401":
sha256: 1fcfab08f6656d28f0b77dfa52359229df9890ac1423541b06bd4a7e97407b44
url: "https://github.com/zuut/moc/archive/refs/tags/0.9.401.tar.gz"
93 changes: 93 additions & 0 deletions recipes/moc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from os import rename
zuut marked this conversation as resolved.
Show resolved Hide resolved
from os.path import isdir, join
from shutil import move
zuut marked this conversation as resolved.
Show resolved Hide resolved

class MocConan(ConanFile):
name = "moc"
homepage = "https://www.github.com/zuut/moc"
description = "Moc, the marked-up object compiler"
topics = ("conan", "moc", "idl", "code generation")
url = "https://github.com/conan-io/conan-center-index"
license = "Apache-2.0"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = { "fPIC": [True, False] }
default_options = { "fPIC": True }
_cmake = None
_supported_compilers = [
("Linux", "gcc", "6"),
("Linux", "clang", "6"),
("Macos", "apple-clang", "10")
]

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def validate(self):
if not self._check_compiler():
raise ConanInvalidConfiguration("%s package is not compatible with os %s and compiler %s version %s." % (self.name, self.settings.os, self.settings.compiler, self.settings.compiler.version))

def _check_compiler(self):
zuut marked this conversation as resolved.
Show resolved Hide resolved
os = self.settings.os
compiler = self.settings.compiler
compiler_version = tools.Version(compiler.version)
return any(os == sc[0] and compiler == sc[1] and compiler_version >= sc[2] for sc in self._supported_compilers)

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def requirements(self):
self.requires("flex/2.6.4")
self.requires("bison/3.7.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
rename(self.name + "-" + self.version, self._source_subfolder)
zuut marked this conversation as resolved.
Show resolved Hide resolved

def build(self):
cmake = self._configure_cmake()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(source_folder=self._source_subfolder)
zuut marked this conversation as resolved.
Show resolved Hide resolved
return self._cmake

def package(self):
cmake = self._configure_cmake()
cmake.install()
tools.remove_files_by_mask(join(self.package_folder, "lib"), "*-config.cmake")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tools.remove_files_by_mask(join(self.package_folder, "lib"), "*-config.cmake")
tools.rmdir(join(self.package_folder, "lib", "moc"))
tools.remove_files_by_mask(join(self.package_folder, "lib", "uf"), "*.cmake")

From what I see in installation layout:

-- Install configuration: "Debug"
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/bin/moc
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/moc/moc-targets.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/moc/moc-targets-debug.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/moc/moc-config.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/cmake/Moc.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/cmake/BisonFlex.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/uf/libuf.a
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/uf/uf-targets.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/lib/uf/uf-targets-debug.cmake
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/generic.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufAll.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufDate.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufDef.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufFileNm.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufIHshT.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufList.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufPtr.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufSHshT.h
-- Installing: /home/conan/w/BuildSingleReference/.conan/data/moc/0.9.401/_/_/package/5ab7aa3bc61b93e1b46714a0ee54d9a856dbe3b6/include/ufString.h

self.copy(pattern="LICENSE", dst="licenses",
src=self._source_subfolder,
keep_path=False)
cmakeModulesDir=join(self.package_folder, "cmake-modules")
if isdir(cmakeModulesDir):
move(cmakeModulesDir,join(self.package_folder, "lib", "cmake"))
return

def package_info(self):
self.env_info.MOC_TOOL = join(self.package_folder, "bin", "moc").replace("\\", "/")

self.env_info.PATH.append(join(self.package_folder, "bin"))
zuut marked this conversation as resolved.
Show resolved Hide resolved

self.cpp_info.names["cmake_find_package"] = "Moc"
self.cpp_info.names["cmake_find_package_multi"] = "Moc"

self.cpp_info.build_modules["cmake_find_package"].append(join("lib", "cmake", "BisonFlex.cmake"))
self.cpp_info.build_modules["cmake_find_package_multi"].append(join("lib", "cmake", "BisonFlex.cmake"))
self.cpp_info.build_modules["cmake_find_package"].append(join("lib", "cmake", "Moc.cmake"))
self.cpp_info.build_modules["cmake_find_package_multi"].append(join("lib", "cmake", "Moc.cmake"))
self.cpp_info.builddirs.append(join("lib", "cmake"))
self.cpp_info.builddirs.append(join("lib", "moc"))
self.cpp_info.builddirs.append(join("lib", "uf"))
Comment on lines +91 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cpp_info.builddirs.append(join("lib", "moc"))
self.cpp_info.builddirs.append(join("lib", "uf"))

Those folders contain CMake target files, they shouldn't be packaged

self.cpp_info.libs = tools.collect_libs(self)
zuut marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions recipes/moc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.12)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
zuut marked this conversation as resolved.
Show resolved Hide resolved

find_package(Moc REQUIRED CONFIG)
include(Moc)


set(CMAKE_PROJECT_VARS
CONAN_MOC_ROOT
MOC_TOOL
)

foreach(MOC_VAR ${CMAKE_PROJECT_VARS})
message("${MOC_VAR}: ${${MOC_VAR}}")
if(NOT ${MOC_VAR})
message(FATAL_ERROR "${MOC_VAR} NOT FOUND")
endif()
endforeach()

set(TARGET_GEN_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/genSrc)
file(MAKE_DIRECTORY ${TARGET_GEN_SRC_DIR})

bld_add_custom_moc_target(${CMAKE_SOURCE_DIR}/test_app.moc
SET_VAR MOC_GEN_SRC_FILES
INCLUDE ${CMAKE_SOURCE_DIR}
TEMPLATE ${CMAKE_SOURCE_DIR}/test_app.tpl
DEPENDS_ON ${CMAKE_SOURCE_DIR}/test_app.moh
OUTPUT ${TARGET_GEN_SRC_DIR}
)

add_executable(${CMAKE_PROJECT_NAME}
main.cpp
${MOC_GEN_SRC_FILES}
)

target_include_directories(${CMAKE_PROJECT_NAME}
PRIVATE ${TARGET_GEN_SRC_DIR}/include
)

target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
zuut marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 53 additions & 0 deletions recipes/moc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanException
import os
import sys
from six import StringIO


class MocTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
moc_bin = tools.which("moc")
self.output.info("Moc was located at '%s'" % moc_bin);
if not moc_bin.startswith(self.deps_cpp_info["moc"].rootpath):
raise ConanException("Wrong moc executable captured")
versionInfo=""
try:
mybuf = StringIO()
self.run("moc -v", output=mybuf, run_environment=True)
versionInfo = mybuf.getvalue().rstrip()
if versionInfo == "":
self.output.error("NO OUTPUT FROM MOC")
else:
self.output.info("MOC Version: '%s'" % versionInfo)
except ConanException as err:
raise
except:
raise ConanException("Moc version not found. Moc may not have been built correctly")

if not "version" in versionInfo:
raise ConanException("Moc version not found. Moc may not have been built correctly")
cppExe = "/usr/lib/cpp"
cpp_bin = tools.which(cppExe)
if cpp_bin == None:
self.output.warn("%s is required by moc, but cpp was not found" % cppExe);
return

cmake = CMake(self)
cmake.definitions["MOC_ROOT"] = self.deps_cpp_info["moc"].rootpath
cmake.configure()
cmake.build()

def test(self):
cppExe = "/usr/lib/cpp"
cpp_bin = tools.which(cppExe)
if cpp_bin == None:
self.output.warn("%s is required by moc, but cpp was not found" % cppExe);
return
if not tools.cross_building(self.settings, skip_x64_x86=True):
os.chdir("bin")
self.run(".%stest_package" % os.sep)
9 changes: 9 additions & 0 deletions recipes/moc/all/test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
typedef char* String;
typedef int integer;
typedef long Long;

#include "bizobj/address/Address.h"

int main(int argc, char **argv) {
Address address;
}
Comment on lines +1 to +9
Copy link
Contributor

@SpaceIm SpaceIm Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it test link to uf library? It's the only one I see under lib/uf folder. Since this folder was not added to of cpp_info.libdirs, I'm wondering if cpp_info.libs is not empty...

Why upstream CMakeLists install this library in this subfolder instead of lib folder directly?

15 changes: 15 additions & 0 deletions recipes/moc/all/test_package/test_app.moc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include "test_app.moh"

class Address {
[[ bizObject {1} ]];
[[ description { An address of some real world entity } ]];

String street1, [[ description {The street}]];
String street2, [[ description {2nd line of street info}]];
String city, [[ description {The City}]];
String state, [[ description {The State}]];
String zipcode, [[ description {The Zip Code}]];
};


5 changes: 5 additions & 0 deletions recipes/moc/all/test_package/test_app.moh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

type String {
Header "<string>";
[[ type {std::string} ]];
};
42 changes: 42 additions & 0 deletions recipes/moc/all/test_package/test_app.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@# Template for the moc compiler.
zuut marked this conversation as resolved.
Show resolved Hide resolved
@{if exists MODULE
@{ foreach my-class in ALL_CLASSES
@{ if ( is-from-current-module ) && ( ! is-a Interface ) && exists bizObject
@{ if ! exists BizObjIntfDir
@> set BizObjIntfDir=bizobj/@(:lowercase-all @(Name))
@} end if ! exists BizObjIntfDir
@{ if ! exists BizObjIntfPkg
@> set BizObjIntfPkg=bizobj/@(:lowercase-all @(Name)).h
@} end if ! exists BizObjIntfPkg
@{ if ! exists BizObjDefineGuards
@> set BizObjDefineGuards=@(:uppercase-all bizobj_@(:uppercase-all @(Name))
@} end if ! exists BizObjDefineGuards
@# ///////////////////////////////////////////////
@# //
@# //
@# //
@# //
@# //
@# //
@# //
@# ///////////////////////////////////////////////
@{ open include/@(BizObjIntfDir)/@(Name).h
#ifndef @(BizObjDefineGuards)
#define @(BizObjDefineGuards)

class @(Name) @(:if exists HasParents :then : @\
@(:format-list : suffix-sep=',' :foreach parent in parents @\
: public @(Name)) @\
) {
public:
@{ foreach property in properties
/**The @(Name) property - @(description). */
@(Type.TypeString) @(Name);
@} end foreach property in properties
};
#endif // @(BizObjDefineGuards)
@} end open include/@(BizObjIntfDir)/@(Name).h
@# ///////////////////////////////////////////////
@} end if is-from-current-module
@} end foreach my-class in ALL_CLASSES
@}endif exists MODULE
3 changes: 3 additions & 0 deletions recipes/moc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.9.401":
folder: all