Author: 7py9aeed21x2

  • gradle-javacpp

    Gradle JavaCPP

    Gitter Maven Central Sonatype Nexus (Snapshots) Build Status Commercial support: xscode

    Introduction

    Gradle JavaCPP offers plugins that make it easy to use JavaCPP and JavaCV as part of the Gradle build system.

    Please feel free to ask questions on the mailing list if you encounter any problems with the software! I am sure it is far from perfect…

    Required Software

    To use Gradle JavaCPP, you will need to download and install the following software:

    Getting Started

    Gradle JavaCPP comes with 2 plugins:

    • The build plugin to create new packages containing native libraries using JavaCPP, and
    • The platform plugin to select from existing artifacts the ones corresponding to user-specified platforms.

    Fully functional sample projects are also provided in the samples subdirectory and can be used as templates.

    The Build Plugin

    To understand how JavaCPP is meant to be used, one should first take a look at the Mapping Recipes for C/C++ Libraries, but a high-level overview of the Basic Architecture is also available to understand the bigger picture.

    Once comfortable enough with the command line interface, the build plugin for Gradle can be used to integrate easily that workflow as part of build.gradle as shown below. By default, for Java libraries and applications, it creates a javacppJar task that archives the native libraries into a separate JAR file and sets its classifier to $javacppPlatform$javacppPlatformExtension, while excluding those files from the default jar task. To customize the behavior, there are properties that can be modified and whose documentation is available as part of the source code in these files:

    plugins {
        id 'java-library'
        id 'org.bytedeco.gradle-javacpp-build' version "$javacppVersion"
    }
    
    // We can set this on the command line too this way: -PjavacppPlatform=android-arm64
    ext {
        javacppPlatform = 'android-arm64' // or any other platform, defaults to Loader.getPlatform()
    }
    
    dependencies {
        api "org.bytedeco:javacpp:$javacppVersion"
    }
    
    tasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {
        // set here default values for all build tasks below, typically just includePath and linkPath,
        // but also properties to set the path to the NDK and its compiler in the case of Android
    }
    
    javacppBuildCommand {
        // typically set here the buildCommand to the script that fills up includePath and linkPath
    }
    
    javacppBuildParser {
        // typically set here the classOrPackageNames to class names implementing InfoMap
    }
    
    javacppBuildCompiler {
        // typically set here boolean flags like copyLibs
    }

    Integration with Android Studio

    It is also possible to integrate the BuildTask with Android Studio for projects with C/C++ support by:

    1. Following the instructions at https://developer.android.com/studio/projects/add-native-code ,
    2. Adding something like below to the app/build.gradle file, and
    android.applicationVariants.all { variant ->
        def variantName = variant.name.capitalize() // either "Debug" or "Release"
        def javaCompile = project.tasks.getByName("compile${variantName}JavaWithJavac")
        def configureCMake = project.tasks.findAll {
            it.name.startsWith("configureCMake$variantName")
        }
    
        // Compiles NativeLibraryConfig.java
        task "javacppCompileJava$variantName"(type: JavaCompile) {
            include 'com/example/myapplication/NativeLibraryConfig.java'
            source = javaCompile.source
            classpath = javaCompile.classpath
            destinationDir = javaCompile.destinationDir
        }
    
        // Parses NativeLibrary.h and outputs NativeLibrary.java
        task "javacppBuildParser$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
            dependsOn "javacppCompileJava$variantName"
            classPath = [javaCompile.destinationDir]
            includePath =  ["$projectDir/src/main/cpp/"]
            classOrPackageNames = ['com.example.myapplication.NativeLibraryConfig']
            outputDirectory = file("$projectDir/src/main/java/")
        }
    
        // Compiles NativeLibrary.java and everything else
        javaCompile.dependsOn "javacppBuildParser$variantName"
    
        // Generates jnijavacpp.cpp and jniNativeLibrary.cpp
        task "javacppBuildCompiler$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
            dependsOn javaCompile
            classPath = [javaCompile.destinationDir]
            classOrPackageNames = ['com.example.myapplication.NativeLibrary']
            compile = false
            deleteJniFiles = false
            outputDirectory = file("$projectDir/src/main/cpp/")
        }
    
        // Picks up the C++ files listed in CMakeLists.txt
        configureCMake.forEach {
            it.dependsOn "javacppBuildCompiler$variantName"
        }
    }
    1. Updating the CMakeLists.txt file to include the generated .cpp files.

    The Platform Plugin

    With Maven, we are able to modify dependencies transitively using profiles, and although Gradle doesn’t provide such functionality out of the box, it can be emulated via plugins. After adding a single line to the build.gradle script as shown below, the platform plugin will filter the dependencies of artifacts whose names contain “-platform” using the comma-separated values given in $javacppPlatform. To understand better how this works, it may be worth taking a look at the source code of the plugin:

    plugins {
        id 'java-library'
        id 'org.bytedeco.gradle-javacpp-platform' version "$javacppVersion"
    }
    
    // We can set this on the command line too this way: -PjavacppPlatform=linux-x86_64,macosx-x86_64,windows-x86_64,etc
    ext {
        javacppPlatform = 'linux-x86_64,macosx-x86_64,windows-x86_64,etc' // defaults to Loader.getPlatform()
    }
    
    dependencies {
        api "org.bytedeco:javacv-platform:$javacvVersion" // or any other "-platform" artifacts
    }

    Moreover, in the case of Android, its plugin is not able to use native libraries found in JAR files when building Android App Bundles (AAB files). However, to work around this limitation we can easily use Gradle to extract the files automatically, for example, in the following manner with an additional javacppExtract task inside app/build.gradle:

    configurations {
        javacpp
    }
    
    task javacppExtract(type: Copy) {
        dependsOn configurations.javacpp
    
        from { configurations.javacpp.collect { zipTree(it) } }
        include "lib/**"
        into "$buildDir/javacpp/"
        android.sourceSets.main.jniLibs.srcDirs += ["$buildDir/javacpp/lib/"]
    
        tasks.getByName('preBuild').dependsOn javacppExtract
    }
    
    dependencies {
        implementation group: 'org.bytedeco', name: 'javacv', version: "$javacvVersion"
        javacpp group: 'org.bytedeco', name: 'openblas-platform', version: "$openblasVersion-$javacppVersion"
        javacpp group: 'org.bytedeco', name: 'opencv-platform', version: "$opencvVersion-$javacppVersion"
        javacpp group: 'org.bytedeco', name: 'ffmpeg-platform', version: "$ffmpegVersion-$javacppVersion"
        ...
    }

    Project lead: Samuel Audet samuel.audet at gmail.com
    Developer site: https://github.com/bytedeco/gradle-javacpp
    Discussion group: http://groups.google.com/group/javacpp-project

    Visit original content creator repository https://github.com/bytedeco/gradle-javacpp
  • pysvinst

    pysvinst

    License: MIT Actions Status codecov PyPI version Join the chat at https://gitter.im/sgherbst/pysvinst

    This Python library examines SystemVerilog files to determine what modules are defined and what modules are instantiated. The backend uses sv-parser, which has good support of SystemVerilog 2017.

    Purpose

    The Verilog language has contains features for defining configs and libraries. However, these features are not well-supported by open-source tools, and even some commercial synthesis tools. By extracting a list of modules defined and instantiated in a file, a user can work around this problem by constructing their own design hierarchy outside of Verilog, and then passing that list of files back into the simulator / synthesis tool.

    Installation

    This package can be installed via pip:

    > pip install svinst

    Alternatively, you can clone the repository and build the package yourself. This requires that Rust is installed.

    > git clone https://github.com/sgherbst/pysvinst.git
    > cd pysvinst
    > pip install -e .

    Usage

    The main functionality of this package is provided through the function get_defs. In this first example, a list of module definitions is returned, each one containing a list module instantiations (if any) contained in that module definition.

    >>> from svinst import get_defs
    >>> defs = get_defs('tests/verilog/test.sv')
    >>> _ = [print(str(def_)) for def_ in defs]
    ModDef("A", [
    ])
    ModDef("B", [
    ])
    ModDef("C", [
      ModInst("A", "I0"),
      ModInst("B", "I1")
    ])
    ModDef("D", [
      ModInst("X", "I0"),
      ModInst("Y", "I1")
    ])

    It is also possible to add define variables and include directory paths, since both of these can change the modules that get defined and instantiated:

    >>> get_defs('tests/verilog/inc_test.sv', includes=['tests/verilog'])
    >>> get_defs('tests/verilog/def_test.sv',
                 defines={'MODULE_NAME': 'module_name_from_define', 'EXTRA_INSTANCE': None})

    If there is a syntax error, an error message is printed and an Exception is raised.

    >>> get_defs('tests/verilog/broken.sv')
    parse failed: "tests/verilog/broken.sv"
     tests/verilog/broken.sv:5:10
      |
    5 | endmodule
      |  

    Finally, the user can get a full syntax tree for advanced processing, using the command get_syntax_tree. That command also allows the arguments includes and defines.

    >>> from svinst import get_syntax_tree
    >>> tree = get_syntax_tree('tests/verilog/simple.sv')
    >>> _ = [print(elem) for elem in tree]
    SyntaxNode("SourceText", [
      SyntaxNode("Description", [
        SyntaxNode("ModuleDeclaration", [
          SyntaxNode("ModuleDeclarationAnsi", [
            SyntaxNode("ModuleAnsiHeader", [
              SyntaxNode("ModuleKeyword", [
                SyntaxNode("Keyword", [
                  SyntaxToken("module", line=1)
                ])
              ]),
              SyntaxNode("ModuleIdentifier", [
                SyntaxNode("Identifier", [
                  SyntaxNode("SimpleIdentifier", [
                    SyntaxToken("A", line=1)
                  ])
                ])
              ]),
              SyntaxNode("Symbol", [
                SyntaxToken(";", line=1)
              ])
            ]),
            SyntaxNode("Keyword", [
              SyntaxToken("endmodule", line=2)
            ])
          ])
        ])
      ])
    ])
    Visit original content creator repository https://github.com/sgherbst/pysvinst
  • Dota 2 Discord Bot

    Dota 2 Discord Bot

    The main purpose of this bot is to post a message on your Discord group, whenever you or your friends play a match. But it does some other tasks as well. Below is a list of the functionalities.

    Implemented

    1. Dota 2 Game tracking – Post a message on your Discord group after someone finishes a match. Win/Loss, Hero played, KDA and a Dotabuff link of the match is posted.
    2. Daily Game tracking – At midnight the number of matches played on that day and the number of wins are displayed.
    3. Polls – Initiate a poll, vote on it, and display the results of the poll.
    4. Spam Control – Same message sent within 2 seconds of the previous one by a user is deleted.

    Upcoming

    1. Gametime tracking – Keep track of time spent by a user on a particular game.

    Complete Documentation

    !doc                                    Display available commands
    !ping                                   Find the ping time between the bot and the Discord server
    !vote <Topic> <option1>|<option2>...    Start a poll with the given topic and options
      !vote <number>                        Vote for an existing poll with the option corresponding to the number
      !vote status                          Display the status of an the existing poll
      !vote end                             End an existing poll
    !RemindMe <Reminder> <Time><Unit>       Set a reminder which evaluates in the given time.
    !abuse <@mention>                       Abuse a user.
      !abuse add <Abuse>                    Add an expletive to the abuse list.
    !medal                                  Display your current dota medal.
      !medal <@mention>                     Display the user's current dota medal.
    !recent <@mention> <Hours>              Display the number of games played by a user in the last <Hours> hours.
                                            If omitted:
                                            <@mention> defaults to - you
                                            <Hours> defaults to 12
    

    Iterative Development

    Make your changes, commit them, and push them to the remote. Next, on the server where the bot is running, stop the bot and run the deploying script:

    ./deploy.sh <branch-name>

    where <branch-name> is the name of the branch you want to deploy. The script will automatically download the latest code from the remote, build your bot and run it. Make sure you have execute permissions to run this script.

    Visit original content creator repository
    https://github.com/pratikyoff/dota-discord-bot