Unknown type name 'WINBOOL' - windows

I'm trying to link psapi in to a kotlin-native application and I encountered this error that I don't know how to fix.
By the type of error it looks like I'm missing something in the linker options but I couldn't find any information about it.
build.gradle.kts:
plugins {
kotlin("multiplatform") version "1.3.50"
}
repositories {
mavenCentral()
}
kotlin {
mingwX64("HelloWorld") {
val main by compilations.getting
val psapi by main.cinterops.creating
binaries {
executable("HelloWorldApp") {
entryPoint = "sample.helloworld.main"
}
}
}
}
src/nativeInterop/cinterop/psapi.def:
headers = psapi.h
headerFilter = psapi/*
linkerOpts.mingw = -lpsapi
The actual exception message:
Exception in thread "main" java.lang.Error: C:\Users\pawer\.konan\dependencies\msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1-2\x86_64-w64-mingw32\include\psapi.h:75:3: error: unknown type name 'WINBOOL'
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:146)
at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:963)
at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:952)
at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:222)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:38)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:69)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:18)
FAILURE: Build failed with an exception.

Problem solved
src/nativeInterop/cinterop/psapi.def:
headers = windows.h \ psapi.h
headerFilter = psapi.h
package = psapi
linkerOpts.mingw = -lpsapi

Related

Kotlin Mock Spring boot test can't compile

So I have the following test
#Test
fun `when save claims is called with email saved to that profile` () {
//arrange
given(profileRepository.findProfileByEmail(anyString())).willAnswer { daoProfile }
given(patientRepository.findById(anyInt())).willAnswer { Optional.of(daoPatient) }
given(claimRepository.saveAll(anyList())).willAnswer { mutableListOf(daoClaim) }
//act
val result = claimService.saveClaimsForEmail(listOf(dtoClaim), "Test#test.test")
//assert
assert(result != null)
assert(result?.isNotEmpty() ?: false)
verify(claimRepository).saveAll(anyList())
}
The line given(claimRepository.saveAll(anyList())).willAnswer { mutableListOf(daoClaim) } gives the folowing error
e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: KtBlockExpression
File being compiled at position: (217,71) in /Users/archer/Work/masterhealth/master_billing/src/test/kotlin/com/masterhealthsoftware/master_billing/data/service/ClaimServiceTest.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.state.KotlinTypeMapper$typeMappingConfiguration$1.processErrorType(KotlinTypeMapper.kt:113)
...
Caused by: java.lang.IllegalStateException: Error type encountered: (???..???) (FlexibleTypeImpl).
at org.jetbrains.kotlin.codegen.state.KotlinTypeMapper$typeMappingConfiguration$1.processErrorType(KotlinTypeMapper.kt:113)
When the line is removed, it compiles but the test fails for obvious reasons.
claimRespoitory is annotated #MockBean at the top of the test class, and is a JpaInterface. Line 217 is the start of the function. I've also trie using when and other various willReturn or willAnswer....
Any idea why?
I was facing the same issue when using Mockito any(). Changing it to ArgumentMatchers.any(YourClass::class.java)) solved the compilation error, there is a deprecated ArgumentMatchers.anyListOf(YourClass::class.java) that might do the job.

FileNotFoundException: `generated/source/apollo/generatedIR/main`

I try to generate my graphql schema using gradle apollo generateApolloClasses. So the first step is to generateMainApolloIR and it is working fine. It is generating a MainAPI.json under
/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/MainAPI.json. But the generateApolloClasses is failing with:
> java.io.FileNotFoundException: /Users/mctigg/Documents/Repositories/generated/source/apollo/generatedIR/main (Is a directory)
So it is looking into the wrong path! This is my gradle config:
apollo {
nullableValueType = "javaOptional"
outputPackageName = "generated.client.backend"
}
task generateBackendSchemaJson(type: ApolloSchemaIntrospectionTask) {
url = 'src/main/graphql/client/backend/schema.graphqls'
output = 'src/main/graphql/client/backend/schema.json'
}
tasks.findByName('generateMainApolloIR').dependsOn(['generateBackendSchemaJson'])
So how can I configure generateApolloClasses to look into:
/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/
Instead of
/generated/source/apollo/generatedIR/main/
May be you should set schema file path as follows:
apollo {
schemaFilePath = "/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/schema.json"
nullableValueType = "javaOptional"
outputPackageName = "generated.client.backend"
}

Update build.gradle 3.3.0 Breaks applicationVariants.all apk Assembly

I have just upgraded an Android project's build.gradle to use build version 3.3.0
com.android.tools.build:gradle:3.3.0
Doing so has created this warning:
WARNING: API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getAssemble(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
It is caused by this code in the app build.gradle:
android.applicationVariants.all { variant ->
variant.assemble.doLast {
variant.outputs.each { output ->
def apk = variant.outputs[0].outputFile
File versionInfo = new File(apk.parent, "versionInfo.properties")
versionInfo.text = "versionCode=${android.defaultConfig.versionCode}\nversionName=${android.defaultConfig.versionName}"
copy {
from "${versionInfo}"
into "$project.projectDir/temp_archive"
}
}
}
}
I haven't been able to find where I can rewrite this to make the warning disappear. I tried to follow this Stack Overflow post, but didn't make any progress. Any suggestions would be greatly appreciated.
I found a potential solution that has resolved the warning. Below is the code I am using. Leaving the question for now in case there is a better solution.
android.applicationVariants.all { variant ->
variant.getAssembleProvider().get().doLast {
variant.outputs.each { output ->
def apk = variant.outputs[0].outputFile
File versionInfo = new File(apk.parent, "versionInfo.properties")
versionInfo.text = "versionCode=${android.defaultConfig.versionCode}\nversionName=${android.defaultConfig.versionName}"
copy {
from "${versionInfo}"
into "$project.projectDir/temp_archive"
}
}
}
}

Autogenerate REST endpoints from .proto

I am having problem with compiling the .proto file. Looking to generate REST endpoints from the .proto files. Below is the code and error :
syntax = "proto3";
package pb;
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
service UrlShortener {
rpc Hello(HelloRequest) returns (HelloResponse);
rpc Encrypt(EncryptRequest) returns (EncryptResponse);
rpc Decrypt(DecryptRequest) returns (DecryptResponse) {
option (google.api.http) = {
get: "/{hash}"
};
}
}
message HelloRequest {
string Name = 1;
}
message HelloResponse {
string Message = 1;
}
message EncryptRequest {
string OriginalUrl = 1;
}
message EncryptResponse {
UrlMap ResponseMap = 1;
}
message DecryptRequest {
string hash = 1;
}
Error :
github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist.
google/api/annotations.proto: File not found.
urlshortener.proto: Import "google/api/annotations.proto" was not found or had errors.
Please help with fixing this.
I tried : go get -u github.com/grpc-ecosystem/grpc-gateway
But it failed saying : no buildable go source files in path.
I think you have more than one errors in your definition
You are missing the syntax version at the very beginning of your definition:
syntax = "proto3";
There are some undefined types
service.proto:32:3: "UrlMap" is not defined.
service.proto:12:40: "DecryptResponse" is not defined.
You are importing and unused empty.proto
You can use the googleapies from
{GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
Then run using:
protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include -I. service.proto --go_out=plugins=grpc:.
I made the previous changes and it compiles, so I have the service.pb.go file
Edited:
Take a look of this grpc-gateway, maybe can help you
https://github.com/grpc-ecosystem/grpc-gateway
Found out the solution : The problem is that google/api/annotations has moved from the earlier path grpc-ecosystem/grpc-gateway/third_party/googleapis to https://github.com/grpc-ecosystem/grpc-gateway/tree/master/third_party/googleapis/google/api.
Running the following resolved the error : go get -u github.com/grpc-ecosystem/grpc-gateway/...

multiple times triggering of Datasource.groovy in grails application ( throwing exception when called second time)

Work Around for creating the application :
creating a Grails Application using Postgres database.
Needs to create Database when the application is executed (i.e database is to be created from the project itself instead of creating the database manually).
For creating the database I am calling a groovy service CreateDatabaseService in datasource.groovy as follows :
import demo.grails.CreateDatabaseService
CreateDatabaseService.serviceMethod()
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.postgresql.Driver"
dialect = "org.hibernate.dialect.PostgreSQLDialect"
username = "postgres"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://localhost:5432/SampleAppDb"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/SampleAppDb"
}
} .....
Full code for CreateDatabaseService :
package demo.grails
import groovy.sql.Sql
import java.sql.DriverManager
import java.sql.Connection
import java.sql.SQLException
import java.sql.*
class CreateDatabaseService {
public static flag =0
def static serviceMethod() {
Connection conn = null;
Statement stmt = null;
try{
if(flag == 0) {
//STEP 2: Register JDBC driver
Class.forName("org.postgresql.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432", "postgres", "password");
//STEP 4: Execute a query
System.out.println("Creating database...");
stmt = conn.createStatement();
String isDatabase = "select datname from pg_catalog.pg_database where lower(datname) = lower('SampleAppDb')"
ResultSet rs = stmt.executeQuery(isDatabase);
String idr
while(rs.next()){
//Retrieve by column name
idr = rs.getString("datname");
}
if(!idr.equals("SampleAppDb")) {
String sql = "create database SampleAppDb";
stmt.executeUpdate(sql);
System.out.println("Database created successfully...");
flag =1
}
else {
flag =1
}
}
}catch(Exception e){
e.printStackTrace();
}
finally{
stmt.close();
conn.close();
}
}
}
On running the grails app following is the full stack trace that shows datasource.groovy is called multiple times, though the database is created from the application but complains about no suitable driver found when datasource.groovy is called second time.
|Loading Grails 2.4.5
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
................Connecting to database...
Creating database...
Database created successfully...
....................
|Running Grails application
Connecting to database...
Error |
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432
Error |
at java.sql.DriverManager.getConnection(DriverManager.java:689)
Error |
at java.sql.DriverManager.getConnection(DriverManager.java:247)
Error |
at java_sql_DriverManager$getConnection.call(Unknown Source)
Error |
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
Error |
at demo.grails.CreateDatabaseService.serviceMethod(CreateDatabaseService.groovy:23)
Error |
at demo.grails.CreateDatabaseService$serviceMethod.call(Unknown Source)
Error |.......
Please suggest how to overcome this error.
BuildConfig.groovy
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
runtime 'postgresql:postgresql:9.0-801.jdbc4'
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55.2" // or ":tomcat:8.0.20"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:2.1.5"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.8.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
Validate that you have the following configuration in your BuildConfig
dependencies {
...
compile 'org.grails.plugins:hibernate:4.3.10.4'
provided 'org.postgresql:postgresql:9.4-1203-jdbc4'
...
}

Resources