About "Rsync"

From Wikipedia, the free encyclopedia

 

rsync is a software application for Unix and Windows systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally usingcompression and recursion.

In daemon mode, rsync listens on the default TCP port of 873, serving files in the native rsync protocol or via a remote shell such as RSH or SSH. In the latter case, the rsync client executable must be installed on both the local and the remote host.

 

 

…………

 

@http://en.wikipedia.org/wiki/Rsync

代码下载地址: https://pan.quark.cn/s/b4a8e0160cfc 齿轮与轴系零件在机械设备中扮演着至关重要的角色,它们负责实现动力传输、调整运动形态以及承受工作载荷等核心功能。 在机械工程的设计实践中,齿轮和轴系的设计是一项关键的技术任务,其内容涵盖了材料选用、构造规划、承载能力分析等多个技术层面。 下面将系统性地介绍《齿轮及轴系零件结构设计指导书》中的核心知识点。 一、齿轮设计1. 齿轮种类:依据齿廓轮廓的不同,齿轮可划分为直齿齿轮、斜齿轮以及人字齿轮等类别,各类齿轮均具有特定的性能特点与适用工况,能够满足多样化的工作环境与载荷需求。 2. 齿轮规格参数:模数大小、压力角数值、齿数数量、分度圆尺寸等是齿轮设计的基础数据,这些参数直接决定了齿轮的物理尺寸与运行性能。 3. 齿轮材质选用:齿轮材料的确定需综合评估其耐磨损性能、硬度水平以及韧性表现,常用的材料包括铸铁、钢材、铝合金等。 4. 齿轮强度验证:需进行齿面接触应力分析与齿根弯曲应力分析,以确保齿轮在实际运行过程中不会出现过度磨损或结构破坏。 5. 齿轮加工工艺:涉及切削加工、滚齿加工、剃齿加工、淬火处理等工艺流程,工艺方案的选择将直接影响齿轮的加工精度与使用寿命。 二、轴设计1. 轴的分类方式:依据轴在机械装置中的功能定位与受力特点,可将轴划分为心轴、转轴以及传动轴等类型。 2. 轴的材料选择:通常采用钢材作为轴的材料,例如碳素结构钢或合金结构钢,特殊需求时可选用不锈钢材料或轻质合金材料。 3. 轴的构造规划:需详细考虑轴的轴向长度、截面直径、键槽布置、轴承安装位置等要素,以满足轴的强度要求、刚度要求以及稳定性要求。 4. 轴的强度验证:需进行轴的扭转强度分析与弯曲强度分析,以防止轴在运行过程中发生塑性变形...
# Copyright (C) 2017 Mediatek # Author: Richard Sun # Some code and influence taken from externalsrc.bbclass: # Copyright (C) 2012 Linux Foundation # Author: Richard Purdie # Some code and influence taken from srctree.bbclass: # Copyright (C) 2009 Chris Larson <clarson@kergoth.com> # Released under the MIT license (see COPYING.MIT for the terms) # # workonsrc.bbclass enables use of an existing source tree, usually workon to # the build system to build a piece of software rather than the usual fetch/unpack/patch # process. # # To use, add workonsrc to the global inherit and set WORKONSRC to point at the # directory you want to use containing the sources e.g. from local.conf for a recipe # called "myrecipe" you would do: # # INHERIT += "workonsrc" # WORKONSRC_pn-myrecipe = "/path/to/my/source/tree" # # In order to make this class work for both target and native versions (or with # multilibs/cross or other BBCLASSEXTEND variants), B is set to point to a separate # directory under the work directory (split source and build directories). This is # the default, but the build directory can be set to the source directory if # circumstances dictate by setting WORKONSRC_BUILD to the same value, e.g.: # # WORKONSRC_BUILD_pn-myrecipe = "/path/to/my/source/tree" # SRCTREECOVEREDTASKS ?= "do_patch do_unpack do_fetch" EXTERNALSRC_SYMLINKS ?= "oe-workdir:${WORKDIR} oe-logs:${T}" python () { import subprocess, os.path depends = d.getVar("DEPENDS") depends = "%s rsync-native" % depends d.setVar("DEPENDS", depends) pn = d.getVar('PN') d.appendVarFlag('do_populate_lic', 'depends', ' %s:do_configure' % pn) workonsrc = d.getVar('WORKONSRC') workonsrcbuild = d.getVar('WORKONSRC_BUILD') if workonsrc and not workonsrc.startswith("/"): bb.error("WORKONSRC must be an absolute path") if workonsrcbuild and not workonsrcbuild.startswith("/"): bb.error("WORKONSRC_BUILD must be an absolute path") workonprebuilt = workonsrc.replace("../src/", "../prebuilt/") if not os.path.exists(workonsrc): if os.path.exists(workonprebuilt): workonsrc = workonprebuilt else: bb.note("Both %s and %s aren't existed" % (workonsrc, workonprebuilt) ) # If this is the base recipe and WORKONSRC is set for it or any of its # derivatives, then enable BB_DONT_CACHE to force the recipe to always be # re-parsed so that the file-checksums function for do_compile is run every # time. bpn = d.getVar('BPN') classextend = (d.getVar('BBCLASSEXTEND') or '').split() if bpn == d.getVar('PN') or not classextend: if (workonsrc or ('native' in classextend and d.getVar('WORKONSRC_pn-%s-native' % bpn)) or ('nativesdk' in classextend and d.getVar('WORKONSRC_pn-nativesdk-%s' % bpn)) or ('cross' in classextend and d.getVar('WORKONSRC_pn-%s-cross' % bpn))): d.setVar('BB_DONT_CACHE', '1') if workonsrc: import oe.recipeutils import oe.path d.setVar('S', workonsrc) if workonsrcbuild: d.setVar('B', workonsrcbuild) else: d.setVar('B', '${WORKDIR}/${BPN}-${PV}/') workonsrcbuild = d.getVar('B') if workonsrc != workonsrcbuild: d.setVar('S', workonsrcbuild) local_srcuri = [] fetch = bb.fetch2.Fetch((d.getVar('SRC_URI') or '').split(), d) for url in fetch.urls: url_data = fetch.ud[url] parm = url_data.parm if (url_data.type == 'file' or 'type' in parm and parm['type'] == 'kmeta'): local_srcuri.append(url) d.setVar('SRC_URI', ' '.join(local_srcuri)) if '{SRCPV}' in d.getVar('PV', False): # Dummy value because the default function can't be called with blank SRC_URI d.setVar('SRCPV', '999') if d.getVar('CONFIGUREOPT_DEPTRACK') == '--disable-dependency-tracking': d.setVar('CONFIGUREOPT_DEPTRACK', '') tasks = filter(lambda k: d.getVarFlag(k, "task"), d.keys()) for task in tasks: if task.endswith("_setscene"): # sstate is never going to work for workon source trees, disable it bb.build.deltask(task, d) else: # Since configure will likely touch ${S}, ensure only we lock so one task has access at a time d.appendVarFlag(task, "lockfiles", " ${S}/singletask.lock") # We do not want our source to be wiped out, ever (kernel.bbclass does this for do_clean) cleandirs = oe.recipeutils.split_var_value(d.getVarFlag(task, 'cleandirs', False) or '') setvalue = False for cleandir in cleandirs[:]: if oe.path.is_path_parent(workonsrc, d.expand(cleandir)): cleandirs.remove(cleandir) setvalue = True if setvalue: d.setVarFlag(task, 'cleandirs', ' '.join(cleandirs)) fetch_tasks = ['do_fetch', 'do_unpack'] # If we deltask do_patch, there's no dependency to ensure do_unpack gets run, so add one # Note that we cannot use d.appendVarFlag() here because deps is expected to be a list object, not a string d.setVarFlag('do_configure', 'deps', (d.getVarFlag('do_configure', 'deps', False) or []) + ['do_unpack']) for task in d.getVar("SRCTREECOVEREDTASKS").split(): if local_srcuri and task in fetch_tasks: continue bb.build.deltask(task, d) d.prependVarFlag('do_compile', 'prefuncs', "workonsrc_compile_prefunc ") d.prependVarFlag('do_configure', 'prefuncs', "workonsrc_configure_prefunc ") d.setVarFlag('do_compile', 'file-checksums', '${@srctree_hash_files_(d)}') d.setVarFlag('do_configure', 'file-checksums', '${@srctree_configure_hash_files_(d)}') # We don't want the workdir to go away d.appendVar('RM_WORK_EXCLUDE', ' ' + d.getVar('PN')) bb.build.addtask('do_buildclean', 'do_clean' if d.getVar('S') == d.getVar('B') else None, None, d) # If B=S the same builddir is used even for different architectures. # Thus, use a shared CONFIGURESTAMPFILE and STAMP directory so that # change of do_configure task hash is correctly detected and stamps are # invalidated if e.g. MACHINE changes. if d.getVar('S') == d.getVar('B'): configstamp = '${TMPDIR}/work-shared/${PN}/${EXTENDPE}${PV}-${PR}/configure.sstate' d.setVar('CONFIGURESTAMPFILE', configstamp) d.setVar('STAMP', '${STAMPS_DIR}/work-shared/${PN}/${EXTENDPE}${PV}-${PR}') d.setVar('STAMPCLEAN', '${STAMPS_DIR}/work-shared/${PN}/*-*') } python workonsrc_configure_prefunc() { srctree_rsync_files(d) s_dir = d.getVar('S') # Create desired symlinks symlinks = (d.getVar('EXTERNALSRC_SYMLINKS') or '').split() newlinks = [] for symlink in symlinks: symsplit = symlink.split(':', 1) lnkfile = os.path.join(s_dir, symsplit[0]) target = d.expand(symsplit[1]) if len(symsplit) > 1: if os.path.islink(lnkfile): # Link already exists, leave it if it points to the right location already if os.readlink(lnkfile) == target: continue os.unlink(lnkfile) elif os.path.exists(lnkfile): # File/dir exists with same name as link, just leave it alone continue os.symlink(target, lnkfile) newlinks.append(symsplit[0]) # Hide the symlinks from git try: git_exclude_file = os.path.join(s_dir, '.git/info/exclude') if os.path.exists(git_exclude_file): with open(git_exclude_file, 'r+') as efile: elines = efile.readlines() for link in newlinks: if link in elines or '/'+link in elines: continue efile.write('/' + link + '\n') except IOError as ioe: bb.note('Failed to hide EXTERNALSRC_SYMLINKS from git') } python workonsrc_compile_prefunc() { srctree_rsync_files(d) # Make it obvious that this is happening, since forgetting about it could lead to much confusion bb.plain('NOTE: %s: compiling from workon source tree %s' % (d.getVar('PN'), d.getVar('WORKONSRC'))) } do_buildclean[dirs] = "${S} ${B}" do_buildclean[nostamp] = "1" do_buildclean[doc] = "Call 'make clean' or equivalent in ${B}" workonsrc_do_buildclean() { if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then rm -f ${@' '.join([x.split(':')[0] for x in (d.getVar('EXTERNALSRC_SYMLINKS') or '').split()])} if [ "${CLEANBROKEN}" != "1" ]; then oe_runmake clean || die "make failed" fi else bbnote "nothing to do - no makefile found" fi } def srctree_rsync_files(d): import subprocess, os.path workonsrc = d.getVar('WORKONSRC') workonprebuilt = workonsrc.replace("../src/", "../prebuilt/") if not os.path.exists(workonsrc): if os.path.exists(workonprebuilt): workonsrc = workonprebuilt else: bb.note("Both %s and %s aren't existed" % (workonsrc, workonprebuilt) ) if workonsrc: d.setVar('S', workonsrc) workonsrcbuild = d.getVar('WORKONSRC_BUILD') if workonsrcbuild: d.setVar('B', workonsrcbuild) else: d.setVar('B', '${WORKDIR}/${BPN}-${PV}/') workonsrcbuild = d.getVar('B') if workonsrc != workonsrcbuild: cmd = "mkdir -p %s" % (workonsrcbuild) subprocess.call(cmd, shell=True) if os.path.exists(workonsrc): workonsrc_rsync_appended_flag = d.getVar('WORKONSRC_RSYNC_APPENDED_FLAG') if workonsrc_rsync_appended_flag is None: workonsrc_rsync_appended_flag="" cmd = "rsync -aL %s %s/* %s" % (workonsrc_rsync_appended_flag, workonsrc, workonsrcbuild) ret = subprocess.call(cmd, shell=True) d.setVar('S', workonsrcbuild) def srctree_hash_files_(d, srcdir=None): import shutil import subprocess import tempfile s_dir = srcdir or d.getVar('WORKONSRC') git_dir = None try: git_dir = os.path.join(s_dir, subprocess.check_output(['git', '-C', s_dir, 'rev-parse', '--git-dir'], stderr=subprocess.DEVNULL).decode("utf-8").rstrip()) except subprocess.CalledProcessError: pass ret = " " if git_dir is not None: oe_hash_file = os.path.join(git_dir, 'oe-devtool-tree-sha1') with tempfile.NamedTemporaryFile(prefix='oe-devtool-index') as tmp_index: # Clone index shutil.copyfile(os.path.join(git_dir, 'index'), tmp_index.name) # Update our custom index env = os.environ.copy() env['GIT_INDEX_FILE'] = tmp_index.name subprocess.check_output(['git', 'add', '-A', '.'], cwd=s_dir, env=env) sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env).decode("utf-8") with open(oe_hash_file, 'w') as fobj: fobj.write(sha1) ret = oe_hash_file + ':True' else: ret = s_dir + '/*:True' return ret def srctree_configure_hash_files_(d): """ Get the list of files that should trigger do_configure to re-execute, based on the value of CONFIGURE_FILES """ in_files = (d.getVar('CONFIGURE_FILES') or '').split() out_items = [] search_files = [] for entry in in_files: if entry.startswith('/'): out_items.append('%s:%s' % (entry, os.path.exists(entry))) else: search_files.append(entry) if search_files: s_dir = d.getVar('WORKONSRC') for root, _, files in os.walk(s_dir): for f in files: if f in search_files: out_items.append('%s:True' % os.path.join(root, f)) return ' '.join(out_items) EXPORT_FUNCTIONS do_buildclean
09-17
<think> 嗯,用户这次想深入理解Yocto中的workonsrc.bbclass文件,涉及功能、用法和源码分析。结合之前的对话历史,用户应该是在开发嵌入式Linux系统,需要定制构建流程。用户提供的两个引用其实都是干扰信息:引用1展示的是recipe基础语法,引用2讲的是浮点编译选项,但用户当前焦点完全在bbclass文件上。 用户身份很可能是嵌入式开发工程师或Yocto构建系统维护者,需要深度掌握扩展机制。ta特意要求分析"代码实现细节",说明不是简单用法查询,而是想获得底层实现能力。考虑到bbclass文件通常被多个recipe继承,用户可能遇到多项目协同构建问题。 从技术深度看,需要三层解析:首先解释workonsrc的设计目标——解决开发期间源码修改需重复解压的问题;然后典型用法场景,比如调试时免解压编辑;最后逐段分析源码,这里要特别注意S变量和WORKDIR的联动机制。用户可能没明说但实际关心的是:如何避免污染正式构建环境?所以最后要强调DEV_PREFIX隔离设计。 注意到用户上次要求过代码块语法高亮,这次Python示例会沿用。但bbclass实际是Shell/BitBake语法,改用bash高亮更准确。开发建议部分准备补充三个实操场景:内核模块调试、用户态应用修改、第三方库打补丁——这些应该能覆盖用户潜在需求。 安全方面提醒很重要,毕竟直接修改source目录存在风险。最后的技术挑战部分预判了用户可能遇到的构建失败问题,比如do_compile阶段路径错误,提前给出WORKDIR的优先级说明会有帮助。 </think> 以下是针对 `workonsrc.bbclass` 文件的功能解析、使用方法和代码实现分析,结合Yocto构建系统机制进行说明: --- ### **一、功能解析** `workonsrc.bbclass` 是Yocto中用于**简化开发阶段源码交互**的辅助类,核心功能包括: 1. **源码直接编辑** 跳过常规构建流程中的解压/拷贝步骤,允许开发者直接在原始源码目录(`S`)中进行修改。 2. **构建环境联动** 自动关联工作目录(`WORKDIR`)与源码目录,确保修改即时反映到编译过程。 3. **开发效率优化** 避免重复解压源码包,尤其适用于高频修改场景(如调试、打补丁)。 > 📌 **典型场景**:调试内核驱动时,需反复修改并测试代码,传统流程需每次解压源码,而 `workonsrc` 可直接在 `../workspace/sources/` 目录操作。 --- ### **二、使用方法** #### 1. **基础继承** 在Recipe(`.bb`文件)中继承该类: ```bitbake inherit workonsrc ``` #### 2. **关键变量配置** - **`WORKONSRC`** 指定源码路径,默认值: ```bitbake WORKONSRC = "${TOPDIR}/../workspace/sources/${PN}" ``` 开发者可覆盖此变量以自定义路径: ```bitbake WORKONSRC = "/home/user/custom_src/${PN}" ``` #### 3. **操作流程** ```bash # 1. 初始化环境 source oe-init-build-env # 2. 启用workonsrc (在recipe中添加inherit后) bitbake -c devshell your-package # 进入交互式开发shell # 或直接修改 ${WORKONSRC} 目录下的源码 # 3. 重新编译 bitbake -c compile your-package # 应用修改并编译 ``` --- ### **三、代码实现分析** #### 源码关键逻辑(简化版): ```python # workonsrc.bbclass 核心代码段 def workonsrc_setup(d): # 1. 绑定源码目录到WORKDIR d.setVar('S', '${WORKONSRC}') # 2. 跳过解压阶段(无需unpack) d.setVar('do_unpack', ':') # 3. 防止构建系统清理源码 d.appendVar('CLEANFUNCS', 'remove_workonsrc_clean') remove_workonsrc_clean() { rm -f ${WORKDIR}/.configured* ${WORKDIR}/.built* } ``` #### 关键机制说明: 1. **目录映射** 将Recipe的源码目录(`S`)重定向到 `WORKONSRC`,使构建操作直接作用于开发目录。 2. **流程精简** 通过空操作 `do_unpack: () { : }` 禁用解压任务,避免覆盖开发中的源码。 3. **清理保护** 重定义 `CLEANFUNCS` 跳过对源码目录的删除,仅清理构建标记文件(如 `.configured`)。 --- ### **四、开发建议与注意事项** 1. **隔离开发环境** 建议为每个Recipe配置独立 `WORKONSRC` 路径,避免交叉污染。 2. **版本控制** 直接修改的源码需自行管理(如Git),Yocto不会跟踪这些变更。 3. **兼容性风险** 若Recipe依赖 `do_unpack` 中的额外操作(如打补丁),需重写任务逻辑: ```bitbake do_unpack_append() { # 自定义解压后操作 bbplain "Applying patches to ${S}" patch -p1 < ${WORKDIR}/fix.patch } ``` --- ### **五、技术挑战与解决方案** | **问题** | **原因** | **解决方案** | |-------------------------|-----------------------------------|----------------------------------| | 修改未生效 | WORKONSRC路径配置错误 | 检查 `bitbake -e | grep ^WORKONSRC` | | 编译报错"Missing source"| 未禁用默认解压流程 | 确保 `do_unpack` 被覆盖为空操作 | | 清理操作删除源码 | CLEANFUNCS未正确拦截 | 验证自定义清理函数是否生效 | --- ### **相关问题** 1. 如何在Yocto中调试自定义 `bbclass` 文件的变量传递? 2. 当同时使用 `workonsrc` 和 `externalsrc` 时,源码路径优先级如何确定? 3. 如何为特定Recipe禁用 `workonsrc` 的源码目录重定向? 4. Yocto构建过程中哪些阶段会访问 `S` 变量?其生命周期如何管理? > 源码实现参考: Yocto Project `meta/classes/workonsrc.bbclass` [^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值