Skip to content

Running Bazel build on Windows with default Execution Policy doesn't work #29760

Closed

Description

@frederikprijck

🐞 bug report

Affected Package

This issue is related to running Bazel on Windows.

Is this a regression?

N/A

Description

I checked out Angular and did a fresh yarn install. Once that was done, I tried running one of the package/examples, in this case it was my own example package (for my PR at #29755), which runs fine on the CI.

Once I run my example using yarn bazel run //packages/examples/router/activated-route:devserver, I get the error I mentioned below.

To resolve this, all I had to do was open PowerShell and execute the following command:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

When I now try and run yarn bazel run //packages/examples/router/activated-route:devserver, everything works fine! :)

As this unblocked me, I used this aproach and decided to see if anyone on twitter had a way to solve this.
The friendly @alexeagle replied to my tweet asking if I had an Github issue. I didn't, but now I do 😄 !

🔬 Minimal Reproduction

Just run the master on Windows 10 with the default Execution Policy (Resitricted) and run any example mini-app ( ensure to empty your bazel directory with cache etc). If you want to execute the command I've been pasting (yarn bazel run //packages/examples/router/activated-route:devserver), you'll need to run my branch for this PR: #29755

🔥 Exception or Error

Extracting Bazel installation...
Starting local Bazel server and connecting to it...
ERROR: error loading package '': Encountered error while reading extension file 'package.bzl': no such package '@npm_bazel_karma//': copy_repository failed:
STDOUT:

STDERR:
File C:\users\frederik\_bazel_frederik\p5aerkcd\external\npm_bazel_karma\_copy.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess
ERROR: error loading package '': Encountered error while reading extension file 'package.bzl': no such package '@npm_bazel_karma//': copy_repository failed:
STDOUT:

STDERR:
File C:\users\frederik\_bazel_frederik\p5aerkcd\external\npm_bazel_karma\_copy.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess
INFO: Elapsed time: 54.276s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

🌍 Your Environment

Angular Version:
N/A

Anything else relevant?
So I'm running on Windows 10, My Execution-Policy is set to its default value.
If any other environmental information is needed, feel free to reach out.

Activity

  1. frederikprijck commented on Apr 8, 2019

    @frederikprijck
    ContributorAuthor

    I got a feeling it's an issue on my end. I mean, the ExecutionPolicy is doing what it's expected, right? Not allowing bazel to execute the script ...
    However, I wanted to create this issue anyway, but feel free to close it if it's expected behavior.

  2. added
    area: bazel
    on Apr 8, 2019
  3. added this to the needsTriage milestone on Apr 8, 2019
  4. meteorcloudy commented on Apr 9, 2019

    @meteorcloudy
    Contributor

    @frederikprijck I guess this is WAI.
    I am able to yarn bazel run packages/examples/common:devserver on Windows with

    PS C:\Users\pcloudy> Get-ExecutionPolicy -List
    
            Scope ExecutionPolicy
            ----- ---------------
    MachinePolicy    RemoteSigned
       UserPolicy       Undefined
          Process       Undefined
      CurrentUser       Undefined
     LocalMachine          Bypass
    
  5. frederikprijck commented on Apr 9, 2019

    @frederikprijck
    ContributorAuthor

    @meteorcloudy Yes, I guess the reason it's working for you is because you've set the ExecutionPolicy to Bypass for the LocalMachine scope. Setting it to Unrestricted also works for me.

    Do you recommend people to update their ExecutionPolicy to either Bypass or Unrestricted ? I'm not familiar with PowerShell, but it doesn't sound like a setting you wanna have.

  6. meteorcloudy commented on Apr 9, 2019

    @meteorcloudy
    Contributor

    I'm not very familiar with powershell, either. I think users should only be required to set ExecutionPolicy when their default setting doesn't work. @alexeagle What do you think it the best way to document this?

  7. frederikprijck commented on Apr 9, 2019

    @frederikprijck
    ContributorAuthor

    Important to note that:

    PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the the execution of malicious scripts.

    I'm not familiar with Bazel, I guess it needs this setting. However it would be good if it could be avoided or configured to only set it for the bazel process (if that's even possible).

  8. meteorcloudy commented on Apr 9, 2019

    @meteorcloudy
    Contributor

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6#set-a-different-execution-policy-for-one-session

    Looks like we can run powershell.exe with -ExecutionPolicy Unrestricted option.

    The execution policy that you set isn't stored in the registry. Instead, it's stored in the $env:PSExecutionPolicyPreference environment variable. The variable is deleted when you close the session in which the policy is set. You cannot change the policy by editing the variable value.

  9. alexeagle commented on Apr 16, 2019

    @alexeagle
    Contributor

    Is there a way we can run code without the user having to modify a setting? Using .bat instead of powershell? We should always treat this kind of bad user ergonomics as a bug (I imagine many devs wouldn't have rights to change that kind of policy on their machine anyway)

    @gregmagolan has a plan to remove the need for powershell in this case I believe.

  10. gregmagolan commented on Apr 23, 2019

    @gregmagolan
    Contributor

    Finally got around to this. bazel-contrib/rules_nodejs#717 removes the powershell dep & used a .bat file instead

  11. meteorcloudy commented on Apr 23, 2019

    @meteorcloudy
    Contributor

    There is another powershell dependency coming from rules_webtesting:
    https://github.com/bazelbuild/rules_webtesting/blob/master/web/internal/extract.bat
    But I'm not sure there's any equivalent command in batch.
    @gregmagolan

  12. modified the milestones: needsTriage, Backlog on Apr 24, 2019
  13. added a commit that references this issue on Jun 6, 2019
  14. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  15. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: bazelfreq1: lowtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions