Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 1 | inherit terminal |
| 2 | |
| 3 | python do_ccmake() { |
| 4 | import shutil |
| 5 | |
| 6 | # copy current config for diffing |
| 7 | config = os.path.join(d.getVar("B"), "CMakeCache.txt") |
| 8 | if os.path.exists(config): |
| 9 | shutil.copy(config, config + ".orig") |
| 10 | |
| 11 | oe_terminal(d.expand("ccmake ${OECMAKE_GENERATOR_ARGS} ${OECMAKE_SOURCEPATH} -Wno-dev"), |
| 12 | d.getVar("PN") + " - ccmake", d) |
| 13 | |
| 14 | if os.path.exists(config) and os.path.exists(config + ".orig"): |
| 15 | if bb.utils.md5_file(config) != bb.utils.md5_file(config + ".orig"): |
| 16 | # the cmake class uses cmake --build, which will by default |
| 17 | # regenerate configuration, simply mark the compile step as tainted |
| 18 | # to ensure it is re-run |
| 19 | bb.note("Configuration changed, recompile will be forced") |
| 20 | bb.build.write_taint('do_compile', d) |
| 21 | |
| 22 | } |
| 23 | do_ccmake[depends] += "cmake-native:do_populate_sysroot" |
| 24 | do_ccmake[nostamp] = "1" |
| 25 | do_ccmake[dirs] = "${B}" |
| 26 | addtask ccmake after do_configure |
| 27 | |
| 28 | def cmake_parse_config_cache(path): |
| 29 | with open(path, "r") as f: |
| 30 | for i in f: |
| 31 | i = i.rstrip("\n") |
| 32 | if len(i) == 0 or i.startswith("//") or i.startswith("#"): |
| 33 | continue # empty or comment |
| 34 | key, value = i.split("=", 1) |
| 35 | key, keytype = key.split(":") |
| 36 | if keytype in ["INTERNAL", "STATIC"]: |
| 37 | continue # skip internal and static config options |
| 38 | yield key, keytype, value |
| 39 | |
| 40 | def cmake_diff_config_vars(a, b): |
| 41 | removed, added = [], [] |
| 42 | |
| 43 | for ak, akt, av in a: |
| 44 | found = False |
| 45 | for bk, bkt, bv in b: |
| 46 | if bk == ak: |
| 47 | found = True |
| 48 | if bkt != akt or bv != av: # changed |
| 49 | removed.append((ak, akt, av)) |
| 50 | added.append((bk, bkt, bv)) |
| 51 | break |
| 52 | # remove any missing from b |
| 53 | if not found: |
| 54 | removed.append((ak, akt, av)) |
| 55 | |
| 56 | # add any missing from a |
| 57 | for bk, bkt, bv in b: |
| 58 | if not any(bk == ak for ak, akt, av in a): |
| 59 | added.append((bk, bkt, bv)) |
| 60 | |
| 61 | return removed, added |
| 62 | |
| 63 | python do_ccmake_diffconfig() { |
| 64 | import shutil |
| 65 | config = os.path.join(d.getVar("B"), "CMakeCache.txt") |
| 66 | if os.path.exists(config) and os.path.exists(config + ".orig"): |
| 67 | if bb.utils.md5_file(config) != bb.utils.md5_file(config + ".orig"): |
| 68 | # scan the changed options |
| 69 | old = list(cmake_parse_config_cache(config + ".orig")) |
| 70 | new = list(cmake_parse_config_cache(config)) |
| 71 | _, added = cmake_diff_config_vars(old, new) |
| 72 | |
| 73 | if len(added) != 0: |
| 74 | with open(d.expand("${WORKDIR}/configuration.inc"), "w") as f: |
| 75 | f.write("EXTRA_OECMAKE += \" \\\n") |
| 76 | for k, kt, v in added: |
| 77 | escaped = v if " " not in v else "\"{0}\"".format(v) |
| 78 | f.write(" -D{0}:{1}={2} \\\n".format(k, kt, escaped)) |
| 79 | f.write(" \"\n") |
| 80 | bb.plain("Configuration recipe fragment written to: {0}".format(d.expand("${WORKDIR}/configuration.inc"))) |
| 81 | |
| 82 | with open(d.expand("${WORKDIR}/site-file.cmake"), "w") as f: |
| 83 | for k, kt, v in added: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 84 | f.write("SET({0} \"{1}\" CACHE {2} \"\")\n".format(k, v, kt)) |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 85 | bb.plain("Configuration cmake fragment written to: {0}".format(d.expand("${WORKDIR}/site-file.cmake"))) |
| 86 | |
| 87 | # restore the original config |
| 88 | shutil.copy(config + ".orig", config) |
| 89 | else: |
| 90 | bb.plain("No configuration differences, skipping configuration fragment generation.") |
| 91 | else: |
| 92 | bb.fatal("No config files found. Did you run ccmake?") |
| 93 | } |
| 94 | do_ccmake_diffconfig[nostamp] = "1" |
| 95 | do_ccmake_diffconfig[dirs] = "${B}" |
| 96 | addtask ccmake_diffconfig |
| 97 | |