Running script before building on Unity - build

Is there a way to run a script method automatically before I build via File > Build Settings... > Build?
I know I can make a menu item to call my method and call build afterwards.

You can Use IPreprocessBuildWithReport interface in Unity 5.6+

AFAIK, Unity API doesn't offer any pre-processing/pre-building capabilities connected to the build command from the menu.
But on the other hand, you can make an editor script that does all the process from building your DLLs, importing them and then building your app. Take a look at the BuildPipeline to achieve this purpose.
This way you can write your own pipeline. But you will need to call this from an editor script though, not from the menu as you asked for in your question.

Related

UE4 Can I load .umap into packaged standalone?

I need to load on start .umap files created after packaging standalone version of my app. The problem is that .umap need to be cooked (even when I uncheck Pak flag). How can I solve that?
What I want to accomplish is that to build standalone app. Let designers to create some .umap level files in Unreal Editor. And finally to be able to start my app with new .umap level.
I see 2 possible ways:
Find some plugin or tool which can separately cook .umap file and add it to packaged project. Does such a plugin exists?
Build standalone project without cooking (I don't need to redistribute the project, it's tool for internal use). Is it possible?
Any thoughts?
You should take a look at UAssetManager class, which could be used for loading UE4 assets at runtime. However, I can't promise you it will load entire map for you, i've never used this mechanism at my own.

Adding empty platform configuration to MSBuild

As part of a test process, I'm trying to create an empty MSBuild Platform Target for MVS 2010 whose only job is to call a batch file when I click "build". I want to completely ignore the build and link process of the c++ files, just call a batch file (perhaps with the post-build events?).
So far I've duplicated the Win32 platform at \MSBuild\Microsoft.Cpp\v4.0\Platforms and named it "TestPlatform", and started hacking away at it and managed to disable the build step, but it, quite reasonably, fails during the link step when it cant find my SampleProject.o file that the build file did not generate.
I've ordered the book "Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build" book by Hashimi and Bartholomew, but while it gets here I would appreciate if anyone has any words of wisdom on the subject. Specifically:
1 - How do I bypass the link step.
2 - How do I add a custom step to call a DoSomething.bat file instead
Thank you for your help :)
For my particular case, I found that adding a copy of the C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32 platform (C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\TestPlatform) and adding the TestPlatform to my project configuration was enough to bring out the TestPlatform tab in the Configuration Manager dropdown menu.
To make it not compile or link anything but still run postbuild events the easiest way is to select in project properties:
Configuration Properties / General / Configuration Type : Utility
This seems to bypass all building steps but does call the postbuild events, where I simply put a call to a batch file.
It's not exactly what you are proposing, but a different way of achieving some of the same results is found here: run a custom msbuild target from VisualStudio
That shows how to wire up a command in the IDE to call a custom target in your project. So you could wire up an IDE command to call your RunThisBatchFile target in the current project.
Alternatively, you could override the rogue targets with a condition, something like:
<Target Name="Link" Condition="'$(Platform)' == 'TestPlatform'">
...
You may need to find a bunch of these and I'm not sure if it is 100% possible to get around the InitialTargets that may be defined for a C++ project file.
This is all covered in "MSBuild Trickery"

Run a script in eclipse before build

Simply put:
In eclipse how do I run a shell/batch script when I build? I have an external tool that can be run by hand but I want to trigger it when the project is built. Using build variables in the script would be an added bonus.
Why I want this:
I work on multi-platform games for mobile. The teams in the company I'm at use X-Code, Visual Studio, and Eclipse (Momentics) for our games. We want to be able to pick up a phone and see overlay on-top of it with information such as who built it, when it was built, what branch and revision it's from, and what library versions are being used. I've done this with X-Code by running a script on build that dumps some of that information to the resource directory of my game that I can then parse at runtime. It's really simple and I'm up for alternate suggestions if you have them; keeping in mind it must work for the three IDE's our developers use.
Bonus Sugar:
In X-Code we can use build variables which would be super nice to have for eclipse as well. I use them to change to the active cocos2d-x repository and get a git log to tell us when the last commit to that repository was made and by who. If that isn't possible in eclipse I can figure something out.
Thanks in advance!
Add a custom builder to your project: open Project properties from the popup menu, on the builders page add a new Program. That will open a "External tool configuration" page.
There you can define a script to run, and also add parameters, where you can add Eclipse variables, such as ${workspace}, etc.
Be careful though: this will run every time when the incremental project builder runs, and the configuration is shared through version control (so beware of absolute paths).

run tests automatically after sources changed

I use Cxxtest for unit-testing my C++ code. I would like that each time I change and save my code, tests are run (simply, by make tests). I know that for Python there is Nosy that enables that. Is there some generic program that would allow this for Cxxtest or any other testing unit?
Simply, I just need running a single command of files` change. It wouldn't be difficult to write script like that, but maybe there is some tool already : )
On Linux you can use a filesystem monitoring daemon like incron to run a command (e.g. make tests) every time a file is changed in a directory (a so-called IN_CLOSE_WRITE event).
You could use TeamCity for this. It can monitor your code repository and run automated builds + unit tests when changes are detected.. Includes a decent web style interface and emailing capability to notify of build/test failures..
It can also be configured for both windows and linux builds..
http://www.jetbrains.com/teamcity/
If thats a bit heavyweight for you, then you should be able to configure your build process to run the tests for you (e.g. edit your makefile on linux), but obviously this would still mean you manually kicking off a build when you make changes (which I guess you'd probably do anyway)..
Annoyed that there is no ready and simple solution, i just created a simple tool: changerun to run commands when files' change. I hope someone will find it useful : )

How to incorporate this script into build process using VC++

I'm using VC++ and want to write a script that can scan my source-code and at some places where it sees a text like "abc" then extract characters of that text and generate a selective piece of code like ones below at build time:
first example of a piece of code :
Func1(a);
Func2(b);
Func3(c);
second example of a piece of code:
{'a','b','c'}
I want to incorporate the script into build process as somebody has told me it is possible but don't know how, please tell how.
In the project properties of Visual Studio, you will have the option "Pre-Build Event" and "Post-Build Event".
At these configurations you can input programs that should be executed before and after your build. You can use project variables to identify your solution folder, project folder, binary, etc. If you are using a recent version of Visual Studio, there is a button below the text box that give you access to those variables.
Make sure that whatever you call at this configuration would be executed from the shell environment (cmd), otherwise you will receive a build error. Scripts will probably required that you input a call to the interpreter and pass the file as a parameter.
For example, let's say I need to run a Python script before I build my code. I would configure the Pre-Build Event as:
c:\python\python myscript.py
One good advice is to use DOS Batch files (.bat) to wrap around whatever you need to run and add those to your build events. There are plenty of tutorials over the net on how to create bat files, and they are fairly simple.