Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoBazelRepository in empty package fails #24150

Closed
fzakaria opened this issue Oct 30, 2024 · 0 comments
Closed

AutoBazelRepository in empty package fails #24150

fzakaria opened this issue Oct 30, 2024 · 0 comments
Labels

Comments

@fzakaria
Copy link
Contributor

out.printf("package %s;\n", generatedClassPackage);

Here is a sample:

import com.google.devtools.build.runfiles.AutoBazelRepository;
import com.google.devtools.build.runfiles.Runfiles;
import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;

@AutoBazelRepository
public class ExampleTest {

    @Test
    public void doNothingTest() throws Exception {
        Runfiles.Preloaded runfiles = Runfiles.preload();
        String path = runfiles.withSourceRepository(AutoBazelRepository_ExampleTest.NAME)
                .rlocation("my_workspace/path/to/my/data.txt");
    }
}

This produces a generated class for the following:

package ;

class AutoBazelRepository_ExampleTest {
  /**
   * The canonical name of the repository containing the Bazel target that
   * compiled {@link TestContainerExampleTest}.
   */
  static final String NAME = "";

  private AutoBazelRepository_ExampleTest () {}
}

Please notice the package ; this fails to compile

bazel-out/darwin_arm64-fastbuild/bin/src/_javac/ExampleTest/TExampleTest_sources/AutoBazelRepository_ExampleTest.java:1: error: <identifier> expected
package ;
fzakaria added a commit to fzakaria/bazel that referenced this issue Oct 31, 2024
Add support for when the AutoBazelRepository annotation is placed
on a file in a root package (ie. one where there is no package)

fixes bazelbuild#24150
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Nov 4, 2024
Add support for when the AutoBazelRepository annotation is placed on a file in a root package (ie. one where there is no package)

fixes bazelbuild#24150

Closes bazelbuild#24161.

PiperOrigin-RevId: 692888334
Change-Id: Idd85e79250f64cf50ca709cf6ad8d025a0db032c
github-merge-queue bot pushed a commit that referenced this issue Nov 4, 2024
Add support for when the AutoBazelRepository annotation is placed on a
file in a root package (ie. one where there is no package)

fixes #24150

Closes #24161.

PiperOrigin-RevId: 692888334
Change-Id: Idd85e79250f64cf50ca709cf6ad8d025a0db032c

Commit
1560047

Co-authored-by: Farid Zakaria <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants