Remake
Loading...
Searching...
No Matches
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 1916 of file remake.cpp.

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

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

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

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

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

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

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

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

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

Referenced by instantiate_rule().