diff options
| author | Tom Zanussi <tom.zanussi@intel.com> | 2012-12-12 22:56:40 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-12-13 16:54:34 +0000 |
| commit | 76b2ef26e7ee23cbf05051c3978a37f0ee4062b9 (patch) | |
| tree | 7e5308a9e4cee6dd7c4dad7c53c9fb064dee75ca /scripts/lib/bsp/kernel.py | |
| parent | 8a1d25cdce6dd7e3f03587382127676f95dadf30 (diff) | |
| download | poky-76b2ef26e7ee23cbf05051c3978a37f0ee4062b9.tar.gz | |
yocto-bsp: remove patch-related SRC_URI processing
We no longer have to include patches in the SRC_URI, since things now
work using only patch in the .scc file, so remove anything to do with
maintaining patches in the SRC_URI and fix up all previous users of
that code.
(From meta-yocto rev: 8f3cd1f80f898d963797bc96b3fe599f7f8ea343)
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/bsp/kernel.py')
| -rw-r--r-- | scripts/lib/bsp/kernel.py | 227 |
1 files changed, 34 insertions, 193 deletions
diff --git a/scripts/lib/bsp/kernel.py b/scripts/lib/bsp/kernel.py index d2e4f403d6..883beac00c 100644 --- a/scripts/lib/bsp/kernel.py +++ b/scripts/lib/bsp/kernel.py | |||
| @@ -199,18 +199,6 @@ def yocto_kernel_config_list(scripts_path, machine): | |||
| 199 | print gen_choices_str(config_items) | 199 | print gen_choices_str(config_items) |
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | def map_choice(choice_str, array): | ||
| 203 | """ | ||
| 204 | Match the text of a choice with a list of choices, returning the | ||
| 205 | index of the match, or -1 if not found. | ||
| 206 | """ | ||
| 207 | for i, item in enumerate(array): | ||
| 208 | if choice_str == array[i]: | ||
| 209 | return i | ||
| 210 | |||
| 211 | return -1 | ||
| 212 | |||
| 213 | |||
| 214 | def yocto_kernel_config_rm(scripts_path, machine): | 202 | def yocto_kernel_config_rm(scripts_path, machine): |
| 215 | """ | 203 | """ |
| 216 | Display the list of config items (CONFIG_XXX) in a machine's | 204 | Display the list of config items (CONFIG_XXX) in a machine's |
| @@ -293,109 +281,24 @@ def find_current_kernel(bsp_layer, machine): | |||
| 293 | return preferred_kernel | 281 | return preferred_kernel |
| 294 | 282 | ||
| 295 | 283 | ||
| 296 | def find_bsp_kernel_src_uri(scripts_path, machine, start_end_only = False): | 284 | def find_filesdir(scripts_path, machine): |
| 297 | """ | 285 | """ |
| 298 | Parse the SRC_URI append in the kernel .bb or .bbappend, returing | 286 | Find the name of the 'files' dir associated with the machine |
| 299 | a list of individual components, and the start/end positions of | 287 | (could be in files/, linux-yocto-custom/, etc). Returns the name |
| 300 | the SRC_URI statement, so it can be regenerated in the same | 288 | of the files dir if found, None otherwise. |
| 301 | position. If start_end_only is True, don't return the list of | ||
| 302 | elements, only the start and end positions. | ||
| 303 | |||
| 304 | Returns (SRC_URI start line, SRC_URI end_line, list of split | ||
| 305 | SRC_URI items). | ||
| 306 | |||
| 307 | If no SRC_URI, start line = -1. | ||
| 308 | |||
| 309 | NOTE: this and all the src_uri functions are temporary and | ||
| 310 | deprecated and will be removed, but are needed until the | ||
| 311 | equivalent .scc mechanism works. i.e. for now we unfortunately | ||
| 312 | can't get around putting patches in the SRC_URI. | ||
| 313 | """ | 289 | """ |
| 314 | layer = find_bsp_layer(scripts_path, machine) | 290 | layer = find_bsp_layer(scripts_path, machine) |
| 291 | filesdir = None | ||
| 292 | linuxdir = os.path.join(layer, "recipes-kernel/linux") | ||
| 293 | linuxdir_list = os.listdir(linuxdir) | ||
| 294 | for fileobj in linuxdir_list: | ||
| 295 | fileobj_path = os.path.join(linuxdir, fileobj) | ||
| 296 | if os.path.isdir(fileobj_path): | ||
| 297 | # this could be files/ or linux-yocto-custom/, we have no way of distinguishing | ||
| 298 | # so we take the first (and normally only) dir we find as the 'filesdir' | ||
| 299 | filesdir = fileobj_path | ||
| 315 | 300 | ||
| 316 | kernel = find_current_kernel(layer, machine) | 301 | return filesdir |
| 317 | if not kernel: | ||
| 318 | print "Couldn't determine the kernel for this BSP, exiting." | ||
| 319 | sys.exit(1) | ||
| 320 | |||
| 321 | kernel_bbfile = os.path.join(layer, "recipes-kernel/linux/" + kernel + ".bbappend") | ||
| 322 | try: | ||
| 323 | f = open(kernel_bbfile, "r") | ||
| 324 | except IOError: | ||
| 325 | kernel_bbfile = os.path.join(layer, "recipes-kernel/linux/" + kernel + ".bb") | ||
| 326 | try: | ||
| 327 | f = open(kernel_bbfile, "r") | ||
| 328 | except IOError: | ||
| 329 | print "Couldn't find a .bb or .bbappend file for this BSP's kernel, exiting." | ||
| 330 | sys.exit(1) | ||
| 331 | |||
| 332 | src_uri_line = "" | ||
| 333 | in_src_uri = False | ||
| 334 | lines = f.readlines() | ||
| 335 | first_line = last_line = -1 | ||
| 336 | quote_start = quote_end = -1 | ||
| 337 | for n, line in enumerate(lines): | ||
| 338 | line = line.strip() | ||
| 339 | if line.startswith("SRC_URI"): | ||
| 340 | first_line = n | ||
| 341 | in_src_uri = True | ||
| 342 | if in_src_uri: | ||
| 343 | src_uri_line += line | ||
| 344 | if quote_start == -1: | ||
| 345 | idx = line.find("\"") | ||
| 346 | if idx != -1: | ||
| 347 | quote_start = idx + 1 | ||
| 348 | idx = line.find("\"", quote_start) | ||
| 349 | quote_start = 0 # set to 0 for all but first line | ||
| 350 | if idx != -1: | ||
| 351 | quote_end = idx | ||
| 352 | last_line = n | ||
| 353 | break | ||
| 354 | |||
| 355 | if first_line == -1: # no SRC_URI, which is fine too | ||
| 356 | return (-1, -1, None) | ||
| 357 | if quote_start == -1: | ||
| 358 | print "Bad kernel SRC_URI (missing opening quote), exiting." | ||
| 359 | sys.exit(1) | ||
| 360 | if quote_end == -1: | ||
| 361 | print "Bad SRC_URI (missing closing quote), exiting." | ||
| 362 | sys.exit(1) | ||
| 363 | if start_end_only: | ||
| 364 | return (first_line, last_line, None) | ||
| 365 | |||
| 366 | idx = src_uri_line.find("\"") | ||
| 367 | src_uri_line = src_uri_line[idx + 1:] | ||
| 368 | idx = src_uri_line.find("\"") | ||
| 369 | src_uri_line = src_uri_line[:idx] | ||
| 370 | |||
| 371 | src_uri = src_uri_line.split() | ||
| 372 | for i, item in enumerate(src_uri): | ||
| 373 | idx = item.find("\\") | ||
| 374 | if idx != -1: | ||
| 375 | src_uri[i] = item[idx + 1:] | ||
| 376 | |||
| 377 | if not src_uri[len(src_uri) - 1]: | ||
| 378 | src_uri.pop() | ||
| 379 | |||
| 380 | for i, item in enumerate(src_uri): | ||
| 381 | idx = item.find(SRC_URI_FILE) | ||
| 382 | if idx == -1: | ||
| 383 | print "Bad SRC_URI (invalid item, %s), exiting." % item | ||
| 384 | sys.exit(1) | ||
| 385 | src_uri[i] = item[idx + len(SRC_URI_FILE):] | ||
| 386 | |||
| 387 | return (first_line, last_line, src_uri) | ||
| 388 | |||
| 389 | |||
| 390 | def find_patches(src_uri): | ||
| 391 | """ | ||
| 392 | Filter out the top-level patches from the SRC_URI. | ||
| 393 | """ | ||
| 394 | patches = [] | ||
| 395 | for item in src_uri: | ||
| 396 | if item.endswith(".patch") and "/" not in item: | ||
| 397 | patches.append(item) | ||
| 398 | return patches | ||
| 399 | 302 | ||
| 400 | 303 | ||
| 401 | def read_patch_items(scripts_path, machine): | 304 | def read_patch_items(scripts_path, machine): |
| @@ -426,10 +329,7 @@ def write_patch_items(scripts_path, machine, patch_items): | |||
| 426 | """ | 329 | """ |
| 427 | f = open_user_file(scripts_path, machine, "user-patches.scc", "w") | 330 | f = open_user_file(scripts_path, machine, "user-patches.scc", "w") |
| 428 | for item in patch_items: | 331 | for item in patch_items: |
| 429 | pass | 332 | f.write("patch " + item + "\n") |
| 430 | # this currently breaks do_patch, but is really what we want | ||
| 431 | # once this works, we can remove all the src_uri stuff | ||
| 432 | # f.write("patch " + item + "\n") | ||
| 433 | f.close() | 333 | f.close() |
| 434 | 334 | ||
| 435 | kernel_contents_changed(scripts_path, machine) | 335 | kernel_contents_changed(scripts_path, machine) |
| @@ -440,8 +340,7 @@ def yocto_kernel_patch_list(scripts_path, machine): | |||
| 440 | Display the list of patches in a machine's user-defined patch list | 340 | Display the list of patches in a machine's user-defined patch list |
| 441 | [user-patches.scc]. | 341 | [user-patches.scc]. |
| 442 | """ | 342 | """ |
| 443 | (start_line, end_line, src_uri) = find_bsp_kernel_src_uri(scripts_path, machine) | 343 | patches = read_patch_items(scripts_path, machine) |
| 444 | patches = find_patches(src_uri) | ||
| 445 | 344 | ||
| 446 | print "The current set of machine-specific patches for %s is:" % machine | 345 | print "The current set of machine-specific patches for %s is:" % machine |
| 447 | print gen_choices_str(patches) | 346 | print gen_choices_str(patches) |
| @@ -452,8 +351,7 @@ def yocto_kernel_patch_rm(scripts_path, machine): | |||
| 452 | Remove one or more patches from a machine's user-defined patch | 351 | Remove one or more patches from a machine's user-defined patch |
| 453 | list [user-patches.scc]. | 352 | list [user-patches.scc]. |
| 454 | """ | 353 | """ |
| 455 | (start_line, end_line, src_uri) = find_bsp_kernel_src_uri(scripts_path, machine) | 354 | patches = read_patch_items(scripts_path, machine) |
| 456 | patches = find_patches(src_uri) | ||
| 457 | 355 | ||
| 458 | print "Specify the patches to remove:" | 356 | print "Specify the patches to remove:" |
| 459 | input = raw_input(gen_choices_str(patches)) | 357 | input = raw_input(gen_choices_str(patches)) |
| @@ -462,8 +360,10 @@ def yocto_kernel_patch_rm(scripts_path, machine): | |||
| 462 | 360 | ||
| 463 | removed = [] | 361 | removed = [] |
| 464 | 362 | ||
| 465 | layer = find_bsp_layer(scripts_path, machine) | 363 | filesdir = find_filesdir(scripts_path, machine) |
| 466 | src_uri_dir = os.path.join(layer, "recipes-kernel/linux/files") | 364 | if not filesdir: |
| 365 | print "Couldn't rm patch(es) since we couldn't find a 'files' dir" | ||
| 366 | sys.exit(1) | ||
| 467 | 367 | ||
| 468 | for choice in reversed(rm_choices): | 368 | for choice in reversed(rm_choices): |
| 469 | try: | 369 | try: |
| @@ -474,14 +374,13 @@ def yocto_kernel_patch_rm(scripts_path, machine): | |||
| 474 | if idx < 0 or idx >= len(patches): | 374 | if idx < 0 or idx >= len(patches): |
| 475 | print "Invalid choice (%d), exiting" % (idx + 1) | 375 | print "Invalid choice (%d), exiting" % (idx + 1) |
| 476 | sys.exit(1) | 376 | sys.exit(1) |
| 477 | src_uri_patch = os.path.join(src_uri_dir, patches[idx]) | 377 | filesdir_patch = os.path.join(filesdir, patches[idx]) |
| 478 | if os.path.isfile(src_uri_patch): | 378 | if os.path.isfile(filesdir_patch): |
| 479 | os.remove(src_uri_patch) | 379 | os.remove(filesdir_patch) |
| 480 | idx = map_choice(patches[idx], src_uri) | 380 | removed.append(patches[idx]) |
| 481 | removed.append(src_uri.pop(idx)) | 381 | patches.pop(idx) |
| 482 | 382 | ||
| 483 | write_patch_items(scripts_path, machine, patches) | 383 | write_patch_items(scripts_path, machine, patches) |
| 484 | write_kernel_src_uri(scripts_path, machine, src_uri) | ||
| 485 | 384 | ||
| 486 | print "Removed patches:" | 385 | print "Removed patches:" |
| 487 | for r in removed: | 386 | for r in removed: |
| @@ -493,16 +392,17 @@ def yocto_kernel_patch_add(scripts_path, machine, patches): | |||
| 493 | Add one or more patches to a machine's user-defined patch list | 392 | Add one or more patches to a machine's user-defined patch list |
| 494 | [user-patches.scc]. | 393 | [user-patches.scc]. |
| 495 | """ | 394 | """ |
| 496 | (start_line, end_line, src_uri) = find_bsp_kernel_src_uri(scripts_path, machine) | 395 | existing_patches = read_patch_items(scripts_path, machine) |
| 497 | src_uri_patches = find_patches(src_uri) | ||
| 498 | 396 | ||
| 499 | for patch in patches: | 397 | for patch in patches: |
| 500 | if os.path.basename(patch) in src_uri_patches: | 398 | if os.path.basename(patch) in existing_patches: |
| 501 | print "Couldn't add patch (%s) since it's already been added" % os.path.basename(patch) | 399 | print "Couldn't add patch (%s) since it's already been added" % os.path.basename(patch) |
| 502 | sys.exit(1) | 400 | sys.exit(1) |
| 503 | 401 | ||
| 504 | layer = find_bsp_layer(scripts_path, machine) | 402 | filesdir = find_filesdir(scripts_path, machine) |
| 505 | src_uri_dir = os.path.join(layer, "recipes-kernel/linux/files") | 403 | if not filesdir: |
| 404 | print "Couldn't add patch (%s) since we couldn't find a 'files' dir to add it to" % os.path.basename(patch) | ||
| 405 | sys.exit(1) | ||
| 506 | 406 | ||
| 507 | new_patches = [] | 407 | new_patches = [] |
| 508 | 408 | ||
| @@ -511,33 +411,19 @@ def yocto_kernel_patch_add(scripts_path, machine, patches): | |||
| 511 | print "Couldn't find patch (%s), exiting" % patch | 411 | print "Couldn't find patch (%s), exiting" % patch |
| 512 | sys.exit(1) | 412 | sys.exit(1) |
| 513 | basename = os.path.basename(patch) | 413 | basename = os.path.basename(patch) |
| 514 | src_uri_patch = os.path.join(src_uri_dir, basename) | 414 | filesdir_patch = os.path.join(filesdir, basename) |
| 515 | shutil.copyfile(patch, src_uri_patch) | 415 | shutil.copyfile(patch, filesdir_patch) |
| 516 | new_patches.append(basename) | 416 | new_patches.append(basename) |
| 517 | 417 | ||
| 518 | cur_items = read_patch_items(scripts_path, machine) | 418 | cur_items = read_patch_items(scripts_path, machine) |
| 519 | cur_items.extend(new_patches) | 419 | cur_items.extend(new_patches) |
| 520 | write_patch_items(scripts_path, machine, cur_items) | 420 | write_patch_items(scripts_path, machine, cur_items) |
| 521 | 421 | ||
| 522 | (unused, unused, src_uri) = find_bsp_kernel_src_uri(scripts_path, machine) | ||
| 523 | src_uri.extend(new_patches) | ||
| 524 | write_kernel_src_uri(scripts_path, machine, src_uri) | ||
| 525 | |||
| 526 | print "Added patches:" | 422 | print "Added patches:" |
| 527 | for n in new_patches: | 423 | for n in new_patches: |
| 528 | print "\t%s" % n | 424 | print "\t%s" % n |
| 529 | 425 | ||
| 530 | 426 | ||
| 531 | def write_uri_lines(ofile, src_uri): | ||
| 532 | """ | ||
| 533 | Write URI elements to output file ofile. | ||
| 534 | """ | ||
| 535 | ofile.write("SRC_URI += \" \\\n") | ||
| 536 | for item in src_uri: | ||
| 537 | ofile.write("\t%s%s \\\n" % (SRC_URI_FILE, item)) | ||
| 538 | ofile.write("\t\"\n") | ||
| 539 | |||
| 540 | |||
| 541 | def inc_pr(line): | 427 | def inc_pr(line): |
| 542 | """ | 428 | """ |
| 543 | Add 1 to the PR value in the given bbappend PR line. For the PR | 429 | Add 1 to the PR value in the given bbappend PR line. For the PR |
| @@ -588,51 +474,6 @@ def kernel_contents_changed(scripts_path, machine): | |||
| 588 | ifile.close() | 474 | ifile.close() |
| 589 | 475 | ||
| 590 | 476 | ||
| 591 | def write_kernel_src_uri(scripts_path, machine, src_uri): | ||
| 592 | """ | ||
| 593 | Write (replace) the SRC_URI append for a machine from a list | ||
| 594 | SRC_URI elements. | ||
| 595 | """ | ||
| 596 | layer = find_bsp_layer(scripts_path, machine) | ||
| 597 | |||
| 598 | kernel = find_current_kernel(layer, machine) | ||
| 599 | if not kernel: | ||
| 600 | print "Couldn't determine the kernel for this BSP, exiting." | ||
| 601 | sys.exit(1) | ||
| 602 | |||
| 603 | kernel_bbfile = os.path.join(layer, "recipes-kernel/linux/" + kernel + ".bbappend") | ||
| 604 | if not os.path.isfile(kernel_bbfile): | ||
| 605 | kernel_bbfile = os.path.join(layer, "recipes-kernel/linux/" + kernel + ".bb") | ||
| 606 | if not os.path.isfile(kernel_bbfile): | ||
| 607 | print "Couldn't find a .bb or .bbappend file for this BSP's kernel, exiting." | ||
| 608 | sys.exit(1) | ||
| 609 | |||
| 610 | (uri_start_line, uri_end_line, unused) = find_bsp_kernel_src_uri(scripts_path, machine, True) | ||
| 611 | |||
| 612 | kernel_bbfile_prev = kernel_bbfile + ".prev" | ||
| 613 | shutil.copyfile(kernel_bbfile, kernel_bbfile_prev) | ||
| 614 | ifile = open(kernel_bbfile_prev, "r") | ||
| 615 | ofile = open(kernel_bbfile, "w") | ||
| 616 | |||
| 617 | ifile_lines = ifile.readlines() | ||
| 618 | if uri_start_line == -1: | ||
| 619 | uri_end_line = len(ifile_lines) # make sure we add at end | ||
| 620 | wrote_src_uri = False | ||
| 621 | for i, ifile_line in enumerate(ifile_lines): | ||
| 622 | if ifile_line.strip().startswith("PR"): | ||
| 623 | ifile_line = inc_pr(ifile_line) | ||
| 624 | if i < uri_start_line: | ||
| 625 | ofile.write(ifile_line) | ||
| 626 | elif i > uri_end_line: | ||
| 627 | ofile.write(ifile_line) | ||
| 628 | else: | ||
| 629 | if not wrote_src_uri: | ||
| 630 | write_uri_lines(ofile, src_uri) | ||
| 631 | wrote_src_uri = True | ||
| 632 | if uri_start_line == -1: | ||
| 633 | write_uri_lines(ofile, src_uri) | ||
| 634 | |||
| 635 | |||
| 636 | def kernels(context): | 477 | def kernels(context): |
| 637 | """ | 478 | """ |
| 638 | Return the list of available kernels in the BSP i.e. corresponding | 479 | Return the list of available kernels in the BSP i.e. corresponding |
