aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/do_info_action.cc
blob: ea864287a59f74a8e229dfcb8e34ddaffdc8cac0 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2010, 2011 Ciaran McCreesh
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <paludis/repositories/e/do_info_action.hh>
#include <paludis/repositories/e/eapi.hh>
#include <paludis/repositories/e/eapi_phase.hh>
#include <paludis/repositories/e/check_userpriv.hh>
#include <paludis/repositories/e/make_use.hh>
#include <paludis/repositories/e/ebuild.hh>

#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/join.hh>
#include <paludis/util/make_null_shared_ptr.hh>

#include <paludis/dep_spec_flattener.hh>
#include <paludis/action.hh>
#include <paludis/metadata_key.hh>
#include <paludis/environment.hh>
#include <paludis/output_manager.hh>

#include <algorithm>
#include <unistd.h>

using namespace paludis;
using namespace paludis::erepository;

void
paludis::erepository::do_info_action(
        const Environment * const env,
        const ERepository * const repo,
        const std::shared_ptr<const ERepositoryID> & id,
        const InfoAction & a)
{
    using namespace std::placeholders;

    Context context("When infoing '" + stringify(*id) + "':");

    std::shared_ptr<OutputManager> output_manager(a.options.make_output_manager()(a));

    bool userpriv_restrict;
    {
        DepSpecFlattener<PlainTextSpecTree, PlainTextDepSpec> restricts(env, id);
        if (id->restrict_key())
            id->restrict_key()->parse_value()->top()->accept(restricts);

        userpriv_restrict =
            indirect_iterator(restricts.end()) != std::find_if(indirect_iterator(restricts.begin()), indirect_iterator(restricts.end()),
                    std::bind(std::equal_to<std::string>(), std::bind(std::mem_fn(&StringDepSpec::text), _1), "userpriv")) ||
            indirect_iterator(restricts.end()) != std::find_if(indirect_iterator(restricts.begin()), indirect_iterator(restricts.end()),
                    std::bind(std::equal_to<std::string>(), std::bind(std::mem_fn(&StringDepSpec::text), _1), "nouserpriv"));
    }
    bool userpriv_ok((! userpriv_restrict) && (env->reduced_gid() != getgid()) &&
            check_userpriv(FSPath(repo->params().builddir()), env, id->eapi()->supported()->userpriv_cannot_use_root()));

    /* make use */
    std::string use(make_use(env, *id, repo->profile()));

    /* add expand to use (iuse isn't reliable for use_expand things), and make the expand
     * environment variables */
    std::shared_ptr<Map<std::string, std::string> > expand_vars(make_expand(
                env, *id, repo->profile()));

    std::shared_ptr<const FSPathSequence> exlibsdirs(repo->layout()->exlibsdirs(id->name()));

    EAPIPhases phases(id->eapi()->supported()->ebuild_phases()->ebuild_info());
    for (EAPIPhases::ConstIterator phase(phases.begin_phases()), phase_end(phases.end_phases()) ;
            phase != phase_end ; ++phase)
    {
        if (phase->option("installed=true"))
            continue;

        EbuildCommandParams command_params(make_named_values<EbuildCommandParams>(
                n::builddir() = repo->params().builddir(),
                n::clearenv() = phase->option("clearenv"),
                n::commands() = join(phase->begin_commands(), phase->end_commands(), " "),
                n::distdir() = repo->params().distdir(),
                n::ebuild_dir() = repo->layout()->package_directory(id->name()),
                n::ebuild_file() = id->fs_location_key()->parse_value(),
                n::eclassdirs() = repo->params().eclassdirs(),
                n::environment() = env,
                n::exlibsdirs() = exlibsdirs,
                n::files_dir() = repo->layout()->package_directory(id->name()) / "files",
                n::maybe_output_manager() = output_manager,
                n::package_builddir() = repo->params().builddir() / (stringify(id->name().category()) + "-" + stringify(id->name().package()) + "-" + stringify(id->version()) + "-info"),
                n::package_id() = id,
                n::permitted_directories() = make_null_shared_ptr(),
                n::portdir() =
                    (repo->params().master_repositories() && ! repo->params().master_repositories()->empty()) ?
                    (*repo->params().master_repositories()->begin())->params().location() : repo->params().location(),
                n::root() = stringify(env->preferred_root_key()->parse_value()),
                n::sandbox() = phase->option("sandbox"),
                n::sydbox() = phase->option("sydbox"),
                n::userpriv() = phase->option("userpriv") && userpriv_ok
                ));

        EbuildInfoCommandParams info_params(
                make_named_values<EbuildInfoCommandParams>(
                n::expand_vars() = expand_vars,
                n::info_vars() = repo->info_vars_key() ?
                    repo->info_vars_key()->parse_value() : std::make_shared<const Set<std::string>>(),
                n::load_environment() = static_cast<const FSPath *>(0),
                n::profiles() = repo->params().profiles(),
                n::profiles_with_parents() = repo->profile()->profiles_with_parents(),
                n::use() = use,
                n::use_ebuild_file() = true,
                n::use_expand() = join(repo->profile()->use_expand()->begin(), repo->profile()->use_expand()->end(), " "),
                n::use_expand_hidden() = join(repo->profile()->use_expand_hidden()->begin(), repo->profile()->use_expand_hidden()->end(), " ")
                ));

        EbuildInfoCommand cmd(command_params, info_params);
        cmd();
    }

    output_manager->succeeded();
}