src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
/*
   * Making the location in BUILD file the default for "crosses boundary of subpackage" errors does
   * not work in this case since the error actually happens in the bzl file. However, because of
   * the current design, we can neither show the location in the bzl file nor display both
   * locations (BUILD + bzl).
   *
   * Since this case is less common than having such an error in a BUILD file, we can live
   * with it.
   */
Making the location in BUILD file the default for "crosses boundary of subpackage" errors does
not work in this case since the error actually happens in the bzl file. However, because of
the current design, we can neither show the location in the bzl file nor display both
locations (BUILD + bzl).

Since this case is less common than having such an error in a BUILD file, we can live
with it.
Making the location in BUILD file the default for " crosses boundary of subpackage " errors does not work in this case since the error actually happens in the bzl file . However because of the current design we can neither show the location in the bzl file nor display both locations ( BUILD + bzl ) . Since this case is less common than having such an error in a BUILD file we can live with it .
@Test
  public void testPackageBoundaryError_SkylarkMacroWithErrorInBzlFile() throws Exception {
    scratch.file("test/BUILD",
        "load('//test:macros.bzl', 'macro_skylark_rule')",
        "macro_skylark_rule(name = 'm_skylark')");
    scratch.file("test/sub/BUILD",
        "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
    scratch.file("test/macros.bzl",
        "def _impl(ctx):",
        "  return",
        "skylark_rule = rule(",
        "  implementation = _impl,",
        "  attrs = {",
        "    'srcs': attr.label_list(allow_files=True)",
        "  }",
        ")",
        "def macro_skylark_rule(name, srcs=[]):",
        "  skylark_rule(name = name, srcs = srcs + ['sub/my_sub_lib.h'])");
    reporter.removeHandler(failFastHandler);
    getConfiguredTarget("//test:m_skylark");
    assertContainsEvent("ERROR /workspace/test/BUILD:2:1: Label '//test:sub/my_sub_lib.h' "
        + "crosses boundary of subpackage 'test/sub' (perhaps you meant to put the colon here: "
        + "'//test/sub:my_sub_lib.h'?)");
  }
@ Test public void testPackageBoundaryError_SkylarkMacroWithErrorInBzlFile ( ) throws Exception { scratch . file ( "test/BUILD" , "load('//test:macros.bzl', 'macro_skylark_rule')" , "macro_skylark_rule(name = 'm_skylark')" ) ; scratch . file ( "test/sub/BUILD" , "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])" ) ; scratch . file ( "test/macros.bzl" , "def _impl(ctx):" , "  return" , "skylark_rule = rule(" , "  implementation = _impl," , "  attrs = {" , "    'srcs': attr.label_list(allow_files=True)" , "  }" , ")" , "def macro_skylark_rule(name, srcs=[]):" , "  skylark_rule(name = name, srcs = srcs + ['sub/my_sub_lib.h'])" ) ; reporter . removeHandler ( failFastHandler ) ; getConfiguredTarget ( "//test:m_skylark" ) ; assertContainsEvent ( "ERROR /workspace/test/BUILD:2:1: Label '//test:sub/my_sub_lib.h' " + "crosses boundary of subpackage 'test/sub' (perhaps you meant to put the colon here: " + "'//test/sub:my_sub_lib.h'?)" ) ; }
Making the location in BUILD file the default for "crosses boundary of subpackage" errors does
 not work in this case since the error actually happens in the bzl file.
Making the location in BUILD file the default for " crosses boundary of subpackage " errors does not work in this case since the error actually happens in the bzl file .