Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
284 lines (167 sloc) 7 KB

Open multiple blocks

Working with your own blocks

In the :ref:`Getting Started guide <cpp_getting_started>` we built a program and reused the sum function. Now it's time to add new functionality to your published myuser/math block, like a subtract function, and use it in your block myuser/calc.

The layout is:

+-- mycalc
|    +-- blocks
|    |    +-- myuser
|    |    |    +-- calc
|    |    |    |    +-- main.cpp
|    +-- deps
|    |    +-- myuser
|    |    |    +-- math
|    |    |    |    +-- operations.cpp
|    |    |    |    +-- operations.h

Opening your block

Open the block myuser/math for editing on the same project, execute:

~/mycalc$ bii open myuser/math

bii open command retrieves the complete block to your blocks folder, and deletes it from your deps folder. In this case, it will open the specific version you depend on.

The resulting layout is:

+-- mycalc
|    +-- blocks
|    |    +-- myuser
|    |    |    +-- calc
|    |    |    |    +-- main.cpp
|    |    |    +-- math
|    |    |    |    +-- main.cpp
|    |    |    |    +-- operations.cpp
|    |    |    |    +-- operations.h
|    +-- deps

Now, add the new function, subtract and use it on your main.cpp


#pragma once
int sum(int a, int b);
int subtract(int a, int b);


#include "operations.h"
int sum(int a, int b) {return a+b;}
int subtract(int a, int b){return a-b;}


#include "google/gtest/gtest.h"
#include "operations.h"

TEST(Sum, Normal) {
 EXPECT_EQ(5, sum(2, 3));
TEST(Subtract, Normal) {
 EXPECT_EQ(-1, subtract(2, 3));
int main(int argc, char **argv) {
 testing::InitGoogleTest(&argc, argv);
 return RUN_ALL_TESTS();

Build, bii build and run your tests myuser_math_main to check everything is working.

Publishing updated code

Publish the math block again. As you now have 2 blocks opened (calc, math), specify the name of the block you want to publish:

~/mycalc$ bii publish myuser/math

By default, bii publish uses the DEV tag. Check on your online biicode profile it's been published.

Using DEV tag, the latest DEV version is overrided, so [parents] section of your biicode.conf remains unmodified:

   myuser/math: 0

Closing edited block

You can now close myuser/math block, it and it will return, with the code already updated, to your deps folder:

~/mycalc$ bii close myuser/math

Then you can modify the content of your myuser/calc:


#include <iostream>
#include "myuser/math/operations.h"

using namespace std;
int main() {
   cout<<"2 + 3 = "<< sum(2, 3)<<endl;
   cout<<"2 - 3 = "<< subtract(2,3)<<endl;

and build it, reusing also the new function:

~/mycalc$ bii build
~/mycalc$ bin\myuser_calc_main
2 + 3 = 5
2 - 3 = -1

Congrats! You just edited your dependencies and updated the changes. You know that we are available at biicode's forum for any problems. You can also write us for suggestions and feedback, they are always welcomed.

Working with any published block

To edit a published block, follow the steps below:

Open a block

Open a block locally to modify and publish a new version of a block.

~/$ bii init myproject
~/$ cd myproject
~/myproject$ bii open username/blockname:VERSION


Let's open lasote/json11 block (version=lastest by default) to edit it:

$ bii open lasote/json11

Then you can code on it as if it was yours and changes will be reflected in your code, at build time.

Suppose that you want to open version 1 instead of the latest lasote/json11 version, you should execute:

$ bii open lasote/json:1

Publish the changes

Once your changes build, publish your own version of the block.

If the block in edition isn't yours:

  • Rename lasote folder with your username.
  • Delete the [parents] section content in your biicode.conf file.
Remember to bii build before publishing!

And publish:

$ bii publish

Close the block

Then you can close the block to remove it from your blocks folder:

$ bii close user_name/block_name

If you're following the Example, execute:

$ bii close user_name/json11

Depend on the block you've just published

Now, if you want to depend on the block you've just published:

If you need more information about publish or close command:

Check our biicode's forum and/or StackOverflow tag for questions and answers. You can also write us for suggestions and feedback.

Got any doubts? Do not hesitate to contact us visit our forum and feel free to ask any questions.