How to transform gyb files into swift code - ios

I'm reading the swift source code on github and I have noticed there are files with the extension gyb e.g. Swift github Integers.swift.gyb.
I did a bit of research and I think (correct me if i'm wrong) gyb is a preprocessor that the swift team wrote so that they dont have to write repetitive code e.g. dont have to write many different version of code for different int types, which only vary slight from each other.
But I dont really understand the python code in which the gyb files are written in. Is there any way that I can transform those gyb files into swift code? so it is possible study how swift e.g. Int type is implemented?

What you can do is:
Obtain the Swift source code, following the instructions at https://github.com/apple/swift.
Install the prerequisites for compiling the source code (cmake, ninja, ...)
Then compile the source code with the "verbose option":
cd swift-source/swift
utils/build-script --verbose
This shows all commands which are executed, including those to preprocess the .gyb
files. In particular you'll find something like
/usr/bin/python /path/to/swift-source/swift/utils/gyb -DunicodeGraphemeBreakPropertyFile=/path/to/swift-source/swift/utils/UnicodeData/GraphemeBreakProperty.txt -DunicodeGraphemeBreakTestFile=/path/to/swift-source/swift/utils/UnicodeData/GraphemeBreakTest.txt -DCMAKE_SIZEOF_VOID_P=8 -o /path/to/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/stdlib/public/core/8/Integers.swift.tmp Integers.swift.gyb && /opt/local/bin/cmake -E copy_if_different /path/to/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/stdlib/public/core/8/Integers.swift.tmp /path/to/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/stdlib/public/core/8/Integers.swift && /opt/local/bin/cmake -E remove /path/to/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/stdlib/public/core/8/Integers.swift.tmp
which shows that the Python script swift-source/swift/utils/gyb is called to
preprocess the Integers.swift.gyb file, and the result is copied to
/path/to/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/stdlib/public/core/8/Integers.swift
You can also call the script yourself, using the above commands as a template:
cd swift-source/swift/stdlib/public/core
/usr/bin/python /path/to/swift-source/swift/utils/gyb \\
-DunicodeGraphemeBreakPropertyFile=/path/to/swift-source/swift/utils/UnicodeData/GraphemeBreakProperty.txt \\
-DunicodeGraphemeBreakTestFile=/path/to/swift-source/swift/utils/UnicodeData/GraphemeBreakTest.txt \\
-DCMAKE_SIZEOF_VOID_P=8 \\
-o Integers.swift.tmp Integers.swift.gyb

Related

How bobril translation import/export works in bobril-build?

How bb translation works together?
When I used bb b -l 1 worked fine but there is still needed to rewrite all strings for other languages.
bb t -a adds new language, e.g. "cs-CZ" and creates json file with language code.
The question is how can I export/import all strings into json file to translation?
bb t -e - fileName is json or js in dist? Export doesn't work in my case no strings are exported.
bb t -e filename.txt -l cs-CZ is correct way to export untranslated strings to text file with very simple structure. After it will get back from translation agency you can just import it by bb t -i filename.txt -l cs-CS.
Before exporting always update translation files by bb b -l 1 -u 1 as you already find out. Actual JSON files in translations directory contains array of arrays of 3 or 4 items [original, hint, 0/1 - with/out parameters, translation]. So you can directly translate them if you will create some editor for these...
Also please update bobril-build to 0.56.1, I just fixed wrong error message in export even-though everything was ok. Maybe that confuse you so you have to ask, sorry for that.

How to get the path where the library is installed

I am working in Linux and I have a library written in Fortran 90 (written by 3rd party), that is reading from a file in the current working directory. I would like to be able to call the resulting library from other folders, hence I need to read the path where the library is installed. How can I know the path to the compiled library within the Fortran code?
I need to store in a variable the path within the code.
For who knows python, I want to achieve the same as
import os
os.path.dirname(os.path.abspath(__file__))
but in f90 (see Get location of the .py source file)
Using the suggestions in the comment I have done the following:
export DATAPATH=`pwd`
make
in the Makefile
ifort -O3 -fpic -fpp -DDATAPATH -c mysource.f90
in mysource.f90
subroutine mysub
character(len=100)::dpath
#ifdef DATAPATH
dpath=DATAPATH
#endif
open(10,file=trim(dpath)//'initialise.dat')
....
....
the problem is that at compile time I get
mysource.f90(42): error #6054: A CHARACTER data type is required in this context. [1]
dpath=1
----------^
compilation aborted for mysource.f90 (code 1)
If you wish you can fix the path at compile time. Something like
gfortran -cpp mylib.f90 -DPREFIX=\"/usr/local/\"
open(newunit=u,file=PREFIX//'mylib/initialise.dat')
You must than make sure the library is indeed installed in that place PREFIX/mylib/
You can create an environment variable containing the path of your data. This variable can be set by hand, in your .bashrc or .bash_profile or in the system /etc/profile.d/ or /etc/bash.bashrc, there are manyways and they depend if the library is just for one user or for all users of some large computer.
For example
export MYLIB_PATH='/usr/local/mylib'
Then you can read the variable in Fortran as
CALL get_environment_variable("MYLIB_PATH", mylib_path, status=stat)
and the path is now in variable mylib_path. You can check the success by checking if stat==0.
This is not the only possible approach. You can also have a configuration file for your library in your home directory:
mkdir $HOME/.config/mylib/
echo "/usr/local/mylib" > $HOME/.config/mylib/path
and then you can try to read the path from this file if the environment variable was not set
if (stat/=0) then
CALL get_environment_variable("HOME", home_dir)
open(newunit=path_unit, file=home_dir//'/.config/mylib/path',status='old',action='read',iostat=stat)
if (stat/=0) complain
read(path_unit,'(a)',iostat=stat) mylib_path
if (stat/=0) complain
end if
So when you compiled with -DDATAPATH you have not passed the variable DATAPATH into your code only declared a symbol called DATAPATH as being true, so ifort will substitute DATAPATH as 1. What you need to do is pass it as a value:
-DDATAPATH="$(DATAPATH)"
For the compilation to work.

GNU m4 macros auto generated file

I download latex package on which I want do some changes, but in this packege exist file include.m4 and I don't know what it does and how it was generated. Here its lines:
m4_changequote([[, ]])m4_dnl
m4_dnl
m4_define([[m4_FILE_INIT]], [[m4_dnl
%
% This is automaticaly generated file, do not edit it.
%
]])m4_dnl
m4_dnl
m4_define([[m4_FILE_ID]], [[m4_dnl
m4_patsubst([[$1]], [[\$Date::? \([0-9]+\)-\([0-9]+\)-\([0-9]+\).*]], [[\1/\2/\3]])m4_dnl
v[[]]m4_ESKDX_VERSION]])m4_dnl
m4_dnl
m4_define([[m4_FILE_DATE]], [[m4_dnl
m4_patsubst([[$1]], [[\$Date::? \([0-9]+\)-\([0-9]+\)-\([0-9]+\).*]], [[\1/\2/\3]])]])m4_dnl
m4_dnl
Can you explain with which tool it was generated?
Thk. So this file is not autogenerated? ANd can you help me understand these lines from Makefile:
M4FLAGS = -P -Dm4_ESKDX_INIT="m4_include($(TOP_DIR)/include.m4)" \
-Dm4_ESKDX_VERSION=$(VERSION) -Dm4_ESKDX_DATE=$(RELEASE_DATE)
And rule:
%.def: %.def.in $(M4DEPS)
m4 $(M4FLAGS) $< >$#
%.sty: %.sty.in $(M4DEPS)
m4 $(M4FLAGS) $< >$#
%.cls: %.cls.in $(M4DEPS)
m4 $(M4FLAGS) $< >$#
As I can see GNU m4 options '-D' substitutes macro m4_ESKDX_INIT in .sty .cls files to m4_include(../include.m4) and then options '-P' first expands file include.m4 and furthemore expands macros in include.m4.
This is a macro for the GNU m4 macro processor. This file is designed to be used with the -P or --prefix-builtins commandline option. The m4_ part will be stripped away when m4 evaluates this file. This file doesn't do anything itself, it just defines three macros (FILE_INIT, FILE_ID and FILE_DATE) which presumably will be used in another step. You might want to look in the other files for references to this one. The basic idea will be to load this file before running another file through m4 and it will replace those macros as it goes.
The message about automatically generated is supposed to end up in the final file as a comment. As we can see in the rules in the Makefile, each of the .def, .sty and .cls files are generated from an equivalently named .in file (so result.cls will be built from result.cls.in. by evaluating the macros in these files and replacing them with the equivalents.
So, to modify these files, you will want to edit the .in files.

Clang_complete not worrking

unfortunately I can't manage to make clang_complete work and I could need your help.
I've already compiled vim 7.4 with python support. Here is the output of vim --version | grep python:
+cryptv +linebreak +python/dyn +viminfo
-cscope +lispindent +python3/dyn +vreplace
I followed this guide: https://vtluug.org/wiki/Clang_Complete
Please note that I've started from a clean installation (i.e. no other plugins and no further entries in my .vimrc (except for those shown in the guide above)).
According to the tutorials I've seen so far everything should be working.
However, if I try to get code completion for the following example nothing happens. If I press <c-x><x-u> I receive the error "completefunc not set".
#include <string>
int main()
{
std::string s;
s.
}
Moreover, I've installed the newest version of clang from source and it in my $PATH.
Is there a way to verify that clang_complete is actually installed?
What might cause this problem?
Any help is much appreciated.
Add
filetype plugin indent on
to your vimrc, its missing from the vimrc snippet in the link. This tells vim to do filetype detection and fire autocommands related to those file types. Without it you won't run the following autocommands.
au FileType c,cpp,objc,objcpp call <SID>ClangCompleteInit()
au FileType c.*,cpp.*,objc.*,objcpp.* call <SID>ClangCompleteInit()
Which probably initalize ClangComplete.

How can I use cmake to compile .fx files

According to this MSDN blog entry it is recommended to compile .fx effect files with fxc as part of your build process. Given a list of fx files, how do I tell cmake to add some to my project files (VS2010)?
Use find_program to find fxc and add_custom_command to build:
find_program(FXC fxc DOC "fx compiler")
if(NOT FXC)
message(SEND_ERROR "Cannot find fxc.")
endif(NOT FXC)
add_custom_target(fx ALL)
foreach(FILE foo.fx bar.fx baz.fx)
get_filename_component(FILE_WE ${FILE} NAME_WE)
add_custom_command(OUTPUT ${FILE_WE}.obj
COMMAND ${FXC} /Fo ${FILE_WE}.obj ${FILE}
MAIN_DEPENDENCY ${FILE}
COMMENT "Effect-compile ${FILE}"
VERBATIM)
add_dependencies(fx ${FILE_WE}.obj)
endforeach(FILE)
Not being a Windows user, I'm not sure if that's exactly the right way to invoke fxc, but you can tinker with it. Note also that this doesn't link the object files into wherever they need to go. This mailing list post might help you.

Resources