In the Getting Started guide 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
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
operations.h
#pragma once
int sum(int a, int b);
int subtract(int a, int b);
operations.cpp
#include "operations.h"
int sum(int a, int b) {return a+b;}
int subtract(int a, int b){return a-b;}
main.cpp
#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.
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:
[parent]
myuser/math: 0
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:
main.cpp
#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.
To edit a published block, follow the steps below:
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
Example
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
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.
And publish:
$ bii publish
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
Now, if you want to depend on the block you’ve just published:
- Update your #include (s) to the ones referring to your new published version
- If you didn’t publish it as STABLE, do it or update your policies.bii file to accept DEV versions.
- Execute bii find and you’re ready to build as usual. Here’s bii find command documentation.
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.