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

vsenv: fix ValueError parsing multi-line env variables #13682

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ylatuya
Copy link

@ylatuya ylatuya commented Sep 16, 2024

This helps debugging issues like https://gitlab.freedesktop.org/ylatuya/gstreamer/-/jobs/63636384#L259.

Another question is if it should be treated as an error or ignored like it's done when parsing the key-value string a few lines above.

@eli-schwartz
Copy link
Member

Did you try it again with this patch to meson? What was the reported "illegal variable name"?

@ylatuya
Copy link
Author

ylatuya commented Sep 16, 2024

I found the root issue... So the CI adds an env variable CI_MERGE_REQUEST_DESCRIPTION with the description of the issue and containing this (edited for format see the original ):

CI_MERGE_REQUEST_DESCRIPTION=The following MR migrates all the existing code/format/message checks to [pre-commit](https://pre-commit.com/):
- gitlint: Commit messages with gitlint
- rustfmt: Rust format checks
- gst-indent: C format checks
- dotnet-format: C# format checks
Caching of dependencies follows the same decisions discussed in https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1315 https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1322.
## Installation
➜ pre-commit run  --show-diff-on-failure --files subprojects/gstreamer-sharp/sources/custom/Caps.cs subprojects/gstreamer/libs/gst/helpers/ptp/args.rs subprojects/gstreamer/gst/gst.c  
dotnet-format............................................................Passed
gst-indent...............................................................Failed
- hook id: gst-indent
- exit code: 1
--Checking style--
--- .merge_file_YzhXVL  2024-01-14 20:35:33
+++ /tmp/.merge_file_YzhXVL.ut9WE0      2024-01-14 20:35:33
@@ -1291,7 +1335,7 @@ gst_version_string (void)
     return g_strdup_printf ("GStreamer %d.%d.%d (GIT)", major, minor, micro);
   else
     return g_strdup_printf ("GStreamer %d.%d.%d (prerelease)", major, minor,
-        micro);
+                           micro);
 }
 
 /**
=================================================================================================
 Code style error in: subprojects/gstreamer/gst/gst.c                                                                      
=================================================================================================
=================================================================================================
 Code style error in:                                                                            
   subprojects/gstreamer/gst/gst.c
                                                                                                 
 Please fix before committing. Don't forget to run git add before trying to commit again.        
 If the whole file is to be committed, this should work (ru...

And well... that is broken into lines bat_lines = bat_output.split("\n") and split by = with k, v = bat_line.split("=", 1) ending with k being empty and v =====

@ylatuya ylatuya force-pushed the vsenv-log-errors branch 2 times, most recently from c8d9d18 to d0241ce Compare September 17, 2024 08:43
@ylatuya ylatuya changed the title vsenv: improve error when failing so set an environment variable vsenv: fix ValueError parsing multi-line env variables Sep 17, 2024
@ylatuya
Copy link
Author

ylatuya commented Sep 17, 2024

I updated the unit tests with 2 env variables that replicates the 2 possible errors:

  • A line with ==== that would result in an empty key
  • A line with %=bar that would result in k being % and therefore an invalid name

@eli-schwartz
Copy link
Member

I wonder if it's instead possible to filter those out from subprocess.check_output(bat_file.name, ...) by passing a copied+filtered env, on the rationale that those variables won't affect the VS detection process and having the bat script print them out at all is wasteful.

@ylatuya
Copy link
Author

ylatuya commented Sep 18, 2024

I wonder if it's instead possible to filter those out from subprocess.check_output(bat_file.name, ...) by passing a copied+filtered env, on the rationale that those variables won't affect the VS detection process and having the bat script print them out at all is wasteful.

That is an optimization I can implement. I will also change the code to call the script directly with subprocess instead of having to create a temporary file, that will speed up things as well.

Some CI's include variables containing the issue description, like
GitLab's CI_MERGE_REQUEST_DESCRIPTION. The description itself can
have multiple lines and any kind of content.
If one of these lines is '=========', it will leave k empty
when it's split by '='S.

Also improve how lines without '=' are parsed by checking the
parts of the split by '=' rather than trying to unpack a 1 value
array and handle the exception
@ylatuya ylatuya force-pushed the vsenv-log-errors branch 3 times, most recently from 794eb52 to d83e2a9 Compare September 18, 2024 12:39
Use a command instead of creating a temporary file
for the .bat script and process only newly created variables
@eli-schwartz
Copy link
Member

That is an optimization I can implement. I will also change the code to call the script directly with subprocess instead of having to create a temporary file, that will speed up things as well.

I had been thinking to do something like

newenv = {k:v for k, v in os.environ.items() if '\n' not in v}
bat_output = subprocess.check_output(bat_file.name, env=newenv, universal_newlines=True,
                                     encoding=locale.getpreferredencoding(False))

Or if we knew the minimal set of existing variables the vcvars*.bat file needs to be functional, we could make the new environment only contain those.

I suppose iterating over the set difference of lines would work too as long as none of the different lines are themselves part of a multiline variable which I suppose vcvars should not be producing. It just felt a bit weird to be recovering via random sort. But maybe it's fine.

@eli-schwartz
Copy link
Member

The test errors appear to be relevant but I do not understand them.

@jpakkane
Copy link
Member

The error messages come from trying to use the GCC compiler. So maybe PATH is messed up somehow?

@ylatuya
Copy link
Author

ylatuya commented Sep 18, 2024

The error messages come from trying to use the GCC compiler. So maybe PATH is messed up somehow?

Somehow the environment is not being set correctly after my changes. I will iterate again over the code and reproduce the error locally with the tests.

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 this pull request may close these issues.

3 participants