summaryrefslogtreecommitdiff
path: root/tests/projects/c++/modules/reuse_strict_private_defines/test.lua
blob: 7f136218ed0df2bebcc7d94a7eea52f8737e9012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
inherit(".test_base")
import("utils.ci.is_running", {alias = "ci_is_running"})

local PRIVATE_DEFINE = "PRIVATE_DEP_DEFINE_DO_NOT_PROPAGATE"
local PUBLIC_SYSINCLUDEDIR = path.translate("src/include")

function _build()
    local flags = ""
    if ci_is_running() then
        flags = "-vD"
    end
    local leaked = false
    local missing_sysincludedir = true
    local outdata = try { function () return os.iorun("xmake -rv") end }
    if outdata then
        for line in outdata:gmatch("[^\r\n]+") do
            if line:find("Consumer", 1, true) then
                if line:find(PRIVATE_DEFINE, 1, true) then
                    leaked = true
                end
                if line:find(PUBLIC_SYSINCLUDEDIR, 1, true) then
                    missing_sysincludedir = false
                end
            end
        end
        if leaked then
            raise("Private dependency defines leaked into Consumer module rebuilds under reuse.strict\n%s", outdata)
        end
        if missing_sysincludedir then
            raise("Missing public sysincludedir in Consumer module rebuilds under reuse.strict\n%s", outdata)
        end
    else
        -- maybe build failed, we need to see verbose errors
        os.run("xmake " .. flags)
    end
end

function main(_)
    local clang_options = {compiler = "clang", version = clang_min_ver(), build = _build}
    local gcc_options = {compiler = "gcc", version = gcc_min_ver(), build = _build}
    local msvc_options = {version = msvc_min_ver(), build = _build}
    run_tests(clang_options, gcc_options, msvc_options)
end