What are .swift.gyb files?

I'm reading the stdlib source code and I see .gyb files. What are those
files for?

Thanks.

I'm reading the stdlib source code and I see .gyb files. What are those files for?

gyb stands for Generate Your Boilerplate. It’s a preprocessor the Swift team wrote so that when they needed to build, say, ten nearly-identical variants of Int, they wouldn’t have to literally copy and paste the same code ten times. If you open one of those files, you’ll see that they’re mainly Swift code, but with some lines of code intermixed that are written in Python. The actual preprocessor itself is in the Swift source repository at utils/gyb, though most of the code is in utils/gyb.py.

···

--
Brent Royal-Gordon
Architechies

Ah thank you. I did notice some Python syntax in there. Very cool!

···

On Tuesday, December 8, 2015, Brent Royal-Gordon <brent@architechies.com> wrote:

> I'm reading the stdlib source code and I see .gyb files. What are those
files for?

gyb stands for Generate Your Boilerplate. It’s a preprocessor the Swift
team wrote so that when they needed to build, say, ten nearly-identical
variants of Int, they wouldn’t have to literally copy and paste the same
code ten times. If you open one of those files, you’ll see that they’re
mainly Swift code, but with some lines of code intermixed that are written
in Python. The actual preprocessor itself is in the Swift source repository
at utils/gyb, though most of the code is in utils/gyb.py.

--
Brent Royal-Gordon
Architechies

if I wanted to use that script to generate xctests, how do I feed it a
custom gyb file in? Is there a help file somewhere I can read? I know
this is not meant for that but it would be useful.

···

On Tuesday, December 8, 2015, Brent Royal-Gordon <brent@architechies.com> wrote:

> I'm reading the stdlib source code and I see .gyb files. What are those
files for?

gyb stands for Generate Your Boilerplate. It’s a preprocessor the Swift
team wrote so that when they needed to build, say, ten nearly-identical
variants of Int, they wouldn’t have to literally copy and paste the same
code ten times. If you open one of those files, you’ll see that they’re
mainly Swift code, but with some lines of code intermixed that are written
in Python. The actual preprocessor itself is in the Swift source repository
at utils/gyb, though most of the code is in utils/gyb.py.

--
Brent Royal-Gordon
Architechies

For example:

./utils/gyb -D CMAKE_SIZEOF_VOID_P=8
./stdlib/public/core/FloatingPoint.swift.gyb

Also try running `gyb --help`.

Dmitri

···

On Sat, Dec 26, 2015 at 1:59 AM, J. Cheyo Jimenez via swift-users < swift-users@swift.org> wrote:

if I wanted to use that script to generate xctests, how do I feed it a
custom gyb file in? Is there a help file somewhere I can read? I know
this is not meant for that but it would be useful.

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

ah, nice. Thank you!

···

On Sat, Dec 26, 2015 at 3:19 AM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Sat, Dec 26, 2015 at 1:59 AM, J. Cheyo Jimenez via swift-users < > swift-users@swift.org> wrote:

if I wanted to use that script to generate xctests, how do I feed it a
custom gyb file in? Is there a help file somewhere I can read? I know
this is not meant for that but it would be useful.

For example:

./utils/gyb -D CMAKE_SIZEOF_VOID_P=8
./stdlib/public/core/FloatingPoint.swift.gyb

Also try running `gyb --help`.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/