05a24dd8becaa3706a462e5abc010f3844f8074c
[AGL/documentation.git] / docs / ATTIC / 3_Developer_Guides / 4_X(cross)_Development_System:_User's_Guide / 2_Create_your_first_AGL_application / 3.4.2.3_Build_Using_the_Command_Line.md
1 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/devguides/master/xds-docs-guides-devguides-book.yml -->
2
3 # Build Using the Command Line
4
5 One option for building your application using XDS is to use
6 the command line (i.e. `xds-cli`).
7 Building the application consists of declaring your project, identifying
8 some key ID values, and then using the command line to build it.
9
10 <!-- section-note -->
11 **NOTE:**
12
13 XDS tools, including `xds-cli`, are installed by default in
14 the `/opt/AGL/bin` directory.
15 During installation, this directory is automatically added to your
16 `PATH` variable.
17 If, for some reason, the tool is not in your `PATH` directory,
18 you can manually add it using the `export PATH=${PATH}:/opt/AGL/bin`
19 command.
20 <!-- end-section-note -->
21
22
23 ## Declare Project
24
25 Use the `projects add` command to declare your project:
26
27 ```bash
28 xds-cli prj add --label="Project_helloworld-native-application" --type=pm --path=/home/seb/xds-workspace/helloworld-native-application --server-path=/home/devel/xds-workspace/helloworld-native-application
29 ```
30
31 When you declare the project, XDS creates the `xds-project.conf`
32 configuration file if one does not already exist.
33 You should examine this configuration file before you build the
34 project to be sure all configurations are correct for your project.
35
36 <!-- section-note -->
37 **NOTE:**
38
39 If the Server Part (i.e. `xds-agent`) is not running on the default
40 port, you can use the `--url=http://localhost:<port>` option with the
41 `xds-cli prj add` command to specify the port.
42 Just substitute the actual port for `<port>` with the option.
43 <!-- end-section-note -->
44
45 ## Determine the ID of Your Project
46
47 After declaring your project, you need to determine the
48 unique ID of your project.
49
50 From the command line, use the `prj ls` command, which is an abbreviation
51 for the `projects list` command:
52
53 ```bash
54 xds-cli prj ls
55 ID                                       Label                                   LocalPath
56 f9904f70-d441-11e7-8c59-3c970e49ad9b     Project_helloworld-service              /home/seb/xds-workspace/helloworld-service
57 4021617e-ced0-11e7-acd2-3c970e49ad9b     Project_helloworld-native-application   /home/seb/xds-workspace/helloworld-native-application
58 ```
59
60 Once you have the ID of the project, you can use the `--id` option
61 or the `XDS_PROJECT_ID` environment variable to refer to your project.
62
63 <!-- section-note -->
64 **NOTE:**
65
66 When using the project ID from the command line, you can use the "short"
67 notation by providing a non-ambiguous portion of the ID.
68 For example, to refer to the `Project_helloworld-native-application` project
69 shown in the previous example, you can use `-id 40` rather than
70 `--id 40 instead of --id 4021617e-ced0-11e7-acd2-3c970e49ad9b`.
71 <!-- end-section-note -->
72
73 ## Determine the ID of Your SDK
74
75 You also need to determine the ID of the SDK you want to use to cross-build
76 your application.
77
78 To list installed SDKs, use the following command:
79
80 ```bash
81 xds-cli sdks ls
82 List of installed SDKs:
83   ID                                    NAME
84   7aa19224-b769-3463-98b1-4c029d721766  aarch64  (3.99.1+snapshot)
85   41a1efc4-8443-3fb0-afe5-8313e0c96efd  corei7-64  (3.99.2+snapshot)
86   c226821b-b5c0-386d-94fe-19f807946d03  aarch64  (3.99.3)
87 ```
88
89 SDK IDs are returned by architecture and version.
90 Be sure to identify the SDK you need.
91
92 ## Build the Application
93
94 You can now use XDS to cross-build your project.
95 Following is an example that builds a project that is based on CMake:
96
97 ```bash
98 # First, export the target IP address, or it's DNS name
99 export TARGET_ADDRESS=<target_adress>
100
101 # Go into your project directory and create a build directory
102 cd $MY_PROJECT_DIR
103 mkdir build
104 ```
105
106 Before using the command line to build the project, you should be
107 sure the project's configuration file is correct.
108 Examine the `xds-project.conf` configuration file and edit it
109 as needed.
110
111 Generate the build system using CMake:
112
113 ```
114 # You must set RSYNC_* variables so that you deploy and populate widgets on the target
115 xds-cli exec --id=4021617e --sdkid=c226821b -- "export RSYNC_TARGET=root@${TARGET_ADDRESS} ; export RSYNC_PREFIX=/opt ; cd build && cmake .."
116 ```
117
118 Now you can build the project:
119
120 ```
121 xds-cli exec --id=4021617e --sdkid=c226821b -- "cd build && make widget"
122 ```
123
124 <!-- section-note -->
125 **NOTE:**
126
127 If you use `&&`, `||` or `;` statements in the executed command line,
128 you need to double quote the command (e.g. `"cd build && make"`).
129 <!-- end-section-note -->
130
131 To avoid having to set the project ID, SDK ID, and URL for each
132 command line, you can define these settings as environment variables
133 using an environment file.
134 Use the `--config` option or source file before executing
135 the `xds-cli` command.
136
137 To specify your configuration file with the command line,
138 use the `--config` option.
139 For example, the equivalent of the previous build command but
140 with a specified configuration file is as follows:
141
142 ```bash
143 # MY_PROJECT_DIR=/home/seb/xds-workspace/helloworld-native-application
144 cd $MY_PROJECT_DIR
145
146 # Edit and potentially adapt xds-project.conf file that has been created
147 # automatically on project declaration using XDS Dashboard
148 cat xds-project.conf
149   # XDS project settings
150   export XDS_AGENT_URL=localhost:8800
151   export XDS_PROJECT_ID=4021617e-ced0-11e7-acd2-3c970e49ad9b
152   export XDS_SDK_ID=c226821b-b5c0-386d-94fe-19f807946d03
153
154 # Create build directory and invoke cmake and then build project
155 xds-cli exec --config=./xds-project.conf -- "mkdir -p build && cd build && cmake .."
156 cd build && xds-cli exec --config=../xds-project.conf -- "make all"
157 ```
158
159 Alternatively, you could first source the configuration file to avoid using the
160 `--config` option as follows:
161
162 ```
163 source xds-project.conf
164 xds-cli exec "mkdir -p build && cd build && cmake .."
165 cd build && xds-cli exec "make all"
166 ```
167
168 <!-- section-note -->
169 **NOTE:**
170
171 All parameters after a double dash (`--`) are considered as the command
172 to execute.
173 <!-- end-section-note -->