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

Better unknow target handling & build.cmd #954

Merged
merged 3 commits into from
Sep 22, 2015

Conversation

vbfox
Copy link
Contributor

@vbfox vbfox commented Sep 17, 2015

Changes

TLDR:

  • Used SETLOCAL in build.cmd to ensure that it doesn't touch the global environment
  • Also made build.cmd handle build target names quoted or not as first arg
  • Replaced all direct access to the target dictionary with the getTarget function that provide an nice error display.

Why

I had a problem today where FAKE wasn't building some of our projects anymore, after searching the real reason was that I built fake in the same terminal a little bit before and that build.cmd set the environment variable TARGET to "Default" (With the quotes).

The problem with that is that while FAKE build.cmd pass it on the command line, and the extra quotes are removed from there our own build script doesn't and just call :

RunTargetOrDefault "Default"

(The fact that we also use a task named Default made that a lot harder to debug, took me time to understand who set this evironment variable)

But RunTargetOrDefault will also use an environment variable TARGET if it exists, except that it doesn't trim quotes :D

And then fake was failing with the not really helpful :

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an
invocation. ---> System.Collections.Generic.KeyNotFoundException: The given key was not
present in the dictionary.                                                                 

build.cmd wasn't using SETLOCAL but was using SET on an environment
variable named 'TARGET' that was leaking out of the script.

The 'TARGET' variable was also adding needless quotes to the name of the
target (That were later trimed due to argument processing but still
needless)
The dictionary of targets was sometimes acceded directly and was throwing
KeyNotFoundException. The getTarget helper is now used everywhere,
providing the name of the invalid target and also printing the list of
valid target on the console.
Both of the following invocations are now equivalent

    build.cmd Test
    build.cmd "Test"
@forki
Copy link
Member

forki commented Sep 22, 2015

thx

forki added a commit that referenced this pull request Sep 22, 2015
Better unknow target handling & build.cmd
@forki forki merged commit e6c71c8 into fsprojects:master Sep 22, 2015
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.

2 participants