Go language: Change the build folder when running "go run" - go

Using Go on Windows, whenever I execute go run myprog.go from the console, Go builds a new executable with a random name somewhere on my C drive.
Is there a way to configure it so it will always build the file to a specific location, and preferably to also avoid the randomness of the name? (i.e., always build to D:\Temp\LastBuild.exe).
I was able to find some info that did not help when doing go help run and go help build. The latter had an output flag -o outfile but it is not accepted in go run.
Any help is appreciated.

Do not use go run. It's intended for quick testing out snippets of code the size of a single screenful of lines.
The working approach is
Edit the code.
go build it.
Run your executable which will have predictable name.
Go to step (1).
If you write tests in parallel with the implementation (and you should), this changes to
Edit the code.
Edit the test suite.
go test it.
Go to step (1).
Please see this recent thread on the mailing list for more insight on the same subject.

Related

go build command equivalent api

To compile a plugin in go I need to run the command below.
go build -buildmode=plugin
Is it possible to call some internal API instead of the command-line option to do this? I can always package the go binary and call os.exec("") but I want to avoid that if I can.
Since go is build with go, the go/internal (https://pkg.go.dev/std see internal) place is where you want to start looking. It is a rabbit hole but contains all the items like environment variables (GOOS), build config, go root, etc.
Other projects building some code for immediate usage (like skaffold) seem to have opted for os.Exec

How to add breakpoints to .feature files

As a developer
I want to put breakpoint(s) in feature files
So that I can debug a feature/scenario/step
Have any of you implemented this functionality with Behave or Cucumber?
You can not put breakpoints to .feature files, because it is a plain text files. Instead you can put breakpoints inside test-steps which implement your BDD steps.
Example
When I click button "save"
Then saved page opened
You need to go inside that step and see something like that:
public void iClickButton(String buttonName) {
getButtonByName(buttonName).click();
}
You can put breakpoint inside method iClickButton and debug it.
That is how you can debug execution in BDD style.
I can't say I've ever been able to put breakpoints in feature files. Instead, I put them inside the step files so when that step runs, you can verify it did its job. It's a lot of switching back and forth between feature and step files, but it works
I just want to point out that in 2018 feature files are used by a lot more than Behave or Cucumber [i.e. Codeception for PHP]. "Gherkin" is supposed to be a business readable DSL and the concept of a "breakpoint" really doesn't apply in that domain. I'd say it's definitionally impossible to put a break point in a Gherkin feature file. You could certainly do that if you want, go for it, but there isn't a standard way of doing it, and it's possible you'd be confusing things in a large organization or team.
First of all you need to add debug in step definition not in feature file
Now, You are running it by maven command like:
mvn clean install
But you need to run it using junit or testng.
Put an debug point in your step defination and run the project as junit/testng in debug section
OR
If you still need to run it using maven you can try below parameter in maven command
-Dmaven.surefire.debug test -DforkCount=0 test

How to Debug Following Fortran Program

I am trying to compile the following software so that I can step through and debug it. I am only a novice programmer and I am trying to understand how this whole makefile business works with Fortran. I know that there is a ton of literature on makefiles but I just need to insert a simple debug flag and I think if someone provided me with the answer to this question that would be the best way for me to learn.
So the program I am trying to compile, TINKER, is actually made up of several packages, located at http://dasher.wustl.edu/tinkerwiki/index.php/Main_Page. I would like to compile and debug JUST ONE specific executable, "analyze". I contacted the developer and received the following reply but I am still stuck...
Since TINKER has lots of small source code files, what we do is
compile each of the small files to an object file using the "-c" flag.
Then we put all of these object code files (ie, the ".o" files) into
an object library. Finally, we link each of the TINKER top level
programs, such as "analyze", against the object library. There is a
Makefile supplied with TINKER that does this. We also supply
individual scripts called "compile.make", "library.make" and
"link.make" for various CPU/compiler combinations that can be run in
order to perform the steps I describe above. To build a "debuggable"
executable, you just need to include the appropriate debug flags
(usually "-g") as part of the compile and link stages.
I am currently running OSX 10.6.8. If someone could show me which folders I cd into, what commands I enter that would be so great!
Thanks!
My follow up question (once I can figure out how to answer the above via command line will concern how to import the same procedure but using the Photran IDE - http://wiki.eclipse.org/PTP/photran/documentation/photran5#Starting_a_Project_with_a_Hand-Written_Makefile)
The directions are at http://dasher.wustl.edu/tinkerwiki/index.php/Main_Page#Installing_TINKER_on_your_Computer
Maybe out of date? g77 is obsolete -- it would be better to use gfortran.
The key steps: "The first step in building TINKER using the script files is to run the appropriate compile.make script for your operating system and compiler version. Next you must use a library.make script to create an archive of object code modules. Finally, run a link.make script to produce the complete set of TINKER executables. The executables can be renamed and moved to wherever you like by editing and running the ‘‘rename’’ script."
So cd to the directory for the Mac -- based on "we also provide machine-specific directories with three separate shell scripts to compile the source, build an object library, and link binary executables." Then run the command scripts. Probably ./compile.make. Look around for the directories ... you can probably figure it out from the names. Or search for the file "compile.make".
Or find someone local to you who knows more about programming.

Xcode build phase

Hey, I'm implementing MD5 checksum on my app(for preventing binary crack). I created a command line tool that will generate the hash for the binary and will add it to the .app folder. However, I didn't figure out how to add it as a build phase. I've read Apple's documentation with no luck. Could anyone explain me how to do that step by step?
Thanks!
To do any kind of post-processing, use a Run Script build phase (add such a phase to your target). Use the list of environment variables Xcode provides (you can see them when the phase runs by expanding the script's results in the build results window) to locate the binary. From there you know where its Resources file is. The rest is standard Unix command-line stuff (run the command line and put the file into the target folder).
Now for advice you didn't ask for: It's trivial to re-hash the modified binary and replace yours with the new one in the resources folder. Anyone experienced enough to crack binaries would likely just disable the call to your "verify the MD5 against a file" code anyway, eliminating the need to replace the saved hash altogether. Long story short: You're wasting your time with this approach. :-)

Automatically compile any Java class when the file is dropped in a directory

I look at a lot of small Java programs. It would be convenient if I could set up a directory (or directory structure) on my Mac where any time I add a .java file, javac automatically runs and attempts to compile that file. I've briefly looked into Automator actions, but found nothing that fits the bill. Then I got to thinking: on my PC, I would use the .Net FileSystemWatcher class and write the code myself. But before I try that on my Mac with Mono, I want to ask the community for other ideas. Any advice is appreciated. Thanks.
In JDK6 you can programmatically compile, so you could write your own program to do this, which may be slightly better than doing it in mono.
So you would just have a program that is always running, it looks for either any new files or a file that has been changed since the last check and then just compiles them, and you may want it to pass information to a dashboard window when there are errors, and perhaps some status info so you know it is working.
http://binkley.blogspot.com/2005/09/programmatically-compiling-java-in-jdk.html
If you have all the .java files available at the start, you could write a shell script to compile them all in one run -- in different directories if you need to.
If you explained why you would want this, maybe I/we could be more helpful.

Resources