Remake
Functions
Rule resolution

Functions

static void merge_rule (rule_t &dest, rule_t const &src)
 
static void substitute_pattern (std::string const &pat, string_list const &src, string_list &dst)
 
static void instantiate_rule (std::string const &target, rule_t const &src, rule_t &dst)
 
static void find_generic_rule (job_t &job, std::string const &target)
 
static void find_rule (job_t &job, std::string const &target)
 

Detailed Description

Function Documentation

◆ find_generic_rule()

static void find_generic_rule ( job_t job,
std::string const &  target 
)
static

Find a generic rule matching target:

  • the one leading to shorter matches has priority,
  • among equivalent rules, the earliest one has priority.

Definition at line 1918 of file remake.cpp.

1919 {
1920  for (rule_list::const_iterator i = generic_rules.begin(),
1921  i_end = generic_rules.end(); i != i_end; ++i)
1922  {
1923  instantiate_rule(target, *i, job.rule);
1924  }
1925 }
static void instantiate_rule(std::string const &target, rule_t const &src, rule_t &dst)
Definition: remake.cpp:1887
static rule_list generic_rules
Definition: remake.cpp:634
rule_t rule
Original rule.
Definition: remake.cpp:580

Referenced by find_rule().

◆ find_rule()

static void find_rule ( job_t job,
std::string const &  target 
)
static

Find a specific rule matching target. Return a generic one otherwise. If there is both a specific rule with an empty script and a generic rule, the generic one is returned after adding the dependencies of the specific one.

Definition at line 1932 of file remake.cpp.

1933 {
1934  rule_map::const_iterator i = specific_rules.find(target),
1935  i_end = specific_rules.end();
1936  // If there is a specific rule with a script, return it.
1937  if (i != i_end && !i->second->script.empty())
1938  {
1939  job.rule = *i->second;
1940  return;
1941  }
1942  find_generic_rule(job, target);
1943  // If there is no generic rule, return the specific rule (no script), if any.
1944  if (job.rule.targets.empty())
1945  {
1946  if (i != i_end)
1947  {
1948  job.rule = *i->second;
1949  return;
1950  }
1951  }
1952  // Optimize the lookup when there is only one target (already looked up).
1953  if (job.rule.targets.size() == 1)
1954  {
1955  if (i == i_end) return;
1956  merge_rule(job.rule, *i->second);
1957  return;
1958  }
1959  // Add the dependencies of the specific rules of every target to the
1960  // generic rule. If any of those rules has a nonempty script, error out.
1961  for (string_list::const_iterator j = job.rule.targets.begin(),
1962  j_end = job.rule.targets.end(); j != j_end; ++j)
1963  {
1964  i = specific_rules.find(*j);
1965  if (i == i_end) continue;
1966  if (!i->second->script.empty()) return;
1967  merge_rule(job.rule, *i->second);
1968  }
1969 }
static void find_generic_rule(job_t &job, std::string const &target)
Definition: remake.cpp:1918
static void merge_rule(rule_t &dest, rule_t const &src)
Definition: remake.cpp:1848
static rule_map specific_rules
Definition: remake.cpp:639
string_list targets
Files produced by this rule.
Definition: remake.cpp:562

Referenced by start().

◆ instantiate_rule()

static void instantiate_rule ( std::string const &  target,
rule_t const &  src,
rule_t dst 
)
static

Instantiate a specific rule, given a target and a generic rule. If the rule dst already contains a stem longer than the one found, it is left unchanged.

Definition at line 1887 of file remake.cpp.

1888 {
1889  size_t tlen = target.length(), plen = dst.stem.length();
1890  for (string_list::const_iterator j = src.targets.begin(),
1891  j_end = src.targets.end(); j != j_end; ++j)
1892  {
1893  size_t len = j->length();
1894  if (tlen < len) continue;
1895  if (plen && plen <= tlen - (len - 1)) continue;
1896  size_t pos = j->find('%');
1897  if (pos == std::string::npos) continue;
1898  size_t len2 = len - (pos + 1);
1899  if (j->compare(0, pos, target, 0, pos) ||
1900  j->compare(pos + 1, len2, target, tlen - len2, len2))
1901  continue;
1902  plen = tlen - (len - 1);
1903  dst = rule_t();
1904  dst.stem = target.substr(pos, plen);
1905  dst.script = src.script;
1906  substitute_pattern(dst.stem, src.targets, dst.targets);
1907  substitute_pattern(dst.stem, src.deps, dst.deps);
1908  substitute_pattern(dst.stem, src.wdeps, dst.wdeps);
1909  break;
1910  }
1911 }
static void substitute_pattern(std::string const &pat, string_list const &src, string_list &dst)
Definition: remake.cpp:1871
std::string stem
Stem used to instantiate the rule, if any.
Definition: remake.cpp:566

Referenced by find_generic_rule(), and load_rule().

◆ merge_rule()

static void merge_rule ( rule_t dest,
rule_t const &  src 
)
static

Definition at line 1848 of file remake.cpp.

1849 {
1850  dest.deps.insert(dest.deps.end(), src.deps.begin(), src.deps.end());
1851  dest.wdeps.insert(dest.wdeps.end(), src.wdeps.begin(), src.wdeps.end());
1852  for (assign_map::const_iterator i = src.assigns.begin(),
1853  i_end = src.assigns.end(); i != i_end; ++i)
1854  {
1855  if (!i->second.append)
1856  {
1857  new_assign:
1858  dest.assigns[i->first] = i->second;
1859  continue;
1860  }
1861  assign_map::iterator j = dest.assigns.find(i->first);
1862  if (j == dest.assigns.end()) goto new_assign;
1863  j->second.value.insert(j->second.value.end(),
1864  i->second.value.begin(), i->second.value.end());
1865  }
1866 }
assign_map assigns
Assignment of variables.
Definition: remake.cpp:565
string_list wdeps
Like deps, except that they are not registered as dependencies.
Definition: remake.cpp:564
string_list deps
Dependencies used for an implicit call to remake at the start of the script.
Definition: remake.cpp:563

Referenced by find_rule(), and register_transparent_rule().

◆ substitute_pattern()

static void substitute_pattern ( std::string const &  pat,
string_list const &  src,
string_list dst 
)
static

Substitute a pattern into a list of strings.

Definition at line 1871 of file remake.cpp.

1872 {
1873  for (string_list::const_iterator i = src.begin(),
1874  i_end = src.end(); i != i_end; ++i)
1875  {
1876  size_t pos = i->find('%');
1877  if (pos == std::string::npos) dst.push_back(*i);
1878  else dst.push_back(i->substr(0, pos) + pat + i->substr(pos + 1));
1879  }
1880 }

Referenced by instantiate_rule().