@@ -1582,8 +1582,33 @@ def _impl(name, visibility, **kwargs):
1582
1582
.doesNotContainKey ("disabled_attr" );
1583
1583
}
1584
1584
1585
+ @ Test
1586
+ public void inheritAttrs_disabledByDefault () throws Exception {
1587
+ scratch .file (
1588
+ "pkg/foo.bzl" ,
1589
+ """
1590
+ def _my_macro_impl(name, visibility, **kwargs):
1591
+ pass
1592
+
1593
+ my_macro = macro(
1594
+ implementation = _my_macro_impl,
1595
+ inherit_attrs = native.cc_library,
1596
+ )
1597
+ """ );
1598
+ scratch .file (
1599
+ "pkg/BUILD" ,
1600
+ """
1601
+ load(":foo.bzl", "my_macro")
1602
+ """ );
1603
+ reporter .removeHandler (failFastHandler );
1604
+ assertThat (getPackage ("pkg" )).isNull ();
1605
+ assertContainsEvent (
1606
+ "parameter 'inherit_attrs' is experimental and thus unavailable with the current flags" );
1607
+ }
1608
+
1585
1609
@ Test
1586
1610
public void inheritAttrs_fromInvalidSource_fails () throws Exception {
1611
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1587
1612
scratch .file (
1588
1613
"pkg/foo.bzl" ,
1589
1614
"""
@@ -1608,6 +1633,7 @@ def _my_macro_impl(name, visibility, **kwargs):
1608
1633
1609
1634
@ Test
1610
1635
public void inheritAttrs_withoutKwargsInImplementation_fails () throws Exception {
1636
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1611
1637
scratch .file (
1612
1638
"pkg/foo.bzl" ,
1613
1639
"""
@@ -1632,6 +1658,7 @@ def _my_macro_impl(name, visibility, tags):
1632
1658
1633
1659
@ Test
1634
1660
public void inheritAttrs_fromCommon_withOverrides () throws Exception {
1661
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1635
1662
scratch .file (
1636
1663
"pkg/my_macro.bzl" ,
1637
1664
"""
@@ -1694,6 +1721,7 @@ public void inheritAttrs_fromAnyNativeRule() throws Exception {
1694
1721
// * a new AttributeValueSource or a new attribute type is introduced, and symbolic macros
1695
1722
// cannot inherit an attribute with a default with this source or of such a type (to fix, add
1696
1723
// a check for it in MacroClass#forceDefaultToNone).
1724
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1697
1725
for (RuleClass ruleClass : getBuiltinRuleClasses (false )) {
1698
1726
if (ruleClass .getAttributes ().isEmpty ()) {
1699
1727
continue ;
@@ -1771,6 +1799,7 @@ def _impl(name, visibility, **kwargs):
1771
1799
1772
1800
@ Test
1773
1801
public void inheritAttrs_fromExportedStarlarkRule () throws Exception {
1802
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1774
1803
scratch .file (
1775
1804
"pkg/my_rule.bzl" ,
1776
1805
"""
@@ -1813,6 +1842,7 @@ def _my_macro_impl(name, visibility, **kwargs):
1813
1842
1814
1843
@ Test
1815
1844
public void inheritAttrs_fromUnexportedStarlarkRule () throws Exception {
1845
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1816
1846
scratch .file (
1817
1847
"pkg/my_macro.bzl" ,
1818
1848
"""
@@ -1850,6 +1880,7 @@ def _my_macro_impl(name, visibility, **kwargs):
1850
1880
1851
1881
@ Test
1852
1882
public void inheritAttrs_fromExportedMacro () throws Exception {
1883
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1853
1884
scratch .file (
1854
1885
"pkg/other_macro.bzl" ,
1855
1886
"""
@@ -1890,6 +1921,7 @@ def _my_macro_impl(name, visibility, **kwargs):
1890
1921
1891
1922
@ Test
1892
1923
public void inheritAttrs_fromUnexportedMacro () throws Exception {
1924
+ setBuildLanguageOptions ("--experimental_enable_macro_inherit_attrs" );
1893
1925
scratch .file (
1894
1926
"pkg/my_macro.bzl" ,
1895
1927
"""
0 commit comments