Xcode New "Run Script Phase" - How to handle output files? - swift

I want to add a Run Script Phase to my Build Phases to call a swift executable that takes a plist file from my project and uses it to generate a swift file with some boilerplate code.
I figured out how to specify the input file for the Run Script Phase like this:
$(SRCROOT)/MyProject/MyData.plist
But for output files, Xcode gives me this $(DERIVED_FILE_DIR)/newOutputFile default value which, if I echo it via echo "$SCRIPT_OUTPUT_FILE_0", prints some strange path to the ....MyProject.build/DerivedSources folder. What is that? What do I do with this and how can I generate my output swift file and place it inside my project?
I don't really find much information about this $(DERIVED_FILE_DIR) (at least nothing that I understand, I've never worked with these things before).
Thanks!

Presumably the derived file directory is just a safe place to write output results to. It isn't in the project directory, but it is unique to the project.
However, you do want to write directly into the project directory (I presume), so just go ahead and do so, using the environmental variable PROJECT_DIR.

Related

How to use class/function in another swift file which in same folder without Xcode

I write protocol and classes in G.swift, and write functions and tests in L.swift. These two files in same folder, and I need "import" G.someclass in L.swift.
I searched on internet and it said I do not need import command if two files in same directory. But I am not using Xcode to write these file. I just want write lite function, and run them like Python or Go.
Could it happen? Or I have to use Xcode to make "import" operation happen?
If you're not using xcode, I assume you're running them either via swift or swiftc. In either case, just list both files on the command line and they will be treated as the same module. Your L.swift file should have a main() function that runs the tests.

Change simulink rtwbuild output folder

I'm automating my build process, but I wasn't able to change the model_target_rtw folder to something different.
I'm not talking about CodegenFolder, but about the folder that's created inside it during compilation.
I'm currently working this around by renaming the folder after compilation, but it would be grate to remove that step.
The folder you are referring to is the RTW (Real Time Workshop) BuildDirectory.
You can get the value of BuildDirectory by running the command:
RTW.getBuildDir('MyModel')
See:
https://se.mathworks.com/matlabcentral/answers/274082-how-can-i-change-the-build-folder-of-a-model
Also look at this question:
Save generated code in a special folder in "rtwbuild"
If you run this command in MATLAB:
set_param(0, 'CodeGenFolder', 'C:\MyBuildDir')
and then run the RTW.getBuildDir command again you will see that the BuildDirectory has changed.

Is it possible to save settings and load resources when compiling to just one standalone exe?

If I compile a script for distribution as a standalone exe, is there any way I can store settings within the exe itself, to save having to write to an external file? The main incentive for this is to save having to develop an installation process. I only need to store a few bytes.
Also, can resources such as images be compiled into the exe?
Using alternate data streams opens up a can of worms so i wouldn't go that way. Writing back config data into the exe itself won't work as the file is locked for write access during execution.
What i usually do is to store config data under %A_AppData%\%A_ScriptName%\%A_ScriptName%.ini
When the script starts i use IniRead which also provides a default value if the key isn't found - which is the case the script is executing for the first time.
The complementing IniWrite's in a OnExit subroutine/function will create the ini file if necessary.
This way no installation is needed and the config is stored in the proper, familiar place.
The autohotkey forum has dealt with this question before.
In that case, the user didn't want extra files -- period.
The method was to use the file system to save alternate data.
Unfortunately I can't find the post.
A simpler method is to use fileinstall command.
When the script is compiled, the external file is stored within the exe.
When the script executes the same command as an exe, the file is copied to the same
directory as the running script. It is a simple yet effective 'install'.
With a little testing for the config file, the fileinstall command can be skipped.
Skipping the fileinstall could allow changes to be made to the configuration after 'installation'
I have not tried saving settings within the compiled exe file, but I have included resources. I'm not sure which version of AHK you're using or how you are compiling, but I can right-click my scripts to compile. There's an option to compile with options, where you can include resources in your compiled exe.Compile with options

Why can't I step into or set a breakpoint in my XCode source?

I have several source files (all in one Group) that seem to compile with the project, but I cannot step into them or set any breakpoints within.
These files are newer versions of the same files I had in my project. (I updated the code I am using from a 3rd party). After the update, these newer files seem to compile with the project, but somehow they don't seem to be the ones the linker is putting in my final object (its like its using the older files).
So I can do this:
1. forcibly create a syntax error in one of these file and the compiler complains
I cannot do this:
1. hit a breakpoint in any of these files
2. step into any code in these files from a breakpoint outside
3. add a NSLog statement and see the output
Its like the project file (or something else) has its hand on the old compiled files (hence the project compiles fine and runs) and won't replace with these files.
help!
Sometimes it happens that the new version gets put in some unexpected place and that you indeed have two versions of the file in your project without noticing.
Do a project wide search of some unique content in the old and new files. You should get both files displayed and you can delete the old one.
Are you running in release mode? Breakpoints and NSLog statements don't execute when you build and run in release mode.
Set your Active Build Configuration to Debug.

How to get the app path name from an Xcode project on the command line?

I'm writing a build script to compile and package my app, and I'd like a nice way to get the full path name of the .app created. I can't find any command line tools other than xcodebuild, which doesn't appear to have much in the way of inspecting an Xcode project. My full compile command is
xcodebuild -sdk iphoneos2.2.1
so it'll build with the default configuration, and I don't want to hard-code the .app filename in (although it'll be something like build/<config>iphoneos/<name>.app). Currently, I'm parsing the output from the xcodebuild command and grabbing the line
CodeSign (.*)
which works correctly, but seems like an awfully roundabout way of doing it. Is there another command line tool to do this, or at least an easier way than my solution?
Tough to say since the build location can be project/target specific or a global preference that's never explicitly set anywhere in the project file.
Never tried it, but maybe add a Run Script build phase to your project that simply prints the environment to stdout and parse that?