<commit_before>local system = require 'system'

local P = {}

function P:get_shared(pkg)
    local o = {}
    local function w(format, ...)
        table.insert(o, string.format(format, ...))
    end

    local source = pkg.source

    if source.type and source.location then
        w('pkg_source="%s %s"', source.type, source.location)
    end
    if source.branch then
        w('pkg_source_branch="%s"', source.branch)
    end
    if source.path then
        w('pkg_source_dir="%s"', source.path)
    end

    if pkg.patches then
        w('jagen_pkg_apply_patches() {')
        for _, patch in ipairs(pkg.patches or {}) do
            local name = patch[1]
            local strip = patch[2]
            w('  pkg_run_patch %d "%s"', strip, name)
        end
        w('}')
    end

    if pkg.build then
        local build = pkg.build
        if build.type then
            w("pkg_build_type='%s'", build.type)
        end
        if build.generate then
            w("pkg_build_generate='yes'")
        end
        if build.configure_needs_install_dir then
            w("pkg_configure_needs_install_dir='yes'")
        end
    end

    return o
end

function P:get(pkg, config)
    local o = {}
    local function w(format, ...)
        table.insert(o, string.format(format, ...))
    end

    local env = pkg.env or { config }
    for _, e in ipairs(env or {}) do
        w('use_env %s || return', e)
    end

    -- put install variables before build to allow referencing them from
    -- configure options
    if config and pkg.configs[config] and pkg.configs[config].install then
        local i = pkg.configs[config].install
        if i.root then
            w('pkg_sysroot="%s"', i.root)
        end
        if i.prefix then
            w('pkg_prefix="%s"', i.prefix)
        end
    end

    local build_dir

    if pkg.build then
        local build = pkg.build

        if build.profile then
            w("pkg_build_profile='%s'", build.profile)
        end

        if build.options then
            local o = build.options
            if type(build.options) == 'string' then
                o = { build.options }
            end
            w('pkg_options="%s"', table.concat(o, '\n'))
        end
        if build.libs then
            w("pkg_libs='%s'", table.concat(build.libs, ' '))
        end<commit_msg>Simplify install rule handling<commit_after>local system = require 'system'

local P = {}

function P:get_shared(pkg)
    local o = {}
    local function w(format, ...)
        table.insert(o, string.format(format, ...))
    end

    local source = pkg.source

    if source.type and source.location then
        w('pkg_source="%s %s"', source.type, source.location)
    end
    if source.branch then
        w('pkg_source_branch="%s"', source.branch)
    end
    if source.path then
        w('pkg_source_dir="%s"', source.path)
    end

    if pkg.patches then
        w('jagen_pkg_apply_patches() {')
        for _, patch in ipairs(pkg.patches or {}) do
            local name = patch[1]
            local strip = patch[2]
            w('  pkg_run_patch %d "%s"', strip, name)
        end
        w('}')
    end

    if pkg.build then
        local build = pkg.build
        if build.type then
            w("pkg_build_type='%s'", build.type)
        end
        if build.generate then
            w("pkg_build_generate='yes'")
        end
        if build.configure_needs_install_dir then
            w("pkg_configure_needs_install_dir='yes'")
        end
    end

    return o
end

function P:get(pkg, config)
    local o = {}
    local function w(format, ...)
        table.insert(o, string.format(format, ...))
    end

    local env = pkg.env or { config }
    for _, e in ipairs(env or {}) do
        w('use_env %s || return', e)
    end

    -- put install variables before build to allow referencing them from
    -- configure options
    do local install = pkg:get('install', config)
        if install then
            if install.root then
                w('pkg_sysroot="%s"', install.root)
            end
            if install.prefix then
                w('pkg_prefix="%s"', install.prefix)
            end
        end
    end

    local build_dir

    if pkg.build then
        local build = pkg.build

        if build.profile then
            w("pkg_build_profile='%s'", build.profile)
        end

        if build.options then
            local o = build.options
            if type(build.options) == 'string' then
                o = { build.options }
            end
            w('pkg_options="%s"', table.concat(o, '\n'))
        end
        if build.libs then
            w("pkg_libs='%s'", table.concat(build.libs, ' '))
        end
{'fraction_non_alphanumeric': 0.11658141517476556, 'fraction_numerical': 0.0008525149190110827, 'mean_word_length': 1.796781883194279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2679950', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1408, 'n_words': 383}