├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── Readme.md ├── Requirements.txt ├── SECURITY.md ├── compile_all.py ├── config.json ├── create_libpack.py ├── generate_patch.py ├── patches ├── icu-01-remove_makedata_target.patch ├── medfile-01-const_cast_argv.patch ├── netgen-01-compiler_bug_workaround_msvc14_std_atomic.patch ├── netgen-01-python-file-include-order.patch ├── opencascade-01-StdPrs_BRepFont.patch ├── pivy-01-add-python-libraries.patch └── quarter-01-add-QOpenGLContext-to-QuarterWidgetP.patch ├── path_cleaner.py ├── test_compile_all.py ├── test_create_libpack.py ├── test_generate_patch.py └── test_path_cleaner.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .vscode/ 3 | working* 4 | LibPack-* 5 | .venv 6 | venv 7 | .idea 8 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: LGPL-2.1-or-later 2 | 3 | # See https://pre-commit.com for more information 4 | # See https://pre-commit.com/hooks.html for more hooks 5 | exclude: 'patches/.*' 6 | 7 | repos: 8 | - repo: https://github.com/pre-commit/pre-commit-hooks 9 | rev: v5.0.0 10 | hooks: 11 | - id: trailing-whitespace 12 | - id: end-of-file-fixer 13 | - id: check-yaml 14 | - id: mixed-line-ending 15 | - repo: https://github.com/psf/black 16 | rev: 25.1.0 17 | hooks: 18 | - id: black 19 | args: ['--line-length', '100'] 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | This repository is to provide libraries needed to compile FreeCAD under Windows. Releases are named according to which version of FreeCAD they are expected to work with. The most recent LibPack is typically only designed to work with the current development branch of FreeCAD. To compile release versions of FreeCAD you typically must use older versions of the LibPack. LibPacks release names include the version of FreeCAD they are designed to work with. 2 | 3 | The current LibPack, v3.1, is tested to work with [Microsoft Visual Studio](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B) version 17.12, e.g. MSVC 143, and is known to not work with earlier versions (e.g. Visual Studio 2019 will not work with LibPack v3, and must use LibPack v2.11) It should be possible to use other compilers like MinGW, however this is not tested. This LibPack only supports FreeCAD compilation in Release or RelWithDebInfo mode. It may be possible to compile the LibPack in Debug mode, but changes will certainly be required (and patches are welcome!). In particular, the pip installation of Numpy will have to be adjusted to compile a debug version of Numpy, which will otherwise fail to load from a debug compilation of Python. 4 | 5 | For information how to use the LibPack to compile, see this Wiki page: https://wiki.freecadweb.org/Compile_on_Windows 6 | 7 | ## Building the LibPack ## 8 | 9 | To build the LibPack locally, you will need the following: 10 | * Network access 11 | * Visual Studio 17.12.x, accessible by cMake (other versions may work, but are not supported) 12 | * CMake 13 | * git 14 | * 7z (see https://www.7-zip.org) 15 | * Python >= 3.8 (**not** used inside the LibPack itself, just used to run the creation script) 16 | * The "requests" Python package (e.g. 'pip install requests') 17 | * The "diff-match-patch" Python package (e.g. 'pip install diff-match-patch') 18 | * Qt - the base installation plus Qt Image Formats and Qt PDF 19 | * GNU Bison (for Windows see https://github.com/lexxmark/winflexbison/) 20 | 21 | With those pieces in place, the next step is to configure the contents of the LibPack by editing `config.json`. This file 22 | lists the source for each LibPack component. Depending on the component, there are three different ways it might be included: 23 | 1) Source code checked out from a git repository and built using the local compiler toolchain 24 | 1) A pip package installed to the LibPack directory using the LibPack's Python interpreter 25 | * Note that `pip` itself is installed using the `ensure_pip` Python module 26 | 1) Files copied from a local source 27 | 1) Compressed files downloaded from a remote source and unpacked 28 | 29 | The JSON file just lists out the sources and versions: beyond specifying which method is used for the installation by setting 30 | either "git-repo" and "git_ref", or "install-directory", the actual details of how things are built when source 31 | code is provided are set in the `compile_all.py` script. In that file, the class `Compiler` contains methods following the 32 | naming convention `build_XXX` where `XXX` is the "name" provided in the JSON configuration file. If you need to add a compiled 33 | or copied package, you must both specify it in the config.json file and provide a matching `build_XXX` method. For pip 34 | installation, only the config.json file needs to be edited to include the new dependency. 35 | 36 | To change the way a package is compiled, you edit its entry in `compile_all.py`. See the contents of that file for various 37 | examples. 38 | 39 | ## Running the build script ## 40 | 41 | ``` 42 | python.exe create_libpack [arguments] 43 | ``` 44 | Arguments: 45 | * `-m`, `--mode` -- 'release' or 'debug' (Default: 'release' -- debug is not currently functional) 46 | * `-c`, `--config` -- Path to a JSON configuration file for this utility (Default: './config.json') 47 | * `-w`, `--working` -- Directory to put all the clones and downloads in (Default: './working') 48 | * `-e`, `--no-skip-existing-clone` -- If a given clone (or download) directory exists, delete it and download it again 49 | * `-b`, `--no-skip-existing-build` -- If a given build already exists, run the build process again anyway 50 | * `-s`, `--silent` -- I kow what I'm doing, don't ask me any questions 51 | * `--7zip` -- Path to 7-zip executable if not in PATH 52 | * `--bison` -- Path to Bison executable if not in PATH 53 | -------------------------------------------------------------------------------- /Requirements.txt: -------------------------------------------------------------------------------- 1 | # NOTE: These are the requirements for the LibPack-generation scripts, NOT for FreeCAD. They do not describe 2 | # the contents of the LibPack (for that see config.json) 3 | 4 | diff-match-patch 5 | requests 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | The FreeCAD project is a FOSS (Free and Open-Source Software) project that has a community of thousands of users and 4 | hundreds of developers worldwide. We encourage responsible reporting of security vulnerabilities that may affect users 5 | of this software, and will endeavor to address these vulnerabilities when they are discovered. 6 | 7 | The LibPack is a collection of many subprojects. As such, subproject vulnerabilities are common, and we strive for 8 | frequent updates to the LibPack to ensure that self-compiling FreeCAD users have limited exposure to the vulnerabilities 9 | that arise. 10 | 11 | To report a vulnerability use GitHub's security reporting tool: 12 | https://github.com/FreeCAD/FreeCAD-LibPack/security/advisories/new 13 | -------------------------------------------------------------------------------- /compile_all.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later 4 | 5 | # Every package has its own compilation and installation idiosyncrasies, so we have to use a custom 6 | # build script for each one. 7 | 8 | from diff_match_patch import diff_match_patch 9 | from typing import Dict, List 10 | 11 | from enum import Enum 12 | import os 13 | import pathlib 14 | import platform 15 | import re 16 | import shutil 17 | import subprocess 18 | import stat 19 | import sys 20 | 21 | 22 | class BuildMode(Enum): 23 | DEBUG = 1 24 | RELEASE = 2 25 | 26 | def __str__(self) -> str: 27 | if self == BuildMode.DEBUG: 28 | return "Debug" 29 | elif self == BuildMode.RELEASE: 30 | return "Release" 31 | else: 32 | return "Unknown" 33 | 34 | 35 | def remove_readonly(func, path, _) -> None: 36 | """Remove a read-only file.""" 37 | 38 | os.chmod(path, stat.S_IWRITE) 39 | func(path) 40 | 41 | 42 | def patch_single_file(filename, patch_data) -> None: 43 | with open(filename, "r", encoding="utf-8") as f: 44 | original_data = f.read() 45 | dmp = diff_match_patch() 46 | patches = dmp.patch_fromText(patch_data) 47 | new_text, applied = dmp.patch_apply(patches, original_data) 48 | if not all(applied): 49 | print(f"ERROR: Failed to apply some patches to {filename}") 50 | # TODO: Someday actually print out what patches failed? 51 | exit(1) 52 | with open(filename, "w", encoding="utf-8") as f: 53 | f.write(new_text) 54 | 55 | 56 | def split_patch_data(patch_data: str) -> List[Dict[str, str]]: 57 | filename_regex = re.compile("@@@ ([^@]*) @@@\n") 58 | split_data = re.split(filename_regex, patch_data) 59 | result = [] 60 | for index, entry in enumerate(split_data): 61 | if index == 0: 62 | if entry != "": 63 | print("ERROR: Bad patch file, must start with @@@ filename @@@") 64 | exit(1) 65 | continue 66 | if index % 2 == 1: 67 | result.append({"file": entry}) 68 | else: 69 | result[-1]["data"] = entry 70 | return result 71 | 72 | 73 | def apply_patch(patch_file_path: str) -> None: 74 | """Apply a patch that was generated by the generate_patch.py script""" 75 | # Path is relative to *this* file, not our working directory 76 | absolute_path = os.path.join(pathlib.Path(__file__).parent.absolute(), patch_file_path) 77 | with open(absolute_path, "r", encoding="utf-8") as f: 78 | patch_data = f.read() 79 | patches = split_patch_data(patch_data) 80 | for patch in patches: 81 | patch_single_file(patch["file"], patch["data"]) 82 | 83 | 84 | def patch_files(patches: List[str]) -> None: 85 | """Given a list of patches, apply them sequentially in the current working directory. The patches themselves are 86 | expected to be given as paths relative to **this** Python script file""" 87 | for patch in patches: 88 | start = len("patches/") 89 | print(f" Applying patch {patch[start:]}") 90 | apply_patch(patch) 91 | 92 | 93 | def libpack_dir(config: dict, mode: BuildMode): 94 | lp_dir = "LibPack-{}-v{}-{}".format( 95 | config["FreeCAD-version"], config["LibPack-version"], str(mode) 96 | ) 97 | return os.path.join(os.path.dirname(__file__), "working", lp_dir) 98 | 99 | 100 | def to_exe(base: str = ""): 101 | """Append .exe to Windows executables, but not to macOS or Linux. If given no argument, just returns the extension 102 | for the current OS, suitable for appending to an executable's name.""" 103 | return base + ".exe" if sys.platform.startswith("win32") else "" 104 | 105 | 106 | def to_static(base: str = ""): 107 | """Append .lib to Windows libraries, or .a macOS or Linux. If given no argument, just returns the extension 108 | for the current OS, suitable for appending to a static library's name.""" 109 | return base + ".lib" if sys.platform.startswith("win32") else ".a" 110 | 111 | 112 | def to_dynamic(base: str = ""): 113 | """Append .dll to Windows libraries, or .so to macOS or Linux. If given no argument, just returns the extension 114 | for the current OS, suitable for appending to a dynamic library's name.""" 115 | return base + ".dll" if sys.platform.startswith("win32") else ".so" 116 | 117 | 118 | class Compiler: 119 | def __init__( 120 | self, config, bison_path, skip_existing: bool = False, mode: BuildMode = BuildMode.RELEASE 121 | ): 122 | self.config = config 123 | self.bison_path = bison_path 124 | self.base_dir = os.getcwd() 125 | self.skip_existing = skip_existing 126 | self.install_dir = libpack_dir(config, mode) 127 | self.init_script = None 128 | self.mode = mode 129 | self.strict_mode = True 130 | 131 | # Right now there are two packages where the version number gets coded into the path when: Boost and Coin: 132 | # store those two separately from all the other paths we have to track 133 | self.boost_include_path = None 134 | self.coin_cmake_path = None 135 | 136 | def get_cmake_options(self) -> List[str]: 137 | """Get a comprehensive list of cMake options that can be used in any cMake build. Not all options apply 138 | to all builds, but none conflict.""" 139 | pcre_lib = self.install_dir + "/lib/pcre2-8" 140 | if self.mode == BuildMode.DEBUG: 141 | pcre_lib += "d" 142 | pcre_lib += to_static() 143 | 144 | base = [ 145 | "-D CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=FALSE", # Never use system packages, always use only the libpack 146 | "-D CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=TRUE", # Same as above? 147 | "-D CMAKE_CXX_STANDARD=20", 148 | "-T fortran=ifx", 149 | "-D CMAKE_Fortran_COMPILER='C:/Program Files (x86)/Intel/oneAPI/compiler/2025.0/bin/ifx.exe'", # Intel Fortran is called ifx now 150 | f"-D BISON_EXECUTABLE={self.bison_path}", 151 | f"-D BOOST_ROOT={self.install_dir}", 152 | "-D BUILD_DOC=No", 153 | "-D BUILD_DOCS=No", 154 | "-D BUILD_EXAMPLES=No", 155 | "-D BUILD_SHARED=Yes", 156 | "-D BUILD_SHARED_LIB=Yes", 157 | "-D BUILD_SHARED_LIBS=Yes", 158 | "-D BUILD_TEST=No", 159 | "-D BUILD_TESTS=No", 160 | "-D BUILD_TESTING=No", 161 | f"-D BZIP2_DIR={self.install_dir}/lib/cmake/", 162 | f"-D Boost_INCLUDE_DIRS={self.install_dir}/include", 163 | f"-D CMAKE_BUILD_TYPE={self.mode}", 164 | f"-D CMAKE_INSTALL_PATH={self.install_dir}", 165 | f"-D CMAKE_INSTALL_PREFIX={self.install_dir}", 166 | f"-D HarfBuzz_DIR={self.install_dir}/lib/cmake/", 167 | f"-D HDF5_DIR={self.install_dir}/share/cmake/", 168 | f"-D HDF5_LIBRARY_DEBUG={self.install_dir}/lib/hdf5d.lib", 169 | f"-D HDF5_LIBRARY_RELEASE={self.install_dir}/lib/hdf5.lib", 170 | f"-D HDF5_DIFF_EXECUTABLE={self.install_dir}/bin/hdf5diff" + to_exe(), 171 | f"-D INSTALL_DIR={self.install_dir}", 172 | f"-D PCRE2_LIBRARY={pcre_lib}", 173 | "-D PIVY_USE_QT6=Yes", 174 | f"-D pybind11_DIR={self.install_dir}/share/cmake/pybind11", 175 | f"-D Python_ROOT_DIR={self.install_dir}/bin", 176 | f"-D Python_DIR={self.install_dir}/bin", 177 | f"-D Python3_ROOT_DIR={self.install_dir}/bin", 178 | f"-D Python3_DIR={self.install_dir}/bin", 179 | "-D Python_FIND_REGISTRY=NEVER", 180 | f"-D Qt6_DIR={self.install_dir}/lib/cmake/Qt6", 181 | f"-D SWIG_EXECUTABLE={self.install_dir}/bin/swig" + to_exe(), 182 | f"-D ZLIB_DIR={self.install_dir}/lib/cmake/", 183 | f"-D ZLIB_INCLUDE_DIR={self.install_dir}/include", 184 | f"-D ZLIB_LIBRARY_RELEASE={self.install_dir}/lib/zlib" + to_static(), 185 | f"-D ZLIB_LIBRARY_DEBUG={self.install_dir}/lib/zlibd" + to_static(), 186 | "-D CMAKE_DISABLE_FIND_PACKAGE_SoQt=True", 187 | # Absolutely never find SoQt (it's deprecated and we don't want it!) 188 | ] 189 | if self.boost_include_path: 190 | base.append(f"-D Boost_INCLUDE_DIR={self.boost_include_path}") 191 | if self.coin_cmake_path: 192 | base.append(f"-D Coin_DIR={self.coin_cmake_path}") 193 | if sys.platform.startswith("win32"): 194 | inc_path = self.install_dir.replace("\\", "/") 195 | cxx_flags = f"/I{inc_path}/include /EHsc /DWIN32 /DWIN64" 196 | if self.strict_mode: 197 | # NOTE: /permissive- is required with Qt6 but could be disabled for anything that doesn't link against 198 | # Qt. The same is true for /Zc:__cplusplus /std:c++20 199 | cxx_flags += " /Zc:__cplusplus /std:c++20 /permissive-" 200 | else: 201 | cxx_flags = f"-I{self.install_dir}/include" 202 | base.append(f"-D CMAKE_CXX_FLAGS={cxx_flags}") 203 | return base 204 | 205 | def compile_all(self): 206 | for item in self.config["content"]: 207 | # All build methods are named using "build_XXX" where XXX is the name of the package in the config file 208 | os.chdir(item["name"]) 209 | build_function_name = "build_" + item["name"] 210 | if hasattr(self, build_function_name): 211 | print(f"Building {item['name']}") 212 | build_function = getattr(self, build_function_name) 213 | build_function(item) 214 | else: 215 | print( 216 | f"No '{build_function_name}' found in compile_all.py -- " 217 | "did you forget to add one when adding a dependency?" 218 | ) 219 | exit(2) 220 | os.chdir(self.base_dir) 221 | 222 | def build_nonexistent(self, _=None): 223 | """Used for automated testing to allow easy Mock injection""" 224 | 225 | def python_exe(self): 226 | if self.mode == BuildMode.RELEASE: 227 | return os.path.join(self.install_dir, "bin", "python") + to_exe() 228 | return os.path.join(self.install_dir, "bin", "python_d") + to_exe() 229 | 230 | def build_python(self, args=None): 231 | if self.skip_existing: 232 | if os.path.exists(os.path.join(self.install_dir, "bin", "DLLs")): 233 | print(" Not rebuilding Python, it is already in the LibPack") 234 | return 235 | if sys.platform.startswith("win32"): 236 | expected_exe_path = self.python_exe() 237 | if self.skip_existing and os.path.exists(expected_exe_path): 238 | print( 239 | "Not rebuilding, instead just using existing Python in the LibPack installation path" 240 | ) 241 | return 242 | try: 243 | arch = "x64" if platform.machine() == "AMD64" else "ARM64" 244 | path = "amd64" if platform.machine() == "AMD64" else "arm64" 245 | subprocess.run( 246 | [ 247 | self.init_script, 248 | "&", 249 | "PCbuild\\build.bat", 250 | "-p", 251 | arch, 252 | "-c", 253 | str(self.mode), 254 | ], 255 | check=True, 256 | capture_output=True, 257 | ) 258 | except subprocess.CalledProcessError as e: 259 | print("Python build failed") 260 | print(e.stdout.decode("utf-8")) 261 | if e.stderr: 262 | print(e.stderr.decode("utf-8")) 263 | exit(e.returncode) 264 | bin_dir = os.path.join(self.install_dir, "bin") 265 | dll_dir = os.path.join(bin_dir, "DLLs") 266 | lib_dir = os.path.join(bin_dir, "Lib") 267 | libs_dir = os.path.join(bin_dir, "libs") 268 | inc_dir = os.path.join(bin_dir, "Include") 269 | tools_dir = os.path.join(bin_dir, "Tools") 270 | os.makedirs(bin_dir, exist_ok=True) 271 | os.makedirs(dll_dir, exist_ok=True) 272 | os.makedirs(lib_dir, exist_ok=True) 273 | os.makedirs(libs_dir, exist_ok=True) 274 | os.makedirs(bin_dir, exist_ok=True) 275 | os.makedirs(tools_dir, exist_ok=True) 276 | tools_subs = ["i18n", "scripts"] 277 | for sub in tools_subs: 278 | os.makedirs(os.path.join(tools_dir, sub), exist_ok=True) 279 | 280 | # NOTES: 281 | # When installed via the Python installer, the top-level Python folder contains: 282 | # python.exe 283 | # python.pdb 284 | # python3.dll 285 | # python3xx.dll 286 | # python3xx.pdb 287 | # python3xx_d.dll 288 | # python3xx_d.pdb 289 | # python3_d.dll 290 | # pythonw.exe 291 | # pythonw.pdb 292 | # pythonw_d.exe 293 | # pythonw_d.pdb 294 | # python_d.exe 295 | # python_d.pdb 296 | # vcruntime140.dll 297 | # vcruntime140_1.dll 298 | # It also contains 5 subdirectories: DLLs, include, Lib, libs, and Tools, plus LICENSE.txt 299 | # DLLS folder contains *.pyd, *.pdb, and *.dll 300 | # include contains the header file directory tree 301 | # Lib contains the Python standard libraries 302 | # libs contains the actual Python *.lib files (python3.lib and python3xx.lib and their debug equivalents 303 | # Tools contains a number of subdirectories with Python scripts: i18n, scripts, and demo 304 | # Finally, we also need the file "pyconfig.h" which is in yet another directory of the Python build, "PC" 305 | 306 | shutil.copytree(f"PCBuild\\{path}", dll_dir, dirs_exist_ok=True) 307 | shutil.copytree(f"Lib", lib_dir, dirs_exist_ok=True) 308 | shutil.copytree(f"Include", inc_dir, dirs_exist_ok=True) 309 | for sub in tools_subs: 310 | shutil.copytree(f"Tools\\{sub}", os.path.join(tools_dir, sub), dirs_exist_ok=True) 311 | 312 | # Figure out what version of Python we just built: 313 | major, minor = self.get_python_version( 314 | os.path.join("PCBuild", path, "python.exe") 315 | ).split(".") 316 | 317 | # Construct the list of files we expect to exist that need to be placed in the toplevel directory, or in 318 | # libs: 319 | move_to_bin = ["vcruntime"] 320 | for base in ["python", f"python{major}", f"python{major}{minor}", "pythonw"]: 321 | final = base 322 | if self.mode == BuildMode.DEBUG: 323 | final += "_d" 324 | move_to_bin.append(final) 325 | # They are all in the DLLs subdirectory now: move the ones that match: 326 | for file in pathlib.Path(dll_dir).iterdir(): 327 | if file.is_file(): 328 | if file.stem in move_to_bin: 329 | if file.suffix == ".lib": 330 | target = os.path.join(libs_dir, file.name) 331 | elif file.suffix in [".dll", ".exe", ".pdb"]: 332 | target = os.path.join(bin_dir, file.name) 333 | else: 334 | continue 335 | if os.path.exists(target): 336 | os.unlink(target) 337 | file.rename(target) 338 | pyconfig = os.path.join("PC", "pyconfig.h") 339 | target = os.path.join(inc_dir, "pyconfig.h") 340 | if not os.path.exists(pyconfig): 341 | print("ERROR: Could not locate pyconfig.h, cannot complete installation of Python") 342 | exit(1) 343 | if os.path.exists(target): 344 | os.unlink(target) 345 | print(f"Copying {pyconfig} to {target}") 346 | shutil.copyfile(pyconfig, target) 347 | else: 348 | raise NotImplemented("Non-Windows compilation of Python is not implemented yet") 349 | 350 | # Check these even if we didn't actually have to build Python 351 | self._build_pip() 352 | if "requirements" in args: 353 | self._install_python_requirements(args["requirements"]) 354 | 355 | def get_python_version(self, exe: str = None) -> str: 356 | if exe is None: 357 | path_to_python = self.python_exe() 358 | else: 359 | path_to_python = exe 360 | try: 361 | result = subprocess.run([path_to_python, "--version"], capture_output=True, check=True) 362 | _, _, version_number = result.stdout.decode("utf-8").strip().partition(" ") 363 | components = version_number.split(".") 364 | python_version = f"{components[0]}.{components[1]}" 365 | return python_version 366 | except subprocess.CalledProcessError as e: 367 | print("ERROR: Failed to run LibPack's Python executable") 368 | print(e.stdout.decode("utf-8")) 369 | if e.stderr: 370 | print(e.stderr.decode("utf-8")) 371 | exit(1) 372 | 373 | def _build_pip(self, _=None): 374 | print(" Installing the latest pip") 375 | path_to_python = self.python_exe() 376 | try: 377 | subprocess.run( 378 | [path_to_python, "-m", "ensurepip", "--upgrade"], capture_output=True, check=True 379 | ) 380 | subprocess.run( 381 | [path_to_python, "-m", "pip", "install", "--upgrade", "pip"], 382 | capture_output=True, 383 | check=True, 384 | ) 385 | except subprocess.CalledProcessError as e: 386 | print("ERROR: Failed to run LibPack's Python executable") 387 | print(e.stdout.decode("utf-8")) 388 | if e.stderr: 389 | print(e.stderr.decode("utf-8")) 390 | exit(1) 391 | 392 | def _install_python_requirements(self, requirements): 393 | print(" Installing the following requirements (and their dependencies) using pip:") 394 | for req in requirements: 395 | print(" " + req) 396 | path_to_python = self.python_exe() 397 | call_args = [path_to_python, "-m", "pip", "install", "--ignore-installed"] 398 | call_args.extend(requirements) 399 | try: 400 | subprocess.run( 401 | call_args, 402 | check=True, 403 | capture_output=True, 404 | ) 405 | except subprocess.CalledProcessError as e: 406 | print(f"ERROR: Failed to pip install requirements") 407 | print(e.output.decode("utf-8")) 408 | if e.stderr: 409 | print(e.stderr.decode("utf-8")) 410 | exit(1) 411 | 412 | def build_qt(self, options: dict): 413 | """Doesn't really "build" Qt, just copies the pre-compiled libraries from the configured path""" 414 | qt_dir = options["install-directory"] 415 | if self.skip_existing: 416 | if os.path.exists(os.path.join(self.install_dir, "metatypes")): 417 | print( 418 | " Not re-copying, instead just using existing Qt in the LibPack installation path" 419 | ) 420 | return 421 | if not os.path.exists(qt_dir): 422 | print(f"Error: specified Qt installation path does not exist ({qt_dir})") 423 | exit(1) 424 | print(" (Note that Qt isn't really 'built,' it is just copied from a local installation)") 425 | shutil.copytree(qt_dir, self.install_dir, dirs_exist_ok=True) 426 | 427 | def build_boost(self, _=None): 428 | """Builds boost shared libraries and installs libraries and headers""" 429 | if self.skip_existing: 430 | self._configure_boost_version() 431 | if self.boost_include_path is not None: 432 | print(" Not rebuilding boost, it is already in the LibPack") 433 | return 434 | 435 | # NOTE: You can't build boost in-source twice, it will report an error the second time. So if you need to 436 | # rebuild boost and you've already built it once, delete the entire Boost working directory, as well as the 437 | # installed copy in the LibPack, then re-run this script. TODO: autodelete boost's build files 438 | 439 | # Boost uses a custom build system and needs a config file to find our Python 440 | with open( 441 | os.path.join("tools", "build", "src", "user-config.jam"), "w", encoding="utf-8" 442 | ) as user_config: 443 | exe = self.python_exe() 444 | if sys.platform.startswith("win32"): 445 | exe = exe.replace("\\", "\\\\") 446 | inc_dir = os.path.join(self.install_dir, "bin", "include").replace("\\", "\\\\") 447 | lib_dir = os.path.join(self.install_dir, "bin", "libs").replace("\\", "\\\\") 448 | python_version = self.get_python_version() 449 | full_version = python_version + ("d" if self.mode == BuildMode.DEBUG else "") 450 | print(f" (boost-python is being built against Python {full_version})") 451 | user_config.write(f"using python : {python_version} ") 452 | user_config.write(f': "{exe}" ') 453 | user_config.write(f': "{inc_dir}" ') 454 | user_config.write(f': "{lib_dir}" ') 455 | if self.mode == BuildMode.DEBUG: 456 | user_config.write(f": on ") 457 | user_config.write(";\n") 458 | try: 459 | # When debugging on the command line, add --debug-configuration to get more verbose output 460 | install_dir = self.install_dir 461 | subprocess.run( 462 | [self.init_script, "&", "bootstrap.bat", f"--prefix={install_dir}"], 463 | capture_output=True, 464 | check=True, 465 | ) 466 | arch = "x86" if platform.machine() == "AMD64" else "arm" 467 | subprocess.run( 468 | [ 469 | self.init_script, 470 | "&", 471 | "b2", 472 | f"install", 473 | "address-model=64", 474 | f"architecture={arch}", 475 | "link=static,shared", 476 | "cxxstd=20", 477 | str(self.mode).lower(), 478 | f"--prefix={install_dir}", 479 | "--layout=versioned", 480 | "--without-mpi", 481 | "--without-graph_parallel", 482 | "--build-type=complete", 483 | "--debug-configuration", 484 | ], 485 | check=True, 486 | capture_output=True, 487 | ) 488 | except subprocess.CalledProcessError as e: 489 | # Boost is too verbose in its output to be of much use un-processed. Dump it all to a file, and 490 | # then print only the lines with the word "error:" on them to stdout 491 | print( 492 | "Error: failed to build boost -- writing output to " 493 | + os.path.join(os.path.curdir, "stdout.txt") 494 | ) 495 | with open("stdout.txt", "w", encoding="utf-8") as f: 496 | f.write(e.stdout.decode("utf-8")) 497 | lines = e.stdout.decode("utf-8").split("\n") 498 | for line in lines: 499 | if "error:" in line.lower(): 500 | print(line) 501 | exit(e.returncode) 502 | self._configure_boost_version() 503 | 504 | def _configure_boost_version(self): 505 | """Once Boost has been installed, figure out what version it was and set up the correct include path""" 506 | start_crawl_at = os.path.join(self.install_dir, "include") 507 | contents = [ 508 | f for f in os.listdir(start_crawl_at) if os.path.isdir(os.path.join(start_crawl_at, f)) 509 | ] 510 | for item in contents: 511 | if item.startswith("boost"): 512 | self.boost_include_path = os.path.join(start_crawl_at, item) 513 | break 514 | 515 | def _cmake_create_build_dir(self): 516 | build_dir = "build-" + str(self.mode).lower() 517 | if os.path.exists(build_dir): 518 | shutil.rmtree(build_dir, onerror=remove_readonly) 519 | os.mkdir(build_dir) 520 | os.chdir(build_dir) 521 | 522 | def _run_cmake(self, args): 523 | cmake_setup_options = [self.init_script, "&", "cmake"] 524 | cmake_setup_options.extend(args) 525 | try: 526 | process = subprocess.run(cmake_setup_options, check=True, capture_output=True) 527 | with open("build_log.txt", "a", encoding="utf-8") as f: 528 | f.write(process.stdout.decode("utf-8")) 529 | except subprocess.CalledProcessError as e: 530 | print("ERROR: cMake failed!") 531 | print(f"Command: {' '.join(cmake_setup_options)}") 532 | print(e.stdout.decode("utf-8")) 533 | if e.stderr: 534 | print(e.stderr.decode("utf-8")) 535 | exit(e.returncode) 536 | 537 | def _cmake_configure(self, extra_args: List[str] = None): 538 | options = self.get_cmake_options() 539 | if extra_args: 540 | options.extend(extra_args) 541 | options.append( 542 | ".." 543 | ) # Because the source code is located one directory up from our build location 544 | self._run_cmake(options) 545 | 546 | def _cmake_build(self, parallel: bool = True): 547 | cmake_build_options = ["--build", ".", "--config", str(self.mode).lower(), "--verbose"] 548 | if parallel: 549 | cmake_build_options.append("--parallel") 550 | self._run_cmake(cmake_build_options) 551 | 552 | def _cmake_install(self): 553 | cmake_install_options = ["--install", ".", "--config", str(self.mode).lower()] 554 | self._run_cmake(cmake_install_options) 555 | 556 | def _build_standard_cmake(self, extra_args: List[str] = None): 557 | self._cmake_create_build_dir() 558 | self._cmake_configure(extra_args) 559 | self._cmake_build() 560 | self._cmake_install() 561 | 562 | def _pip_install(self, requirement: str) -> None: 563 | path_to_python = self.python_exe() 564 | package_name = requirement.split("==")[0] 565 | try: 566 | # Get rid of any version that's already there. 567 | subprocess.run( 568 | [path_to_python, "-m", "pip", "uninstall", "--yes", package_name], 569 | check=True, 570 | capture_output=True, 571 | ) 572 | except subprocess.CalledProcessError as e: 573 | print(f"{package_name} was not uninstalled... continuing") 574 | pass 575 | try: 576 | subprocess.run( 577 | [path_to_python, "-m", "pip", "install", "--ignore-installed", requirement], 578 | check=True, 579 | capture_output=True, 580 | ) 581 | except subprocess.CalledProcessError as e: 582 | print(f"ERROR: Failed to pip install {requirement}") 583 | print(e.output.decode("utf-8")) 584 | if e.stderr: 585 | print(e.stderr.decode("utf-8")) 586 | exit(1) 587 | 588 | def _build_with_pip(self, options: dict): 589 | if "pip-install" not in options: 590 | print( 591 | f"ERROR: No pip-install provided in config of {options['name']}, so version cannot be determined" 592 | ) 593 | exit(1) 594 | self._pip_install(options["pip-install"]) 595 | 596 | def build_coin(self, _=None): 597 | """Builds and installs Coin using standard CMake settings""" 598 | if self.skip_existing: 599 | self._configure_coin_cmake_path() 600 | if self.coin_cmake_path is not None: 601 | print(" Not rebuilding Coin, it is already in the LibPack") 602 | return 603 | extra_args = ["-D COIN_BUILD_TESTS=Off"] 604 | self._build_standard_cmake(extra_args) 605 | self._configure_coin_cmake_path() 606 | 607 | def _configure_coin_cmake_path(self): 608 | """Coin installs its cMake file into a directory named with the full version, so figure out what that is""" 609 | start_crawl_at = os.path.join(self.install_dir, "lib", "cmake") 610 | contents = [ 611 | f for f in os.listdir(start_crawl_at) if os.path.isdir(os.path.join(start_crawl_at, f)) 612 | ] 613 | for item in contents: 614 | if item.startswith("Coin"): 615 | self.coin_cmake_path = os.path.join(start_crawl_at, item) 616 | break 617 | 618 | def build_quarter(self, _=None): 619 | """Builds and installs Quarter using standard CMake settings""" 620 | if self.skip_existing: 621 | if os.path.exists(os.path.join(self.install_dir, "include", "Quarter")): 622 | print(" Not rebuilding Quarter, it is already in the LibPack") 623 | return 624 | self._build_standard_cmake() 625 | 626 | def build_zlib(self, _=None): 627 | if self.skip_existing: 628 | if os.path.exists(os.path.join(self.install_dir, "include", "zlib.h")): 629 | print(" Not rebuilding zlib, it is already in the LibPack") 630 | return 631 | self._build_standard_cmake() 632 | 633 | def build_bzip2(self, _=None): 634 | """The version of BZip2 in widespread use (1.0.8, the most recent official release) do not yet use cMake""" 635 | if self.skip_existing: 636 | if os.path.exists(os.path.join(self.install_dir, "include", "bzlib.h")): 637 | print(" Not rebuilding bzip2, it is already in the LibPack") 638 | return 639 | if sys.platform.startswith("win32"): 640 | args = [self.init_script, "&", "nmake", "/f", "makefile.msc"] 641 | try: 642 | subprocess.run(args, check=True, capture_output=True) 643 | shutil.copyfile("libbz2.lib", os.path.join(self.install_dir, "lib", "libbz2.lib")) 644 | shutil.copyfile("bzlib.h", os.path.join(self.install_dir, "include", "bzlib.h")) 645 | shutil.copyfile( 646 | "bzlib_private.h", os.path.join(self.install_dir, "include", "bzlib_private.h") 647 | ) 648 | except subprocess.CalledProcessError as e: 649 | print("ERROR: Failed to build bzip2 using nmake") 650 | print(e.output.decode("utf-8")) 651 | if e.stderr: 652 | print(e.stderr.decode("utf-8")) 653 | exit(1) 654 | else: 655 | raise NotImplemented("Non-Windows compilation of bzip2 is not implemented yet") 656 | 657 | def build_pcre2(self, _=None): 658 | if self.skip_existing: 659 | if os.path.exists(os.path.join(self.install_dir, "include", "pcre2.h")): 660 | print(" Not rebuilding pcre2, it is already in the LibPack") 661 | return 662 | self._build_standard_cmake() 663 | 664 | def build_swig(self, _=None): 665 | if self.skip_existing: 666 | if os.path.exists(os.path.join(self.install_dir, "bin", "swig") + to_exe()): 667 | print(" Not rebuilding SWIG, it is already in the LibPack") 668 | return 669 | self._build_standard_cmake() 670 | 671 | def build_pivy(self, _=None): 672 | if self.skip_existing: 673 | if os.path.exists( 674 | os.path.join(self.install_dir, "bin", "Lib", "site-packages", "pivy") 675 | ): 676 | print(" Not rebuilding pivy, it is already in the LibPack") 677 | return 678 | extra_args = [] 679 | self._build_standard_cmake(extra_args) 680 | if self.mode == BuildMode.DEBUG: 681 | base = os.path.join(self.install_dir, "bin", "Lib", "site-packages", "pivy") 682 | os.rename(os.path.join(base, "_coin.pyd"), os.path.join(base, "_coin_d.pyd")) 683 | 684 | def build_libclang(self, _=None): 685 | """libclang is provided as a platform-specific download by Qt.""" 686 | if self.skip_existing: 687 | if os.path.exists(os.path.join(self.install_dir, "include", "clang")): 688 | print(" Not copying libclang, it is already in the LibPack") 689 | return 690 | print(" (not really building libclang, just copying from a build provided by Qt)") 691 | shutil.copytree("libclang", self.install_dir, dirs_exist_ok=True) 692 | 693 | def build_pyside(self, _=None): 694 | # Don't use a pip-install for this, we need the linkable libraries and include files for both PySide and 695 | # Shiboken, which won't get installed by pip, and it needs to be built against the right Python exe 696 | if self.skip_existing: 697 | if os.path.exists( 698 | os.path.join(self.install_dir, "bin", "Lib", "site-packages", "PySide6") 699 | ): 700 | print(" Not rebuilding PySide6, it is already in the LibPack") 701 | return 702 | python = self.python_exe() 703 | qtpaths = "--qtpaths=" + os.path.join(self.install_dir, "bin", "qtpaths6") + to_exe() 704 | clang = "CLANG_INSTALL_DIR=" + os.path.join(self.install_dir, "lib", "clang") 705 | vulkan = "VULKAN_SDK=None" # "VULKAN_SDK=" + os.path.join(self.install_dir, "Vulkan") 706 | parallel = "--parallel=16" 707 | # numpy = "--enable-numpy-support" 708 | if sys.platform.startswith("win32"): 709 | ssl = "--openssl=" + os.path.join(self.install_dir, "bin", "DLLs") 710 | args = [ 711 | self.init_script, 712 | "&", 713 | "set", 714 | clang, 715 | "&", 716 | "set", 717 | vulkan, 718 | "&", 719 | python, 720 | "setup.py", 721 | "install", 722 | qtpaths, 723 | ssl, 724 | parallel, 725 | ] 726 | if self.mode == BuildMode.DEBUG: 727 | args.append("--debug") 728 | else: 729 | ssl = "--openssl=" + os.path.join(self.install_dir, "bin", "DLLs") 730 | args = [clang, "&&", python, "setup.py", "install", qtpaths, ssl] 731 | try: 732 | subprocess.run(args, capture_output=True, check=True) 733 | except subprocess.CalledProcessError as e: 734 | print("ERROR: Failed to build Pyside and/or Shiboken") 735 | print(e.stdout.decode("utf-8")) 736 | if e.stderr: 737 | print(e.stderr.decode("utf-8")) 738 | exit(1) 739 | 740 | def build_vtk(self, _=None): 741 | if self.skip_existing: 742 | if os.path.exists(os.path.join(self.install_dir, "share", "licenses", "VTK")): 743 | print(" Not rebuilding VTK, it is already in the LibPack") 744 | return 745 | extra_args = [ 746 | "-D VTK_WRAP_PYTHON=YES", 747 | "-D VTK_MODULE_ENABLE_VTK_WrappingPythonCore=YES", 748 | "-D VTK_PYTHON_SITE_PACKAGES_SUFFIX=bin/Lib/site-packages/", 749 | ] 750 | if sys.platform.startswith("win32"): 751 | extra_args.append( 752 | "-D VTK_MODULE_ENABLE_VTK_IOIOSS=NO", # Workaround for bug in Visual Studio MSVC 143 753 | ) 754 | extra_args.append( 755 | "-D VTK_MODULE_ENABLE_VTK_ioss=NO", # Workaround for bug in Visual Studio MSVC 143 756 | ) 757 | 758 | print(" (VTK is big, this will take some time)") 759 | 760 | old_strict_mode = self.strict_mode 761 | self.strict_mode = False 762 | self._build_standard_cmake(extra_args) 763 | self.strict_mode = old_strict_mode 764 | 765 | def build_harfbuzz(self, _=None): 766 | if self.skip_existing: 767 | if os.path.exists(os.path.join(self.install_dir, "include", "harfbuzz")): 768 | print(" Not rebuilding harfbuzz, it is already in the LibPack") 769 | return 770 | self._build_standard_cmake() 771 | 772 | def build_libpng(self, _=None): 773 | if self.skip_existing: 774 | if os.path.exists(os.path.join(self.install_dir, "lib", "libpng")): 775 | print(" Not rebuilding libpng, it is already in the LibPack") 776 | return 777 | self._build_standard_cmake() 778 | 779 | def build_pybind11(self, _=None): 780 | if self.skip_existing: 781 | if os.path.exists(os.path.join(self.install_dir, "include", "pybind11")): 782 | print(" Not rebuilding pybind11, it is already in the LibPack") 783 | return 784 | self._build_standard_cmake() 785 | 786 | def build_freetype(self, _=None): 787 | if self.skip_existing: 788 | if os.path.exists(os.path.join(self.install_dir, "include", "freetype2")): 789 | print(" Not rebuilding freetype, it is already in the LibPack") 790 | return 791 | self._build_standard_cmake() 792 | if self.mode == BuildMode.DEBUG: 793 | # OCCT *really* wants these libraries named like this: 794 | shutil.copyfile( 795 | f"{self.install_dir}/bin/freetyped.dll", f"{self.install_dir}/bin/freetype.dll" 796 | ) 797 | shutil.copyfile( 798 | f"{self.install_dir}/lib/freetyped.lib", f"{self.install_dir}/lib/freetype.lib" 799 | ) 800 | 801 | def force_copy(self, src_components: List[str], dst_components: List[str]): 802 | full_src = self.install_dir 803 | for src in src_components: 804 | full_src = os.path.join(full_src, src) 805 | full_dst = self.install_dir 806 | for dst in dst_components: 807 | full_dst = os.path.join(full_dst, dst) 808 | if not os.path.exists(full_src): 809 | print(f" (Can't rename {full_src}, no such file or directory)") 810 | return 811 | if os.path.exists(full_dst): 812 | os.unlink(full_dst) 813 | shutil.copyfile(full_src, full_dst) 814 | 815 | def build_tcl(self, _=None): 816 | """tcl does not use cMake""" 817 | if self.skip_existing: 818 | if os.path.exists(os.path.join(self.install_dir, "include", "tcl.h")): 819 | print(" Not rebuilding tcl, it is already in the LibPack") 820 | return 821 | if sys.platform.startswith("win32"): 822 | try: 823 | os.chdir("win") 824 | args = [self.init_script, "&", "nmake", "/f", "makefile.vc", "release"] 825 | if self.mode == BuildMode.DEBUG: 826 | args.append("OPTS=symbols") 827 | subprocess.run(args, check=True, capture_output=True) 828 | args = [ 829 | self.init_script, 830 | "&", 831 | "nmake", 832 | "/f", 833 | "makefile.vc", 834 | "install", 835 | f"INSTALLDIR={self.install_dir}", 836 | ] 837 | if self.mode == BuildMode.DEBUG: 838 | args.append("OPTS=symbols") 839 | subprocess.run(args, check=True, capture_output=True) 840 | if self.mode == BuildMode.RELEASE: 841 | self.force_copy(["bin", "tclsh86t.exe"], ["bin", "tclsh.exe"]) 842 | self.force_copy(["bin", "tcl86t.dll"], ["bin", "tcl86.dll"]) 843 | self.force_copy(["lib", "tcl86t.lib"], ["lib", "tcl86.lib"]) 844 | else: 845 | self.force_copy(["bin", "tclsh86tg.exe"], ["bin", "tclsh.exe"]) 846 | self.force_copy(["bin", "tcl86tg.dll"], ["bin", "tcl86.dll"]) 847 | self.force_copy(["lib", "tcl86tg.lib"], ["lib", "tcl86.lib"]) 848 | except subprocess.CalledProcessError as e: 849 | print("ERROR: Failed to build tcl using nmake") 850 | print(e.stdout.decode("utf-8")) 851 | if e.stderr: 852 | print(e.stderr.decode("utf-8")) 853 | exit(1) 854 | else: 855 | raise NotImplemented("Non-Windows compilation of tcl is not implemented yet") 856 | 857 | def build_tk(self, _=None): 858 | """tk does not use cMake""" 859 | if self.skip_existing: 860 | if os.path.exists(os.path.join(self.install_dir, "include", "tk.h")): 861 | print(" Not rebuilding tk, it is already in the LibPack") 862 | return 863 | if sys.platform.startswith("win32"): 864 | try: 865 | os.chdir("win") 866 | args = [self.init_script, "&", "nmake", "/f", "makefile.vc", "release"] 867 | if self.mode == BuildMode.DEBUG: 868 | args.append("OPTS=symbols") 869 | subprocess.run(args, check=True, capture_output=True) 870 | args = [ 871 | self.init_script, 872 | "&", 873 | "nmake", 874 | "/f", 875 | "makefile.vc ", 876 | "install", 877 | f"INSTALLDIR={self.install_dir}", 878 | ] 879 | if self.mode == BuildMode.DEBUG: 880 | args.append("OPTS=symbols") 881 | subprocess.run(args, check=True, capture_output=True) 882 | if self.mode == BuildMode.RELEASE: 883 | self.force_copy(["bin", "wish86t.exe"], ["bin", "wish.exe"]) 884 | self.force_copy(["bin", "tk86t.dll"], ["bin", "tk86.dll"]) 885 | self.force_copy(["lib", "tk86t.lib"], ["lib", "tk86.lib"]) 886 | else: 887 | self.force_copy(["bin", "wish86tg.exe"], ["bin", "wish.exe"]) 888 | self.force_copy(["bin", "tk86tg.dll"], ["bin", "tk86.dll"]) 889 | self.force_copy(["lib", "tk86tg.lib"], ["lib", "tk86.lib"]) 890 | except subprocess.CalledProcessError as e: 891 | print("ERROR: Failed to build tk using nmake") 892 | print(e.output.decode("utf-8")) 893 | if e.stderr: 894 | print(e.stderr.decode("utf-8")) 895 | exit(1) 896 | else: 897 | raise NotImplemented("Non-Windows compilation of tk is not implemented yet") 898 | 899 | def build_rapidjson(self, _): 900 | if os.path.exists(os.path.join(self.install_dir, "include", "rapidjson")): 901 | if self.skip_existing: 902 | print(" Not re-copying RapidJSON, it is already in the LibPack") 903 | return 904 | shutil.rmtree(os.path.join(self.install_dir, "include", "rapidjson")) 905 | shutil.copytree("include", os.path.join(self.install_dir, "include"), dirs_exist_ok=True) 906 | 907 | def _get_vtk_include_path(self) -> str: 908 | """ 909 | OpenCASCADE needs a manually-set include path for VTK (the find_package script provided by VTK does not provide 910 | the include file path, and OpenCASCADE has not been updated to handle this, as of June 2024). 911 | """ 912 | start_crawl_at = os.path.join(self.install_dir, "include") 913 | contents = [ 914 | f for f in os.listdir(start_crawl_at) if os.path.isdir(os.path.join(start_crawl_at, f)) 915 | ] 916 | for item in contents: 917 | if item.startswith("vtk-"): 918 | return os.path.join(start_crawl_at, item) 919 | raise RuntimeError("Could not find VTK include directory for OpenCASCADE") 920 | 921 | def build_opencascade(self, _=None): 922 | if self.skip_existing: 923 | if os.path.exists(os.path.join(self.install_dir, "cmake", "OpenCASCADEConfig.cmake")): 924 | print(" Not rebuilding OpenCASCADE, it is already in the LibPack") 925 | return 926 | extra_args = [ 927 | f"-D CMAKE_MODULE_PATH={self.install_dir}/lib/cmake;{self.install_dir}/share/cmake;{self.install_dir}" 928 | f"-D TCL_DIR={self.install_dir}/include", 929 | f"-D TK_DIR={self.install_dir}/include", 930 | f"-D FREETYPE_DIR={self.install_dir}/lib/cmake", 931 | f"-D VTK_DIR={self.install_dir}/lib/cmake", 932 | f"-D 3RDPARTY_VTK_INCLUDE_DIRS={self._get_vtk_include_path()}", 933 | f"-D EIGEN_DIR={self.install_dir}/share/eigen3/cmake", 934 | "-D USE_VTK=On", 935 | "-D USE_FREETYPE=On" "-D USE_RAPIDJSON=On", 936 | "-D USE_EIGEN=On" "-D BUILD_CPP_STANDARD=C++17", 937 | "-D BUILD_RELEASE_DISABLE_EXCEPTIONS=OFF", 938 | "-D INSTALL_DIR_BIN=bin", 939 | "-D INSTALL_DIR_LIB=lib", 940 | ] 941 | if self.mode == BuildMode.DEBUG: 942 | extra_args.append("-D BUILD_SHARED_LIBRARY_NAME_POSTFIX=d") 943 | cwd = os.getcwd() 944 | self._cmake_create_build_dir() 945 | self._cmake_configure(extra_args) 946 | self._cmake_build(parallel=False) 947 | if self.mode == BuildMode.DEBUG and sys.platform.startswith("win32"): 948 | # On Windows OpenCASCADE is looking in the wrong location for these files (as of 7.7.1) -- just copy them 949 | # TODO - Don't hardcode the path 950 | shutil.copytree( 951 | os.path.join("win64", "vc14", "bind"), os.path.join("win64", "vc14", "bin") 952 | ) 953 | self._cmake_install() 954 | 955 | os.chdir(cwd) 956 | 957 | # TODO - something is getting messed up in the CMake config output (note the quotes around 26812): for now just 958 | # drop the line entirely 959 | # set (OpenCASCADE_CXX_FLAGS "[...] /wd"26812" /MP /W4") 960 | with open( 961 | os.path.join(self.install_dir, "cmake", "OpenCASCADEConfig.cmake"), 962 | "r", 963 | encoding="utf-8", 964 | ) as f: 965 | occt_cmake_contents = f.readlines() 966 | with open( 967 | os.path.join(self.install_dir, "cmake", "OpenCASCADEConfig.cmake"), 968 | "w", 969 | encoding="utf-8", 970 | ) as f: 971 | for line in occt_cmake_contents: 972 | if "OpenCASCADE_CXX_FLAGS" not in line: 973 | f.write(line + "\n") 974 | 975 | def build_netgen(self, _: None): 976 | if self.skip_existing: 977 | if os.path.exists(os.path.join(self.install_dir, "share", "netgen")): 978 | print(" Not rebuilding netgen, it is already in the LibPack") 979 | return 980 | extra_args = [ 981 | f"-D CMAKE_FIND_ROOT_PATH={self.install_dir}", 982 | "-D USE_SUPERBUILD=OFF", 983 | "-D USE_GUI=OFF", 984 | "-D USE_NATIVE_ARCH=OFF", 985 | "-D USE_INTERNAL_TCL=OFF", 986 | f"-D TCL_DIR={self.install_dir}", 987 | f"-D TK_DIR={self.install_dir}", 988 | "-D USE_OCC=On", 989 | f"-D OpenCASCADE_ROOT={self.install_dir}", 990 | f"-D USE_PYTHON=OFF", 991 | f"-D CMAKE_CXX_FLAGS='-D_USE_MATH_DEFINES /EHsc'", 992 | ] # To get M_PI on MSVC 993 | self._build_standard_cmake(extra_args=extra_args) 994 | 995 | def build_hdf5(self, _: None): 996 | if self.skip_existing: 997 | if os.path.exists(os.path.join(self.install_dir, "include", "hdf5.h")): 998 | print(" Not rebuilding hdf5, it is already in the LibPack") 999 | return 1000 | # HDF5 is VERY picky about how you specify the location of zlib: you must actually set the precise path to the 1001 | # library file itself. TODO future work to internally detect that library name and path and fill them here 1002 | extra_args = [ 1003 | f"-D ZLIB_INCLUDE_DIR={self.install_dir}/include", 1004 | f"-D ZLIB_LIBRARY={self.install_dir}/lib/zlib.lib", 1005 | ] 1006 | self._build_standard_cmake(extra_args) 1007 | 1008 | def build_medfile(self, _: None): 1009 | if self.skip_existing: 1010 | if os.path.exists(os.path.join(self.install_dir, "include", "medfile.h")): 1011 | print(" Not rebuilding medfile, it is already in the LibPack") 1012 | return 1013 | extra_args = ["-D MEDFILE_USE_UNICODE=On", "-D MEDFILE_BUILD_TESTS=OFF"] 1014 | old_strict_mode = self.strict_mode 1015 | self.strict_mode = False 1016 | self._build_standard_cmake(extra_args) 1017 | self.strict_mode = old_strict_mode 1018 | 1019 | def build_gmsh(self, _: None): 1020 | if self.skip_existing: 1021 | if os.path.exists(os.path.join(self.install_dir, "bin", "gmsh" + to_exe())): 1022 | print(" Not rebuilding gmsh, it is already in the LibPack") 1023 | return 1024 | extra_args = [] 1025 | if sys.platform.startswith("win32"): 1026 | extra_args = [ 1027 | f"-D CMAKE_LIBRARY_PATH={self.install_dir}/win64/vc14/lib", # TODO - Remove hardcoding 1028 | "-D ENABLE_OPENMP=No", 1029 | ] # Build fails if OpenMP is enabled 1030 | self._build_standard_cmake(extra_args) 1031 | 1032 | def build_pycxx(self, _: None): 1033 | """PyCXX does not use a cMake-based build system""" 1034 | if self.skip_existing: 1035 | if os.path.exists(os.path.join(self.install_dir, "bin", "Lib", "site-packages", "CXX")): 1036 | print(" Not rebuilding PyCXX, it is already in the LibPack") 1037 | return 1038 | path_to_python = self.python_exe() 1039 | args = [path_to_python, "setup.py", "install"] 1040 | try: 1041 | subprocess.run(args, check=True, capture_output=True) 1042 | except subprocess.CalledProcessError as e: 1043 | print("ERROR: Failed to build PyCXX using its custom build script") 1044 | print(e.output.decode("utf-8")) 1045 | if e.stderr: 1046 | print(e.stderr.decode("utf-8")) 1047 | exit(1) 1048 | 1049 | def build_icu(self, _: None): 1050 | """ICU does not use cMake, but has projects for various OSes""" 1051 | if self.skip_existing: 1052 | if os.path.exists(os.path.join(self.install_dir, "include", "unicode")): 1053 | print(" Not rebuilding ICU, it is already in the LibPack") 1054 | return 1055 | 1056 | os.chdir(os.path.join("icu4c", "source")) 1057 | if sys.platform.startswith("win32"): 1058 | os.chdir("allinone") 1059 | args = [ 1060 | self.init_script, 1061 | "&", 1062 | "msbuild", 1063 | f"/p:Configuration={str(self.mode).lower()}", 1064 | "/t:Build", 1065 | "/p:Platform=x64", # TODO unhardcode 1066 | "/p:SkipUWP=true", 1067 | "allinone.sln", 1068 | ] 1069 | try: 1070 | subprocess.run(args, check=True, capture_output=True) 1071 | except subprocess.CalledProcessError as e: 1072 | print("ERROR: Failed to build ICU using its custom build script") 1073 | print(e.output.decode("utf-8")) 1074 | if e.stderr: 1075 | print(e.stderr.decode("utf-8")) 1076 | exit(1) 1077 | os.chdir(os.path.join("..", "..")) 1078 | bin_dir = os.path.join(self.install_dir, "bin") 1079 | lib_dir = os.path.join(self.install_dir, "lib") 1080 | inc_dir = os.path.join(self.install_dir, "include") 1081 | shutil.copytree(f"bin64", bin_dir, dirs_exist_ok=True) 1082 | shutil.copytree(f"lib64", lib_dir, dirs_exist_ok=True) 1083 | shutil.copytree(f"include", inc_dir, dirs_exist_ok=True) 1084 | else: 1085 | raise NotImplemented("Non-Windows compilation of ICU is not implemented yet") 1086 | 1087 | def build_xercesc(self, _: None): 1088 | if self.skip_existing: 1089 | if os.path.exists(os.path.join(self.install_dir, "include", "xercesc")): 1090 | print(" Not rebuilding xerces-c, it is already in the LibPack") 1091 | return 1092 | extra_args = [ 1093 | f"-D ICU_INCLUDE_DIR={self.install_dir}/include", 1094 | f"-D ICU_ROOT={self.install_dir}", 1095 | f"-D ICU_UC_DIR={self.install_dir}", 1096 | ] 1097 | self._build_standard_cmake(extra_args) 1098 | 1099 | def build_libfmt(self, _: None): 1100 | if self.skip_existing: 1101 | if os.path.exists(os.path.join(self.install_dir, "include", "fmt")): 1102 | print(" Not rebuilding libfmt, it is already in the LibPack") 1103 | return 1104 | extra_args = ["-D FMT_TEST=OFF", "-D FMT_DOC=OFF"] 1105 | self._build_standard_cmake(extra_args) 1106 | 1107 | def build_eigen3(self, _: None): 1108 | if self.skip_existing: 1109 | if os.path.exists(os.path.join(self.install_dir, "include", "eigen3")): 1110 | print(" Not rebuilding Eigen3, it is already in the LibPack") 1111 | return 1112 | self._build_standard_cmake() 1113 | 1114 | def build_yamlcpp(self, _: None): 1115 | if self.skip_existing: 1116 | if os.path.exists(os.path.join(self.install_dir, "include", "yaml-cpp")): 1117 | print(" Not rebuilding yaml-cpp, it is already in the LibPack") 1118 | return 1119 | extra_args = ["-D YAML_BUILD_SHARED_LIBS=ON"] 1120 | self._build_standard_cmake(extra_args) 1121 | 1122 | def build_opencamlib(self, _: None): 1123 | if self.skip_existing: 1124 | if os.path.exists( 1125 | os.path.join(self.install_dir, "bin", "Lib", "site-packages", "opencamlib") 1126 | ): 1127 | print(" Not rebuilding opencamlib, it is already in the LibPack") 1128 | return 1129 | extra_args = ["-D BUILD_CXX_LIB=OFF", "-D BUILD_PY_LIB=ON", "-D BUILD_DOC=OFF"] 1130 | self._build_standard_cmake(extra_args) 1131 | 1132 | def build_calculix(self, _: None): 1133 | """Cannot currently build Calculix (it's in Fortran, and we only support MSVC toolchain right now). Extract 1134 | the relevant files from the downloaded zipfile and copy them""" 1135 | if self.skip_existing: 1136 | if os.path.exists(os.path.join(self.install_dir, "bin", "ccx.exe")): 1137 | print(" Not rebuilding Calculix, it is already in the LibPack") 1138 | return 1139 | path_to_ccx_bin = os.path.join(os.getcwd(), "CL35-win64", "bin", "ccx", "218") 1140 | if not os.path.exists(path_to_ccx_bin): 1141 | raise RuntimeError("Could not locate Calculix") 1142 | shutil.copytree(path_to_ccx_bin, os.path.join(self.install_dir, "bin"), dirs_exist_ok=True) 1143 | # The download we use calls the executable ccx218.exe, but FreeCAD would prefer it be called ccx.exe for 1144 | # automatic location of the executable 1145 | shutil.move( 1146 | os.path.join(self.install_dir, "bin", "ccx218.exe"), 1147 | os.path.join(self.install_dir, "bin", "ccx.exe"), 1148 | ) 1149 | 1150 | def build_libE57Format(self, _: None): 1151 | if self.skip_existing: 1152 | if os.path.exists(os.path.join(self.install_dir, "include", "E57Format")): 1153 | print(" Not rebuilding libE57Format, it is already in the LibPack") 1154 | return 1155 | extra_args = ["-D E57_BUILD_TEST=OFF"] 1156 | self._build_standard_cmake(extra_args) 1157 | 1158 | def build_googletest(self, _: None): 1159 | if self.skip_existing: 1160 | if os.path.exists(os.path.join(self.install_dir, "include", "gtest")): 1161 | print(" Not rebuilding googletest, it is already in the LibPack") 1162 | return 1163 | extra_args = [] 1164 | if sys.platform == "win32": 1165 | extra_args.extend(["-D GTEST_FORCE_SHARED_CRT=ON", "-D GTEST_DISABLE_PTHREADS=ON"]) 1166 | self._build_standard_cmake(extra_args) 1167 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "FreeCAD-version":"1.1.0", 3 | "LibPack-version":"3.1.1.3", 4 | "content": [ 5 | { 6 | "name":"python", 7 | "git-repo":"https://github.com/python/cpython.git", 8 | "git-ref":"v3.12.10", 9 | "note1": "As of 19 November 2024, IfcOpenShell did not support Python 3.13", 10 | "note2": "pynastran 1.4.1 depends on numpy<2", 11 | "requirements": [ 12 | "area==1.1.1", 13 | "cmake==3.31.0.1", 14 | "cog==0.13.2", 15 | "configparser==7.1.0", 16 | "debugpy==1.8.8", 17 | "defusedxml==0.7.1", 18 | "ifcopenshell==0.8.1.post1", 19 | "ladybug-core==0.43.18", 20 | "matplotlib==3.9.2", 21 | "numpy==1.26.4", 22 | "opencv-python==4.10.0.84", 23 | "packaging==24.2", 24 | "pip==25.0.1", 25 | "pillow==11.0.0", 26 | "ply==3.11", 27 | "pycollada==0.8", 28 | "pyNastran==1.4.1", 29 | "pyshp==2.3.1", 30 | "pysolar==0.11", 31 | "PyYAML==6.0.2", 32 | "requests==2.32.3", 33 | "rpdb2==2.0.0.1.2", 34 | "scipy==1.14.1", 35 | "sets==0.3.2", 36 | "setuptools==75.5.0", 37 | "vermin==1.6.0", 38 | "wheel==0.45.0" 39 | ] 40 | }, 41 | { 42 | "name":"zlib", 43 | "git-repo":"https://github.com/madler/zlib", 44 | "git-ref":"v1.3.1" 45 | }, 46 | { 47 | "name":"qt", 48 | "install-directory":"G:\\Qt\\6.8.3\\msvc2022_64" 49 | }, 50 | { 51 | "name":"bzip2", 52 | "git-repo":"https://gitlab.com/bzip2/bzip2.git", 53 | "git-ref":"bzip2-1.0.8" 54 | }, 55 | { 56 | "name":"libpng", 57 | "git-repo":"https://github.com/glennrp/libpng", 58 | "git-ref":"v1.6.47" 59 | }, 60 | { 61 | "name":"pybind11", 62 | "git-repo":"https://github.com/pybind/pybind11", 63 | "git-ref":"v2.13.6" 64 | }, 65 | { 66 | "name": "boost", 67 | "git-repo": "https://github.com/boostorg/boost", 68 | "git-ref": "boost-1.87.0" 69 | }, 70 | { 71 | "name":"coin", 72 | "git-repo":"https://github.com/coin3d/coin", 73 | "git-ref":"master" 74 | }, 75 | { 76 | "name":"quarter", 77 | "git-repo":"https://github.com/coin3d/quarter", 78 | "git-ref":"master", 79 | "patches":["patches/quarter-01-add-QOpenGLContext-to-QuarterWidgetP.patch"] 80 | }, 81 | { 82 | "name":"pcre2", 83 | "git-repo":"https://github.com/PCRE2Project/pcre2", 84 | "git-ref":"pcre2-10.45" 85 | }, 86 | { 87 | "name":"swig", 88 | "git-repo":"https://github.com/swig/swig.git", 89 | "git-tag":"v4.3.0" 90 | }, 91 | { 92 | "name":"pivy", 93 | "git-repo":"https://github.com/coin3d/pivy", 94 | "git-ref":"0.6.9", 95 | "patches": ["patches/pivy-01-add-python-libraries.patch"] 96 | }, 97 | { 98 | "name":"libclang", 99 | "url":"https://download.qt.io/development_releases/prebuilt/libclang/libclang-release_19.1.0-based-windows-vs2019_64.7z" 100 | }, 101 | { 102 | "name":"pyside", 103 | "git-repo": "http://code.qt.io/pyside/pyside-setup", 104 | "git-ref": "6.8.3" 105 | }, 106 | { 107 | "name":"vtk", 108 | "git-repo":"https://gitlab.kitware.com/vtk/vtk.git", 109 | "git-ref":"v9.4.2", 110 | "note": "checkout is failing, have to manually clone for now" 111 | }, 112 | { 113 | "name":"harfbuzz", 114 | "git-repo":"https://github.com/harfbuzz/harfbuzz", 115 | "git-ref":"10.4.0" 116 | }, 117 | { 118 | "name":"freetype", 119 | "git-repo":"https://gitlab.freedesktop.org/freetype/freetype/", 120 | "git-ref":"VER-2-13-3" 121 | }, 122 | { 123 | "name":"tcl", 124 | "git-repo":"https://github.com/tcltk/tcl", 125 | "git-ref":"core-8-6-15" 126 | }, 127 | { 128 | "name":"tk", 129 | "git-repo":"https://github.com/tcltk/tk", 130 | "git-ref":"core-8-6-15" 131 | }, 132 | { 133 | "name": "rapidjson", 134 | "git-repo":"https://github.com/Tencent/rapidjson", 135 | "git-ref":"v1.1.0" 136 | }, 137 | { 138 | "name":"eigen3", 139 | "git-repo":"https://gitlab.com/libeigen/eigen", 140 | "git-ref":"3.4.0" 141 | }, 142 | { 143 | "name":"opencascade", 144 | "git-repo":"https://github.com/FreeCAD/OCCT", 145 | "git-ref":"patched", 146 | "patches": ["patches/opencascade-01-StdPrs_BRepFont.patch"] 147 | }, 148 | { 149 | "name":"netgen", 150 | "git-repo":"https://github.com/NGSolve/netgen", 151 | "git-ref":"v6.2.2404", 152 | "patches": ["patches/netgen-01-python-file-include-order.patch"] 153 | }, 154 | { 155 | "name":"hdf5", 156 | "git-repo":"https://github.com/HDFGroup/hdf5", 157 | "git-ref":"hdf5-1_12_3", 158 | "note":"Salome medfile 5.0.0 requires HDF5 1.12.x, no later version may be used" 159 | }, 160 | { 161 | "name":"medfile", 162 | "git-repo":"https://github.com/chennes/med", 163 | "git-ref":"v5.0.0", 164 | "patches": ["patches/medfile-01-const_cast_argv.patch"] 165 | }, 166 | { 167 | "name":"gmsh", 168 | "git-repo":"https://gitlab.onelab.info/gmsh/gmsh", 169 | "git-ref":"gmsh_4_13_1" 170 | }, 171 | { 172 | "name":"pycxx", 173 | "git-repo":"https://github.com/montylab3d/pycxx", 174 | "git-ref":"7.1.5" 175 | }, 176 | { 177 | "name":"icu", 178 | "git-repo":"https://github.com/unicode-org/icu", 179 | "git-ref":"release-74-2", 180 | "note":"Cannot yet use the 75.x series, compilation of Xerces 3.2.5 fails against them", 181 | "patches": ["patches/icu-01-remove_makedata_target.patch"] 182 | }, 183 | { 184 | "name":"xercesc", 185 | "git-repo":"https://github.com/apache/xerces-c", 186 | "git-ref":"v3.2.5", 187 | "note": "Compilation of v3.3.0 is failing under MSVC 143 as of this writing" 188 | }, 189 | { 190 | "name":"libfmt", 191 | "git-repo":"https://github.com/fmtlib/fmt", 192 | "git-ref":"11.0.2" 193 | }, 194 | { 195 | "name": "yamlcpp", 196 | "git-repo": "https://github.com/jbeder/yaml-cpp", 197 | "git-ref":"0.8.0" 198 | }, 199 | { 200 | "name": "opencamlib", 201 | "git-repo": "https://github.com/aewallin/opencamlib", 202 | "git-ref": "2023.01.11" 203 | }, 204 | { 205 | "name":"calculix", 206 | "url":"https://drive.usercontent.google.com/download?id=1Z8Mnx9-tyPdPlRi9kdPkFqZhTVA1uemY&export=download&authuser=0&confirm=t&uuid=1808e0cb-38d9-43ea-beea-619109a11527&at=APZUnTWlTXR23jpMPcF6-LBcbOaN:1720405069050", 207 | "note":"Difficult to compile with an MSVC toolchain because it is written in Fortran. Direct download link here is from http://calculixforwin.blogspot.com/2015/05/calculix-launcher.html" 208 | }, 209 | { 210 | "name": "libE57Format", 211 | "git-repo": "https://github.com/asmaloney/libE57Format", 212 | "git-ref": "master", 213 | "note": "Using master branch as of march 2025 because no official release includes proper CMake support yet" 214 | }, 215 | { 216 | "name": "googletest", 217 | "git-repo": "https://github.com/google/googletest", 218 | "git-ref": "main" 219 | } 220 | ] 221 | } 222 | -------------------------------------------------------------------------------- /create_libpack.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later 4 | 5 | # Prerequisites: 6 | # * Network access 7 | # * A working compiler toolchain for your system, accessible by cMake 8 | # * CMake 9 | # * git 10 | # * 7z (see https://www.7-zip.org) 11 | # * Some version of Python that can run this file 12 | # * The "requests" Python package (e.g. 'pip install requests') 13 | # * The "diff-match-patch" Python package (e.g. 'pip install diff-match-patch') 14 | # * Qt - the base installation plus Qt Image Formats, Qt Webengine, Qt Webview, and Qt PDF 15 | # * GNU Bison (for Windows see https://github.com/lexxmark/winflexbison/) 16 | 17 | # Note about Python: Python includes the following dependencies when built on Windows (as of v3.11.5) 18 | # bzip2 19 | # sqlite 20 | # xz 21 | # zlib 22 | # libffi 23 | # openssl-bin 24 | # tcltk 25 | # At present these are not re-used to create the rest of the LibPack -- if needed, they are rebuilt from source 26 | 27 | import argparse 28 | from contextlib import contextmanager 29 | import ctypes 30 | import json 31 | import os 32 | import platform 33 | import shutil 34 | import stat 35 | import subprocess 36 | import tarfile 37 | from urllib.parse import urlparse 38 | import path_cleaner 39 | 40 | try: 41 | import requests 42 | except ImportError: 43 | print("Please pip --install requests") 44 | exit(1) 45 | 46 | try: 47 | import diff_match_patch 48 | except ImportError: 49 | print("Please pip --install diff-match-patch") 50 | exit(1) 51 | 52 | import compile_all 53 | 54 | path_to_7zip = "C:\\Program Files\\7-Zip\\7z.exe" 55 | path_to_bison = "C:\\Program Files\\win_flex_bison\\win_bison.exe" 56 | devel_init_script = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat" 57 | 58 | 59 | def remove_readonly(func, path, _) -> None: 60 | """Remove a read-only file.""" 61 | 62 | os.chmod(path, stat.S_IWRITE) 63 | func(path) 64 | 65 | 66 | def delete_existing(path: str, silent: bool = False): 67 | """Delete a directory tree, with optional confirmation sequence""" 68 | if os.path.exists(path): 69 | if not silent: 70 | response = input(f"Really delete entire path {path}? y/N ") 71 | if response.lower() != "y": 72 | print(f"NOT removing {path}") 73 | return 74 | print(f"Removing {path} prior to beginning") 75 | shutil.rmtree(path, onerror=remove_readonly) 76 | 77 | 78 | def load_config(path: str) -> dict: 79 | """Load a JSON-formatted configuration file for this utility""" 80 | if not os.path.exists(path): 81 | print(f"ERROR: No such config file '{path}'") 82 | exit(1) 83 | with open(path, "r", encoding="utf-8") as f: 84 | config_data = f.read() 85 | try: 86 | return json.loads(config_data) 87 | except json.JSONDecodeError: 88 | print("ERROR: The config file does not contain valid JSON data") 89 | exit(1) 90 | 91 | 92 | def create_libpack_dir(config: dict, mode: compile_all.BuildMode) -> str: 93 | """Create a new directory for this LibPack compilation, using the version of FreeCAD, the version of 94 | the LibPack, and whether it's in release or debug mode. Returns the name of the created directory. 95 | """ 96 | 97 | dirname = compile_all.libpack_dir(config, mode) 98 | if os.path.exists(dirname): 99 | backup_name = dirname + "-backup-" + "a" 100 | while os.path.exists(backup_name): 101 | if backup_name[-1] == "z": 102 | print( 103 | "You have too many old LibPack backup directories. Please delete some of them." 104 | ) 105 | exit(1) 106 | backup_name = backup_name[:-1] + chr(ord(backup_name[-1]) + 1) 107 | 108 | os.rename(dirname, backup_name) 109 | if not os.path.exists(dirname): 110 | os.mkdir(dirname) 111 | dirname = os.path.join(dirname, "bin") 112 | if not os.path.exists(dirname): 113 | os.mkdir(dirname) 114 | return dirname 115 | 116 | 117 | def fetch_remote_data(config: dict, skip_existing: bool = False): 118 | """Clone the required repos and download the URLs""" 119 | content = config["content"] 120 | for item in content: 121 | if skip_existing and os.path.exists(item["name"]): 122 | continue 123 | if "git-repo" in item and "git-ref" in item: 124 | clone(item["name"], item["git-repo"], item["git-ref"]) 125 | elif "git-repo" in item: 126 | clone(item["name"], item["git-repo"]) 127 | elif "git-ref" in item: 128 | print(f"ERROR: found a git ref without a git repo for {item['name']}") 129 | exit() 130 | elif "url" in item: 131 | download(item["name"], item["url"]) 132 | else: 133 | # Just make the directory, presumably later code will know what to do 134 | os.makedirs(item["name"], exist_ok=True) 135 | if "patches" in item: 136 | cwd = os.getcwd() 137 | os.chdir(item["name"]) 138 | compile_all.patch_files(item["patches"]) 139 | os.chdir(cwd) 140 | 141 | 142 | def clone(name: str, url: str, ref: str = None): 143 | """Shallow clones a git repo at the given ref using a system-installed git""" 144 | try: 145 | if ref is None: 146 | print(f"Cloning {url}") 147 | else: 148 | print(f"Cloning {url} at {ref}") 149 | args = ["git", "clone"] 150 | if ref is not None: 151 | args.extend(["--branch", ref]) 152 | args.extend(["--depth", "1", "--recurse-submodules", url, name]) 153 | subprocess.run(args, capture_output=True, check=True) 154 | except subprocess.CalledProcessError as e: 155 | print(f"ERROR: failed to clone git repo {url} at ref {ref}") 156 | print(e.output) 157 | exit(e.returncode) 158 | 159 | 160 | def download(name: str, url: str): 161 | """Directly downloads some sort of compressed format file and decompresses it (either using an internal 162 | python method, or using a system-installed 7-zip)""" 163 | print(f"Downloading {name} from {url}") 164 | os.mkdir(name) 165 | request_result = requests.get(url) 166 | parsed_url = urlparse(url) 167 | filename = parsed_url.path.rsplit("/", 1)[-1] 168 | with open(os.path.join(name, filename), "wb") as f: 169 | f.write(request_result.content) 170 | decompress(name, filename) 171 | 172 | 173 | def decompress(name: str, filename: str): 174 | original_dir = os.getcwd() 175 | os.chdir(name) 176 | if filename.endswith("7z") or filename.endswith("7zip"): 177 | try: 178 | subprocess.run([path_to_7zip, "x", filename], capture_output=True, check=True) 179 | except subprocess.CalledProcessError as e: 180 | print("ERROR: failed to unzip {filename} at from {name} using {path_to_7zip}") 181 | print(e.output) 182 | exit(e.returncode) 183 | elif ( 184 | filename.endswith(".tar.gz") 185 | or filename.endswith(".tar.bz2") 186 | or filename.endswith(".tar.xz") 187 | ): 188 | try: 189 | with tarfile.open(filename) as f: 190 | f.extractall(filter="data") 191 | except tarfile.TarError as e: 192 | print(e) 193 | exit(1) 194 | else: # Try to use 7-zip to see if it's something understandable to that program 195 | try: 196 | subprocess.run([path_to_7zip, "x", filename], capture_output=True, check=True) 197 | except subprocess.CalledProcessError as e: 198 | print("ERROR: failed to unzip {filename} at from {name} using {path_to_7zip}") 199 | print(e.output) 200 | exit(e.returncode) 201 | os.chdir(original_dir) 202 | 203 | 204 | def write_manifest(outer_config: dict, mode_used: compile_all.BuildMode): 205 | manifest_file = os.path.join(compile_all.libpack_dir(outer_config, mode_used), "manifest.json") 206 | with open(manifest_file, "w", encoding="utf-8") as f: 207 | f.write(json.dumps(outer_config["content"], indent=" ")) 208 | version_file = os.path.join( 209 | compile_all.libpack_dir(outer_config, mode_used), "FREECAD_LIBPACK_VERSION" 210 | ) 211 | with open(version_file, "w", encoding="utf-8") as f: 212 | f.write(outer_config["LibPack-version"]) 213 | 214 | 215 | @contextmanager 216 | def prevent_sleep_mode(): 217 | system = platform.system() 218 | proc = None 219 | 220 | try: 221 | if system == "Windows": 222 | # Prevent sleep & display off 223 | ctypes.windll.kernel32.SetThreadExecutionState(0x80000000 | 0x00000001 | 0x00000002) 224 | 225 | elif system == "Darwin": # macOS 226 | # Use built-in caffeinate command 227 | proc = subprocess.Popen(["caffeinate"]) 228 | 229 | elif system == "Linux": 230 | # Use systemd-inhibit to prevent sleep 231 | proc = subprocess.Popen( 232 | ["systemd-inhibit", "--why=LibPack build", "--mode=block", "sleep", "infinity"] 233 | ) 234 | 235 | yield 236 | 237 | finally: 238 | if system == "Windows": 239 | ctypes.windll.kernel32.SetThreadExecutionState(0x80000000) 240 | elif proc: 241 | proc.terminate() 242 | 243 | 244 | if __name__ == "__main__": 245 | parser = argparse.ArgumentParser( 246 | description="Builds a collection of FreeCAD dependencies for the current system" 247 | ) 248 | parser.add_argument( 249 | "-m", 250 | "--mode", 251 | help="'release' or 'debug''", 252 | default="release", 253 | ) 254 | parser.add_argument( 255 | "-c", 256 | "--config", 257 | help="Path to a JSON configuration file for this utility", 258 | default="./config.json", 259 | ) 260 | parser.add_argument( 261 | "-w", 262 | "--working", 263 | help="Directory to put all the clones and downloads in", 264 | default="./working", 265 | ) 266 | parser.add_argument( 267 | "-e", 268 | "--no-skip-existing-clone", 269 | action="store_false", 270 | help="If a given clone (or download) directory exists, delete it and download it again", 271 | ) 272 | parser.add_argument( 273 | "-b", 274 | "--no-skip-existing-build", 275 | action="store_false", 276 | help="If a given build already exists, run the build process again anyway", 277 | ) 278 | parser.add_argument( 279 | "-s", 280 | "--silent", 281 | action="store_true", 282 | help="I kow what I'm doing, don't ask me any questions", 283 | ) 284 | parser.add_argument("--7zip", help="Path to 7-zip executable", default=path_to_7zip) 285 | parser.add_argument("--bison", help="Path to Bison executable", default=path_to_bison) 286 | parser.add_argument("path-to-final-libpack-dir", nargs="?", default="./") 287 | args = vars(parser.parse_args()) 288 | 289 | config_dict = load_config(args["config"]) 290 | path_to_7zip = args["7zip"] 291 | path_to_bison = args["bison"] 292 | 293 | os.makedirs("working", exist_ok=True) 294 | os.chdir("working") 295 | mode = ( 296 | compile_all.BuildMode.DEBUG 297 | if args["mode"].lower() == "debug" 298 | else compile_all.BuildMode.RELEASE 299 | ) 300 | if args["no_skip_existing_clone"]: 301 | dirname = compile_all.libpack_dir(config_dict, mode) 302 | if not os.path.exists(dirname): 303 | base = create_libpack_dir(config_dict, mode) 304 | else: 305 | base = dirname 306 | else: 307 | base = create_libpack_dir(config_dict, mode) 308 | with prevent_sleep_mode(): 309 | fetch_remote_data(config_dict, args["no_skip_existing_clone"]) 310 | 311 | compiler = compile_all.Compiler( 312 | config_dict, 313 | bison_path=path_to_bison, 314 | skip_existing=args["no_skip_existing_build"], 315 | mode=mode, 316 | ) 317 | compiler.init_script = devel_init_script 318 | compiler.compile_all() 319 | 320 | # Final cleanup: delete extraneous files and remove local path references from the cMake files 321 | base_path = compile_all.libpack_dir(config_dict, mode) 322 | path_cleaner.delete_extraneous_files(base_path) 323 | path_cleaner.remove_local_path_from_cmake_files(base_path) 324 | path_cleaner.correct_opencascade_freetype_ref(base_path) 325 | path_cleaner.delete_qtwebengine(base_path) 326 | # path_cleaner.delete_qtquick(base_path) 327 | path_cleaner.delete_llvm_executables(base_path) 328 | path_cleaner.delete_clang_executables(base_path) 329 | 330 | write_manifest(config_dict, mode) 331 | -------------------------------------------------------------------------------- /generate_patch.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: LGPL-2.1-or-later 2 | 3 | import diff_match_patch 4 | import sys 5 | 6 | 7 | def print_usage(): 8 | print( 9 | "Generate a patchfile that can be used with the create_libpack.py script to patch source files" 10 | ) 11 | print("Usage: python generate_patch.py original_file corrected_file output_patch_file") 12 | 13 | 14 | def parse_args(): 15 | if len(sys.argv) != 4: 16 | print_usage() 17 | exit(1) 18 | 19 | 20 | def generate_patch(old, new) -> str: 21 | dmp = diff_match_patch.diff_match_patch() 22 | patches = dmp.patch_make(old, new) 23 | return dmp.patch_toText(patches) 24 | 25 | 26 | def run(old_file, new_file, output_file): 27 | with open(old_file, "r", encoding="utf-8") as f: 28 | old = f.read() 29 | with open(new_file, "r", encoding="utf-8") as f: 30 | new = f.read() 31 | patch = generate_patch(old, new) 32 | with open(output_file, "w", encoding="utf-8") as f: 33 | f.write(f"@@@ {old_file} @@@\n") 34 | f.write(patch) 35 | 36 | 37 | if __name__ == "__main__": 38 | parse_args() 39 | run(sys.argv[1], sys.argv[2], sys.argv[3]) 40 | -------------------------------------------------------------------------------- /patches/icu-01-remove_makedata_target.patch: -------------------------------------------------------------------------------- 1 | @@@ icu4c/source/allinone/allinone.sln @@@ 2 | @@ -6375,152 +6375,8 @@ 3 | ect%0A 4 | -Project(%22%7B8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942%7D%22) = %22makedata%22, %22..%5Cdata%5Cmakedata.vcxproj%22, %22%7BD9DF7F2F-93B7-4810-B5CD-96F4F33C079B%7D%22%0AEndProject%0A 5 | Proj 6 | @@ -12094,160 +12094,8 @@ 7 | ect%0A 8 | -Project(%22%7B8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942%7D%22) = %22makedata_uwp%22, %22..%5Cdata%5Cmakedata_uwp.vcxproj%22, %22%7BB1D53358-37BD-48BC-B27C-68BAF1E78508%7D%22%0AEndProject%0A 9 | Proj 10 | -------------------------------------------------------------------------------- /patches/medfile-01-const_cast_argv.patch: -------------------------------------------------------------------------------- 1 | @@@ tools/medimport/medimportcxx.cxx @@@ 2 | @@ -836,26 +836,8 @@ 3 | %7B%0A%0A 4 | - char * fileOut;%0A 5 | in 6 | @@ -1000,57 +1000,174 @@ 7 | %7D%0A 8 | -if (argc == 2 ) fileOut=%22%22; else 9 | +char fileOut%5B4096%5D;%0A if (argc == 2 ) %7B%0A strncpy(fileOut, %22%22, 1);%0A %7D else %7B%0A strncpy( 10 | fileOut 11 | -= 12 | +, 13 | argv%5B2%5D 14 | -; 15 | +, strlen(argv%5B2%5D)+1); // Include the terminating null%0A %7D 16 | %0A%0A 17 | @@ -1195,16 +1195,36 @@ 18 | port 19 | +(const_cast%3Cchar *%3E 20 | (argv%5B1%5D 21 | , fi 22 | @@ -1219,16 +1219,17 @@ 23 | (argv%5B1%5D 24 | +) 25 | , fileOu 26 | -------------------------------------------------------------------------------- /patches/netgen-01-compiler_bug_workaround_msvc14_std_atomic.patch: -------------------------------------------------------------------------------- 1 | @@@ libsrc/meshing/meshclass.cpp @@@ 2 | @@ -126921,265 +126921,182 @@ 3 | 4 | -ParallelForRange( IntRange(volelements.Size()), %5B&%5D (auto myrange)%0A %7B%0A double local_sum = 0.0;%0A double teterrpow = mp.opterrpow;%0A%0A std::array%3Cint,n_classes%3E classes_local%7B%7D;%0A%0A for (auto i : myrange)%0A %7B%0A 5 | +// NOTE: Patched to eliminate the ParallelForRange, which gives MSVC 14.3 an internal compiler error%0A for (auto &e : volelements) %7B%0A double teterrpow = mp.opterrpow;%0A 6 | 7 | @@ -127139,30 +127139,17 @@ 8 | points, 9 | -volelements%5Bi%5D 10 | +e 11 | , 0, mp) 12 | @@ -127174,31 +127174,24 @@ 13 | ow);%0A%0A 14 | - 15 | - 16 | int qualclas 17 | @@ -127219,31 +127219,24 @@ 18 | elbad + 1);%0A 19 | - 20 | if (qu 21 | @@ -127259,31 +127259,24 @@ 22 | lclass = 1;%0A 23 | - 24 | if (qu 25 | @@ -127329,28 +127329,25 @@ 26 | 27 | - classes_local 28 | +tets_in_qualclass 29 | %5Bqua 30 | @@ -127356,35 +127356,19 @@ 31 | lass 32 | --1 33 | %5D++;%0A 34 | -%0A 35 | 36 | - local_ 37 | sum 38 | @@ -127385,168 +127385,9 @@ 39 | 40 | - %7D%0A%0A AtomicAdd(sum, local_sum);%0A%0A for (auto i : Range(n_classes))%0A AsAtomic(tets_in_qualclass%5Bi%5D) += classes_local%5Bi%5D;%0A %7D); 41 | +%7D 42 | %0A%0A 43 | -------------------------------------------------------------------------------- /patches/netgen-01-python-file-include-order.patch: -------------------------------------------------------------------------------- 1 | @@@ libsrc/meshing/python_mesh.cpp @@@ 2 | @@ -1,20 +1,37 @@ 3 | +#ifdef NG_PYTHON%0A 4 | #include %22pybind11/p 5 | @@ -43,25 +43,8 @@ 6 | s.h%22 7 | -%0A#ifdef NG_PYTHON 8 | %0A%0A#i 9 | -------------------------------------------------------------------------------- /patches/opencascade-01-StdPrs_BRepFont.patch: -------------------------------------------------------------------------------- 1 | @@@ src/StdPrs/StdPrs_BRepFont.cxx @@@ 2 | @@ -15359,16 +15359,25 @@ 3 | const 4 | +unsigned 5 | char* aT 6 | -------------------------------------------------------------------------------- /patches/pivy-01-add-python-libraries.patch: -------------------------------------------------------------------------------- 1 | @@@ interfaces/CMakeLists.txt @@@ 2 | @@ -1224,16 +1224,70 @@ 3 | igobj%22)%0A 4 | + target_link_libraries(coin PUBLIC Python::Python)%0A 5 | elseif(W 6 | -------------------------------------------------------------------------------- /patches/quarter-01-add-QOpenGLContext-to-QuarterWidgetP.patch: -------------------------------------------------------------------------------- 1 | @@@ src\Quarter\QuarterWidgetP.cpp @@@ 2 | @@ -2303,24 +2303,51 @@ 3 | glue/gl.h%3E%0A%0A 4 | +#include %3CQOpenGLContext%3E%0A%0A 5 | #include %22Na 6 | -------------------------------------------------------------------------------- /path_cleaner.py: -------------------------------------------------------------------------------- 1 | # What I really want to do is clean for release. So replace explicit paths with references to CMAKE_CURRENT_SOURCE_DIR 2 | # in cMake files, and also delete some extra files that are spewed out by various installers. The various licenses 3 | # should probably be consolidated. 4 | 5 | import os 6 | import shutil 7 | 8 | paths_to_delete = [ 9 | "custom_vc14_64.bat", 10 | "custom.bat", 11 | "USING_HDF5_CMake.txt", 12 | "USING_HDF5_VS.txt", 13 | "env.bat", 14 | "draw.bat", 15 | "RELEASE.txt", 16 | "samples", 17 | ] 18 | 19 | 20 | def delete_extraneous_files(base_path: str) -> None: 21 | """Delete each of the files listed above from the path specified in base_path. Failure to delete a file does not 22 | constitute a fatal error.""" 23 | print("Removing extraneous files") 24 | if not os.path.exists(base_path): 25 | raise RuntimeError(f"{base_path} does not exist") 26 | if not os.path.isdir(base_path): 27 | raise RuntimeError(f"{base_path} is not a directory") 28 | for file in paths_to_delete: 29 | try: 30 | os.unlink(os.path.join(base_path, file)) 31 | except OSError as e: 32 | # If the file isn't there, that's as good as deleting it, right? 33 | pass 34 | 35 | 36 | def remove_local_path_from_cmake_files(base_path: str) -> None: 37 | """In many cases, the local compilation paths get stored into the cMake files. They should not ever be used, but 38 | a) OpenCASCADE codes in the local path to FreeType, which then fails when the LibPack is distributed, and b) for 39 | good measure cMake files shouldn't refer to non-existent paths on a foreign system. So this method looks for 40 | cmake config files and cleans the ones it finds.""" 41 | print("Removing local paths from cMake files") 42 | for root, dirs, files in os.walk(base_path): 43 | for file in files: 44 | if file.lower().endswith(".cmake"): 45 | remove_local_path_from_cmake_file(base_path, os.path.join(root, file)) 46 | 47 | 48 | def remove_local_path_from_cmake_file(base_path: str, file_to_clean: str) -> None: 49 | """Modify a cMake file to remove base_path and replace it with ${CMAKE_CURRENT_SOURCE_DIR} -- WARNING: effectively 50 | edits the file in-place, no backup is made.""" 51 | depth_string = create_depth_string(base_path, file_to_clean) 52 | with open(file_to_clean, "r", encoding="UTF-8") as f: 53 | contents = f.read() 54 | 55 | if base_path.endswith(os.path.sep): 56 | base_path = base_path[: -len(os.path.sep)] 57 | 58 | # First, just replace the exact string we were given 59 | contents = contents.replace( 60 | base_path, "${CMAKE_CURRENT_SOURCE_DIR}/" + depth_string[:-1] 61 | ) # Skip the final / 62 | 63 | # Most occurrences should NOT have been the exact string if we are on Windows, since cMake paths should always 64 | # use forward slashes, so make sure to do that replacement as well 65 | if os.pathsep != "/": 66 | cmake_base_path = base_path.replace( 67 | os.path.sep, "/" 68 | ) # cMake paths should always use forward slash 69 | contents = contents.replace( 70 | cmake_base_path, "${CMAKE_CURRENT_SOURCE_DIR}/" + depth_string[:-1] 71 | ) # Skip / 72 | with open(file_to_clean, "w", encoding="utf-8") as f: 73 | f.write(contents) 74 | 75 | 76 | def create_depth_string(base_path: str, file_to_clean: str) -> str: 77 | """Given a base path and a file, determine how many "../" must be appended to the file's containing directory 78 | to result in a path that resolves to base_path. Returns a string containing just some number of occurrences of 79 | "../" e.g. "../../../" to move up three levels from file_to_clean's containing folder.""" 80 | 81 | file_to_clean = os.path.normpath(file_to_clean) 82 | if not file_to_clean.startswith(base_path): 83 | raise RuntimeError(f"{file_to_clean} does not appear to be in {base_path}") 84 | 85 | if base_path.endswith(os.path.sep): 86 | base_path = base_path[: -len(os.path.sep)] 87 | 88 | containing_directory = os.path.dirname(file_to_clean) 89 | directories_to_file = len(containing_directory.split(os.path.sep)) 90 | directories_in_base = len(base_path.split(os.path.sep)) 91 | num_steps_up = directories_to_file - directories_in_base 92 | return "../" * num_steps_up # For use in cMake, so always a forward slash here 93 | 94 | 95 | def correct_opencascade_freetype_ref(base_path: str): 96 | """OpenCASCADE hardcodes the path to the freetype it was compiled against. The above code doesn't correct it to 97 | the necessary path because of the way this variable is used within cMake. So just remove the path altogether and 98 | rely on the rest of our configuration to find the correct one.""" 99 | files_to_fix = ["OpenCASCADEDrawTargets.cmake", "OpenCASCADEVisualizationTargets.cmake"] 100 | for fix in files_to_fix: 101 | path = os.path.join(base_path, "cmake", fix) 102 | with open(path, "r", encoding="utf-8") as f: 103 | contents = f.read() 104 | contents = contents.replace( 105 | "${CMAKE_CURRENT_SOURCE_DIR}/../lib/freetype.lib", "freetype.lib" 106 | ) 107 | with open(path, "w", encoding="utf-8") as f: 108 | f.write(contents) 109 | 110 | 111 | def delete_qtwebengine(base_path: str): 112 | """QtWebEngine is huge and pervasive -- it's also not used by FreeCAD (anymore). Delete anything that seems to be 113 | related to it from the LibPack.""" 114 | 115 | print("Removing QtWebEngine (and related code)") 116 | for root, dirs, files in os.walk(base_path): 117 | for dir in dirs: 118 | if ( 119 | "webengine" in dir.lower() 120 | or "webchannel" in dir.lower() 121 | or "websockets" in dir.lower() 122 | ): 123 | try: 124 | full_path = os.path.join(root, dir) 125 | shutil.rmtree(full_path) 126 | except OSError as e: 127 | print(f"Failed to delete file {full_path}: {e}") 128 | for file in files: 129 | if "webengine" in file.lower() or "webchannel" in file.lower(): 130 | try: 131 | full_path = os.path.join(root, file) 132 | os.unlink(full_path) 133 | except OSError as e: 134 | print(f"Failed to delete path {full_path}: {e}") 135 | 136 | 137 | def delete_qtquick(base_path: str): 138 | """QtQuick is unused in FreeCAD at this time.""" 139 | 140 | def is_qtquick(name: str) -> bool: 141 | lc = name.lower() 142 | if "qtquick" in lc or "qml" in lc: 143 | return True 144 | if lc.startswith("q") and "quick" in lc: 145 | return True 146 | return False 147 | 148 | print("Removing QtQuick/QML") 149 | for root, dirs, files in os.walk(base_path): 150 | for dir in dirs: 151 | if is_qtquick(dir): 152 | try: 153 | full_path = os.path.join(root, dir) 154 | shutil.rmtree(full_path) 155 | except OSError as e: 156 | print(f"Failed to delete file {full_path}: {e}") 157 | for file in files: 158 | if is_qtquick(file): 159 | try: 160 | full_path = os.path.join(root, file) 161 | os.unlink(full_path) 162 | except OSError as e: 163 | print(f"Failed to delete path {full_path}: {e}") 164 | 165 | 166 | def delete_llvm_executables(base_path: str): 167 | """During the build of the libpack, a number of llvm executable files are created: these are not needed to compile 168 | or run FreeCAD, so remove them.""" 169 | print("Removing llvm executables") 170 | files_in_bin = os.listdir(os.path.join(base_path, "bin")) 171 | for file in files_in_bin: 172 | if file.startswith("llvm") and file.endswith(".exe"): 173 | try: 174 | os.unlink(os.path.join(base_path, "bin", file)) 175 | except OSError as e: 176 | pass 177 | 178 | 179 | def delete_clang_executables(base_path: str): 180 | """During the build of the libpack, a number of clang executable files are created: these are not needed to compile 181 | or run FreeCAD, so remove them.""" 182 | print("Removing clang executables") 183 | files_in_bin = os.listdir(os.path.join(base_path, "bin")) 184 | for file in files_in_bin: 185 | if file.startswith("clang") and file.endswith(".exe"): 186 | try: 187 | os.unlink(os.path.join(base_path, "bin", file)) 188 | except OSError as e: 189 | pass 190 | -------------------------------------------------------------------------------- /test_compile_all.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later 4 | 5 | import os 6 | import unittest 7 | from unittest.mock import MagicMock, patch, mock_open 8 | 9 | import compile_all 10 | 11 | """ Developer tests for the compile_all module. """ 12 | 13 | 14 | class TestCompileAll(unittest.TestCase): 15 | def setUp(self) -> None: 16 | super().setUp() 17 | config = { 18 | "FreeCAD-version": "0.22", 19 | "LibPack-version": "3.0.0", 20 | "content": [{"name": "nonexistent"}], 21 | } 22 | self.compiler = compile_all.Compiler(config, compile_all.BuildMode.RELEASE, "bison_path") 23 | self.original_dir = os.getcwd() 24 | 25 | def tearDown(self) -> None: 26 | os.chdir(self.original_dir) 27 | super().tearDown() 28 | 29 | @patch("os.chdir") 30 | @patch("compile_all.Compiler.build_nonexistent") 31 | def test_compile_all_calls_build_function(self, nonexistent_mock: MagicMock, _): 32 | config = {"content": [{"name": "nonexistent"}]} 33 | self.compiler.compile_all() 34 | nonexistent_mock.assert_called_once() 35 | 36 | @patch("subprocess.run") 37 | def test_get_python_version(self, run_mock: MagicMock): 38 | """Checking the Python version stores the Major and Minor components (but not the Patch)""" 39 | 40 | # Arrange 41 | mock_result = MagicMock() 42 | mock_result.stdout = b"Python 3.9.13" 43 | run_mock.return_value = mock_result 44 | 45 | # Act 46 | version = self.compiler.get_python_version() 47 | 48 | # Assert 49 | self.assertEqual(version, "3.9") 50 | 51 | def test_split_patch_data_finds_single_file(self): 52 | filename = "filename" 53 | patch_data = "@@ -1,3 +1,1 @@ -The +A" 54 | data = f"@@@ {filename} @@@\n{patch_data}" 55 | patches = compile_all.split_patch_data(data) 56 | self.assertEqual(1, len(patches)) 57 | self.assertEqual(patches[0]["file"], filename) 58 | 59 | def test_split_patch_data_finds_multiple_files(self): 60 | filename = "filename" 61 | patch_data = "@@ -1,3 +1,1 @@\n-The +A" 62 | expected_number = 5 63 | data = "" 64 | for i in range(expected_number): 65 | data += f"@@@ {filename}{i} @@@\n{patch_data}" 66 | patches = compile_all.split_patch_data(data) 67 | self.assertEqual(expected_number, len(patches)) 68 | 69 | 70 | class TestPatchSingleFile(unittest.TestCase): 71 | 72 | @patch("builtins.open", mock_open(read_data="The End.")) 73 | def test_integration_patch_single_file(self): 74 | mo = mock_open(read_data="The End.") 75 | with patch("builtins.open", mo): 76 | compile_all.patch_single_file("filename", "@@ -1,7 +1,5 @@\n-The\n+A\n End\n") 77 | mo.assert_any_call("filename", "w", encoding="utf-8") 78 | handle = mo() 79 | handle.write.assert_called_once_with("A End.") 80 | 81 | 82 | if __name__ == "__main__": 83 | unittest.main() 84 | -------------------------------------------------------------------------------- /test_create_libpack.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later 4 | 5 | import os 6 | import shutil 7 | from subprocess import CalledProcessError 8 | import tempfile 9 | import unittest 10 | from unittest.mock import MagicMock, patch, mock_open 11 | 12 | import create_libpack 13 | 14 | 15 | class TestDeleteExisting(unittest.TestCase): 16 | def setUp(self) -> None: 17 | super().setUp() 18 | self.temp_dir = tempfile.TemporaryDirectory() 19 | 20 | def tearDown(self) -> None: 21 | super().tearDown() 22 | shutil.rmtree(self.temp_dir.name) 23 | 24 | @patch("builtins.print") 25 | def test_no_directory_not_silent(self, mock_print: MagicMock): 26 | """Nothing happens when asking to delete a directory that does not exist""" 27 | create_libpack.delete_existing( 28 | os.path.join(self.temp_dir.name, "no_such_dir"), silent=False 29 | ) 30 | mock_print.assert_not_called() 31 | 32 | @patch("builtins.print") 33 | def test_with_directory_silent_is_silent(self, mock_print: MagicMock): 34 | """In silent mode, nothing is printed even when deleting""" 35 | dir_to_delete = os.path.join(self.temp_dir.name, "existing_dir") 36 | os.mkdir(dir_to_delete) 37 | create_libpack.delete_existing(dir_to_delete, silent=True) 38 | mock_print.assert_not_called() 39 | 40 | @patch("builtins.print") 41 | def test_with_directory_silent_deletes_dir(self, mock_print: MagicMock): 42 | """In silent mode, the directory is deleted""" 43 | dir_to_delete = os.path.join(self.temp_dir.name, "existing_dir") 44 | os.mkdir(dir_to_delete) 45 | create_libpack.delete_existing(dir_to_delete, silent=True) 46 | self.assertFalse(os.path.exists(dir_to_delete)) 47 | 48 | @patch("builtins.input") 49 | def test_with_directory_not_silent_asks_for_confirmation(self, mock_input: MagicMock): 50 | """When not in silent mode, the user is asked to confirm""" 51 | dir_to_delete = os.path.join(self.temp_dir.name, "existing_dir") 52 | os.mkdir(dir_to_delete) 53 | create_libpack.delete_existing(dir_to_delete, silent=False) 54 | mock_input.assert_called_once() 55 | 56 | @patch("builtins.input") 57 | def test_confirm_defaults_to_no(self, mock_input: MagicMock): 58 | """If the user just hits enter, the default is to NOT delete the directory""" 59 | dir_to_delete = os.path.join(self.temp_dir.name, "existing_dir") 60 | mock_input.return_value = "" 61 | os.mkdir(dir_to_delete) 62 | create_libpack.delete_existing(dir_to_delete, silent=False) 63 | self.assertTrue(os.path.exists(dir_to_delete)) 64 | 65 | @patch("builtins.input") 66 | def test_confirm_with_y_deletes(self, mock_input: MagicMock): 67 | """If the user types 'y' then the directory is deleted""" 68 | dir_to_delete = os.path.join(self.temp_dir.name, "existing_dir") 69 | mock_input.return_value = "y" 70 | os.mkdir(dir_to_delete) 71 | create_libpack.delete_existing(dir_to_delete, silent=False) 72 | self.assertFalse(os.path.exists(dir_to_delete)) 73 | 74 | 75 | class TestLoadConfig(unittest.TestCase): 76 | def setUp(self) -> None: 77 | super().setUp() 78 | self.temp_dir = tempfile.TemporaryDirectory() 79 | 80 | def tearDown(self) -> None: 81 | super().tearDown() 82 | shutil.rmtree(self.temp_dir.name) 83 | 84 | @patch("builtins.open", mock_open(read_data='{"entry1":1,"entry2":2}')) 85 | def test_json_is_loaded(self): 86 | """When appropriate JSON data exists it is loaded and returned""" 87 | loaded_data = create_libpack.load_config(self.temp_dir.name) 88 | self.assertIn("entry1", loaded_data) 89 | self.assertIn("entry2", loaded_data) 90 | 91 | @patch("builtins.print") 92 | def test_non_existent_file_prints_error(self, mock_print: MagicMock): 93 | """If a non-existent file is given, an error is printed (and exit() is called)""" 94 | with self.assertRaises(SystemExit): 95 | create_libpack.load_config(os.path.join(self.temp_dir.name, "no_such_file.json")) 96 | mock_print.assert_called_once() 97 | 98 | @patch("builtins.print") 99 | @patch("builtins.open", mock_open(read_data="bad json data!")) 100 | def test_bad_file_prints_error(self, mock_print: MagicMock): 101 | """If a bad JSON data is given, an error is printed (and exit() is called)""" 102 | with self.assertRaises(SystemExit): 103 | create_libpack.load_config(self.temp_dir.name) 104 | mock_print.assert_called_once() 105 | 106 | 107 | class TestRemoteFetchFunctions(unittest.TestCase): 108 | """Git and direct download""" 109 | 110 | def setUp(self) -> None: 111 | super().setUp() 112 | self.temp_dir = tempfile.TemporaryDirectory() 113 | 114 | def tearDown(self) -> None: 115 | super().tearDown() 116 | shutil.rmtree(self.temp_dir.name) 117 | 118 | @patch("create_libpack.clone") 119 | def test_repos_are_discovered(self, mock_clone: MagicMock): 120 | """Any dictionary with both a git-repo and a git-ref is passed along to clone""" 121 | test_config = { 122 | "content": [ 123 | {"name": "test1", "git-repo": "test1_repo", "git-ref": "test1_ref"}, 124 | {"name": "test2", "git-repo": "test2_repo", "git-ref": "test2_ref"}, 125 | {"name": "test3", "git-repo": "test3_repo", "git-ref": "test3_ref"}, 126 | ] 127 | } 128 | create_libpack.fetch_remote_data(test_config) 129 | self.assertEqual(mock_clone.call_count, 3) 130 | 131 | @patch("builtins.print") 132 | def test_missing_repo_errors_if_ref(self, mock_print: MagicMock): 133 | """An entry with a git-ref but no git-repo is an error""" 134 | test_config = {"content": [{"name": "test1", "git-ref": "test1_ref"}]} 135 | with self.assertRaises(SystemExit): 136 | create_libpack.fetch_remote_data(test_config) 137 | mock_print.assert_called() 138 | 139 | @patch("create_libpack.clone") 140 | def test_missing_ref_is_omitted(self, mock_clone: MagicMock): 141 | """An entry with a git-repo but no git-ref just doesn't use the ref""" 142 | test_config = { 143 | "content": [ 144 | {"name": "test1", "git-repo": "test1_repo"}, 145 | ] 146 | } 147 | create_libpack.fetch_remote_data(test_config) 148 | mock_clone.assert_called_once_with("test1", "test1_repo") 149 | 150 | @patch("create_libpack.clone") 151 | def test_non_git_entries_are_ignored(self, mock_clone: MagicMock): 152 | """Non-git entries are just ignored""" 153 | test_config = { 154 | "content": [ 155 | {"name": "test1"}, 156 | ] 157 | } 158 | create_libpack.fetch_remote_data(test_config) 159 | mock_clone.assert_not_called() 160 | 161 | @patch("subprocess.run") 162 | def test_clone_calls_git_with_ref(self, run_mock: MagicMock): 163 | """When given a repo and a ref, git clone is set up appropriately""" 164 | create_libpack.clone("name", "https://some.url", "some_git_ref") 165 | run_mock.assert_called_once() 166 | call_data: list = run_mock.call_args[0][0] 167 | self.assertIn("https://some.url", call_data) 168 | self.assertIn("some_git_ref", call_data) 169 | self.assertEquals(call_data[-1], "name") 170 | 171 | @patch("subprocess.run") 172 | def test_clone_calls_git_without_ref(self, run_mock: MagicMock): 173 | """When given a repo and a ref, git clone is set up appropriately""" 174 | create_libpack.clone("test", "https://some.url") 175 | run_mock.assert_called_once() 176 | call_data = run_mock.call_args[0][0] 177 | self.assertNotIn(None, call_data) 178 | self.assertNotIn("--branch", call_data) 179 | 180 | @patch("subprocess.run") 181 | def test_exception_is_caught_and_calls_exit(self, run_mock: MagicMock): 182 | """When given a repo and a ref, git clone is set up appropriately""" 183 | run_mock.side_effect = CalledProcessError(1, "command_that_was_called") 184 | with self.assertRaises(SystemExit): 185 | create_libpack.clone("some_name", "https://some.url") 186 | 187 | @patch("os.path.exists", MagicMock(return_value=True)) 188 | @patch("create_libpack.clone") 189 | def test_skips_existing_paths_with_flag(self, clone_mock: MagicMock): 190 | test_config = { 191 | "content": [ 192 | {"name": "test1", "git-repo": "test1_repo", "git-ref": "test1_ref"}, 193 | {"name": "test2", "git-repo": "test2_repo", "git-ref": "test2_ref"}, 194 | {"name": "test3", "git-repo": "test3_repo", "git-ref": "test3_ref"}, 195 | ] 196 | } 197 | create_libpack.fetch_remote_data(test_config, skip_existing=True) 198 | clone_mock.assert_not_called() 199 | 200 | @patch("create_libpack.download") 201 | def test_url_calls_download(self, download_mock: MagicMock): 202 | test_config = {"content": [{"name": "test", "url": "https://some.url"}]} 203 | create_libpack.fetch_remote_data(test_config) 204 | download_mock.assert_called_once() 205 | 206 | @patch("os.mkdir") # Patch so it doesn't actually make a directory 207 | @patch("requests.get") # Patch so no network request is made 208 | @patch("create_libpack.decompress") # Patch so no attempt is made to decompress 209 | def test_download_creates_file(self, decompress_mock: MagicMock, _1, _2): 210 | with patch("builtins.open", mock_open()) as open_mock: 211 | create_libpack.download("make_this_dir", "https://some.url/test.7z") 212 | open_mock.assert_called_once_with(os.path.join("make_this_dir", "test.7z"), "wb") 213 | decompress_mock.assert_called_once_with("make_this_dir", "test.7z") 214 | 215 | @patch("os.chdir") 216 | @patch("subprocess.run") 217 | def test_decompress_calls_subprocess(self, run_mock: MagicMock, chdir_mock: MagicMock): 218 | create_libpack.decompress("path_to_file", "file_name") 219 | run_mock.assert_called_once() 220 | self.assertEqual(chdir_mock.call_count, 2) 221 | 222 | 223 | if __name__ == "__main__": 224 | unittest.main() 225 | -------------------------------------------------------------------------------- /test_generate_patch.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later 4 | 5 | import diff_match_patch 6 | import unittest 7 | from unittest.mock import MagicMock, patch, mock_open 8 | 9 | import generate_patch 10 | 11 | """ Developer tests for the generate_patch module. """ 12 | 13 | 14 | class TestGeneratePatch(unittest.TestCase): 15 | 16 | def setUp(self): 17 | super().setUp() 18 | 19 | def tearDown(self): 20 | super().tearDown() 21 | 22 | @patch("sys.argv", ["exe", "old", "new", "patch"]) 23 | def test_command_line_options_count_is_correct(self): 24 | generate_patch.parse_args() 25 | 26 | @patch("sys.argv", ["exe"]) 27 | def test_command_line_args_missing_is_error(self): 28 | with self.assertRaises(SystemExit): 29 | generate_patch.parse_args() 30 | 31 | def test_patch_generated(self): 32 | # Arrange 33 | old = "Line1\nLine2\nLine4\n" 34 | new = "Line1\nLine2\nLine3\n" 35 | dmp = diff_match_patch.diff_match_patch() 36 | difference = dmp.patch_toText(dmp.patch_make(old, new)) 37 | 38 | # Act 39 | result = generate_patch.generate_patch(old, new) 40 | 41 | # Assert 42 | self.assertEqual(result, difference) 43 | 44 | def test_run_loads_all_files(self): 45 | with patch("builtins.open", mock_open()) as open_mock: 46 | generate_patch.run("old", "new", "patch") 47 | expected_calls = [ 48 | unittest.mock.call("old", "r", encoding="utf-8"), 49 | unittest.mock.call("new", "r", encoding="utf-8"), 50 | unittest.mock.call("patch", "w", encoding="utf-8"), 51 | ] 52 | for call in expected_calls: 53 | self.assertIn(call, open_mock.mock_calls) 54 | -------------------------------------------------------------------------------- /test_path_cleaner.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import os 3 | 4 | # SPDX-License-Identifier: LGPL-2.1-or-later 5 | 6 | import unittest 7 | from unittest.mock import MagicMock, patch, mock_open 8 | 9 | import path_cleaner 10 | 11 | 12 | class TestPathCleaner(unittest.TestCase): 13 | """Tests the methods in path_cleaner.py""" 14 | 15 | def test_create_depth_string_simple(self): 16 | """The Depth String method should return a cMake-style string consisting of dots and slashes (never 17 | backslashes).""" 18 | # Arrange 19 | starts_with = os.path.join("some", "fake", "path") 20 | fake_file_path = os.path.join(starts_with, "to", "a", "file.txt") 21 | 22 | # Act 23 | result = path_cleaner.create_depth_string(starts_with, fake_file_path) 24 | 25 | # Assert 26 | self.assertEqual( 27 | "../../", result, "Expected a cMake-style path string going up two directories" 28 | ) 29 | 30 | def test_create_depth_string_trailing_path_sep(self): 31 | """Even if there is an extraneous trailing path separator on the base path, the method should return the 32 | correct results.""" 33 | # Arrange 34 | starts_with = os.path.join("some", "fake", "path") 35 | fake_file_path = os.path.join(starts_with, "to", "a", "file.txt") 36 | 37 | # Act 38 | result = path_cleaner.create_depth_string(starts_with + os.path.sep, fake_file_path) 39 | 40 | # Assert 41 | self.assertEqual( 42 | "../../", result, "Expected a cMake-style path string going up two directories" 43 | ) 44 | 45 | def test_create_depth_string_extraneous_slashes(self): 46 | """Even if there are extraneous slashes in the path, it should still return the correct result""" 47 | # Arrange 48 | starts_with = os.path.join("some", "fake", "path") 49 | fake_file_path = os.path.join(starts_with, "to", "a", "file.txt") 50 | fake_file_path = fake_file_path.replace(os.path.sep, os.path.sep + os.path.sep) 51 | 52 | # Act 53 | result = path_cleaner.create_depth_string(starts_with, fake_file_path) 54 | 55 | # Assert 56 | self.assertEqual( 57 | "../../", result, "Expected a cMake-style path string going up two directories" 58 | ) 59 | 60 | def test_remove_local_path_from_cmake_file(self): 61 | """Given a cMake file that contains some local paths, this should remove those local paths and convert them 62 | into references relative to the file's location.""" 63 | # Arrange 64 | fake_cmake_data = ( 65 | ' set(_BOOST_CMAKEDIR "Z:/FreeCAD/FreeCAD-LibPack-1.0.0-v3.0.0-Release/lib/cmake")\n' 66 | ) 67 | cleaned_data = ' set(_BOOST_CMAKEDIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib/cmake")\n' 68 | 69 | # Act 70 | with patch("builtins.open", mock_open(read_data=fake_cmake_data)) as open_mock: 71 | path_cleaner.remove_local_path_from_cmake_file( 72 | "Z:\\FreeCAD\\FreeCAD-LibPack-1.0.0-v3.0.0-Release\\", 73 | "Z:\\FreeCAD\\FreeCAD-LibPack-1.0.0-v3.0.0-Release\\lib\\cmake\\mock.cmake", 74 | ) 75 | 76 | # Assert (still in the context manager, so we can query the mocked file) 77 | open_mock().write.assert_called_with(cleaned_data) 78 | 79 | def test_remove_local_path_from_cmake_file_bad_path(self): 80 | """There is at least one package (MEDfile) that puts in a Windows-style path into cMake, even though they 81 | should not do so. Make sure we handle that.""" 82 | # Arrange 83 | fake_cmake_data = ( 84 | 'SET(_hdf5_path "Z:\\FreeCAD\\FreeCAD-LibPack-1.0.0-v3.0.0-Release/share/cmake/")\n' 85 | ) 86 | cleaned_data = 'SET(_hdf5_path "${CMAKE_CURRENT_SOURCE_DIR}/../../share/cmake/")\n' 87 | 88 | # Act 89 | with patch("builtins.open", mock_open(read_data=fake_cmake_data)) as open_mock: 90 | path_cleaner.remove_local_path_from_cmake_file( 91 | "Z:\\FreeCAD\\FreeCAD-LibPack-1.0.0-v3.0.0-Release\\", 92 | "Z:\\FreeCAD\\FreeCAD-LibPack-1.0.0-v3.0.0-Release\\share\\cmake\\mock.cmake", 93 | ) 94 | 95 | # Assert (still in the context manager, so we can query the mocked file) 96 | open_mock().write.assert_called_with(cleaned_data) 97 | 98 | 99 | if __name__ == "__main__": 100 | unittest.main() 101 | --------------------------------------------------------------------------------