aboutsummaryrefslogtreecommitdiff
path: root/build2/cli/target.cxx
blob: 200f6f0c68bdbdecf1b15225e65d784ed1897b31 (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
// file      : build2/cli/target.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build2/cli/target>

#include <build2/filesystem> // file_mtime()

using namespace std;
using namespace butl;

namespace build2
{
  namespace cli
  {
    // cli
    //
    extern const char cli_ext_var[] = "extension";  // VC14 rejects constexpr.
    extern const char cli_ext_def[] = "cli";

    const target_type cli::static_type
    {
      "cli",
      &file::static_type,
      &target_factory<cli>,
      &target_extension_var<cli_ext_var, cli_ext_def>,
      nullptr,
      &search_file,
      false
    };

    // cli.cxx
    //
    group_view cli_cxx::
    group_members (action_type)
    {
      static_assert (offsetof (cli_cxx_members, i) -
                     offsetof (cli_cxx_members, h) == sizeof (target*) * 2,
                     "member layout incompatible with array");

      return h != nullptr
        ? group_view {reinterpret_cast<target* const*> (&h),
                      (i != nullptr ? 3U : 2U)}
        : group_view {nullptr, 0};
    }

    timestamp cli_cxx::
    load_mtime () const
    {
      // The rule has been matched which means the members should
      // be resolved and paths assigned.
      //
      return file_mtime (h->path ());
    }

    static pair<target*, optional<string>>
    cli_cxx_factory (const target_type&,
                     dir_path d,
                     dir_path o,
                     string n,
                     optional<string> e)
    {
      tracer trace ("cli::cli_cxx_factory");

      // Pre-enter (potential) members as targets. The main purpose
      // of doing this is to avoid searching for existing files in
      // src_base if the buildfile mentions some of them explicitly
      // as prerequisites.
      //
      targets.insert<cxx::hxx> (d, o, n, trace);
      targets.insert<cxx::cxx> (d, o, n, trace);
      targets.insert<cxx::ixx> (d, o, n, trace);

      return make_pair (new cli_cxx (move (d), move (o), move (n)), move (e));
    }

    const target_type cli_cxx::static_type
    {
      "cli.cxx",
      &mtime_target::static_type,
      &cli_cxx_factory,
      nullptr,
      nullptr,
      &search_target,
      true // "See through" default iteration mode.
    };
  }
}