Show or log preprocessor macros during build - iphone

Is it possible to log or print preprocessor macros in XCode to the build results?
I want to see the current defined macros during a build.
For example if I have defined DEBUG and TESTSERVER as preprocessor macro there should be some lines in the build results like:
Compile Class.m ....
GenerateDSYMFile .....
Used macros: DEBUG, TESTSERVER...
Maybe there is custom shell script that could be executed after build.

OK I found the solution in the Apple documentation
Just enter a echo $GCC_PREPROCESSOR_DEFINITIONS to the run script build phase.

If you add a Run Script to the build phase and make sure "Show environment variables in build log" is checked it will print out all the environment variables for you. The run script can be empty and you will get a dump of all of the environment variables set for that current build. What you will not get is macros defined in header files.
To access the information once your project is built go to build results and expand the section "Run custom shell script " to view the values.
If you have set up Preprocessor definitions it will show on a line like this
setenv GCC_PREPROCESSOR_DEFINITIONS "DEBUG=1 Debug=1"

Related

Get CircleCI environment variables into Swift via Fastlane

I want to add some secrets to CircleCI environment variables so that its not hardcoded in my project for security and so that we can cycle them as needed too.
I know I can access the environment variables from Fastlane with ENV["SOME_ENVIRONMENT_VARIABLE_KEY"] and from what I understand I can pass that into build_app's xcargs parameter. This is supposedly then available in build phase in Xcode.
eg build_app(..., xcargs: "Testing='SUCCESS'")
I cannot seem to find much documentation on this but I did see in a couple questions that you should be able to add a step to Build Phases and then in the script you export an environment variable that can be used in code. I tried export TESTING=${Testing} and when I try access that in code it (with ProcessInfo.processInfo.environment["TESTING"]) it comes back as nil.
I was not convinced that my script was actually doing anything so hardcoded it in the build phase to export TESTING="SUCCESS" and even then ProcessInfo.processInfo.environment["TESTING"] comes back as nil, just to be sure I added a breakpoint and printed ProcessInfo.processInfo.environment.keys and the TESTING key is not present
I have tried running from Fastlane directly with both the hardcoded value in the build phase and the variable that should come back from Fastlane and, despited me having prints in the unit test and echos in the script, nothing prints (It does print ▸ Running script 'Set up environment variables from CircleCI' but not my debugging echos where I print a string just to see where I am and try print all the environment variables and doesn't print anything for the unit test)
Am I missing something very obvious here? Surely it shouldn't be this complicated?
Thanks in advance

VSCode Test Explorer Pytest Inject Environment Variables using AWS Parameter Store

I am currently Using Pytest though the Python Test Explorer (see screen). I would like to pass my tests some environment variables at runtime. However, I currently get my AWS Parameter Store BEFORE I run tests. Meaning, I run a command in BASH that loads my environment variables into my current terminal session. Then I can run my test from the command line using pytest exampletest.py, and it finds the environment variable perfectly.
Trying to run exampletest.py from the integrated VSCode Test Explorer results in an error telling me that it could not find my environment variable. This means that whatever environment that is used when you hit the "Play Button" on the Test Explorer is not the same terminal session that I set my environment variables in.
The conventional way of setting environment variables such that they can be accessed when using the Test Explorer in VSCode is by either using an ini file or a .env file. The only caveat there is that you must hardcode the key value pair. I would not like to hardcode anything, as I would just like to inject them in at runtime from aws Parameter Store.
I really would like to continue using the Test Explorer to run my tests, as it has been great in the past, but if I cannot find a way to somehow get the Test Explorer to use my environment variables without using an ini or a .env file, I may have to abandon it.
Some questions:
When you click the play button on the Test Explorer to execute a test or suite of tests, what exactly happens? Does it open a Terminal session? Can you access that terminal session before runtime?
How does the Test Explorer set environment variables. When I raise Exception(os.environ), I can see all the environment variables that are quite different from the ones that I get when I run from the command line.
Is there a way to say "Hey Test Explorer, please run the tests inside of this specified Terminal window that is already running"
Perhaps a virtual environment is a way to go (not really a question more of a thought). Doing some cursory research reveals more headaches to come if I pursue this route I believe.
Do you have any further reading about that VsCode Test Explorer that goes beyond the official documentation. I feel like I can make some changes to it's source code or something, but I feel like documentation on it is a bit lacking.
Let me know your thoughts on this matter, and thanks in advance.
I have the same question. The only way I could make it work was by this unwieldy series of steps before running the tests via the vscode UI:
Execute your script or command in a terminal to set the env
variables.
Copy those env variables into your .env file (placed at the root of your project/vscode-workspace). I usually do :
env | grep AWS_ or whatever you want and you'll see them as name-value pairs. I then copy and paste those entries at the bottom of the .env file each time I run the test via the UI.
Now execute your tests via the vscode UI (the test 'beaker'/flask). The testing UI/flask seems to execute the .env file every time before it runs the tests and hence picks up those env variables.
I know, it's not preferable - you would want it to just pick it up from the env values you see in your integrated terminal but so far that is not happening.

WARNING: No screenshots were found for '( locale )' when trying to -exportLocalizations

I have a set of XCUITests that step through a Swift-based application. In the test plan configuration, I've selected to create Localization screenshots for the Dutch language.
When I then try to export the localization from XCode 12.5, I am able to see Dutch as an option and the screenshots export as I would expect.
However, when I attempt to actually export them from the command line (which I need to do in order to embed them in automation), I get an error:
xcodebuild -exportLocalizations -project 'test/test-inhouse.xcodeproj' -localizationPath localizations_output -exportLanguage nl -includeScreenshots
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportLocalizations -project test/test-inhouse.xcodeproj -localizationPath localizations_output -exportLanguage nl -includeScreenshots
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
--- xcodebuild: WARNING: No screenshots were found for '(
nl
)'
It doesn't matter what spelling I use, or if I put in Dutch. The error is always similar, it can't find the screenshots. I even looked at the project.pbxproj to ensure I'm putting it in exactly as is in the array.
I'm trying to not introduce further dependencies to our CI process, and simply use the built-in XCodeBuild command. Any thoughts on why it can't find the screenshots? Do I have to also specify what device type was built to or something?
It turned out that I was using a project instead of a workspace reference.
From what I can tell, a project is only a single compilable set of code and targets.
Our UITest target is actually a separate compilable object, so when I exported localizations with screenshots for workspace instead of project, it worked.

How to activate "treat warning as error" for specific build definitions?

I would like to make my main branch TFS build definitions to treat warnings as errors so that the build fails when the projects are not error free. Since I do not want to activate "treat error as warning" in all project as a default, my first idea was to add a powershell script to my main build definition that substitues false with true in the line <TreatWarningsAsErrors>...</TreatWarningsAsErrors> in all csproj files it finds (something along the line of this). Is there any better/straighter way via some option as part of the build definition settings?
In the build definition specify /p:TreatWarningsAsErrors=True in the MSBuild argument field.
This will override any setting from the csproj files.
Unfortunately, there is no this kind of settings as part of the build definition.
However, you could be able to return warnings and errors from your powershell script using logging commands. With using task.logissue type=error you could fail the build task and then fail the build.
More details you could take a look at this similar question: Is it possible to raise and display build warnings from build steps using TFS 2015

Using multiple custom dictionaries using FxCop command line arguments

I had set up fxcop Custom Dictionaries for several projects in Visual Studio. However when it comes to running FxCop as part of our build process (using NAnt), we ran into trouble.
We currently have FxCop set up to run with the command line arguments /project:ProjectPath as well as /file:OutputPath/*.dll, and it seems to be respecting those arguments.
How can I tell FxCop to respect what I've set up in my .csproj files; through either the command line, or in a .fxcop project file?
Ideally, we don't want to have to change anything any time we add a new project or a new CustomDictionary.xml file. Hopefully, it would find all the custom dictionaries by itself.
The task that executes FxCopCmd in MSBuild actually fetches the codeanalysisdictionary.xml file location from the .csproj. So if you want to execute fxcop yourself, you'd either have to run it through MSBuild or duplicate the behavior into your nant task.