How to switch PHP versions in environment variables? - yii

Since I'm required to work on both PHP5.x and PHP7.x projects in Yii framework, I've installed WAMP.
I've also set up my environment variables to link to both paths containing php.exe and for just working with the projects, that's just fine.
However, whenever I need to run migrations, there's a problem: if PHP7 path is defined first, PHP5 migrations won't run and if PHP5 path is listed first, PHP7 migrations won't work anymore.
Error message for PHP5:
'yii' is not recognized as an internal or external command, operable program or batch file.
Error message for PHP7:
Parse error: syntax error, unexpected '?' in C:\wamp64\www\project\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 822
Is there a clean way to be able to define which PHP version you wish to use when running migrations, without having to reconfigure your environment variables again and again?

Thank you #RiggsFolly for your help. Based on the link you provided, I compiled a handy solution:
I started off by creating 2 new files in C:\Windows\System32 (since this path is already included in the environment variables):
startphp5.cmd and startphp7.cmd.
startphp5.cmd contains just this (start7.php is obviously almost the same):
PATH=%PATH%;C:\wamp64\bin\php\php5.6.31
php -v
Before running my migrations in my command prompt, all I have to do now is run either "startphp5" or "startphp7".

Related

Running software build in MSYS2 MINGW32 shell

I'm trying to run a piece of software I built in MSYS2 MINGW32 shell. The software is 32bits (don't have time to port it to 64bits) and there is one statically linked executable. Here is how I setup the build environment:
Installed a fresh copy of MSYS2;
$ pacman -Syu
Installed the following packages: git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-SDL mingw-w64-i686-SDL_mixer mingw-w64-i686-zlib mingw-w64-i686-libpng mingw-w64-i686-make
Git checkout the repo
Run the build in CMake
Build runs fine and the exe is generated.
Now the problem starts: the executable can't run and displays an error message about missing DLLs. I copied the missing DLLs to the same folder of the executable, and them another error message pops up complaining about error 0xC000007B, which I tracked down to be missing dependencies. After a while I figured out that the problem was that some of the DLLs is missing a dependency itself. Copied this last dependency to the folder.
Now, the big question: I can run the exe perfectly fine in the MINGW32 shell but I can't run it neither in cmd.exe nor by double-clicking in Windows Explorer and this is a problem (I can't ship a software this way). Is there any way to produce a binary that is able to run from explorer and from cmd.exe? What is the cause of this problem? Can it be mitigated?
I solved my problem!
After a lot of research, I realized that nothing was wrong with my MSYS2 build/setup/dependencies. The real problem was that CMake hide one parameter for the linker: -mwindows. Actually, the CMake find_package routine from one of the libraries I'm using (SDL) added this parameter to the linker command line parameters.
Adding a -mconsole to the linker parameters (using add_link_options("-mconsole")) solved the problem. The CLI now works as expected.
Thank you all for your help.

Is it possible to execute a command as a super user while using cmake?

I'm working on a project that uses the proxygen library by facebook.
The latter builds itself by means of a script called deps.sh which uses to invoke apt-get as a super user.
I've successfully created a custom target with cmake using the add_custom_target directive, but it fails because of the above call with the error sudo: no tty present and no askpass program specified and it makes sense, of course.
Anyway I've not been able to find a way of executing that script, thus invoking a command as a super user, using the add_custom_target.
I can safely install the library and write a FindProxygen module for my colleagues, so that the build process remains coherent, but I'd like to know if there is a clean solution to the problem of launching a command as root from cmake and thus put the library as a submodule of the project.
You can run installation script in new terminal, so sudo, executed by this script, will work as usual.
COMMAND x-terminal-emulator -e "<...>/deps.sh"
(This may be written as part of add_custom_target, add_custom_command, execute_process, etc.)
add_custom_target(
apt-downloads ALL
COMMAND sudo apt install -y ${DEPENDENCY_LIBRARIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "download required dependencies straight from apt on ubuntu"
)
Worked for me
The response is pretty simple: no.
As remarked in the comments, cmake expects to find all the required libraries already installed in the system (or at least, within the search paths) and any other solution would stop the execution and wait for user inputs.
As far as I've seen around, the usual approach, the one I've used too in the above mentioned project and in another one started immediately after, is to create a script that is in charge to download, compile and prepare the project environment, the same way proxygen itself does.
The final user will be asked to firstly executes that script, thus he will be able to proceed using cmake.
That's all, thank you for the comments.

Building C# (Mono) Solution from GitHub with TeamCity on CentOS

I am trying to get TeamCity to do automated builds for me on CentOS, however if I create a runner type of 'MSBuild' I get the following error
Failed to start MSBuild.exe. Failed to find msbuild.exe at path: /usr/lib/mono/4.0/xbuild.exe
I tried a runner type of 'Visual Studio (sln)' setting Visual Studio to be 2012 and got the following error
No enabled compatible agents for this build configuration.
When I look at my Agent Requirements, I see:
Unmet requirements: DotNetFramework4.5_x86 exists
I honestly have no idea what could be wrong. Mono is up and running on this machine, as it is hosting a website built with Mono. Could somebody with a bit more experience let me know what I have done wrong please?
[EDIT]
I have just tried creating a symbolic link of where xbuild actually lives to where TeamCity wants it.
ln -s /usr/bin/xbuild /usr/lib/mono/4.0/xbuild.exe
I now am getting the following error in the Build log, so I am thinking it doesn't like symbolic links.
[MSBuild output] Cannot open assembly '/usr/lib/mono/4.0/xbuild.exe': File does not contain a valid CIL image.
I was able to get around this by adding an environment variable to the buildAgent.properties file on the build agent. Once you find that file add something like this in the Environment Variables section:
env.MSBuild=/usr/local/lib/mono/xbuild/12.0/bin/
I was doing this with ubuntu so that path might not be the same as what you were looking for.

On UnsatisfiedLinkError, clarification needed

When building the project from command line using mvn clean install everything builds without any issues.
When running some tests that use precompiled C libraries from IntelliJ, tests fail with java.lang.UnsatisfiedLinkError
I may be completely off here, but does IntelliJ not see the .so file? Is so, how can it be added please?
Shared library fails to load with UnsatisfiedLinkError if:
it's not in the working directory configured in the test run configuration.
it's not in PATH environment (on Mac Terminal and GUI apps have different environment, see this answer). Run IDEA from the Terminal open -a /Applications/IntelliJ\ IDEA\ 12.app/ to make environment the same.
it's not in the location specified using -Djava.library.path VM option.
.so depends on some other library that is not found for any of the 1-3 reasons (or the dependency of that dependency is not found, etc).

How to run CMakesetup?

I downloaded cmake and I wanted to build LSHKIT using this command:
cmakesetup ", where is the LSHKIT root directory
but it gives me this error:
'cmakesetup' is not recognized as an internal or external command,
operable program or batch file.
could you tell me what is wrong?
BTW, I am working in windows 7.
CMakeSetup is an older program that no longer builds with the most recent releases of CMake. Use "cmake-gui" instead of "CMakeSetup"...