aboutsummaryrefslogtreecommitdiff
path: root/build/context
blob: 8ebce26492a8032b9147bb4875a15835259d6153 (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
// file      : build/context -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_CONTEXT
#define BUILD_CONTEXT

#include <string>
#include <ostream>

#include <build/path>
#include <build/rule>
#include <build/operation>
#include <build/filesystem>

namespace build
{
  class scope;
  class file;

  extern path work;
  extern path home;

  // Current action (meta/operation).
  //
  extern execution_mode current_mode;
  extern const target_rule_map* current_rules;

  // Reset the dependency state. In particular, this removes all the
  // targets, scopes, and variable names.
  //
  void
  reset ();

  // The dual interface wrapper for the {mk,rm}{file,dir}() functions
  // below that allows you to use it as a true/false return or a more
  // detailed enum from <filesystem>
  //
  template <typename T>
  struct fs_status
  {
    T v;
    fs_status (T v): v (v) {};
    operator T () const {return v;}
    explicit operator bool () const {return v == T::success;}
  };

  // Create the directory and print the standard diagnostics. Note that
  // this implementation is not suitable if it is expected that the
  // directory will exist in the majority of case and performance is
  // important. See the fsdir{} rule for details.
  //
  fs_status<mkdir_status>
  mkdir (const path&);

  // Remove the file and print the standard diagnostics. The second
  // argument is only used in diagnostics, to print the target name.
  // Passing the path for target will result in the relative path
  // being printed.
  //
  template <typename T>
  fs_status<rmfile_status>
  rmfile (const path&, const T& target);

  inline fs_status<rmfile_status>
  rmfile (const path& f) {return rmfile (f, f);}

  // Similar to rmfile() but for directories.
  //
  template <typename T>
  fs_status<rmdir_status>
  rmdir (const path&, const T& target);

  inline fs_status<rmdir_status>
  rmdir (const path& d) {return rmdir (d, d);}

  // Return the src/out directory corresponding to the given out/src. The
  // passed directory should be a sub-directory of out/src_root.
  //
  path
  src_out (const path& out, scope&);

  path
  src_out (const path& out, const path& out_root, const path& src_root);

  path
  out_src (const path& src, scope&);

  path
  out_src (const path& src, const path& out_root, const path& src_root);

  // If possible and beneficial, translate an absolute, normalized path
  // into relative to the relative_base directory, which is normally
  // work.
  //
  path
  relative (const path&);

  // By default this points to work. Setting this to something else
  // should only be done in tightly controlled, non-parallel
  // situations (see dump). If base is empty, then relative()
  // returns the original path.
  //
  extern const path* relative_base;
}

#include <build/context.txx>

#endif // BUILD_CONTEXT