Premake, command line options don't do anything - lua

I have the following section in my lua script:
newoption {
trigger = "build-tests",
description = "Build tests."
}
configuration "build-tests"
print("bbbbbbbbb")
include("Src/tests/tests.lua")
configuration "not build-tests"
print("aaaaaaaaaaa")
running premake5 gmake --help gives:
Usage: premake5 [options] action [arguments]
OPTIONS - General
--build-benchmarks Build benchmarks.
--build-tests Build tests.
--debugger Start MobDebug remote debugger. Works with ZeroBrane Studio
--fatal Treat warnings from project scripts as errors
--file=FILE Read FILE as a Premake script; default is 'premake5.lua'
--help Display this information
However running premake5 --build-tests gmake outputs:
bbbbbbbbb
aaaaaaaaaaa
Building configurations...
Running action 'gmake'...
Done (362ms).
BOTH versions are running, I don't understand. I am trying to get a toggle to select whether I want to build tests or not.

configuration() is a function, not an if-then. Your example above is equivalent to...
configuration("build-tests")
print("bbbbbbbbb")
include("Src/tests/tests.lua")
configuration("not build-tests")
print("aaaaaaaaaaa")
It has no effect on which code runs or does not run in your script; all the code in your script is always run, and then the configuration conditions are evaluated later.
Instead look at the actual generated project output to see if things are working or not.

Related

Unable to run single PHP-test in PhpStorm (inside Docker-container). Error: Cannot open file "/path/to/my/project/tests/SomeTestClass.php"

Running all tests (works)
When I run all tests inside PhpStorm, then I go to "Run" >> "MyProject PhpUnit Test". This outputs and runs a command like this:
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --teamcity
That runs all tests inside PhpStorm, so far so good!
Running single test (does not work)
If I go to a single test, right-click on the test-name and click:
"Run testAppendShortToAnswers..."
Shortcut: CTRLShiftR
then it outputs and runs a command like this:
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --filter "/(App\\Tests\\Entity\\CardTest::testAppendShortToAnswers)( .*)?$/" --test-suffix CardTest.php /path/to/my/project/tests/Entity --teamcity
And throws an error immediately:
Cannot open file "/path/to/my/project/tests/Entity.php".
Process finished with exit code 1
I'm assuming that it's because it tries to access that file, not from inside my Docker-container, but rather from my host-machine.
How do I fix this, so I can run a single test in PhpStorm?
Info about the setup
I struggled a bit setting up PhpStorm to run the tests, but you can see the big problem I had (and the solution) alongside links and whatnot here.
I'm on a Mac. It's a Symfony-project, where PhpUnit is located in a folder in the project-root (/bin/phpunit). So it's not installed via Composer.
I'm not really sure why it's setup this way.
Solution attempt 1: Running single test from the terminal
If I go to the terminal and run this command:
docker-compose exec php /usr/local/bin/php /var/www/docroot/bin/phpunit --filter testAppendShortToAnswers
The it runs as it should. Hmm... But I ideally I would like to run it straight from PhpStorm, so I can utilize the CTRLShiftR-shortcut.
#LazyOne pointed me in the right direction.
It was because I had a path mapping setup incorrectly.
So by changing that, then it works now:
I had it like this:
/Users/MYUSERNAME/Code/MYPROJECTNAME/some-wrong-project -> /var/www/docroot
And it fixed it to change it to:
/Users/MYUSERNAME/Code/MYPROJECTNAME/the-project-I-am-working-on -> /var/www/docroot

Is it possible to run a command in a Docker image as a test in Bazel?

I would like to run a command inside a container to test that it works. It should be invoked by bazel test.
Something like this:
container_test(
image = "//:my_image"
test_command = "exit 1"
)
I noticed this: https://github.com/bazelbuild/rules_docker/blob/master/contrib/test.bzl#L125
However it isn't documented.
How should I approach this in Bazel?
Take a look at the sample test rule here
This is a test rule which creates a script (script) that can be invoked in the CLI
The script will then exit with a non-zero error-code to indicate that the test failed (or 0 for success)
The script is then written as an executable output (ctx.actions.write), declares the list of files it needs available at runtime (runfiles)
This python function is then wrapped as a bazel rule (see full guide here)
So, how would you proceed towards creating your container test rule?
The script we want to generate above is probably some usage of docker run --rm IMAGE [COMMAND] [ARG...] to create a container from an image, run a command, and remove the container when done
Don't forget to set the script exit status based on the exit status of the docker command (as done in the example, where they copy the exit status of grep as the exit status for the overall script)
Update the sample above to use the above docker command, and plant the path to the image accordingly
See f.path in the script above showing how they access the path of an individual source file
You will need to make sure docker is available when your bazel rules are evaluated
I haven't done this fully myself since I don't have a computer with both bazel and docker, but this should be enough to get you started :)
Good luck!

How do I debug a 'java_binary' target executed by a Bazel rule via 'ctx.actions.run(...)'?

I have a java_binary target in my workspace that I'm later passing as an executable to ctx.actions.run inside the rule. So far so good.
Now I want to debug this java_binary while Bazel is executing the rule. In order to attach a debugger I need the java_binary run in debug mode. So far, the only thing I came up with is setting jvm_flags on the java_binary. I was able to get that to work. But I was wondering if there is a way to achieve it from the command line instead of baking it into the java_binary.
java_binary(
...
jvm_flags = [
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"
],
)
Is it possible to achieve this from the command line without hard coding jvm_flags?
Try:
bazel run //:my-target -- --debug
One strategy is to run the build with --subcommands, which will tell bazel to print out all the commands it's running during the build. Then find the command line corresponding to the invocation of the java_binary you're interested in. Then you can copy/paste that command (including the cd part) and modify it to include the debug flags, and debug it as you would any other process.
Note also that java_binary outputs a wrapper script that includes a --debug[=<port>] flag, so that should be all that needs to be added to the command line.
Note also that --subcommands will only print the commands that are actually executed during the build, so a fully cached / fully incremental build will print nothing. You may need to do a clean, or delete some of the outputs of the action you're interested in so that bazel runs that command.
It looks like you can pass the --jvm_flag option as part of the program options after the --.
BUILD:
java_binary(
name = "extract",
main_class = "com.pkg.Main",
resources = glob(["src/main/resources/**/*"]),
)
CLI:
bazel run //:extract -- --jvm_flag="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=7942" -path %cd%\config.json
It seems that the --jvm_flag option needs to come immediately after the --, before the program options (-path in the example). This is with Bazel 3.7.0.

Different software binary being executed on Jenkins for the same path

I have installed gems binary at two places on my jenkins server, each is different version:
[myserver]$ /opt/chef/embedded/bin/gem --version
2.4.1
[myserver]$ /opt/chefdk/embedded/bin/gem --version
2.4.4
I am running a job on this jenkins server with following command : /opt/chefdk/embedded/bin/gem inabox
and I get an error saying :
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command inabox
However when i run the same command from the command line , it identifies the inabox option.
To debug , when I ran this command /opt/chefdk/embedded/bin/gem help commands from the console and command line the options available are different and the console output doesnt include "inabox" option.
To make sure that I use the correct binary , I have also exported the binary path : PATH=$PATH:/opt/chefdk/embedded/bin in the job , but that also doesnt solve any thing.
I suspect that for some reason , /opt/chef/embedded/bin/gem binary is getting executed instead of /opt/chefdk/embedded/bin/gem , but I am not sure how and how do I solve it. Any pointers?
EDIT1
Here is output of echo $PATH
Here is the output of the command when I run through Jenkins console : /opt/chefdk/embedded/bin/gem help commands
Here is the output of the command when I run through command line :
1) Restart Jenkins every time you make changes to environment variables
2) if jenkins is executing the code on a slave, you need to define the PATH in your Jenkins settings.
We identified that a GEM_PATH variable being injected into the Jenkins job was causing the gem command to not work as intended. To resolve the issue, we added the “unset GEM_PATH” line to the beginning of the shell portion of the Build steps. This allowed the gem command to again recognize the “inabox” option and successfully upload gems to the Ruby Gems server.

Run new ant target without killing previous target

I've got an ant target ant server that runs a Java application which logs to the console. I need to run a new ant target ant server-gui which also logs to the console. But when I run ant server the logging prevents me from running any new ant targets.
When I enter ^c (which is the only way I know of to get out of situations like that) it kills the Java application. I need both to run. What keystroke will get me out of that "input" mode and able to run new terminal commands?
UPDATE: I haven't found a direct solution to getting out of that mode I mentioned, but opening a new tab/window in terminal does the trick. I can run as many any commands as I'd like that way. Still looking for a good solution to get out the "input" mode, though!
UPDATE 2: #abcdef pointed out another post that has an even more elegant solution.
There are a few ways to do this, assuming you are on *nix
1) Run the ant command with a & at the end to tell *nix to run the command in the background
2) Run the command with nohup at the beginning (https://en.wikipedia.org/wiki/Nohup)
3) when the process is running press ctrl-z then enter the command bg. This manually forces the command to run in the background
I hope this helps you out

Resources