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

#175 fixed #242

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class CppGeneratorTest extends AbstractGeneratorTest
TODO
"""

build_requires = "CMakeMacros/0.4.latest@cab/testing"
build_requires = (
("CMakeMacros/0.4.latest@cab/testing"),
)
# TODO instead of "latest", for maturity RELEASE, this should be replaced by a
# concrete version at some point (maybe not during generation, but during the build?)
# in a similar manner as mvn versions:resolve-ranges
Expand Down Expand Up @@ -235,7 +237,9 @@ class CppGeneratorTest extends AbstractGeneratorTest
TODO
"""

build_requires = "CMakeMacros/0.4.latest@cab/testing"
build_requires = (
("CMakeMacros/0.4.latest@cab/testing"),
)
# TODO instead of "latest", for maturity RELEASE, this should be replaced by a
# concrete version at some point (maybe not during generation, but during the build?)
# in a similar manner as mvn versions:resolve-ranges
Expand Down Expand Up @@ -322,7 +326,9 @@ class CppGeneratorTest extends AbstractGeneratorTest
TODO
"""

build_requires = "CMakeMacros/0.4.latest@cab/testing"
build_requires = (
("CMakeMacros/0.4.latest@cab/testing"),
)
# TODO instead of "latest", for maturity RELEASE, this should be replaced by a
# concrete version at some point (maybe not during generation, but during the build?)
# in a similar manner as mvn versions:resolve-ranges
Expand Down Expand Up @@ -431,7 +437,9 @@ class CppGeneratorTest extends AbstractGeneratorTest
TODO
"""

build_requires = "CMakeMacros/0.3.latest@cab/testing"
build_requires = (
("CMakeMacros/0.3.latest@cab/testing"),
)
# TODO instead of "latest", for maturity RELEASE, this should be replaced by a
# concrete version at some point (maybe not during generation, but during the build?)
# in a similar manner as mvn versions:resolve-ranges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.btc.serviceidl.generator.dotnet.DotNetConstants
import com.btc.serviceidl.generator.java.JavaConstants
import com.google.common.base.MoreObjects
import com.google.common.base.Objects
import com.google.common.collect.ImmutableMap
import com.google.common.collect.ImmutableSet
import com.google.common.collect.Sets
import java.io.InputStream
Expand Down Expand Up @@ -211,13 +210,7 @@ class DefaultGenerationSettingsProvider implements IGenerationSettingsProvider
case Main.OPTION_VALUE_CPP_PROJECT_SYSTEM_CMAKE:
{
result.projectSetFactory = new CMakeProjectSetFactory();

// TODO instead of printing on System.out, use some event mechanism here
System.out.println("Disabling ODB generation, this is unsupported with CMake project system");
result.projectTypes = Sets.difference(result.projectTypes,
ImmutableSet.of(ProjectType.EXTERNAL_DB_IMPL));
result.moduleStructureStrategy = new CABModuleStructureStrategy();

}
case Main.OPTION_VALUE_CPP_PROJECT_SYSTEM_PRINS_VCXPROJ:
{
Expand Down Expand Up @@ -272,6 +265,7 @@ class DefaultGenerationSettingsProvider implements IGenerationSettingsProvider
public static val OPTION_VALUE_PROJECT_SET_SERVER = "server"
public static val OPTION_VALUE_PROJECT_SET_FULL = "full"
public static val OPTION_VALUE_PROJECT_SET_FULL_WITH_SKELETON = "full-with-skeleton"
public static val OPTION_VALUE_PROJECT_SET_FULL_WITH_SKELETON_PERSISTENT = "full-with-skeleton-persistent"

public static val Set<ProjectType> API_PROJECT_SET = ImmutableSet.of(ProjectType.SERVICE_API, ProjectType.COMMON)
public static val Set<ProjectType> CLIENT_PROJECT_SET = Sets.union(API_PROJECT_SET,
Expand All @@ -282,11 +276,17 @@ class DefaultGenerationSettingsProvider implements IGenerationSettingsProvider
public static val Set<ProjectType> SERVER_PROJECT_SET = Sets.union(API_PROJECT_SET,
ImmutableSet.of(ProjectType.PROTOBUF, ProjectType.DISPATCHER /*, ProjectType.SERVER_RUNNER*/ ))
public static val Set<ProjectType> FULL_PROJECT_SET = Sets.union(CLIENT_PROJECT_SET, SERVER_PROJECT_SET)

public static val Map<String, Set<ProjectType>> PROJECT_SET_MAPPING = ImmutableMap.of(OPTION_VALUE_PROJECT_SET_API,
API_PROJECT_SET, OPTION_VALUE_PROJECT_SET_CLIENT, CLIENT_PROJECT_SET, OPTION_VALUE_PROJECT_SET_SERVER,
SERVER_PROJECT_SET, OPTION_VALUE_PROJECT_SET_FULL, FULL_PROJECT_SET,
OPTION_VALUE_PROJECT_SET_FULL_WITH_SKELETON, ImmutableSet.copyOf(ProjectType.values()))
public static val Set<ProjectType> FULL_WITH_SKELETON_PROJECT_SET = Sets.difference(ImmutableSet.copyOf(ProjectType.values()),
ImmutableSet.of(ProjectType.EXTERNAL_DB_IMPL))

public static val Map<String, Set<ProjectType>> PROJECT_SET_MAPPING = #{
OPTION_VALUE_PROJECT_SET_API -> API_PROJECT_SET
,OPTION_VALUE_PROJECT_SET_CLIENT -> CLIENT_PROJECT_SET
,OPTION_VALUE_PROJECT_SET_SERVER -> SERVER_PROJECT_SET
,OPTION_VALUE_PROJECT_SET_FULL -> FULL_PROJECT_SET
,OPTION_VALUE_PROJECT_SET_FULL_WITH_SKELETON -> FULL_WITH_SKELETON_PROJECT_SET
,OPTION_VALUE_PROJECT_SET_FULL_WITH_SKELETON_PERSISTENT -> ImmutableSet.copyOf(ProjectType.values())
}

def reset()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.btc.serviceidl.generator.cpp.cmake.CMakeProjectSet
import com.btc.serviceidl.generator.cpp.cmake.CMakeProjectSet.ProjectReference
import com.btc.serviceidl.generator.cpp.cmake.CMakeTopLevelProjectFileGenerator
import com.btc.serviceidl.generator.cpp.prins.OdbProjectGenerator
import com.btc.serviceidl.generator.cpp.prins.PrinsModuleStructureStrategy
import com.btc.serviceidl.idl.AbstractTypeReference
import com.btc.serviceidl.idl.IDLSpecification
import com.btc.serviceidl.idl.ModuleDeclaration
Expand Down Expand Up @@ -193,7 +194,8 @@ class CppGenerator
generationSettings,
smartPointerMap,
module,
generationSettings.dependencies
generationSettings.dependencies,
generationSettings.moduleStructureStrategy instanceof PrinsModuleStructureStrategy
).generate()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.btc.serviceidl.generator.cpp

import com.btc.serviceidl.generator.common.GeneratorUtil
import com.btc.serviceidl.generator.common.TransformType
import com.btc.serviceidl.generator.cpp.TypeResolver.IncludeGroup
import java.util.ArrayList
import java.util.Arrays
Expand Down Expand Up @@ -196,6 +194,14 @@ class HeaderResolver
"boost::bimap" -> "boost/bimap.hpp"
}

// ******************************* PLEASE ALWAYS KEEP THIS LIST ALPHABETICALLY SORTED !!! ******************************* //
static val odbHeaderMapper = #{
"id_binary" -> "odb/mssql/traits.hxx",
"id_raw" -> "odb/oracle/traits.hxx",
"id_uniqueidentifier" -> "odb/mssql/traits.hxx",
"odb::nullable" -> "odb/nullable.hxx"
}

val Map<String, GroupedHeader> headerMap
val Map<String, GroupedHeader> implementationHeaderMap

Expand Down Expand Up @@ -253,7 +259,7 @@ class HeaderResolver
{
builder.withGroup(stlHeaderMapper, TypeResolver.STL_INCLUDE_GROUP).withGroup(boostHeaderMapper,
TypeResolver.BOOST_INCLUDE_GROUP).withGroup(cabHeaderMapper, TypeResolver.CAB_INCLUDE_GROUP).
withImplementationGroup(cabImplHeaderMapper, TypeResolver.CAB_INCLUDE_GROUP)
withImplementationGroup(cabImplHeaderMapper, TypeResolver.CAB_INCLUDE_GROUP).withGroup(odbHeaderMapper, TypeResolver.ODB_INCLUDE_GROUP)
}

def configureGroup(Iterable<TypeResolver.IncludeGroup> includeGroups, int precedence, String prefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TypeResolver
public static val STL_INCLUDE_GROUP = new IncludeGroup("STL")
public static val BOOST_INCLUDE_GROUP = new IncludeGroup("boost")
public static val CAB_INCLUDE_GROUP = new IncludeGroup("BTC.CAB")
public static val ODB_INCLUDE_GROUP = new IncludeGroup("odb")

val LibResolver libResolver
@Accessors(PACKAGE_GETTER) val HeaderResolver headerResolver
Expand Down Expand Up @@ -154,6 +155,10 @@ class TypeResolver
// do nothing
{
}
case ODB_INCLUDE_GROUP:
// do nothing
{
}
case PrinsHeaderResolver.ODB_INCLUDE_GROUP:
// TODO remove this here, make a subclass in prins.* or so
// do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class CABModuleStructureStrategy implements IModuleStructureStrategy

override createHeaderResolver()
{
new HeaderResolver.Builder().withBasicGroups.configureGroup(TypeResolver.TARGET_INCLUDE_GROUP, 10, "", "",
false).configureGroup(TypeResolver.CAB_INCLUDE_GROUP, 20, "", "", true).configureGroup(
TypeResolver.STL_INCLUDE_GROUP, 30, "", "", true).build
new HeaderResolver.Builder().withBasicGroups
.configureGroup(TypeResolver.TARGET_INCLUDE_GROUP, 10, "", "", false)
.configureGroup(TypeResolver.CAB_INCLUDE_GROUP, 20, "", "", true)
.configureGroup(TypeResolver.ODB_INCLUDE_GROUP, 30, "", "", true)
.configureGroup(TypeResolver.STL_INCLUDE_GROUP, 40, "", "", true).build
}

override getProjectDir(ParameterBundle paramBundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import com.btc.serviceidl.generator.common.ProjectType
import com.btc.serviceidl.generator.cpp.CppConstants
import com.btc.serviceidl.generator.cpp.IProjectSet
import com.btc.serviceidl.generator.cpp.ServiceCommVersion
import com.btc.serviceidl.idl.AbstractTypeReference
import com.btc.serviceidl.idl.IDLSpecification
import com.btc.serviceidl.idl.ModuleDeclaration
import com.btc.serviceidl.idl.StructDeclaration
import com.btc.serviceidl.util.Util
import java.util.Set
import org.eclipse.core.runtime.Path
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.generator.IFileSystemAccess

import static extension com.btc.serviceidl.generator.common.GeneratorUtil.*
import static extension com.btc.serviceidl.generator.cpp.CppExtensions.*
import static extension com.btc.serviceidl.util.Util.*
import com.btc.serviceidl.idl.NamedDeclaration

@Accessors(NONE)
class CMakeTopLevelProjectFileGenerator
Expand Down Expand Up @@ -85,6 +91,11 @@ class CMakeTopLevelProjectFileGenerator
val versionSuffix = if (generationSettings.maturity == Maturity.SNAPSHOT) "-unreleased" else ""
val dependencyChannel = if (generationSettings.maturity == Maturity.SNAPSHOT) "testing" else "stable"

// TODO the ODB data could be parameterized in the future
val odbTargetVersion = "2.5.0-b.9"
val libodbTargetVersion = "2.5.0-b.9"
val odbdependencyChannel = "extern"

// TODO the transitive dependencies do not need to be specified here
'''
from conan_template import *
Expand All @@ -97,7 +108,12 @@ class CMakeTopLevelProjectFileGenerator
TODO
"""

build_requires = "CMakeMacros/«cmakeMacrosVersion».latest@cab/«dependencyChannel»"
build_requires = (
("CMakeMacros/«cmakeMacrosVersion».latest@cab/«dependencyChannel»"),
«IF ! ODBStructsList.empty»
("odb/«odbTargetVersion»@cab/«odbdependencyChannel»")
«ENDIF»
)
# TODO instead of "latest", for maturity RELEASE, this should be replaced by a
# concrete version at some point (maybe not during generation, but during the build?)
# in a similar manner as mvn versions:resolve-ranges
Expand All @@ -115,10 +131,35 @@ class CMakeTopLevelProjectFileGenerator
«FOR dependency : generationSettings.dependencies.sortBy[getID(ArtifactNature.CPP)]»
("«dependency.getID(ArtifactNature.CPP)»/«dependency.version»«versionSuffix»@cab/«dependencyChannel»"),
«ENDFOR»
«IF ! ODBStructsList.empty»
("libodb/«libodbTargetVersion»@cab/«odbdependencyChannel»")
«ENDIF»
)
generators = "cmake"
short_paths = True

«IF ! ODBStructsList.empty»
def generateODBFiles(self):
includedirs = ""
for includedir in self.deps_cpp_info["BTC.CAB.Commons"].includedirs:
includedirs += " -I " + os.path.normpath(os.path.join(includedir))
for includedir in self.deps_cpp_info["odb"].includedirs:
includedirs += " -I " + os.path.normpath(os.path.join(includedir))
for includedir in self.deps_cpp_info["libodb"].includedirs:
includedirs += " -I " + os.path.normpath(os.path.join(includedir))
odbdir = ""
«FOR project : projectSet.projects»
«IF project.projectType == ProjectType.EXTERNAL_DB_IMPL»
odbdir = os.path.normpath(self.source_folder + "\\«project.relativePath»\\odb")
«ENDIF»
«ENDFOR»
odbbindir = os.path.normpath(os.path.join(self.deps_cpp_info["odb"].bindirs[0]))
«FOR struct : ODBStructsList»
self.run(odbbindir + '\\odb.exe --std c++14' + includedirs +
' --multi-database dynamic --database common --database mssql --database oracle --generate-query --generate-prepared --generate-schema --schema-format embedded -x -Wno-unknown-pragmas -x -Wno-pragmas -x -Wno-literal-suffix -x -Wno-attributes --hxx-prologue "#include \"traits.hxx\"" --output-dir ' + odbdir + ' ' + odbdir + '\\«struct».hxx')
«ENDFOR»
«ENDIF»

def generateProtoFiles(self):
protofiles = glob.glob(self.source_folder + "/**/gen/*.proto", recursive=True)
outdir = self.source_folder
Expand All @@ -131,12 +172,15 @@ class CMakeTopLevelProjectFileGenerator

def build(self):
self.generateProtoFiles()
«IF ! ODBStructsList.empty»
self.generateODBFiles()
«ENDIF»
ConanTemplate.build(self)

def package(self):
ConanTemplate.package(self)
self.copy("**/*.proto", dst="proto", keep_path=True)

def imports(self):
self.copy("protoc.exe", "bin", "bin")
'''
Expand Down Expand Up @@ -235,7 +279,9 @@ class CMakeTopLevelProjectFileGenerator

«FOR project : projectSet.projects.sortBy[relativePath.toPortableString]»
«IF module.eResource.URI == project.resourceURI»
include(${CMAKE_CURRENT_LIST_DIR}/«project.relativePath.toPortableString»/build/make.cmakeset)
«IF project.projectType != ProjectType.EXTERNAL_DB_IMPL || (project.projectType == ProjectType.EXTERNAL_DB_IMPL && !ODBStructsList.empty)»
include(${CMAKE_CURRENT_LIST_DIR}/«project.relativePath.toPortableString»/build/make.cmakeset)
«ENDIF»
«ENDIF»
«ENDFOR»

Expand All @@ -250,4 +296,33 @@ class CMakeTopLevelProjectFileGenerator
generationSettings.moduleStructureStrategy.getProjectDir(paramBundle).makeRelativeTo(modulePath)
}

/**
get the list of the names for all ODB structures
*/
private def Set<String> getODBStructsList()
{
getFilterODBStructs(
projectSet.projects.filter[it.projectType == ProjectType.EXTERNAL_DB_IMPL]
.map[e | e.moduleStack]
.flatten
.map[e | e.moduleComponents]
.flatten
.filter[e | e.isStruct]
.map(e | e.structType.ultimateType as StructDeclaration)
.filter[!members.empty]
.map[val AbstractTypeReference res = it ; res]
.resolveAllDependencies
.map[type]
.filter(StructDeclaration)
).map[e | e as NamedDeclaration]
.map[e | e.name.toLowerCase].toSet
}

/**
filter ODB entities from the list of all structures
*/
private def Iterable<StructDeclaration> getFilterODBStructs(Iterable<StructDeclaration> structs)
{
structs.filter[!members.filter[m | m.name.toUpperCase == "ID" && Util.isUUIDType(m.type)].empty]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ import static extension com.btc.serviceidl.util.Util.*

@Accessors
class OdbProjectGenerator extends ProjectGeneratorBase {

val boolean usePrinsEncapsulationHeaders

new(IFileSystemAccess fileSystemAccess, IQualifiedNameProvider qualifiedNameProvider, IScopeProvider scopeProvider,
IDLSpecification idl, IProjectSetFactory projectSetFactory, IProjectSet vsSolution,
IModuleStructureStrategy moduleStructureStrategy, ITargetVersionProvider targetVersionProvider,
Map<AbstractTypeReference, Collection<AbstractTypeReference>> smartPointerMap, ModuleDeclaration module,
Iterable<PackageInfo> importedDependencies)
Iterable<PackageInfo> importedDependencies, boolean usePrinsEncapsulationHeaders)
{
super(fileSystemAccess, qualifiedNameProvider, scopeProvider, idl, projectSetFactory, vsSolution,
moduleStructureStrategy, targetVersionProvider, smartPointerMap, ProjectType.EXTERNAL_DB_IMPL, module,
importedDependencies, new OdbSourceGenerationStrategy)

this.usePrinsEncapsulationHeaders = usePrinsEncapsulationHeaders
}

override void generate()
{
val allElements = module.moduleComponents
Expand Down Expand Up @@ -137,17 +142,21 @@ class OdbProjectGenerator extends ProjectGeneratorBase {
{
'''
#pragma once


«IF usePrinsEncapsulationHeaders»
#include "modules/Commons/include/BeginPrinsModulesInclude.h"

«ENDIF»

«IF useCommonTypes»#include "«Constants.FILE_NAME_ODB_COMMON.hxx»"«ENDIF»
«basicCppGenerator.generateIncludes(true)»
«fileContent»


«IF usePrinsEncapsulationHeaders»
#include "modules/Commons/include/EndPrinsModulesInclude.h"
«ENDIF»
'''
}

private static class OdbSourceGenerationStrategy implements ISourceGenerationStrategy
{
override String generateProjectSource(BasicCppGenerator basicCppGenerator, InterfaceDeclaration interfaceDeclaration)
Expand Down