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

Unwanted output during alr printenv caused by actions #989

Closed
pjljvandelaar opened this issue Apr 13, 2022 · 12 comments · Fixed by #1585
Closed

Unwanted output during alr printenv caused by actions #989

pjljvandelaar opened this issue Apr 13, 2022 · 12 comments · Fixed by #1585
Assignees
Milestone

Comments

@pjljvandelaar
Copy link
Contributor

Dear Alire Developers,

alr help printenv
yields

SUMMARY
   Print the build environment variables

USAGE
   alr printenv [options]

OPTIONS
   --details     Print details about the environment variables and their origin
   --unix        Use a UNIX shell format for the export (default)
   --powershell  Use a Windows PowerShell format for the export
   --wincmd      Use a Windows CMD shell format for the export

GLOBAL OPTIONS
   -c (--config=ARG)       Override configuration folder location
   -f (--force)            Keep going after a recoverable troublesome situation
   -h (--help)             Display general or command-specific help
   -n (--non-interactive)  Assume default answers for all user prompts
   --no-color              Disables colors in output
   --no-tty                Disables control characters in output
   --prefer-oldest         Prefer oldest versions instead of newest when resolving dependencies
   -q                      Limit output to errors
   -v                      Be more verbose (use twice for extra detail)
   -d (--debug[])          Enable debug-specific log messages

DESCRIPTION
   Print the environment variables used to build the crate. This command can be
   used to setup a build environment, for instance before starting an IDE.

   Examples:
     - eval $(alr printenv --unix)
     - alr printenv --powershell | Invoke-Expression

Although the last example is really helpful.
It doesn't always work flawless

PS C:\path\to\Renaissance-Ada\src\tools\Code_Reviewer>  alr printenv --powershell | Invoke-Expression
Note: : The term 'Note:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Note: Synchronizing workspace...
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (Note::String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Dependencies : The term 'Dependencies' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Dependencies automatically updated as follows:
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Dependencies:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Invoke-Expression : Cannot bind argument to parameter 'Command' because it is an empty string.
At line:1 char:30
+  alr printenv --powershell | Invoke-Expression
+                              ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:PSObject) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand

warn: Generating possibly incomplete environment because of missing dependencies
New : The term 'New' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+    New solution is incomplete.
+    ~~~
    + CategoryInfo          : ObjectNotFound: (New:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Invoke-Expression : At line:1 char:5
+    +i gnat            11.2.4  (new,installed,gnat_native,indirect)
+     ~
Missing expression after unary operator '+'.
At line:1 char:5
+    +i gnat            11.2.4  (new,installed,gnat_native,indirect)
+     ~
Unexpected token 'i' in expression or statement.
At line:1 char:35
+    +i gnat            11.2.4  (new,installed,gnat_native,indirect)
+                                   ~
Missing argument in parameter list.
At line:1 char:30
+  alr printenv --powershell | Invoke-Expression
+                              ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator,Microsoft.PowerShell.Commands.InvokeExpressionCommand

This happens when alire is executed for the first time on a project / directory and other output to report progress is also provided.

Hopes this helps to make alire even better!

Pierre

@pjljvandelaar
Copy link
Contributor Author

It took me a time to make the wincmd equivalent of the powershell example.
Maybe you can return it as part of the help text (or put it somewhere in the documentation) to help others:

for /F "usebackq delims=" %x in (`alr printenv --wincmd`) DO %x

Also this trick has the same limitations as I described earlier in this issue!

@mosteo
Copy link
Member

mosteo commented Apr 14, 2022

Thanks for the detailed report and research! We took some measures to make some warnings that can happen during alr printenv go to stderr, but these ones escaped. It's probably too fragile to try to achieve this anyway; maybe we can add to the help that the safe way to invoke printenv is with -q, or force it ourselves.

@Fabien-Chouteau
Copy link
Member

Hello @pjljvandelaar

Looks like alr printenv --powershell | Invoke-Expression didn't work because Alire is outputting more message.
I would recommend running alr printenv --powershell first to see if there anything to update on the Alire side.
And then do alr printenv --powershell | Invoke-Expression

@pjljvandelaar
Copy link
Contributor Author

@Fabien-Chouteau You describe a workaround that is similar to what I am currently using. First alr build to make sure everything is fine. And only then use alr printenv.
My workaround might indeed be slower, since building does problably more than just printing the environment values.

@Blady-Com
Copy link

Blady-Com commented Jun 12, 2022

maybe we can add to the help that the safe way to invoke printenv is with -q, or force it ourselves.

Even with -q, some additional lines are present:

$ alr -q printenv
checking build system type... x86_64-apple-darwin21.5.0
checking host system type... x86_64-apple-darwin21.5.0
checking target system type... x86_64-apple-darwin21.5.0
checking whether gnat can build shared libs... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
configure: creating ./config.status
config.status: creating xmlada_shared.gpr
config.status: creating Makefile
config.status: creating tests/dom/default.gpr
export ALIRE="True"
...

Thus I use: % eval $(alr -q printenv --unix|grep export)

@jklmnn
Copy link

jklmnn commented Feb 21, 2023

I just encountered the same problem on linux. What do you think about omitting all messages except the environment when using --unix, --wincmd or --powershell as these are likely used in an environment that tries to parse the output and therefor breaks if anything other than environment declarations are printed?

@mosteo
Copy link
Member

mosteo commented Feb 21, 2023

If you have some minimal example that produces output to stdout after the fix in #1327 and with -q that would be very useful.

@Blady-Com, is that output caused by some post-fetch action or the like?

@jklmnn

This comment was marked as off-topic.

@mosteo
Copy link
Member

mosteo commented Feb 22, 2023

I tried to build a version after #1327 but I'm always running into the following problem:

Let's try to stay on topic, but see here: #1326

@mosteo mosteo changed the title Example not always working Unwanted output during alr printenv Feb 22, 2023
@jklmnn
Copy link

jklmnn commented Feb 22, 2023

I tried alr -q printenv with an alire built from 0a19027 and it didn't produce any unwanted output for me, even if it was downloading dependencies and setting up the toolchain. So at least for me it seems the problem is fixed in that version.

@Blady-Com
Copy link

@Blady-Com, is that output caused by some post-fetch action or the like?

Yes that's right, try for instance templates_parser crate.

@mosteo
Copy link
Member

mosteo commented Feb 24, 2023

Alright, I can reproduce with templates_parser. That's definitely something concrete to fix.

@mosteo mosteo changed the title Unwanted output during alr printenv Unwanted output during alr printenv caused by actions Feb 24, 2023
@mosteo mosteo added this to the 2.0 milestone Feb 24, 2023
@mosteo mosteo self-assigned this Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants