I am running into a bug that is resulting in an internal compile error, which occurs when I run unity in batch mode. This is important for our automated build system.
Here are the reproduction steps.
- Open an existing project in Unity.
- Close Unity.
- From the Apple Finder window, locate a code file that is part of the project that was just opened. Delete the code and corresponding meta file.
- Open up the console window on your Mac, so that you will be ready to view the Unity Editor output log.
- Open Unity from terminal, using a command that looks something like this: ./Unity -projectPath /depot/ProjectName/ -batchMode –quit
- Now view the console log, and you should see a compiler error that looks something like the following.
-----CompilerOutput:-stdout–exitcode: 1–compilationhadfailure: True–outfile: Temp/Assembly-CSharp.dll
Compilation failed: 1 error(s), 0 warnings
-----CompilerOutput:-stderr----------
error CS2001: Source file `Assets/ExampleFIle.cs’ could not be found
Where “ExampleFile.cs” is the file that has been removed from the project.
It appears that Unity thinks ExampleFile.cs still exists, and it starts compiling the code before it recognizes that this file is no longer a part of the project. I ran a diff on the Library folder before and after this file removal, and there were two files that differed: assetDatabase3, and guidMapper.
Consider how this works for an automated build system. Let’s say a programmer deletes a code file, submits his changes, and then kicks off a jenkins build. If that jenkins build then runs Unity from the command line, in batch mode, it will result in the error above, which means the build will fail.
There are two workarounds that I see: 1.) Delete all of the unversioned files, before doing the build, so that the Library folder gets regenerated. Or 2.) Run Unity twice. The first time it will update the assets, and the compilation will fail, and the second time the compilation will succeed. The second option is pretty hacky, and will make the build log output confusing. And the first option is very time consuming. Rebuilding the Library folder takes about 20 minutes for our project.
I would think the order of operations would be: Update and compile code → Import assets. But it seems like code is considered to be an “asset”, in this pipeline.