# Set up working environment ## Setup a Linux distro on your Windows Machine 1. Get admin rights from our department's PC rep (Yap Teng Hong thyap@globalpsa.com) 2. Install this Linux distribution: Ubuntu 18.04 LTS (or a version number that is higher). Follow the instructions on [this link](https://docs.microsoft.com/en-us/windows/wsl/install-win10) 3. Open your Ubuntu Bash shell, edit ```/etc/wgetrc``` by typing the command ```$ sudo vim /etc/wgetrc```. Then add the following line at the end of the file: ```check-certificate=off```. 4. Install an IDE. We use Visual Studio Code. We highly recommend you follow that. You can download it [here](https://code.visualstudio.com/download) Install the Windows version. After installing VS, add the extension WSL Remote to access VS from WSL terminal. 5. Makes VS code work with the newly installed Linux. Follow instructions in [this section](https://code.visualstudio.com/docs/cpp/config-wsl#_set-up-your-linux-environment) and [this section](https://code.visualstudio.com/docs/cpp/config-wsl#_run-vs-code-in-wsl) only 6. Download the necessary packages to compile code. In your Ubuntu Bash shell, run the follow commands: ``` $ sudo apt update $ sudo apt install g++ $ sudo apt install gdb $ sudo apt install cmake $ sudo apt-get install lcov $ sudo apt install clang-format $ sudo apt install python3-pip ``` 6. Downgrade compilers g++ and gcc. Do this only **after installing python3-pip** ``` $ sudo apt remove g++ g++-7 gcc gcc-7 $ sudo apt install gcc-4.8 g++-4.8 $ sudo ln /usr/bin/gcc-4.8 /usr/bin/gcc $ sudo ln /usr/bin/g++-4.8 /usr/bin/g++ ``` 7. Install conan. Do this only **after downgrading compilers** ``` $ sudo pip3 install conan --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org ``` ## Get the code for the project 1. Ensure that you have access to the code repository. Check with your manager 2. Remove SSL verification requirement ```$ git config --global http.sslverify false``` 3. Clone the code onto your desktop. (Google ```git clone``` if you are not sure). The repo address is found in [TFS](https://tfs.psa.com.sg/psasg) > your project (eg. GTOSP_OS_HTME) > Side-bar > Click "Repos" > Top right side of screen > Click "Clone" to copy the address ## Setting up the project for conan: Conan is a tool that helps "pull in" all the external libraries we are using. It is installed when you run one of the commands above ### Check conan is installed properly ``` $ pip3 list (To list all installed packages. Make sure conan is listed in the list) $ conan (run this to verify conan installed correctly) ``` - If fail, replace the content in ```/usr/local/bin/conan``` to the following file: ``` import re import sys from conans.conan import run if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(run()) ``` ### Setup ./CMakeList.txt for bins and libs to compile See this project's ```./CMakeList.txt``` for reference If your repo already has this file, skip this step. Else check with the project's lead. ### Setup ./conanfile.txt for dependencies required See this project's ```./conanfile.txt``` for reference If your repo already has this file, skip this step. Else check with the project's lead. ### Setup ./tfs/build_run_cover.sh for steps to be automatically done when conan is runned See this project's ```./conanfile.txt``` for reference If your repo already has this file, skip this step. Else check with the project's lead. ### Specify the PSA remotes Type the following commands in bash: ``` $ conan remote add gtospeng https://br.psa/artifactory/api/conan/gtosplus_conan_local False -f $ conan remote add tef https://br.psa/artifactory/api/conan/tef_conan_local False -f $ conan user -p 'Mn").Z7W' -r gtospeng tuaspublish $ conan user -p 'Mn").Z7W' -r tef tuaspublish ``` ### Remove the requirement to verify-ssl when reaching out to remote servers Edit the config file: ~/.conan/remotes.json ``` { "remotes": [ { "name": "conan-center", "verify_ssl": false, "url": "https://conan.bintray.com" }, { "name": "gtospeng", "verify_ssl": false, "url": "https://br.psa/artifactory/api/conan/gtosplus_conan_local" }, { "name": "tef", "verify_ssl": false, "url": "https://br.psa/artifactory/api/conan/tef_conan_local" } ] } ``` ### Essemble everything together! If your repo still doesn't have a ./build folder, ``` $ mkdir build ``` Next, go to ```./build/``` folder and run: ``` $ conan install .. ``` # Build and Test Run ```./tfs/build_run_cover.sh```. This will: - Find all the dependencies and download them - Compile the code - Run the automated tests and produce test coverage report To test individual binaries, run: ``` $ ./build/bin/<binary name> ``` Done! --- # Debugger set up 1. Follow the instructions provided in [this section](https://code.visualstudio.com/docs/cpp/config-wsl#_debug-helloworldcpp) When prompted to configure debugger's language, choose *C/C++* 2. Change the following setting on the json: ```"program": "..." // your test binary is likely in the project's ./build/bin/ folder. Its name likely ends in the *test``` 3. Remove the following setting on the json: ``` "preLaunchTask": "g++ build active file", "miDebuggerPath": "/usr/bin/gdb" ``` # Git set up ## Save credentials so you dont have to enter username password every time ```$ git config credential.helper store``` # Clang formatter set up: Clang formatter is a a tool that indents/space/prettify your code when triggered. It helps to standardise some code conventions for everyone in the team. It is installed when you run one of the commands above ## Check clang formatter is installed properly ```$ which clang-format``` Take note of the path, to be use in next step ## Install the VS code extension 1. Install "Clang-Format by xaver" 2. Go to VS code settings (```ctrl-shift-p```, type "setting", select the one that says "***json") 3. Add two new settings: ``` "clang-format.executable": "/usr/bin/clang-format" // executable path should be the path noted in $ which clang-format "editor.formatOnSave": true ``` 4. Save