yocto-第8篇-开发工具devtool实操(添加git项目learnyocto)

By: fulinux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎订阅!
你的喜欢就是我写作的动力!

返回总目录 Yocto开发讲解系列 - 总目录

推荐gitee网站

继上篇: yocto学习笔记 - 第7篇-开发工具devtool实操(helloyocto)
本篇在讲述新知识前,给大家推荐一个git服务网站https://gitee.com,类似github,但是github只能创建开源项目,而gitee不仅可以创建开源项目,而且可以创建私有项目。大家可以注册使用。另外推荐大家学习廖雪峰的 git教程

在gitee创建简单项目

在讲述devtool新知识前,我们现在gitee创建一个新项目,如下图:
在这里插入图片描述
点击创建后就会有这个项目:

https://gitee.com/fulinux/learnyocto
  • 1

git命令简单实用

在自己的ubuntu系统中下载下来:

~]$ cd code/ #记得吗?这个目录下面有个helloyocto项目
code]$ git clone https://gitee.com/fulinux/learnyocto
正克隆到 'learnyocto'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 0), reused 0 (delta 0), pack-reused 0
展开对象中: 100% (8/8), 完成.
检查连接... 完成。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
code]$ cd learnyocto/
learnyocto]$ git branch -a #查看分支
* master #当前在master分支
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop #开发分支
  remotes/origin/master
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

我们粗略可以这么认为develop用来日常的开发,代码测试和稳定后可以合并到master分支,由管理员维护master分支。这样我们先切换到develop分支进行开发:

learnyocto]$ git checkout develop 
分支 develop 设置为跟踪来自 origin 的远程分支 develop。
切换到一个新分支 'develop'
learnyocto]$ cp ../helloyocto/* . #将之前的项目拷贝一份过来,图省事
cp: 略过目录'../helloyocto/build'
cp: 略过目录'../helloyocto/oe-logs'
cp: 略过目录'../helloyocto/oe-workdir'
learnyocto]$ ls
CMakeLists.txt  LICENSE  main.c  README.en.md  README.md
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

修改项目

修改CMakeLists.txt和main.c文件:

learnyocto]$ vim CMakeLists.txt 
  • 1
project(learnyocto C)
cmake_minimum_required(VERSION 2.6.3)

add_executable (learnyocto main.c)

install(TARGETS learnyocto DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
learnyocto]$ vim main.c 
  • 1
#include <stdio.h>

int main (int argc, char **argv)
{
    printf ("[develop branch]Hello Yocto!\n");

    return 0;
} /* ----- End of main() ----- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

项目提交到gitee

learnyocto]$ git status
位于分支 develop
您的分支与上游分支 'origin/develop' 一致。
未跟踪的文件:
  (使用 "git add <文件>..." 以包含要提交的内容)

        CMakeLists.txt
        main.c

提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
learnyocto]$ git add CMakeLists.txt main.c
learnyocto]$ git commit -m "第一次代码"  #可惜了少了‘添加’两个字
learnyocto]$ git push origin develop 
Username for 'https://gitee.com': **** #输入你自己的用户名
Password for 'https://fulinux@gitee.com': 
对象计数中: 4, 完成.
Delta compression using up to 12 threads.
压缩对象中: 100% (4/4), 完成.
写入对象中: 100% (4/4), 599 bytes | 0 bytes/s, 完成.
Total 4 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/fulinux/learnyocto
   83f1936..351e99f  develop -> develop
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

在网页上就可以看到自己提交的内容了:
在这里插入图片描述

切换到master分支

learnyocto]$ git checkout master 
切换到分支 'master'
您的分支与上游分支 'origin/master' 一致。
  • 1
  • 2
  • 3

合并develop改动到master分支

learnyocto]$ git merge develop
更新 83f1936..351e99f
Fast-forward
 CMakeLists.txt | 6 ++++++
 main.c         | 8 ++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 CMakeLists.txt
 create mode 100644 main.c
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

修改main.c,用以后续区分不同分支项目:

 learnyocto]$ vim main.c #不会用vim的就用其他编辑器
  • 1
#include <stdio.h>

int main (int argc, char **argv)
{
    printf ("[master branch]Hello Yocto!\n");//change develop to master

    return 0;
} /* ----- End of main() ----- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

提交改动到gitee上

learnyocto]$ git add main.c
learnyocto]$ git commit -m "修改main.c"
learnyocto]$ git push origin master
  • 1
  • 2
  • 3

给项目打个tag

learnyocto]$ git tag -a v1.0 -m "add my 1.0 version"  #给自己的项目打个tag
learnyocto]$ git tag -l
v1.0
learnyocto]$ git push origin v1.0
  • 1
  • 2
  • 3
  • 4

将learnyocto添加到yocto上

默认情况下,devtool add从远程URI获取到的内容就是master分支中的最新版本。在某些情况下,您可能希望通过branch,tag或commit-id来指定版本。下面我们尝试使用develop分支的内容
参考上片中内容,将learnyocto添加到yocto中:

learnyocto]$ cd
~]$ cd poky/
poky]$ source oe-init-build-env
  • 1
  • 2
  • 3

要指定源分支,请使用–srcbranch选项:

build]$ devtool add --srcbranch develop learnyocto https://gitee.com/fulinux/learnyocto.git
NOTE: Starting bitbake server...
NOTE: Starting bitbake server...
INFO: Fetching git://gitee.com/fulinux/learnyocto.git;protocol=https;branch=develop...
Loading cache: 100% |########################################################################################################################################################| Time: 0:00:02
Loaded 1321 entries from dependency cache.
Parsing recipes: 100% |######################################################################################################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (779 cached, 3 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "x86_64-poky-linux"
MACHINE              = "qemux86-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "m64 core2"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       = "my-yocto-3.1.2:569b1f5d67c57de957e243997c53ec2f81dc8dfe"
meta-altera          = "master:aa24dfcb39fce3619a87ee6eef6e4296e66d2099"
meta-mylayer         
workspace            = "my-yocto-3.1.2:569b1f5d67c57de957e243997c53ec2f81dc8dfe"

Initialising tasks: 100% |###################################################################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete)
NOTE: No setscene tasks
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be rerun and all succeeded.
INFO: Using default source tree path /home/peeta/poky/build/workspace/sources/learnyocto
NOTE: Starting bitbake server...
INFO: Recipe /home/peeta/poky/build/workspace/recipes/learnyocto/learnyocto_git.bb has been automatically created; further editing may be required to make it fully functional
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

learnyocto的bb文件

build]$ cat workspace/recipes/learnyocto/learnyocto_git.bb
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "LGPLv3"
LIC_FILES_CHKSUM = "file://LICENSE;md5=e6a600fd5e1d9cbde2d983680233ad02"

SRC_URI = "git://gitee.com/fulinux/learnyocto.git;protocol=https;branch=develop"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "351e99f4d4f6045771a920a33ab178b55a8ff829"

S = "${WORKDIR}/git"

inherit cmake

# Specify any options you want to pass to cmake using EXTRA_OECMAKE:
EXTRA_OECMAKE = ""
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

learnyocto源码的位置

build]$ ls workspace/sources/learnyocto/
CMakeLists.txt  LICENSE  main.c  oe-logs  oe-workdir  README.en.md  README.md
build]$ cd workspace/sources/learnyocto/
learnyocto]$ git branch
  develop
* devtool #当前分支,会创建一个devtool分支,不过它是从develop分支切出来的
  master
learnyocto]$ git log
351e99f 第一次代码 (Peeta Chen, 51 分钟前)
83f1936 Initial commit (fulinux, 70 分钟前)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

编译learnyocto

build]$ devtool build learnyocto
  • 1

编译成功。

指定tag和commit-id的方法

本节是一个小知识点,用不上可以忽略。
要指定特定tag或commit hash值,请使用–srcrev选项,可以先记着下面的例子:

devtool add --srcrev v1.0 learnyocto https://gitee.com/fulinux/learnyocto.git
devtool add --srcrev [commit id] learnyocto https://gitee.com/fulinux/learnyocto.git
  • 1
  • 2

注意:如果您希望每次构建配方时都使用最新版本,请使用–autorev或-a选项。

下篇继续 learnyocto 项目更新~

谢谢阅读!希望帮我点个赞加关注,你的喜欢就是我持续更新的动力!