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

Add --trust_install_base option #11905

Conversation

meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Aug 7, 2020

This will allow Bazel client to run individually without the appended
zip archive, which is a requirement for Debian installation.

The following changes are made:

  • Add --trust_install_base option. When this is enabled. Bazel client
    trusts the install base provided by --install_base option and skip
    the step of verifying the install directory. We need it because the
    Bazel client alone doesn't contain information to verify the install
    directory.
  • Reimplement --version as an actual Bazel startup flag. The version
    info is read from the zip archive, but when --trust_install_base is
    enabled it should be read from the given install base.

Related: #9408
Fixes: #11842

@meteorcloudy meteorcloudy force-pushed the allow_bazel_client_as_bazel_binary branch from a449315 to 5685c4c Compare August 10, 2020 15:42
@olekw
Copy link
Contributor

olekw commented Aug 14, 2020

I can confirm that this PR allows the Bazel binary to be safely stripped and will resolve #11842. I tested with a build and install in the current Debian unstable.

@meteorcloudy meteorcloudy force-pushed the allow_bazel_client_as_bazel_binary branch from 5685c4c to 18c42b1 Compare August 20, 2020 13:32
This will allow Bazel client to run individually without the appended
zip archive, which is a requirement for Debian installation.

The following changes are made:
  - Add --trust_install_base option. When this is enabled. Bazel client
    trusts the install base provided by --install_base option and skip
    the step of verifying the install directory. We need it because the
    Bazel client alone doesn't contain information to verify the install
    directory.
  - Reimplement --version as a actual Bazel startup flag. The version
    info is read from the zip archive, but when --trust_install_base is
    enabled it should be read from the given install base.

Related: bazelbuild#9408
Fixes: bazelbuild#11842
@meteorcloudy meteorcloudy force-pushed the allow_bazel_client_as_bazel_binary branch from 18c42b1 to de33eb4 Compare August 20, 2020 14:31
@meteorcloudy meteorcloudy changed the title WIP: Add --trust_install_base option Add --trust_install_base option Aug 20, 2020
@michajlo
Copy link
Contributor

Folding --version into regular option handling is something I had wanted to do when first adding it, but I didn't want to go too deep into figuring out/defining how it would get along with the option parsing semantics and the things that can go wrong between the 3rd line of Main and options parsing. Do you have any thoughts on those?

Also, documentation will need to be updated to reflect that --version is more lenient now, and we should add at least one test to show how it interacts with other options.

@meteorcloudy
Copy link
Member Author

Folding --version into regular option handling is something I had wanted to do when first adding it, but I didn't want to go too deep into figuring out/defining how it would get along with the option parsing semantics and the things that can go wrong between the 3rd line of Main and options parsing. Do you have any thoughts on those?

So with the implementation in this PR. If the option parsing succeeded and --version is passed, Bazel will just print the version info, ignore other flags and possible bazel command, and exits. Comparing to the current behaviour that Bazel complains --version is not a recognized flag when other flags are passed, I think it is better.

Also, documentation will need to be updated to reflect that --version is more lenient now, and we should add at least one test to show how it interacts with other options.

Adding documentation and test sounds a good idea. Is there any original doc or test for --version available somewhere?

@meteorcloudy
Copy link
Member Author

Test and documentation added, please take another look ;)

@philwo
Copy link
Member

philwo commented Aug 21, 2020

LGTM except for the build failures ;)

@meteorcloudy
Copy link
Member Author

Oops, forgot to run git add 😅

Thanks for the fast review!

src/main/cpp/blaze.cc Outdated Show resolved Hide resolved
src/main/cpp/blaze.cc Outdated Show resolved Hide resolved
src/main/cpp/blaze.cc Show resolved Hide resolved
@meteorcloudy
Copy link
Member Author

@michajlo Thanks for the review, please take another look ;)

@aiuto aiuto requested a review from WarkahScott August 21, 2020 14:19
@aiuto aiuto removed their request for review August 21, 2020 14:21
<code>bazel version --gnu_format</code>, except without the side-effect of potentially starting
a Bazel server or unpacking the server archive. <code>bazel --version</code> can be run from
anywhere - it does not require a workspace directory.
anywhere - it does not require a workspace directory. When <code>--version</code> is passed, all
other flags and Bazel command will be ignored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if people will nitpick on this... but all other flags aren't completely ignored... they're parsed (i believe including rc files) then dropped.

actually, this makes me think, should we skip rc parsing if --version is specified, so that a bad rc file doesn't mess things up? i also wonder if we can disallow --version from rc files, but that's probably not worth it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this makes me think, should we skip rc parsing if --version is specified

Sounds like a good idea, but would implement in a different PR.

@@ -20,6 +20,11 @@

namespace blaze {

void DetermineArchiveContentsFromInstallBase(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document the intended use? (when install base is considered trusted, right?)

@@ -1617,11 +1631,21 @@ int Main(int argc, const char *const *argv, WorkspaceLayout *workspace_layout,
StartupOptions *startup_options = option_processor->GetParsedStartupOptions();
startup_options->MaybeLogStartupOptionWarnings();

if (startup_options->trust_install_base && startup_options->install_base.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making me realize, the semantics of --version differ now based on if --trust_install_base is specified. With --trust_install_base we print the version of the server, without --trust_install_base we print the version of the client. These could differ. This should definitely be documented, or (probably overkill) we could have separate flags...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could differ.

How?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client and server versions fall out of sync. Could be user points client at diff install base, or that some update doesn't go as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client and server versions fall out of sync. Could be user points client at diff install base, or that some update doesn't go as expected.

FWIW, this would be a highly improbable situation in the Debian package. Certainly possible, but someone would have to purposely hack some things that they shouldn't be touching unless they're a Bazel developer or Debian package manager. ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be for uses outside of debian as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well of course! I'm just commenting within the scope of my expertise. 🙂 Additional uses are likely in the future but the official Debian package is presently the only user of the trust-install-base option.

<code>bazel version --gnu_format</code>, except without the side-effect of potentially starting
a Bazel server or unpacking the server archive. <code>bazel --version</code> can be run from
anywhere - it does not require a workspace directory.
anywhere - it does not require a workspace directory. When <code>--version</code> is passed, all
other flags and Bazel command will be ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this makes me think, should we skip rc parsing if --version is specified

Sounds like a good idea, but would implement in a different PR.

@@ -1007,6 +1007,11 @@ static DurationMillis ExtractData(const string &self_path,
<< "install base directory '" << install_base
<< "' could not be created. It exists but is not a directory.";
}

if (startup_options.trust_install_base) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little surprised to see this down here.

What's the expected behavior of this option when no install base exists? I would not assume that it should create one (but it does above).

@mcarpenter
Copy link

Meanwhile... workaround for debian/ubuntu users whose bazel gets zapped by the prelinker:

# echo '-b /usr/bin/bazel-real' >> /etc/prelink.conf

(prelink(8) is invoked from /etc/cron.daily/prelink on Ubuntu 20.04).

@meisterT
Copy link
Member

Yun, what's the state of this PR?

@meteorcloudy
Copy link
Member Author

Sorry, I haven't found time for this recently. But it's on my to-do list. Will take on this ASAP!

@lberki lberki added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Oct 21, 2020
@aiuto
Copy link
Contributor

aiuto commented Oct 7, 2021

Friendly ping. If this will never merge, can you close it. That way we will stop seeing it in bug triage.

@meteorcloudy
Copy link
Member Author

Sorry, about that. I'll close this for now until I have time to work on it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow safe stripping of Bazel binary
9 participants