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

build_file_content in new_local_repository overwrites original BUILD file #1697

Closed
PiotrSikora opened this issue Aug 27, 2016 · 9 comments
Closed
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug

Comments

@PiotrSikora
Copy link
Contributor

build_file_content in new_local_repository overwrites original BUILD file at the source and not just locally... build_file works as expected and overwritesBUILD file only locally, without modifying BUILD file at the source.

@katre katre added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Aug 27, 2016
@katre
Copy link
Member

katre commented Aug 27, 2016

If you already have a BUILD file, use local_repository, not new_local_repository.

@PiotrSikora
Copy link
Contributor Author

PiotrSikora commented Aug 29, 2016

I'm aware of local_repository, but sometimes BUILD file needs to be extended with custom targets.

Anyway, this seems like an inconsistency, since build_file doesn't overwrite the original BUILD file at the source.

@damienmg damienmg added type: bug P2 We'll consider working on this in future. (Assignee optional) category: extensibility > external repositories and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Aug 29, 2016
@damienmg
Copy link
Contributor

damienmg commented Aug 29, 2016

We should definitely not overwrite the source's BUILD file, I think this is happening because we write the BUILD file after symlinking everything from the source path. So if a build file exist we overwrite it, that is not good. build_file does symlinking so it does overwrite the symlink whereas build_file_content write the file itself.

@kchodorow kchodorow self-assigned this Sep 13, 2016
@PiotrSikora
Copy link
Contributor Author

Hey @kchodorow,
it looks that your fix broke existing behavior in which it was possible to use build_file_content with a repository that already had BUILD file, i.e. it was possible to provide alternative BUILD file.

// Make sure we're not overwriting an existing BUILD file.
if (buildFilePath.exists()) {
  Preconditions.checkState(buildFilePath.isSymbolicLink());
  buildFilePath.delete();
}

throws:

java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@ngx_brotli' (requested by nodes 'REPOSITORY:@ngx_brotli')
    at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:447)
    at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:496)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException
    at com.google.common.base.Preconditions.checkState(Preconditions.java:159)
    at com.google.devtools.build.lib.util.Preconditions.checkState(Preconditions.java:196)
    at com.google.devtools.build.lib.rules.repository.RepositoryFunction.writeBuildFile(RepositoryFunction.java:203)
    at com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler.finishBuildFile(NewRepositoryBuildFileHandler.java:112)
    at com.google.devtools.build.lib.bazel.repository.NewGitRepositoryFunction.fetch(NewGitRepositoryFunction.java:42)
    at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:155)
    at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:388)
    ... 4 more

@kchodorow
Copy link
Contributor

Whoops. Thanks for the report.

@kchodorow kchodorow reopened this Sep 23, 2016
@kchodorow
Copy link
Contributor

kchodorow commented Sep 23, 2016

Wait, how do you have a BUILD file in that directory that isn't a symbolic link? Could you do ls -l $(bazel info output_base)/external/ngx_brotli?

Edit: just realized that this is probably a remote repository, not a local one.

@PiotrSikora
Copy link
Contributor Author

PiotrSikora commented Sep 23, 2016

Yes, it's git repository.

$ ls -l $(bazel info output_base)/external/ngx_brotli
total 64
-rw-r--r--  1 piotrsikora  wheel  2330 Sep 23 12:45 BUILD
-rw-r--r--  1 piotrsikora  wheel  1466 Sep 23 12:45 CONTRIBUTING.md
-rw-r--r--  1 piotrsikora  wheel  1430 Sep 23 12:45 LICENSE
-rw-r--r--  1 piotrsikora  wheel  4833 Sep 23 12:45 README.md
-rw-r--r--  1 piotrsikora  wheel   113 Sep 23 12:45 WORKSPACE
-rw-r--r--  1 piotrsikora  wheel  5361 Sep 23 12:45 config
drwxr-xr-x  4 piotrsikora  wheel   136 Sep 23 12:45 src

@kchodorow
Copy link
Contributor

kchodorow commented Sep 29, 2016

Note: 2bc0939 should be cherry picked into the release (#1840).

@PiotrSikora
Copy link
Contributor Author

Thanks! It works fine now.

katre pushed a commit that referenced this issue Sep 30, 2016
My previous change carefully checked that the file was a symlink before
removing it and added a test with local repositories... and it of course isn't
a symlink with downloaded repositories and crashes.

Fixes #1697.

--
MOS_MIGRATED_REVID=134536130
katre pushed a commit that referenced this issue Oct 6, 2016
My previous change carefully checked that the file was a symlink before
removing it and added a test with local repositories... and it of course isn't
a symlink with downloaded repositories and crashes.

Fixes #1697.

--
MOS_MIGRATED_REVID=134536130
katre pushed a commit that referenced this issue Oct 7, 2016
My previous change carefully checked that the file was a symlink before
removing it and added a test with local repositories... and it of course isn't
a symlink with downloaded repositories and crashes.

Fixes #1697.

--
MOS_MIGRATED_REVID=134536130
namrata-ibm pushed a commit to linux-on-ibm-z/bazel that referenced this issue Dec 8, 2016
My previous change carefully checked that the file was a symlink before
removing it and added a test with local repositories... and it of course isn't
a symlink with downloaded repositories and crashes.

Fixes bazelbuild#1697.

--
MOS_MIGRATED_REVID=134536130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Projects
None yet
Development

No branches or pull requests

4 participants