• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #856

28 Dec 2022 02:00AM UTC coverage: 86.602% (+0.05%) from 86.55%
#856

push

StellarBot
Merge #6119

6119: Update CMakeLists.txt r=hkaiser a=khuck

updating the default APEX version


Co-authored-by: Kevin Huck <khuck@cs.uoregon.edu>

174566 of 201573 relevant lines covered (86.6%)

1876093.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.52
/libs/core/command_line_handling_local/src/late_command_line_handling_local.cpp
1
//  Copyright (c) 2007-2022 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/assert.hpp>
8
#include <hpx/command_line_handling_local/late_command_line_handling_local.hpp>
9
#include <hpx/command_line_handling_local/parse_command_line_local.hpp>
10
#include <hpx/modules/program_options.hpp>
11
#include <hpx/modules/runtime_configuration.hpp>
12
#include <hpx/type_support/unused.hpp>
13
#include <hpx/util/from_string.hpp>
14

15
#include <cstddef>
16
#include <iostream>
17
#include <string>
18
#include <vector>
19

20
namespace hpx::local::detail {
21

22
    std::string enquote(std::string arg)
6,023✔
23
    {
24
        if (arg.find_first_of(" \t\"") != std::string::npos)
6,023✔
25
        {
26
            return std::string("\"") + HPX_MOVE(arg) + "\"";
×
27
        }
28
        return arg;
6,023✔
29
    }
6,023✔
30

31
    void decode(std::string& str, char const* s, char const* r)
×
32
    {
33
        std::string::size_type pos = 0;
×
34
        while ((pos = str.find(s, pos)) != std::string::npos)
×
35
        {
36
            str.replace(pos, 2, r);
×
37
        }
38
    }
×
39

40
    std::string decode_string(std::string str)
×
41
    {
42
        decode(str, "\\n", "\n");
×
43
        return str;
×
44
    }
45

46
    void set_unknown_commandline_options(util::runtime_configuration& ini,
5✔
47
        std::vector<std::string> const& still_unregistered_options)
48
    {
49
        std::string still_unknown_commandline;
5✔
50
        for (std::size_t i = 1; i < still_unregistered_options.size(); ++i)
8✔
51
        {
52
            if (i != 1)
3✔
53
            {
54
                still_unknown_commandline += " ";
×
55
            }
×
56
            still_unknown_commandline += enquote(still_unregistered_options[i]);
3✔
57
        }
3✔
58

59
        if (!still_unknown_commandline.empty())
5✔
60
        {
61
            util::section* s = ini.get_section("hpx");
3✔
62
            HPX_ASSERT(s != nullptr);
3✔
63
            s->add_entry("unknown_cmd_line_option", still_unknown_commandline);
3✔
64
        }
3✔
65
    }
5✔
66

67
    bool handle_full_help(util::runtime_configuration& ini,
1,812✔
68
        hpx::program_options::options_description const& options)
69
    {
70
        std::string fullhelp(ini.get_entry("hpx.cmd_line_help", ""));
1,812✔
71
        if (!fullhelp.empty())
1,812✔
72
        {
73
            std::string help_option(
74
                ini.get_entry("hpx.cmd_line_help_option", ""));
×
75
            if (0 == std::string("full").find(help_option))
×
76
            {
77
                std::cout << decode_string(fullhelp);
×
78
                std::cout << options << std::endl;
×
79
            }
×
80
            else
81
            {
82
                throw hpx::detail::command_line_error(
×
83
                    "unknown help option: " + help_option);
×
84
            }
85
            return true;
×
86
        }
×
87
        return false;
1,812✔
88
    }
1,812✔
89

90
    std::string get_full_commandline(util::runtime_configuration& ini)
1,812✔
91
    {
92
        return ini.get_entry("hpx.commandline.command", "") + " " +
5,436✔
93
            ini.get_entry("hpx.commandline.prepend_options", "") +
3,624✔
94
            ini.get_entry("hpx.commandline.options", "") +
3,624✔
95
            ini.get_entry("hpx.commandline.config_options", "");
1,812✔
96
    }
×
97

98
    bool handle_late_options(util::runtime_configuration& ini,
1,812✔
99
        hpx::program_options::variables_map& vm,
100
        void (*handle_print_bind)(std::size_t))
101
    {
102
        if (vm.count("hpx:print-bind"))
1,812✔
103
        {
104
            std::size_t num_threads = hpx::util::from_string<std::size_t>(
×
105
                ini.get_entry("hpx.os_threads", 1));
×
106
            handle_print_bind(num_threads);
×
107
        }
×
108

109
        if (vm.count("hpx:exit"))
1,812✔
110
        {
111
            return true;
1✔
112
        }
113

114
        return false;
1,811✔
115
    }
1,812✔
116

117
    int handle_late_commandline_options(util::runtime_configuration& ini,
1,218✔
118
        hpx::program_options::options_description const& options,
119
        void (*handle_print_bind)(std::size_t))
120
    {
121
        // do secondary command line processing, check validity of options only
122
        try
123
        {
124
            std::string unknown_cmd_line(
125
                ini.get_entry("hpx.unknown_cmd_line", ""));
1,218✔
126
            if (!unknown_cmd_line.empty())
1,218✔
127
            {
128
                util::commandline_error_mode mode =
3✔
129
                    util::commandline_error_mode::rethrow_on_error;
130
                std::string allow_unknown(
131
                    ini.get_entry("hpx.commandline.allow_unknown", "0"));
3✔
132
                if (allow_unknown != "0")
3✔
133
                    mode = util::commandline_error_mode::allow_unregistered;
2✔
134

135
                hpx::program_options::variables_map vm;
3✔
136
                std::vector<std::string> still_unregistered_options;
3✔
137
                parse_commandline(ini, options, unknown_cmd_line, vm, mode,
3✔
138
                    nullptr, &still_unregistered_options);
139

140
                set_unknown_commandline_options(
3✔
141
                    ini, still_unregistered_options);
3✔
142
            }
3✔
143

144
            if (handle_full_help(ini, options))
1,218✔
145
            {
146
                return 1;
×
147
            }
148

149
            // secondary command line handling, looking for --exit and other
150
            // options
151
            std::string cmd_line(get_full_commandline(ini));
1,218✔
152
            if (!cmd_line.empty())
1,218✔
153
            {
154
                hpx::program_options::variables_map vm;
1,218✔
155

156
                parse_commandline(ini, options, cmd_line, vm,
2,436✔
157
                    util::commandline_error_mode::allow_unregistered |
1,218✔
158
                        util::commandline_error_mode::
159
                            report_missing_config_file);
160

161
                if (handle_late_options(ini, vm, handle_print_bind))
1,218✔
162
                {
163
                    return 1;
1✔
164
                }
165
            }
1,218✔
166
        }
1,218✔
167
        catch (std::exception const& e)
168
        {
169
            std::cerr
170
                << "handle_late_commandline_options: command line processing: "
×
171
                << e.what() << std::endl;
×
172
            return -1;
×
173
        }
×
174

175
        return 0;
1,217✔
176
    }
1,218✔
177
}    // namespace hpx::local::detail
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc