Remake
Functions
Target status

Functions

static status_t const & get_status (std::string const &target)
 
static void update_status (std::string const &target)
 
static bool still_need_rebuild (std::string const &target)
 

Detailed Description

Function Documentation

static status_t const& get_status ( std::string const &  target)
static

Compute and memoize the status of target:

  • if the file does not exist, the target is obsolete,
  • if any dependency is obsolete or younger than the file, it is obsolete,
  • otherwise it is up-to-date.
Note
For rules with multiple targets, all the targets share the same status. (If one is obsolete, they all are.) The second rule above is modified in that case: the latest target is chosen, not the oldest!

Definition at line 1922 of file remake.cpp.

Referenced by handle_clients(), and server_mode().

1923 {
1924  std::pair<status_map::iterator,bool> i =
1925  status.insert(std::make_pair(target, status_t()));
1926  status_t &ts = i.first->second;
1927  if (!i.second) return ts;
1928  DEBUG_open << "Checking status of " << target << "... ";
1929  dependency_map::const_iterator j = dependencies.find(target);
1930  if (j == dependencies.end())
1931  {
1932  struct stat s;
1933  if (stat(target.c_str(), &s) != 0)
1934  {
1935  DEBUG_close << "missing\n";
1936  ts.status = Todo;
1937  ts.last = 0;
1938  return ts;
1939  }
1940  DEBUG_close << "up-to-date\n";
1941  ts.status = Uptodate;
1942  ts.last = s.st_mtime;
1943  return ts;
1944  }
1945  if (obsolete_targets)
1946  {
1947  DEBUG_close << "forcefully obsolete\n";
1948  ts.status = Todo;
1949  ts.last = 0;
1950  return ts;
1951  }
1952  dependency_t const &dep = *j->second;
1953  status_e st = Uptodate;
1954  time_t latest = 0;
1955  for (string_list::const_iterator k = dep.targets.begin(),
1956  k_end = dep.targets.end(); k != k_end; ++k)
1957  {
1958  struct stat s;
1959  if (stat(k->c_str(), &s) != 0)
1960  {
1961  if (st == Uptodate) DEBUG_close << *k << " missing\n";
1962  s.st_mtime = 0;
1963  st = Todo;
1964  }
1965  status[*k].last = s.st_mtime;
1966  if (s.st_mtime > latest) latest = s.st_mtime;
1967  }
1968  if (st != Uptodate) goto update;
1969  for (string_set::const_iterator k = dep.deps.begin(),
1970  k_end = dep.deps.end(); k != k_end; ++k)
1971  {
1972  status_t const &ts_ = get_status(*k);
1973  if (latest < ts_.last)
1974  {
1975  DEBUG_close << "older than " << *k << std::endl;
1976  st = Todo;
1977  goto update;
1978  }
1979  if (ts_.status != Uptodate && st != Recheck)
1980  {
1981  DEBUG << "obsolete dependency " << *k << std::endl;
1982  st = Recheck;
1983  }
1984  }
1985  if (st == Uptodate) DEBUG_close << "all siblings up-to-date\n";
1986  update:
1987  for (string_list::const_iterator k = dep.targets.begin(),
1988  k_end = dep.targets.end(); k != k_end; ++k)
1989  {
1990  status[*k].status = st;
1991  }
1992  return ts;
1993 }
status_e
Definition: remake.cpp:509
#define DEBUG_open
Definition: remake.cpp:801
string_list targets
Definition: remake.cpp:498
Target is up-to-date.
Definition: remake.cpp:511
static status_t const & get_status(std::string const &target)
Definition: remake.cpp:1922
string_set deps
Definition: remake.cpp:499
static status_map status
Definition: remake.cpp:614
static bool obsolete_targets
Definition: remake.cpp:741
Target is missing or obsolete.
Definition: remake.cpp:512
#define DEBUG
Definition: remake.cpp:800
Target has an obsolete dependency.
Definition: remake.cpp:513
#define DEBUG_close
Definition: remake.cpp:802
time_t last
Last-modified date.
Definition: remake.cpp:526
status_e status
Actual status.
Definition: remake.cpp:525
static dependency_map dependencies
Definition: remake.cpp:609
static bool still_need_rebuild ( std::string const &  target)
static

Check whether all the prerequisites of target ended being up-to-date.

Definition at line 2032 of file remake.cpp.

Referenced by complete_request().

2033 {
2034  status_map::const_iterator i = status.find(target);
2035  assert(i != status.end());
2036  if (i->second.status != RunningRecheck) return true;
2037  DEBUG_open << "Rechecking obsoleteness of " << target << "... ";
2038  dependency_map::const_iterator j = dependencies.find(target);
2039  assert(j != dependencies.end());
2040  dependency_t const &dep = *j->second;
2041  for (string_set::const_iterator k = dep.deps.begin(),
2042  k_end = dep.deps.end(); k != k_end; ++k)
2043  {
2044  if (status[*k].status != Uptodate) return true;
2045  }
2046  for (string_list::const_iterator k = dep.targets.begin(),
2047  k_end = dep.targets.end(); k != k_end; ++k)
2048  {
2049  status[*k].status = Uptodate;
2050  }
2051  DEBUG_close << "no longer obsolete\n";
2052  return false;
2053 }
#define DEBUG_open
Definition: remake.cpp:801
Target is up-to-date.
Definition: remake.cpp:511
static status_map status
Definition: remake.cpp:614
#define DEBUG_close
Definition: remake.cpp:802
static dependency_map dependencies
Definition: remake.cpp:609
Static prerequisites are being rebuilt.
Definition: remake.cpp:515
static void update_status ( std::string const &  target)
static

Change the status of target to Remade or Uptodate depending on whether its modification time changed.

Definition at line 1999 of file remake.cpp.

Referenced by complete_job().

2000 {
2001  DEBUG_open << "Rechecking status of " << target << "... ";
2002  status_map::iterator i = status.find(target);
2003  assert(i != status.end());
2004  status_t &ts = i->second;
2005  ts.status = Remade;
2006  if (ts.last >= now)
2007  {
2008  DEBUG_close << "possibly remade\n";
2009  return;
2010  }
2011  struct stat s;
2012  if (stat(target.c_str(), &s) != 0)
2013  {
2014  DEBUG_close << "missing\n";
2015  ts.last = 0;
2016  }
2017  else if (s.st_mtime != ts.last)
2018  {
2019  DEBUG_close << "remade\n";
2020  ts.last = s.st_mtime;
2021  }
2022  else
2023  {
2024  DEBUG_close << "unchanged\n";
2025  ts.status = Uptodate;
2026  }
2027 }
#define DEBUG_open
Definition: remake.cpp:801
Target is up-to-date.
Definition: remake.cpp:511
static time_t now
Definition: remake.cpp:716
static status_map status
Definition: remake.cpp:614
Target was successfully rebuilt.
Definition: remake.cpp:516
#define DEBUG_close
Definition: remake.cpp:802
status_e status
Actual status.
Definition: remake.cpp:525