Exemplo n.º 1
0
HAMIGAKI_BJAM_DECL string_list import(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& src_module = ctx.get_module(args[0].try_front());
    const string_list& src_rules = args[1];
    const boost::optional<std::string>& tgt_module_name = args[2].try_front();
    module& tgt_module = ctx.get_module(tgt_module_name);
    const string_list& tgt_rules = args[3];
    const bool localize = !args[4].empty();

    if (src_rules.size() != tgt_rules.size())
        throw std::runtime_error("the count of rule names mismatch"); // FIXME

    for (std::size_t i = 0, size = src_rules.size(); i < size; ++i)
    {
        rule_definition def =
            src_module.rules.get_rule_definition(src_rules[i]);

        if (localize)
            def.module_name = tgt_module_name;
        def.exported = false;

        tgt_module.rules.set_rule_definition(tgt_rules[i], def);
    }

    return string_list();
}
Exemplo n.º 2
0
HAMIGAKI_BJAM_DECL string_list normalize_path(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    return string_list(bjam::normalize_path(args[0]));
}
Exemplo n.º 3
0
HAMIGAKI_BJAM_DECL string_list native_rule(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const std::string& module_name = args[0][0];
    const std::string& rule_name = args[1][0];

    typedef std::map<std::string,bjam::native_rule> table_type;
    typedef table_type::const_iterator iter_type;

    module& m = ctx.get_module(module_name);
    const table_type& table = m.native_rules;
    iter_type it = table.find(rule_name);
    if (it == table.end())
        throw rule_not_found(rule_name);

    const bjam::native_rule& rule = it->second;

    rule_definition def;
    def.parameters = rule.parameters;
    def.native = rule.native;
    def.module_name = module_name;
    def.exported = true;
    m.rules.set_native_rule(rule_name, def);

    return string_list();
}
Exemplo n.º 4
0
HAMIGAKI_BJAM_DECL string_list match(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& regexps = args[0];
    const string_list& list = args[1];

    string_list result;

    for (std::size_t j = 0; j < regexps.size(); ++j)
    {
        const std::string& pattern = bjam::convert_regex(regexps[j]);

        // Note: bjam's regex is not the same as "egrep" and "ECMAScript"
        boost::regex rex(pattern);
        for (std::size_t i = 0; i < list.size(); ++i)
        {
            boost::smatch what;
            if (regex_search(list[i], what, rex))
            {
                result.insert(
                    result.end(), boost::next(what.begin()), what.end());
            }
        }
    }

    return result;
}
Exemplo n.º 5
0
HAMIGAKI_BJAM_DECL string_list calc(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& arg1 = args[0];

    if (arg1.size() < 3u)
        return string_list();

    long lhs = arg1[0].empty() ? 0 : std::atoi(arg1[0].c_str()); // FIXME
    char op = arg1[1][0];
    long rhs = arg1[2].empty() ? 0 : std::atoi(arg1[2].c_str()); // FIXME

    long value;
    if (op == '+')
        value = lhs + rhs;
    else if (op == '-')
        value = lhs - rhs;
    else
        return string_list();

    std::ostringstream os;
    os.imbue(std::locale::classic());
    os << value;
    return string_list(os.str());
}
Exemplo n.º 6
0
HAMIGAKI_BJAM_DECL string_list update(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    string_list old = ctx.targets_to_update();
    ctx.targets_to_update(args[0]);
    return old;
}
Exemplo n.º 7
0
HAMIGAKI_BJAM_DECL string_list sort(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    string_list sequence = args[0];
    sequence.sort();

    return sequence;
}
Exemplo n.º 8
0
HAMIGAKI_BJAM_DECL string_list instance(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& instance_module = ctx.get_module(args[0][0]);
    instance_module.class_module = args[1][0];

    return string_list();
}
Exemplo n.º 9
0
HAMIGAKI_BJAM_DECL string_list delete_module(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& m = ctx.get_module(args[0].try_front());
    m.rules.clear();
    m.variables.clear();

    return string_list();
}
Exemplo n.º 10
0
HAMIGAKI_BJAM_DECL string_list imported_modules(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& m = ctx.get_module(args[0].try_front());

    return string_list(
        m.imported_modules.begin(),
        m.imported_modules.end()
    );
}
Exemplo n.º 11
0
HAMIGAKI_BJAM_DECL string_list import_module(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& imported = args[0];
    module& tgt_module = ctx.get_module(args[1].try_front());

    tgt_module.imported_modules.insert(imported.begin(), imported.end());

    return string_list();
}
Exemplo n.º 12
0
HAMIGAKI_BJAM_DECL string_list w32_getreg(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& arg1 = args[0];
    const string_list& arg2 = args[1];

    const std::string& path = arg1[0];
    boost::optional<std::string> name = arg2.try_front();

    return win32::registry_values(path, name);
}
Exemplo n.º 13
0
HAMIGAKI_BJAM_DECL string_list pad(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    std::string str = args[0][0];
    std::size_t width = static_cast<std::size_t>(std::atoi(args[1][0].c_str()));

    if (str.size() < width)
        str.resize(width, ' ');

    return string_list(str);
}
Exemplo n.º 14
0
HAMIGAKI_BJAM_DECL string_list check_if_file(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const std::string& file = args[0][0];

    fs::path ph(file);
    fs::path work(ctx.working_directory());
    ph = fs::complete(ph, work);
    if (fs::is_regular(ph))
        return string_list(std::string("true"));
    else
        return string_list();
}
Exemplo n.º 15
0
HAMIGAKI_BJAM_DECL string_list back_trace(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg1 = args[0];

    int level = boost::integer_traits<int>::const_max;
    if (!arg1.empty())
        level = std::atoi(arg1[0].c_str());

    if (level <= 0)
        return string_list();

    return ctx.back_trace(static_cast<std::size_t>(level), 1u);
}
Exemplo n.º 16
0
HAMIGAKI_BJAM_DECL string_list update_now(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg2 = args[1];
    const string_list& arg3 = args[2];

    const string_list& targets = args[0];
    const boost::optional<std::string>& log = arg2.try_front();
    const boost::optional<std::string>& force = arg3.try_front();

    // TODO: not implemented

    return string_list(std::string("ok"));
}
Exemplo n.º 17
0
HAMIGAKI_BJAM_DECL string_list rebuilds(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& targets = args[0];
    const string_list& sources = args[1];

    for (std::size_t i = 0, size = targets.size(); i < size; ++i)
    {
        target& t = ctx.get_target(targets[i]);
        t.rebuilt_targets.insert(sources.begin(), sources.end());
    }

    return string_list();
}
Exemplo n.º 18
0
HAMIGAKI_BJAM_DECL string_list echo(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg1 = args[0];

    std::ostream& os = ctx.output_stream();

    std::copy(
        arg1.begin(), arg1.end(),
        hamigaki::ostream_iterator<std::string>(os, " ")
    );
    os << '\n';

    return string_list();
}
Exemplo n.º 19
0
HAMIGAKI_BJAM_DECL string_list user_module(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& modules = args[0];
    module& m = ctx.get_module(args[0].try_front());

    for (std::size_t i = 0, size = modules.size(); i < size; ++i)
    {
        module& m = ctx.get_module(modules[i]);
        m.user_module = true;
    }

    return string_list();
}
Exemplo n.º 20
0
HAMIGAKI_BJAM_DECL string_list glob_recursive(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& patterns = args[0];

    string_list result;

    for (std::size_t i = 0; i < patterns.size(); ++i)
    {
        result += bjam::glob_recursive(
            ctx.working_directory(), patterns[i]);
    }

    return result;
}
Exemplo n.º 21
0
HAMIGAKI_BJAM_DECL string_list w32_getregnames(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& arg1 = args[0];
    const string_list& arg2 = args[1];

    const std::string& path = arg1[0];
    const std::string& result_type = arg2[0];

    if (result_type == "subkeys")
        return win32::registry_subkey_names(path);
    else if (result_type == "values")
        return win32::registry_value_names(path);
    else
        return string_list();
}
Exemplo n.º 22
0
HAMIGAKI_BJAM_DECL string_list export_(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& m = ctx.get_module(args[0].try_front());
    const string_list& rules = args[1];

    for (std::size_t i = 0, size = rules.size(); i < size; ++i)
    {
        rule_definition* def = m.rules.get_rule_definition_ptr(rules[i]);
        if (!def)
            throw rule_not_found(rules[i]);

        def->exported = true;
    }

    return string_list();
}
Exemplo n.º 23
0
HAMIGAKI_BJAM_DECL string_list has_native_rule(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    module& m = ctx.get_module(args[0][0]);
    const std::string& rule_name = args[1][0];
    int version = std::atoi(args[2][0].c_str());

    typedef std::map<std::string,bjam::native_rule> table_type;
    typedef table_type::const_iterator iter_type;

    const table_type& table = m.native_rules;
    iter_type it = table.find(rule_name);
    if ((it != table.end()) && (it->second.version == version))
        return string_list(std::string("true"));

    return string_list();
}
Exemplo n.º 24
0
HAMIGAKI_BJAM_DECL string_list search_for_target(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& targets = args[0];
    const string_list& path = args[1];

    const std::string& name = targets[0];

    path_components compo;
    split_path(compo, name);
    compo.grist.clear();
    compo.member.clear();

    bool found = false;
    std::string filename;

    for (std::size_t i = 0, size = path.size(); i < size; ++i)
    {
        compo.root = path[i];
        filename = make_path(compo);

        if (fs::exists(fs::path(filename)))
        {
            found = true;
            break;
        }
    }

    if (!found)
    {
        compo.root.clear();
        fs::path ph(make_path(compo));
        fs::path work(ctx.working_directory());
        filename = fs::complete(ph, work).file_string();
    }

    call_bind_rule(ctx, name, filename);

    return string_list(name);
}
Exemplo n.º 25
0
HAMIGAKI_BJAM_DECL string_list var_names(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg1 = args[0];

    boost::optional<std::string> name;
    if (!arg1.empty())
        name = arg1[0];

    module& m = ctx.get_module(name);

    variable_table::iterator beg, end;
    boost::tie(beg, end) = m.variables.entries();

    return string_list(
        make_first_iterator(beg),
        make_first_iterator(end)
    );
}
Exemplo n.º 26
0
HAMIGAKI_BJAM_DECL string_list shell(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const std::string& cmd = args[0][0];
    const string_list& arg2 = args[1];

    bool need_status = false;
    bool need_capture = true;
    for (std::size_t i = 0, size = arg2.size(); i < size; ++i)
    {
        if (arg2[i] == "exit-status")
            need_status = true;
        else if (arg2[i] == "no-output")
            need_capture = false;
    }

    return bjam::shell(cmd, need_status, need_capture);
}
Exemplo n.º 27
0
HAMIGAKI_BJAM_DECL string_list nearest_user_location(context& ctx)
{
    frame& f = ctx.current_frame();

    frame* user_frame =
        f.current_module().user_module ? &f : f.prev_user_frame();
    if (!user_frame)
        return string_list();

    string_list result;
    result.push_back(user_frame->filename());
    {
        std::ostringstream os;
        os.imbue(std::locale::classic());
        os << user_frame->line();
        result.push_back(os.str());
    }

    return result;
}
Exemplo n.º 28
0
HAMIGAKI_BJAM_DECL string_list exit(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg1 = args[0];
    const string_list& arg2 = args[1];

    std::ostringstream os;
    std::copy(
        arg1.begin(), arg1.end(),
        hamigaki::ostream_iterator<std::string>(os, " ")
    );

    int code = EXIT_FAILURE;
    if (!arg2.empty())
        code = std::atoi(arg2[0].c_str()); // FIXME

    throw exit_exception(os.str(), code);

    BOOST_UNREACHABLE_RETURN(string_list())
}
Exemplo n.º 29
0
HAMIGAKI_BJAM_DECL string_list md5(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const std::string& s = args[0][0];

    checksum::md5 md5;
    md5.process_bytes(s.c_str(), s.size());

    typedef checksum::md5::value_type value_type;
    const value_type& v = md5.checksum();

    std::ostringstream os;
    os.imbue(std::locale::classic());
    os << std::hex << std::setfill('0');
    for (std::size_t i = 0; i < value_type::static_size; ++i)
        os << std::setw(2) << static_cast<unsigned>(v[i]);

    return string_list(os.str());
}
Exemplo n.º 30
0
HAMIGAKI_BJAM_DECL string_list file_open(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const std::string& name = args[0][0];
    const std::string& mode = args[1][0];

    int fd;
    if (mode == "w")
        fd = ::open(name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
    else
        fd = ::open(name.c_str(), O_RDONLY);

    if (fd == -1)
        return string_list();

    std::ostringstream os;
    os.imbue(std::locale::classic());
    os << fd;
    return string_list(os.str());
}