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

antlr4: add package #4369

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

antlr4: add package #4369

wants to merge 3 commits into from

Conversation

star-hengxing
Copy link
Contributor

No description provided.

@star-hengxing
Copy link
Contributor Author

expected:

target("antlr4-lua")
    set_kind("static")
    add_files("g4/LuaLexer.g4", {rules = "@antlr4/lexer"})
    add_files("g4/LuaParser.g4", {rules = "@antlr4/parser"})
    -- add_rules("@antlr4/lexer")
    -- add_rules("@antlr4/parser")

    add_includedirs(".")

    add_packages("antlr4", "antlr4-runtime")

    on_load(function (target)
        if target:is_shared() then
            target:add("defines", "ANTLR4CPP_EXPORTS")
        elseif target:is_static() then
            target:add("defines", "ANTLR4CPP_STATIC", {public = true})
        end
    end)

But add_files can't work with package rule, it's bug?

on_install("windows|x64", "linux|x86_64", "macosx|x86_64", "macosx|arm64", "mingw|x86_64", function (package)
local source = "antlr-" .. package:version() .. "-complete.jar"
local target = path.join(package:installdir("lib"), "antlr-complete.jar")
os.vcp("../" .. source, package:installdir("lib"))
Copy link
Member

Choose a reason for hiding this comment

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

为啥解压出来会调到 source 目录外面去?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

直接下的 jar,不会解压

local target = path.join(package:installdir("lib"), "antlr-complete.jar")
os.vcp("../" .. source, package:installdir("lib"))
os.vmv(package:installdir("lib", source), target)
package:addenv("CLASSPATH", target)
Copy link
Member

Choose a reason for hiding this comment

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

添加路径环境变量,用相对路径,不要用 package:installdir(),否则跑到云端预编译,路径就不对了

然后再用 package:mark_as_pathenv("CLASSPATH") 将它标记为路径,就能自动处理相对路径了。

@waruqi
Copy link
Member

waruqi commented Jun 15, 2024

expected:

target("antlr4-lua")
    set_kind("static")
    add_files("g4/LuaLexer.g4", {rules = "@antlr4/lexer"})
    add_files("g4/LuaParser.g4", {rules = "@antlr4/parser"})
    -- add_rules("@antlr4/lexer")
    -- add_rules("@antlr4/parser")

    add_includedirs(".")

    add_packages("antlr4", "antlr4-runtime")

    on_load(function (target)
        if target:is_shared() then
            target:add("defines", "ANTLR4CPP_EXPORTS")
        elseif target:is_static() then
            target:add("defines", "ANTLR4CPP_STATIC", {public = true})
        end
    end)

But add_files can't work with package rule, it's bug?

包 rule 是有限制的,有些地方不好实现,目前不支持 add_files,只能走 add_rules

import("lib.detect.find_tool")

assert(target:pkg("antlr4"), "Please configure add_packages(antlr4) for target(" .. target:name() .. ")")
local envs = target:pkg("antlr4"):get("envs")
Copy link
Member

Choose a reason for hiding this comment

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

直接用 target:pkgenvs() 就行了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

但这里拿到的 CLASSPATH 还是相对路径

@waruqi
Copy link
Member

waruqi commented Jun 19, 2024

回头我看下 这两天还没空看

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I'll check it out later. I haven't had time to look at it in the past two days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants