How can I execute a script prior to the CMake step using Visual Studio Code's CMake Tools extension? - visual-studio-code

My use case: I want to execute a script setting up a virtual Python environment prior to any configure or build step. While I can simply source this script before calling CMake on the command line, I want to be able to do the same within the CMake Tools extension without having to adapt the CMakeLists.txt files.
The extension has the cmake.environment, cmake.buildEnvironment and cmake.configureEnvironment settings. But I don't want to manually reverse-engineer the script nor maintain the list of possibly changing environment variables. I simply want to execute the script and have CMake run in the sourced context.

Short answer: Have the cmake.cmakePath point to a script that sources the original script (or calls whatever is wanted) then calls the actual CMake executable (along with forwarding all passed parameters).
Example:
#!/bin/bash
source /home/user/the_script_you_want_to_source # or whatever other script you want to have executed
/usr/local/bin/cmake "$#" # don't forget to forward the passed parameters
Note that it may be required to chmod +x the pointed-to script.

Related

How to move a program to a directory in my PATH

Am on a MAC OS following instructions to setup an application(pipelines), and ran the following commands:
curl -o pipelines https://cloud.acquia.com/pipeline-client/download
chmod a+x pipelines
To finalise the instruction, quoting the guide, I need to move the pipelines program to a directory in my PATH.
How do I move the pipelines program to a directory in my PATH?
Not sure if it helps, but I use zhrc and iterm.
On windows, try opening System Properties => Environment Variables
In the Environment Variables window there should be a variable called Path.
Click it and then click Edit
Then click New on the right hand side and add the path to the program
EXP "C:/User/bin/php.exe"

Eclipse Makefile project to be built within a Cygwin environment

We have a project (C) (not a Cygwin exe project, but some embedded cross-compiled one), which has a Makefile designed to be used from within a Cygwin environment. That is the intended use is to open a Cygwin terminal, go t the project directory and run make from there.
I can import this project in Eclipse as a Makefile project, but apparently the regular build command from within Eclipse won't work as it is trying to invoke make in the native (Windows) environment. Is there a way to make Eclipse to run the Cygwin, invoke a make command in it and have the regular CDT error parsers to work? Perhaps by creating a custom builder?
I have managed to work around this problem by using a build script invoking some cygwin commands:
build.bat:
#echo off
c:\cygwin64\bin\bash --login -c "cd %cd:\=/%; make %*"
Breakdown:
c:\cygwin64\bin\bash --login -c "<command>" - used to invoke a command from within cygwin environment
cd %cd:\=/%; - is a "dos" %cd% variable (current path) with backslashes replaced by slashes - to avoid these to be stripped down as unescaped.
make %* - invoke the cygwin make command with all of the arguments passed to this batch file - this is to let Eclipse pass the build target and/or build flags.
Now in "project build" tab in eclipse I replace the make command with build.bat and it is working like a charm. The only drawback i to have this file in addition to the other project files, but since it is pretty generic it can be reused in any project with these restrictions.

Is there a venv-specific equivalent of virtualenvwrapper's 'postactivate'

After starting my virtualenv, I would like to run a script that depends on some specifics of the environment (e.g. bash completions for some tools installed there). Is there a way to do this on a per-venv basis — effectively a local version of postactivate?
AFAIU postactivate is sourced at workon time. You don't automatically activate a virtualenv, you source bin/activate so you can add your code at the end of the bin/activate script.
To emulate predeactivate edit the same bin/activate script, function deactivate.

create a link in windows so it can find msbuild without full path

Not sure how to do this... I work mostly on OSX and linux systems, so when I install an app or use for example G++ or xcodebuild, I just call it from terminal.
On Windows, I did install msbuild with VS2015, but if I am in powershell or regular command prompt, typing msbuild result in an error. I have to specify the whole path to make it work.
What is the equivalent in Windows world, of setting console so when I type msbuild, it gets the correct path?
You can set your path like so in:
PowerShell
$Env:Path = "<Path_to_msbuild>;${Env:Path}"
Batch/Cmd
set "PATH=<Path_to_msbuild>;%PATH%"
Note: The <path_to_msbuild> is the folder where msbuild.exe exists, and NOT the direct path to the executable itself
How it works
This will add the msbuild binary to your path, so you can invoke it from anywhere!
To verify which location msbuild is running from you can simply run (in both languages!):
where.exe msbuild
If you create just a link to msbuild you still won't be able to call for example the compiler from the command line. Which is why VS provides a convenient (pretty much canonical) way to do this by supplying a batch file which sets up the PATH and all the other build-related environment variables.
Example if you are on cmd.exe:
> "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
> msbuild
Microsoft (R) Build Engine version 14.0.25420.1
...
> cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86
...
You can invoke this from the Start menu as well: hit start, type pro vs to look for matches, select Developer Command Prompt for VS2015.
For PowerShell (which I'd recommend spending time on instead of cmd) you'll need an extra function like presented here: https://stackoverflow.com/a/21652729/128384

How do I call a .bat file to determine build environment in eclipse?

In to order to determine the build environment, I have written a .bat that will set the environment variables. How can I call this .bat file before make all?