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

Creating an environment variable from a #196

Closed
Riduidel opened this issue Feb 25, 2019 · 10 comments
Closed

Creating an environment variable from a #196

Riduidel opened this issue Feb 25, 2019 · 10 comments
Assignees
Milestone

Comments

@Riduidel
Copy link

Describe the bug
On Windows, the created environment variable is trunctaed to one line

To Reproduce
I've created the following cargo makefile

[tasks.find_version_set]
condition = { env_set = [ "NEW_VERSION" ] }
script = [ "echo NEW_VERSION is already set by cargo as \"%NEW_VERSION%\"" ]

[tasks.find_version_unset]
condition = { env_not_set  = [ "NEW_VERSION" ] }
env = { NEW_VERSION = { script = [ "git describe --abbrev=0 --tags" ] } }
script = [ "echo NEW_VERSION has been read from git as \"%NEW_VERSION%\"" ]

[tasks.find_values]
dependencies = ["find_version_set", "find_version_unset"]

[tasks.journal]
dependencies = ["find_values"]
env = { CHANGELOG = { script = [ "git journal %NEW_VERSION%" ] } }
script = [ "echo CHANGELOG has been read as \"%CHANGELOG%\"" ]


[tasks.publish_release]
dependencies = ["journal"]

When I run that makefile, I have the following output log

[cargo-make] INFO - cargo make 0.16.8
[cargo-make] INFO - Using Build File: Makefile.toml
[cargo-make] INFO - Task: publish_release
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Setting Up Env.
[cargo-make] INFO - Running Task: init
[cargo-make] INFO - Running Task: find_version_set
[cargo-make] INFO - Running Task: find_version_unset

C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap>cd C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap 

C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap>echo NEW_VERSION has been read from git as "0.1.3" 
NEW_VERSION has been read from git as "0.1.3"
[cargo-make] INFO - Running Task: find_values
[cargo-make] INFO - Running Task: journal

C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap>cd C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap 

C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap>echo CHANGELOG has been read as "- [Fixed] #13 by correctly using match. As
an aside, I've made some logs less visible" 
CHANGELOG has been read as "- [Fixed] #13 by correctly using match. As an aside, I've made some logs less visible"
[cargo-make] INFO - Running Task: publish_release
[cargo-make] INFO - Running Task: end
[cargo-make] INFO - Build Done  in 0 seconds.

Whereas running git journal 0.1.3 gives the following output

[2019[2019-0[2-25-02-25T21:01:49+T21:01:49+01[2019-[2019-:0020-0251T:212:2019001] :-[25gitjournal0] 0] -0T221-[25[T4921::WARN0] 1+Skipping commit: 01::049gitjournal+Summary parsing failed: '[changed] reverted flexi_logger to a version that worked'0
1:] 04901] :+[0gitjournal0] ] [[[WARNgitjournal] ] 01[WARNSkipping commit: :Summary parsing failed: '(cargo-release) version 0.1.3'WARN] 00
] Skipping commit: Summary parsing failed: '[added] human_panic for better UX'[] gitjournal
] Skipping commit: Summary parsing failed: 'Aaaand it failed again'[
WARN] Skipping commit: Summary parsing failed: '[changed] Used pattern matching to better fix #13'
[2019-02-25T21:01:49+01:00] [gitjournal] [INFO] Parsing done. Processed 7 commit messages.

# 0.1.3 (2019-02-20):
- [Added] processing of dc:dates to traditionnal rss date handling. Fixes #14
- [Fixed] #13 by correctly using match. As an aside, I've made some logs less visible

Notice that there are three lines in standalone run, vs one line in environment variable built by cargo make.

What is wrong ? Have I missed something in cargo make configuration ?

@sagiegurari
Copy link
Owner

I'll take a look. thanks!!!

@Riduidel
Copy link
Author

Is there anything I can do to help you on that subject ?

@sagiegurari
Copy link
Owner

well... didn't have a chance to look at it yet.
if you want to take a shot at it, feel free and submit a PR.
the code that invokes the script and sets the env is at
https://github.com/sagiegurari/cargo-make/blob/master/src/lib/environment/mod.rs#L27

if not, I'll probably take a look at it this weekend or so ...

@sagiegurari
Copy link
Owner

ok, so it has been eons since i wrote that piece of code.
but looking at that specific function i put the link to, it seems i only take the last line:

if lines.len() > 0 {
     let line = lines[lines.len() - 1].to_string();

so... in order not to break backward compatibility, i'm thinking of introducing a flag to enable multi line output support, something like:

MULTI_LINE_SCRIPT = { script = ["cat ./somefile.txt"], multi_line = true}

@Riduidel
Copy link
Author

Well, I don't know what user base you have, but I think the sensible default in that case is to get all lines, and allow the ability to get only the last line through a flag. Do you see my point ?

(and I think most of the Windows users of cargo make - provided they exist ;-) - already have coping strategies, which will make that flag useless.

But as you're the developer, I guess my opinion is only an opinion :-)

@sagiegurari
Copy link
Owner

I had bad experience with this in the past.
Few times I broke backward compatibility and each time it caused issues for others.
Sometimes they complain, and one time I got a PR to enable uploading compiled artifacts per release (so something good came out of it).
Anyhow, I try to be careful with these changes.

Also be aware that although i have a multi line output of the script, when I push it via env::set_var (rust api), it gets pushed as a huge single line value.
now... this might only be in Linux and not for windows behavior, but i'm not sure. I don't develop on windows.
But you can take the latest cargo-make from the 0.16.9 branch and try it out if you want.

@Riduidel
Copy link
Author

To test that version, I guess I'll have to checkout cargo make, run cargo build ...
And will it be installed in cargo at build time (sorry to ask noob questions) ?

@sagiegurari
Copy link
Owner

no need for that. you can run cargo install on a git branch directly.
check out cargo install --help

--git <URL>              Git URL to install the specified crate from
--branch <BRANCH>        Branch to use when installing from git

@Riduidel
Copy link
Author

Well ... I've updated cargo make

cargo install --force --git https://github.com/sagiegurari/cargo-make.git --branch 0.16.9
    Updating git repository `https://github.com/sagiegurari/cargo-make.git`
  Installing cargo-make v0.16.8 (https://github.com/sagiegurari/cargo-make.git?branch=0.16.9#9d4d4b08)
    Updating crates.io index

And ...

It's unfortunatly a nope

$ echo NEW_VERSION has been read from git as "
NEW_VERSION has been read from git as "
[cargo-make] INFO - Running Task: find_values
[cargo-make] INFO - Running Task: journal

nicolas-delsaux@NICOLASDELSAUX C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap
$ cd C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap

nicolas-delsaux@NICOLASDELSAUX C:\Users\nicolas-delsaux\Documents\open-source\rrss2imap
$ echo CHANGELOG has been read as "- [Fixed] #13 by correctly using match. As an aside, I've made some logs less visible"
CHANGELOG has been read as "- [Fixed] #13 by correctly using match. As an aside, I've made some logs less visible"
[cargo-make] INFO - Running Task: publish_release
[cargo-make] INFO - Running Task: end
[cargo-make] INFO - Build Done  in 1 seconds.

I think I'll try another solution, because multiline env variables in Windows are a total pity. Thanks anyway for your effort

@sagiegurari
Copy link
Owner

releasing it today as part of 016.9
will work on making it truly multi line value, although it seems the rust api doesn't support that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants