Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 1915 of file remake.cpp.

Referenced by handle_clients(), and server_mode().

1916 {
1917  std::pair<status_map::iterator,bool> i =
1918  status.insert(std::make_pair(target, status_t()));
1919  status_t &ts = i.first->second;
1920  if (!i.second) return ts;
1921  DEBUG_open << "Checking status of " << target << "... ";
1922  dependency_map::const_iterator j = dependencies.find(target);
1923  if (j == dependencies.end())
1924  {
1925  struct stat s;
1926  if (stat(target.c_str(), &s) != 0)
1927  {
1928  DEBUG_close << "missing\n";
1929  ts.status = Todo;
1930  ts.last = 0;
1931  return ts;
1932  }
1933  DEBUG_close << "up-to-date\n";
1934  ts.status = Uptodate;
1935  ts.last = s.st_mtime;
1936  return ts;
1937  }
1938  dependency_t const &dep = *j->second;
1939  status_e st = Uptodate;
1940  time_t latest = 0;
1941  for (string_list::const_iterator k = dep.targets.begin(),
1942  k_end = dep.targets.end(); k != k_end; ++k)
1943  {
1944  struct stat s;
1945  if (stat(k->c_str(), &s) != 0)
1946  {
1947  if (st == Uptodate) DEBUG_close << *k << " missing\n";
1948  s.st_mtime = 0;
1949  st = Todo;
1950  }
1951  status[*k].last = s.st_mtime;
1952  if (s.st_mtime > latest) latest = s.st_mtime;
1953  }
1954  if (st != Uptodate) goto update;
1955  for (string_set::const_iterator k = dep.deps.begin(),
1956  k_end = dep.deps.end(); k != k_end; ++k)
1957  {
1958  status_t const &ts_ = get_status(*k);
1959  if (latest < ts_.last)
1960  {
1961  DEBUG_close << "older than " << *k << std::endl;
1962  st = Todo;
1963  goto update;
1964  }
1965  if (ts_.status != Uptodate && st != Recheck)
1966  {
1967  DEBUG << "obsolete dependency " << *k << std::endl;
1968  st = Recheck;
1969  }
1970  }
1971  if (st == Uptodate) DEBUG_close << "all siblings up-to-date\n";
1972  update:
1973  for (string_list::const_iterator k = dep.targets.begin(),
1974  k_end = dep.targets.end(); k != k_end; ++k)
1975  {
1976  status[*k].status = st;
1977  }
1978  return ts;
1979 }
status_e
Definition: remake.cpp:508
#define DEBUG_open
Definition: remake.cpp:794
string_list targets
Definition: remake.cpp:497
Target is up-to-date.
Definition: remake.cpp:510
static status_t const & get_status(std::string const &target)
Definition: remake.cpp:1915
string_set deps
Definition: remake.cpp:498
static status_map status
Definition: remake.cpp:612
Target is missing or obsolete.
Definition: remake.cpp:511
#define DEBUG
Definition: remake.cpp:793
Target has an obsolete dependency.
Definition: remake.cpp:512
#define DEBUG_close
Definition: remake.cpp:795
time_t last
Last-modified date.
Definition: remake.cpp:524
status_e status
Actual status.
Definition: remake.cpp:523
static dependency_map dependencies
Definition: remake.cpp:607
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 2018 of file remake.cpp.

Referenced by complete_request().

2019 {
2020  DEBUG_open << "Rechecking obsoleteness of " << target << "... ";
2021  status_map::const_iterator i = status.find(target);
2022  assert(i != status.end());
2023  if (i->second.status != Recheck) return true;
2024  dependency_map::const_iterator j = dependencies.find(target);
2025  assert(j != dependencies.end());
2026  dependency_t const &dep = *j->second;
2027  for (string_set::const_iterator k = dep.deps.begin(),
2028  k_end = dep.deps.end(); k != k_end; ++k)
2029  {
2030  if (status[*k].status != Uptodate) return true;
2031  }
2032  for (string_list::const_iterator k = dep.targets.begin(),
2033  k_end = dep.targets.end(); k != k_end; ++k)
2034  {
2035  status[*k].status = Uptodate;
2036  }
2037  DEBUG_close << "no longer obsolete\n";
2038  return false;
2039 }
#define DEBUG_open
Definition: remake.cpp:794
Target is up-to-date.
Definition: remake.cpp:510
static status_map status
Definition: remake.cpp:612
Target has an obsolete dependency.
Definition: remake.cpp:512
#define DEBUG_close
Definition: remake.cpp:795
static dependency_map dependencies
Definition: remake.cpp:607
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 1985 of file remake.cpp.

Referenced by complete_job().

1986 {
1987  DEBUG_open << "Rechecking status of " << target << "... ";
1988  status_map::iterator i = status.find(target);
1989  assert(i != status.end());
1990  status_t &ts = i->second;
1991  ts.status = Remade;
1992  if (ts.last >= now)
1993  {
1994  DEBUG_close << "possibly remade\n";
1995  return;
1996  }
1997  struct stat s;
1998  if (stat(target.c_str(), &s) != 0)
1999  {
2000  DEBUG_close << "missing\n";
2001  ts.last = 0;
2002  }
2003  else if (s.st_mtime != ts.last)
2004  {
2005  DEBUG_close << "remade\n";
2006  ts.last = s.st_mtime;
2007  }
2008  else
2009  {
2010  DEBUG_close << "unchanged\n";
2011  ts.status = Uptodate;
2012  }
2013 }
#define DEBUG_open
Definition: remake.cpp:794
Target is up-to-date.
Definition: remake.cpp:510
static time_t now
Definition: remake.cpp:714
static status_map status
Definition: remake.cpp:612
Target was successfully rebuilt.
Definition: remake.cpp:514
#define DEBUG_close
Definition: remake.cpp:795
status_e status
Actual status.
Definition: remake.cpp:523