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 1778 of file remake.cpp.

Referenced by handle_clients(), and server_mode().

1779 {
1780  std::pair<status_map::iterator,bool> i =
1781  status.insert(std::make_pair(target, status_t()));
1782  status_t &ts = i.first->second;
1783  if (!i.second) return ts;
1784  DEBUG_open << "Checking status of " << target << "... ";
1785  dependency_map::const_iterator j = dependencies.find(target);
1786  if (j == dependencies.end())
1787  {
1788  struct stat s;
1789  if (stat(target.c_str(), &s) != 0)
1790  {
1791  DEBUG_close << "missing\n";
1792  ts.status = Todo;
1793  ts.last = 0;
1794  return ts;
1795  }
1796  DEBUG_close << "up-to-date\n";
1797  ts.status = Uptodate;
1798  ts.last = s.st_mtime;
1799  return ts;
1800  }
1801  dependency_t const &dep = *j->second;
1802  status_e st = Uptodate;
1803  time_t latest = 0;
1804  for (string_list::const_iterator k = dep.targets.begin(),
1805  k_end = dep.targets.end(); k != k_end; ++k)
1806  {
1807  struct stat s;
1808  if (stat(k->c_str(), &s) != 0)
1809  {
1810  if (st == Uptodate) DEBUG_close << *k << " missing\n";
1811  s.st_mtime = 0;
1812  st = Todo;
1813  }
1814  status[*k].last = s.st_mtime;
1815  if (s.st_mtime > latest) latest = s.st_mtime;
1816  }
1817  if (st == Todo) goto update;
1818  for (string_set::const_iterator k = dep.deps.begin(),
1819  k_end = dep.deps.end(); k != k_end; ++k)
1820  {
1821  status_t const &ts_ = get_status(*k);
1822  if (latest < ts_.last)
1823  {
1824  DEBUG_close << "older than " << *k << std::endl;
1825  st = Todo;
1826  goto update;
1827  }
1828  if (ts_.status == Uptodate) continue;
1829  if (st == Uptodate)
1830  DEBUG << "obsolete dependency " << *k << std::endl;
1831  st = Recheck;
1832  }
1833  if (st == Uptodate) DEBUG_close << "all siblings up-to-date\n";
1834  update:
1835  for (string_list::const_iterator k = dep.targets.begin(),
1836  k_end = dep.targets.end(); k != k_end; ++k)
1837  {
1838  status[*k].status = st;
1839  }
1840  return ts;
1841 }
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 1880 of file remake.cpp.

Referenced by complete_request().

1881 {
1882  DEBUG_open << "Rechecking obsoleteness of " << target << "... ";
1883  status_map::const_iterator i = status.find(target);
1884  assert(i != status.end());
1885  if (i->second.status != Recheck) return true;
1886  dependency_map::const_iterator j = dependencies.find(target);
1887  assert(j != dependencies.end());
1888  dependency_t const &dep = *j->second;
1889  for (string_set::const_iterator k = dep.deps.begin(),
1890  k_end = dep.deps.end(); k != k_end; ++k)
1891  {
1892  if (status[*k].status != Uptodate) return true;
1893  }
1894  for (string_list::const_iterator k = dep.targets.begin(),
1895  k_end = dep.targets.end(); k != k_end; ++k)
1896  {
1897  status[*k].status = Uptodate;
1898  }
1899  DEBUG_close << "no longer obsolete\n";
1900  return false;
1901 }
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 1847 of file remake.cpp.

Referenced by complete_job().

1848 {
1849  DEBUG_open << "Rechecking status of " << target << "... ";
1850  status_map::iterator i = status.find(target);
1851  assert(i != status.end());
1852  status_t &ts = i->second;
1853  ts.status = Remade;
1854  if (ts.last >= now)
1855  {
1856  DEBUG_close << "possibly remade\n";
1857  return;
1858  }
1859  struct stat s;
1860  if (stat(target.c_str(), &s) != 0)
1861  {
1862  DEBUG_close << "missing\n";
1863  ts.last = 0;
1864  }
1865  else if (s.st_mtime != ts.last)
1866  {
1867  DEBUG_close << "remade\n";
1868  ts.last = s.st_mtime;
1869  }
1870  else
1871  {
1872  DEBUG_close << "unchanged\n";
1873  ts.status = Uptodate;
1874  }
1875 }