pax_global_header 0000666 0000000 0000000 00000000064 14321173220 0014505 g ustar 00root root 0000000 0000000 52 comment=2cc72be3b307d302afdd042cd920076dfe7380e6
node-gyp-9.3.0/ 0000775 0000000 0000000 00000000000 14321173220 0013240 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/.github/ 0000775 0000000 0000000 00000000000 14321173220 0014600 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/.github/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000004061 14321173220 0017306 0 ustar 00root root 0000000 0000000
Please look thru your error log for the string `gyp info using node-gyp@` and if the version number is less than the [current release of node-gyp](https://github.com/nodejs/node-gyp/releases) then __please upgrade__ using the instructions at https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md and try your command again.
Requests for help with [`node-sass` are very common](https://github.com/nodejs/node-gyp/issues?q=label%3A%22Node+Sass+--%3E+Dart+Sass%22). Please be aware that this package is deprecated, you should seek alternatives and avoid opening new issues about it here.
* **Node Version**:
* **Platform**:
* **Compiler**:
* **Module**:
Verbose output (from npm or node-gyp):
```
Paste your log here, between the backticks. It can be:
- npm --verbose output,
- or contents of npm-debug.log,
- or output of node-gyp rebuild --verbose.
Include the command you were trying to run.
This should look like this:
>npm --verbose
npm info it worked if it ends with ok
npm verb cli [
npm verb cli 'C:\\...\\node\\13.9.0\\x64\\node.exe',
npm verb cli 'C:\\...\\node\\13.9.0\\x64\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli '--verbose'
npm verb cli ]
npm info using npm@6.13.7
npm info using node@v13.9.0
Usage: npm
(...)
```
node-gyp-9.3.0/.github/PULL_REQUEST_TEMPLATE.md 0000664 0000000 0000000 00000001153 14321173220 0020401 0 ustar 00root root 0000000 0000000
##### Checklist
- [ ] `npm install && npm test` passes
- [ ] tests are included
- [ ] documentation is changed or added
- [ ] commit message follows [commit guidelines](https://github.com/googleapis/release-please#how-should-i-write-my-commits)
##### Description of change
node-gyp-9.3.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14321173220 0016635 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/.github/workflows/release-please.yml 0000664 0000000 0000000 00000005331 14321173220 0022251 0 ustar 00root root 0000000 0000000 name: release-please
on:
push:
branches:
- main
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v2
id: release
with:
package-name: node-gyp
release-type: node
changelog-types: >
[{"type":"feat","section":"Features","hidden":false},
{"type":"fix","section":"Bug Fixes","hidden":false},
{"type":"bin","section":"Core","hidden":false},
{"type":"gyp","section":"Core","hidden":false},
{"type":"lib","section":"Core","hidden":false},
{"type":"src","section":"Core","hidden":false},
{"type":"test","section":"Tests","hidden":false},
{"type":"build","section":"Core","hidden":false},
{"type":"clean","section":"Core","hidden":false},
{"type":"configure","section":"Core","hidden":false},
{"type":"install","section":"Core","hidden":false},
{"type":"list","section":"Core","hidden":false},
{"type":"rebuild","section":"Core","hidden":false},
{"type":"remove","section":"Core","hidden":false},
{"type":"deps","section":"Core","hidden":false},
{"type":"python","section":"Core","hidden":false},
{"type":"lin","section":"Core","hidden":false},
{"type":"linux","section":"Core","hidden":false},
{"type":"mac","section":"Core","hidden":false},
{"type":"macos","section":"Core","hidden":false},
{"type":"win","section":"Core","hidden":false},
{"type":"windows","section":"Core","hidden":false},
{"type":"zos","section":"Core","hidden":false},
{"type":"doc","section":"Doc","hidden":false},
{"type":"docs","section":"Doc","hidden":false},
{"type":"readme","section":"Doc","hidden":false},
{"type":"chore","section":"Miscellaneous","hidden":false},
{"type":"refactor","section":"Miscellaneous","hidden":false},
{"type":"ci","section":"Miscellaneous","hidden":false},
{"type":"meta","section":"Miscellaneous","hidden":false}]
# Standard Conventional Commits: `feat` and `fix`
# node-gyp subdirectories: `bin`, `gyp`, `lib`, `src`, `test`
# node-gyp subcommands: `build`, `clean`, `configure`, `install`, `list`, `rebuild`, `remove`
# Core abstract category: `deps`
# Languages/platforms: `python`, `lin`, `linux`, `mac`, `macos`, `win`, `window`, `zos`
# Documentation: `doc`, `docs`, `readme`
# Standard Conventional Commits: `chore` (under "Miscellaneous")
# Miscellaneous abstract categories: `refactor`, `ci`, `meta`
node-gyp-9.3.0/.github/workflows/tests.yml 0000664 0000000 0000000 00000003327 14321173220 0020527 0 ustar 00root root 0000000 0000000 # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# TODO: Line 48, enable pytest --doctest-modules
name: Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
Tests:
strategy:
fail-fast: false
max-parallel: 15
matrix:
node: [14.x, 16.x, 18.x]
python: ["3.6", "3.8", "3.10"]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Use Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
env:
PYTHON_VERSION: ${{ matrix.python }} # Why do this?
- name: Install Dependencies
run: |
npm install --no-progress
pip install flake8 pytest
- name: Set Windows environment
if: startsWith(matrix.os, 'windows')
run: |
echo 'GYP_MSVS_VERSION=2015' >> $Env:GITHUB_ENV
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
- name: Lint Python
if: startsWith(matrix.os, 'ubuntu')
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
- name: Run Python tests
run: python -m pytest
# - name: Run doctests with pytest
# run: python -m pytest --doctest-modules
- name: Environment Information
run: npx envinfo
- name: Run Node tests
run: npm test
node-gyp-9.3.0/.github/workflows/visual-studio.yml 0000664 0000000 0000000 00000002041 14321173220 0022165 0 ustar 00root root 0000000 0000000 # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
name: visual-studio
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
visual-studio:
strategy:
fail-fast: false
max-parallel: 8
matrix:
os: [windows-latest]
msvs-version: [2016, 2019, 2022] # https://github.com/actions/virtual-environments/tree/main/images/win
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install Dependencies
run: |
npm install --no-progress
# npm audit fix --force
- name: Set Windows environment
if: startsWith(matrix.os, 'windows')
run: |
echo 'GYP_MSVS_VERSION=${{ matrix.msvs-version }}' >> $Env:GITHUB_ENV
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
- name: Environment Information
run: npx envinfo
- name: Run Node tests
run: npm test
node-gyp-9.3.0/.gitignore 0000664 0000000 0000000 00000000116 14321173220 0015226 0 ustar 00root root 0000000 0000000 *.swp
gyp/test
node_modules
test/.node-gyp
.ncu
.nyc_output
package-lock.json
node-gyp-9.3.0/CHANGELOG.md 0000664 0000000 0000000 00000265650 14321173220 0015067 0 ustar 00root root 0000000 0000000 # Changelog
## [9.3.0](https://www.github.com/nodejs/node-gyp/compare/v9.2.0...v9.3.0) (2022-10-10)
### Features
* **gyp:** update gyp to v0.14.0 ([#2749](https://www.github.com/nodejs/node-gyp/issues/2749)) ([713b8dc](https://www.github.com/nodejs/node-gyp/commit/713b8dcdbf44532ca9453a127da266386cc737f8))
* remove support for VS2015 in Node.js >=19 ([#2746](https://www.github.com/nodejs/node-gyp/issues/2746)) ([131d1a4](https://www.github.com/nodejs/node-gyp/commit/131d1a463baf034a04154bcda753a8295f112a34))
* support IBM Open XL C/C++ on z/OS ([#2743](https://www.github.com/nodejs/node-gyp/issues/2743)) ([7d0c83d](https://www.github.com/nodejs/node-gyp/commit/7d0c83d2a95aca743dff972826d0da26203acfc4))
## [9.2.0](https://www.github.com/nodejs/node-gyp/compare/v9.1.0...v9.2.0) (2022-10-02)
### Features
* Add proper support for IBM i ([a26494f](https://www.github.com/nodejs/node-gyp/commit/a26494fbb8883d9ef784503979e115dec3e2791e))
* **gyp:** update gyp to v0.13.0 ([3e2a532](https://www.github.com/nodejs/node-gyp/commit/3e2a5324f1c24f3a04bca04cf54fe23d5c4d5e50))
### Bug Fixes
* node.js debugger adds stderr (but exit code is 0) -> shouldn't throw ([#2719](https://www.github.com/nodejs/node-gyp/issues/2719)) ([c379a74](https://www.github.com/nodejs/node-gyp/commit/c379a744c65c7ab07c2c3193d9c7e8f25ae1b05e))
### Core
* enable support for zoslib on z/OS ([#2600](https://www.github.com/nodejs/node-gyp/issues/2600)) ([83c0a12](https://www.github.com/nodejs/node-gyp/commit/83c0a12bf23b4cbf3125d41f9e2d4201db76c9ae))
### Miscellaneous
* update dependency - nopt@6.0.0 ([#2707](https://www.github.com/nodejs/node-gyp/issues/2707)) ([8958ecf](https://www.github.com/nodejs/node-gyp/commit/8958ecf2bb719227bbcbf155891c3186ee219a2e))
## [9.1.0](https://www.github.com/nodejs/node-gyp/compare/v9.0.0...v9.1.0) (2022-07-13)
### Features
* Update function getSDK() to support Windows 11 SDK ([#2565](https://www.github.com/nodejs/node-gyp/issues/2565)) ([ea8520e](https://www.github.com/nodejs/node-gyp/commit/ea8520e3855374bd15b6d001fe112d58a8d7d737))
### Bug Fixes
* extend tap timeout length to allow for slow CI ([6f74c76](https://www.github.com/nodejs/node-gyp/commit/6f74c762fe3c19bdd20245cb5c02e2dfa65d9451))
* new ca & server certs, bundle in .js file and unpack for testing ([147e3d3](https://www.github.com/nodejs/node-gyp/commit/147e3d34f44a97deb7aa507207680cf0f4e662a2))
* re-label ([#2689](https://www.github.com/nodejs/node-gyp/issues/2689)) ([f0b7863](https://www.github.com/nodejs/node-gyp/commit/f0b7863dadfa365afc173025ae95351aec79abd9))
* typo on readme ([bf81cd4](https://www.github.com/nodejs/node-gyp/commit/bf81cd452b931dd4dfa82762c23dd530a075d992))
### Doc
* update docs/README.md with latest version number ([62d2815](https://www.github.com/nodejs/node-gyp/commit/62d28151bf8266a34e1bcceeb25b4e6e2ae5ca5d))
### Core
* update due to rename of primary branch ([ca1f068](https://www.github.com/nodejs/node-gyp/commit/ca1f0681a5567ca8cd51acebccd37a633f19bc6a))
### Tests
* Try msvs-version: [2016, 2019, 2022] ([#2700](https://www.github.com/nodejs/node-gyp/issues/2700)) ([68b5b5b](https://www.github.com/nodejs/node-gyp/commit/68b5b5be9c94ac20c55e88654ff6f55234d7130a))
* Upgrade GitHub Actions ([#2623](https://www.github.com/nodejs/node-gyp/issues/2623)) ([245cd5b](https://www.github.com/nodejs/node-gyp/commit/245cd5bbe4441d4f05e88f2fa20a86425419b6af))
* Upgrade GitHub Actions ([#2701](https://www.github.com/nodejs/node-gyp/issues/2701)) ([1c64ca7](https://www.github.com/nodejs/node-gyp/commit/1c64ca7f4702c6eb43ecd16fbd67b5d939041621))
## [9.0.0](https://www.github.com/nodejs/node-gyp/compare/v8.4.1...v9.0.0) (2022-02-24)
### ⚠ BREAKING CHANGES
* increase "engines" to "node" : "^12.22 || ^14.13 || >=16" (#2601)
### Bug Fixes
* _ in npm_config_ env variables ([eef4eef](https://www.github.com/nodejs/node-gyp/commit/eef4eefccb13ff6a32db862709ee5b2d4edf7e95))
* update make-fetch-happen to a minimum of 10.0.3 ([839e414](https://www.github.com/nodejs/node-gyp/commit/839e414b63790c815a4a370d0feee8f24a94d40f))
### Miscellaneous
* add minimal SECURITY.md ([#2560](https://www.github.com/nodejs/node-gyp/issues/2560)) ([c2a1850](https://www.github.com/nodejs/node-gyp/commit/c2a185056e2e589b520fbc0bcc59c2935cd07ede))
### Doc
* Add notes/disclaimers for upgrading the copy of node-gyp that npm uses ([#2585](https://www.github.com/nodejs/node-gyp/issues/2585)) ([faf6d48](https://www.github.com/nodejs/node-gyp/commit/faf6d48f8a77c08a313baf9332358c4b1231c73c))
* Rename and update Common-issues.md --> docs/README.md ([#2567](https://www.github.com/nodejs/node-gyp/issues/2567)) ([2ef5fb8](https://www.github.com/nodejs/node-gyp/commit/2ef5fb86277c4d81baffc0b9f642a8d86be1bfa5))
* rephrase explanation of which node-gyp is used by npm ([#2587](https://www.github.com/nodejs/node-gyp/issues/2587)) ([a2f2988](https://www.github.com/nodejs/node-gyp/commit/a2f298870692022302fa27a1d42363c4a72df407))
* title match content ([#2574](https://www.github.com/nodejs/node-gyp/issues/2574)) ([6e8f93b](https://www.github.com/nodejs/node-gyp/commit/6e8f93be0443f2649d4effa7bc773a9da06a33b4))
* Update Python versions ([#2571](https://www.github.com/nodejs/node-gyp/issues/2571)) ([e069f13](https://www.github.com/nodejs/node-gyp/commit/e069f13658a8bfb5fd60f74708cf8be0856d92e3))
### Core
* add lib.target as path for searching libnode on z/OS ([1d499dd](https://www.github.com/nodejs/node-gyp/commit/1d499dd5606f39de2d34fa822fd0fa5ce17fbd06))
* increase "engines" to "node" : "^12.22 || ^14.13 || >=16" ([#2601](https://www.github.com/nodejs/node-gyp/issues/2601)) ([6562f92](https://www.github.com/nodejs/node-gyp/commit/6562f92a6f2e67aeae081ddf5272ff117f1fab07))
* make-fetch-happen@10.0.1 ([78f6660](https://www.github.com/nodejs/node-gyp/commit/78f66604e0df480d4f36a8fa4f3618c046a6fbdc))
### [8.4.1](https://www.github.com/nodejs/node-gyp/compare/v8.4.0...v8.4.1) (2021-11-19)
### Bug Fixes
* windows command missing space ([#2553](https://www.github.com/nodejs/node-gyp/issues/2553)) ([cc37b88](https://www.github.com/nodejs/node-gyp/commit/cc37b880690706d3c5d04d5a68c76c392a0a23ed))
### Doc
* fix typo in powershell node-gyp update ([787cf7f](https://www.github.com/nodejs/node-gyp/commit/787cf7f8e5ddd5039e02b64ace6b7b15e06fe0a4))
### Core
* npmlog@6.0.0 ([8083f6b](https://www.github.com/nodejs/node-gyp/commit/8083f6b855bd7f3326af04c5f5269fc28d7f2508))
## [8.4.0](https://www.github.com/nodejs/node-gyp/compare/v8.3.0...v8.4.0) (2021-11-05)
### Features
* build with config.gypi from node headers ([a27dc08](https://www.github.com/nodejs/node-gyp/commit/a27dc08696911c6d81e76cc228697243069103c1))
* support vs2022 ([#2533](https://www.github.com/nodejs/node-gyp/issues/2533)) ([5a00387](https://www.github.com/nodejs/node-gyp/commit/5a00387e5f8018264a1822f6c4d5dbf425f21cf6))
## [8.3.0](https://www.github.com/nodejs/node-gyp/compare/v8.2.0...v8.3.0) (2021-10-11)
### Features
* **gyp:** update gyp to v0.10.0 ([#2521](https://www.github.com/nodejs/node-gyp/issues/2521)) ([5585792](https://www.github.com/nodejs/node-gyp/commit/5585792922a97f0629f143c560efd74470eae87f))
### Tests
* Python 3.10 was release on Oct. 4th ([#2504](https://www.github.com/nodejs/node-gyp/issues/2504)) ([0a67dcd](https://www.github.com/nodejs/node-gyp/commit/0a67dcd1307f3560495219253241eafcbf4e2a69))
### Miscellaneous
* **deps:** bump make-fetch-happen from 8.0.14 to 9.1.0 ([b05b4fe](https://www.github.com/nodejs/node-gyp/commit/b05b4fe9891f718f40edf547e9b50e982826d48a))
* refactor the creation of config.gypi file ([f2ad87f](https://www.github.com/nodejs/node-gyp/commit/f2ad87ff65f98ad66daa7225ad59d99b759a2b07))
## [8.2.0](https://www.github.com/nodejs/node-gyp/compare/v8.1.0...v8.2.0) (2021-08-23)
### Features
* **gyp:** update gyp to v0.9.6 ([#2481](https://www.github.com/nodejs/node-gyp/issues/2481)) ([ed9a9ed](https://www.github.com/nodejs/node-gyp/commit/ed9a9ed653a17c84afa3c327161992d0da7d0cea))
### Bug Fixes
* add error arg back into catch block for older Node.js users ([5cde818](https://www.github.com/nodejs/node-gyp/commit/5cde818aac715477e9e9747966bb6b4c4ed070a8))
* change default gyp update message ([#2420](https://www.github.com/nodejs/node-gyp/issues/2420)) ([cfd12ff](https://www.github.com/nodejs/node-gyp/commit/cfd12ff3bb0eb4525173413ef6a94b3cd8398cad))
* doc how to update node-gyp independently from npm ([c8c0af7](https://www.github.com/nodejs/node-gyp/commit/c8c0af72e78141a02b5da4cd4d704838333a90bd))
* missing spaces ([f0882b1](https://www.github.com/nodejs/node-gyp/commit/f0882b1264b2fa701adbc81a3be0b3cba80e333d))
### Core
* deep-copy process.config during configure ([#2368](https://www.github.com/nodejs/node-gyp/issues/2368)) ([5f1a06c](https://www.github.com/nodejs/node-gyp/commit/5f1a06c50f3b0c3d292f64948f85a004cfcc5c87))
### Miscellaneous
* **deps:** bump tar from 6.1.0 to 6.1.2 ([#2474](https://www.github.com/nodejs/node-gyp/issues/2474)) ([ec15a3e](https://www.github.com/nodejs/node-gyp/commit/ec15a3e5012004172713c11eebcc9d852d32d380))
* fix typos discovered by codespell ([#2442](https://www.github.com/nodejs/node-gyp/issues/2442)) ([2d0ce55](https://www.github.com/nodejs/node-gyp/commit/2d0ce5595e232a3fc7c562cdf39efb77e2312cc1))
* GitHub Actions Test on node: [12.x, 14.x, 16.x] ([#2439](https://www.github.com/nodejs/node-gyp/issues/2439)) ([b7bccdb](https://www.github.com/nodejs/node-gyp/commit/b7bccdb527d93b0bb0ce99713f083ce2985fe85c))
### Doc
* correct link to "binding.gyp files out in the wild" ([#2483](https://www.github.com/nodejs/node-gyp/issues/2483)) ([660dd7b](https://www.github.com/nodejs/node-gyp/commit/660dd7b2a822c184be8027b300e68be67b366772))
* **wiki:** Add a link to the node-midi binding.gyp file. ([b354711](https://www.github.com/nodejs/node-gyp/commit/b3547115f6e356358138310e857c7f1ec627a8a7))
* **wiki:** add bcrypt ([e199cfa](https://www.github.com/nodejs/node-gyp/commit/e199cfa8fc6161492d2a6ade2190510d0ebf7c0f))
* **wiki:** Add helpful information ([4eda827](https://www.github.com/nodejs/node-gyp/commit/4eda8275c03dae6d2f5c40f3c1dbe930d84b0f2b))
* **wiki:** Add node-canvas ([13a9553](https://www.github.com/nodejs/node-gyp/commit/13a955317b39caf98fd1f412d8d3f41599e979fd))
* **wiki:** Add node-openvg-canvas and node-openvg. ([61f709e](https://www.github.com/nodejs/node-gyp/commit/61f709ec4d9f256a6467e9ff84430a48eeb629d1))
* **wiki:** add one more example ([77f3632](https://www.github.com/nodejs/node-gyp/commit/77f363272930d3d4d24fd3973be22e6237128fcc))
* **wiki:** add topcube, node-osmium, and node-osrm ([1a75d2b](https://www.github.com/nodejs/node-gyp/commit/1a75d2bf2f562ba50846893a516e111cfbb50885))
* **wiki:** Added details for properly fixing ([3d4d9d5](https://www.github.com/nodejs/node-gyp/commit/3d4d9d52d6b5b49de06bb0bb5b68e2686d2b7ebd))
* **wiki:** Added Ghostscript4JS ([bf4bed1](https://www.github.com/nodejs/node-gyp/commit/bf4bed1b96a7d22fba6f97f4552ad09f32ac3737))
* **wiki:** added levelup ([1575bce](https://www.github.com/nodejs/node-gyp/commit/1575bce3a53db628bfb023fd6f3258fdf98c3195))
* **wiki:** Added nk-mysql (nodamysql) ([5b4f2d0](https://www.github.com/nodejs/node-gyp/commit/5b4f2d0e1d5d3eadfd03aaf9c1668340f76c4bea))
* **wiki:** Added nk-xrm-installer .gyp references, including .py scripts for providing complete reference to examples of fetching source via http, extracting, and moving files (as opposed to copying) ([ceb3088](https://www.github.com/nodejs/node-gyp/commit/ceb30885b74f6789374ef52267b84767be93ebe4))
* **wiki:** Added tip about resolving frustrating LNK1181 error ([e64798d](https://www.github.com/nodejs/node-gyp/commit/e64798de8cac6031ad598a86d7599e81b4d20b17))
* **wiki:** ADDED: Node.js binding to OpenCV ([e2dc777](https://www.github.com/nodejs/node-gyp/commit/e2dc77730b09d7ee8682d7713a7603a2d7aacabd))
* **wiki:** Adding link to node-cryptopp's gyp file ([875adbe](https://www.github.com/nodejs/node-gyp/commit/875adbe2a4669fa5f2be0250ffbf98fb55e800fd))
* **wiki:** Adding the sharp library to the list ([9dce0e4](https://www.github.com/nodejs/node-gyp/commit/9dce0e41650c3fa973e6135a79632d022c662a1d))
* **wiki:** Adds node-fann ([23e3d48](https://www.github.com/nodejs/node-gyp/commit/23e3d485ed894ba7c631e9c062f5e366b50c416c))
* **wiki:** Adds node-inotify and v8-profiler ([b6e542f](https://www.github.com/nodejs/node-gyp/commit/b6e542f644dbbfe22b88524ec500696e06ee4af7))
* **wiki:** Bumping Python version from 2.3 to 2.7 as per the node-gyp readme ([55ebd6e](https://www.github.com/nodejs/node-gyp/commit/55ebd6ebacde975bf84f7bf4d8c66e64cc7cd0da))
* **wiki:** C++ build tools version upgraded ([5b899b7](https://www.github.com/nodejs/node-gyp/commit/5b899b70db729c392ced7c98e8e17590c6499fc3))
* **wiki:** change bcrypt url to binding.gyp file ([e11bdd8](https://www.github.com/nodejs/node-gyp/commit/e11bdd84de6144492d3eb327d67cbf2d62da1a76))
* **wiki:** Clarification + direct link to VS2010 ([531c724](https://www.github.com/nodejs/node-gyp/commit/531c724561d947b5d870de8d52dd8c3c51c5ec2d))
* **wiki:** Correcting the link to node-osmium ([fae7516](https://www.github.com/nodejs/node-gyp/commit/fae7516a1d2829b6e234eaded74fb112ebd79a05))
* **wiki:** Created "binding.gyp" files out in the wild (markdown) ([d4fd143](https://www.github.com/nodejs/node-gyp/commit/d4fd14355bbe57f229f082f47bb2b3670868203f))
* **wiki:** Created Common issues (markdown) ([a38299e](https://www.github.com/nodejs/node-gyp/commit/a38299ea340ceb0e732c6dc6a1b4760257644839))
* **wiki:** Created Error: "pre" versions of node cannot be installed (markdown) ([98bc80d](https://www.github.com/nodejs/node-gyp/commit/98bc80d7a62ba70c881f3c39d94f804322e57852))
* **wiki:** Created Linking to OpenSSL (markdown) ([c46d00d](https://www.github.com/nodejs/node-gyp/commit/c46d00d83bac5173dea8bbbb175a1a7de74fdaca))
* **wiki:** Created Updating npm's bundled node gyp (markdown) ([e0ac8d1](https://www.github.com/nodejs/node-gyp/commit/e0ac8d15af46aadd1c220599e63199b154a514e6))
* **wiki:** Created use of undeclared identifier 'TypedArray' (markdown) ([65ba711](https://www.github.com/nodejs/node-gyp/commit/65ba71139e9b7f64ac823e575ee9dbf17d937ce4))
* **wiki:** Created Visual Studio 2010 Setup (markdown) ([5b80e83](https://www.github.com/nodejs/node-gyp/commit/5b80e834c8f79dda9fb2770a876ff3cf649c06f3))
* **wiki:** Created Visual studio 2012 setup (markdown) ([becef31](https://www.github.com/nodejs/node-gyp/commit/becef316b6c46a33e783667720ee074a0141d1a5))
* **wiki:** Destroyed Visual Studio 2010 Setup (markdown) ([93423b4](https://www.github.com/nodejs/node-gyp/commit/93423b43606de9664aeb79635825f5e9941ec9bc))
* **wiki:** Destroyed Visual studio 2012 setup (markdown) ([3601508](https://www.github.com/nodejs/node-gyp/commit/3601508bb10fa05da0ddc7e70d57e4b4dd679657))
* **wiki:** Different commands for Windows npm v6 vs. v7 ([0fce46b](https://www.github.com/nodejs/node-gyp/commit/0fce46b53340c85e8091cde347d5ed23a443c82f))
* **wiki:** Drop in favor of ([9285ff6](https://www.github.com/nodejs/node-gyp/commit/9285ff6e451c52c070a05f05f0a9602621d91d53))
* **wiki:** Explicit link to Visual C++ 2010 Express ([378c363](https://www.github.com/nodejs/node-gyp/commit/378c3632f02c096ed819ec8f2611c65bef0c0554))
* **wiki:** fix link to gyp file used to build libsqlite3 ([54db8d7](https://www.github.com/nodejs/node-gyp/commit/54db8d7ac33e3f98220960b5d86cfa18a75b53cb))
* **wiki:** Fix link to node-zipfile ([92e49a8](https://www.github.com/nodejs/node-gyp/commit/92e49a858ed69cb4847a26a5676ab56ef5e2de33))
* **wiki:** fixed node-serialport link ([954ee53](https://www.github.com/nodejs/node-gyp/commit/954ee530b3972d1db591fce32368e4e31b5a25d8))
* **wiki:** I highly missing it in common issue as every windows biggner face that issue ([d617fae](https://www.github.com/nodejs/node-gyp/commit/d617faee29c40871ca5c8f93efd0ce929a40d541))
* **wiki:** if ouns that the -h did not help. I founs on github that there was support for visual studio 2015, while i couldn't install node-red beacuse it kept telling me the key 2015 was missing. looking in he gyp python code i found the local file was bot up t dat with the github repo. updating took several efforts before i tried to drop the -g option. ([408b72f](https://www.github.com/nodejs/node-gyp/commit/408b72f561329408daeb17834436e381406efcc8))
* **wiki:** If permissions error, please try and then the command. ([ee8e1c1](https://www.github.com/nodejs/node-gyp/commit/ee8e1c1e5334096d58e0d6bca6c006f2ee9c88cb))
* **wiki:** Improve Unix instructions ([c3e5487](https://www.github.com/nodejs/node-gyp/commit/c3e548736645b535ea5bce613d74ca3e98598243))
* **wiki:** link to docs/ from README ([b52e487](https://www.github.com/nodejs/node-gyp/commit/b52e487eac1eb421573d1e67114a242eeff45a00))
* **wiki:** Lower case L ([3aa2c6b](https://www.github.com/nodejs/node-gyp/commit/3aa2c6bdb07971b87505e32e32548d75264bd19f))
* **wiki:** Make changes discussed in https://github.com/nodejs/node-gyp/issues/2416 ([1dcad87](https://www.github.com/nodejs/node-gyp/commit/1dcad873539027511a5f0243baf770ea90f6f4e2))
* **wiki:** move wiki docs into doc/ ([f0a4835](https://www.github.com/nodejs/node-gyp/commit/f0a48355d86534ec3bdabcdb3ce3340fa2e17f39))
* **wiki:** node-sass in the wild ([d310a73](https://www.github.com/nodejs/node-gyp/commit/d310a73d64d0065050377baac7047472f7424a1b))
* **wiki:** node-srs was a 404 ([bbca21a](https://www.github.com/nodejs/node-gyp/commit/bbca21a1e1ede4c473aff365ca71989a5bda7b57))
* **wiki:** Note: VS2010 seems to be no longer available! VS2013 or nothing! ([7b5dcaf](https://www.github.com/nodejs/node-gyp/commit/7b5dcafafccdceae4b8f2b53ac9081a694b6ade8))
* **wiki:** safer doc names, remove unnecessary TypedArray doc ([161c235](https://www.github.com/nodejs/node-gyp/commit/161c2353ef5b562f4acfb2fd77608fcbd0800fc0))
* **wiki:** sorry, forgot to mention a specific windows version. ([d69dffc](https://www.github.com/nodejs/node-gyp/commit/d69dffc16c2b1e3c60dcb5d1c35a49270ba22a35))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([7444b47](https://www.github.com/nodejs/node-gyp/commit/7444b47a7caac1e14d1da474a7fcfcf88d328017))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([d766b74](https://www.github.com/nodejs/node-gyp/commit/d766b7427851e6c2edc02e2504a7be9be7e330c0))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([d319b0e](https://www.github.com/nodejs/node-gyp/commit/d319b0e98c7085de8e51bc5595eba4264b99a7d5))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([3c6692d](https://www.github.com/nodejs/node-gyp/commit/3c6692d538f0ce973869aa237118b7d2483feccd))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([93392d5](https://www.github.com/nodejs/node-gyp/commit/93392d559ce6f250b9c7fe8177e6c88603809dc1))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([8841158](https://www.github.com/nodejs/node-gyp/commit/88411588f300e9b7c00fe516ecd977a1feeeb15c))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([81bfa1f](https://www.github.com/nodejs/node-gyp/commit/81bfa1f1b63d522a9f8a9ae9ca0c7ae90fe75140))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([d1cd237](https://www.github.com/nodejs/node-gyp/commit/d1cd237bad06fa507adb354b9e2181a14dc63d24))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([3de9e17](https://www.github.com/nodejs/node-gyp/commit/3de9e17e0b8a387eafe7bd18d0ec1e3191d118e8))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([a9b7096](https://www.github.com/nodejs/node-gyp/commit/a9b70968fb956eab3b95672048b94350e1565ca3))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([3236069](https://www.github.com/nodejs/node-gyp/commit/3236069689e7e0eb15b324fce74ab58158956f98))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([1462755](https://www.github.com/nodejs/node-gyp/commit/14627556966e5d513bdb8e5208f0e1300f68991f))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([7ab1337](https://www.github.com/nodejs/node-gyp/commit/7ab133752a6c402bb96dcd3d671d73e03e9487ad))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([640895d](https://www.github.com/nodejs/node-gyp/commit/640895d36b7448c646a3b850c1e159106f83c724))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([ced8c96](https://www.github.com/nodejs/node-gyp/commit/ced8c968457f285ab8989c291d28173d7730833c))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([27b883a](https://www.github.com/nodejs/node-gyp/commit/27b883a350ad0db6b9130d7b996f35855ec34c7a))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([d29fb13](https://www.github.com/nodejs/node-gyp/commit/d29fb134f1c4b9dd729ba95f2979e69e0934809f))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([2765891](https://www.github.com/nodejs/node-gyp/commit/27658913e6220cf0371b4b73e25a0e4ab11108a1))
* **wiki:** Updated "binding.gyp" files out in the wild (markdown) ([dc97766](https://www.github.com/nodejs/node-gyp/commit/dc9776648d432bca6775c176641f16da14522d4c))
* **wiki:** Updated Error: "pre" versions of node cannot be installed (markdown) ([e9f8b33](https://www.github.com/nodejs/node-gyp/commit/e9f8b33d1f87d04f22cb09a814d7c55d0fa38446))
* **wiki:** Updated Home (markdown) ([3407109](https://www.github.com/nodejs/node-gyp/commit/3407109325cf7ba1e925656b9eb75feffab0557c))
* **wiki:** Updated Home (markdown) ([6e392bc](https://www.github.com/nodejs/node-gyp/commit/6e392bcdd3dd1691773e6e16e1dffc35931b81e0))
* **wiki:** Updated Home (markdown) ([65efe32](https://www.github.com/nodejs/node-gyp/commit/65efe32ccb8d446ce569453364f922dd9d27c945))
* **wiki:** Updated Home (markdown) ([ea28f09](https://www.github.com/nodejs/node-gyp/commit/ea28f0947af91fa638be355143f5df89d2e431c8))
* **wiki:** Updated Home (markdown) ([0e37ff4](https://www.github.com/nodejs/node-gyp/commit/0e37ff48b306c12149661b375895741d3d710da7))
* **wiki:** Updated Home (markdown) ([b398ef4](https://www.github.com/nodejs/node-gyp/commit/b398ef46f660d2b1506508550dadfb4c35639e4b))
* **wiki:** Updated Linking to OpenSSL (markdown) ([8919028](https://www.github.com/nodejs/node-gyp/commit/8919028921fd304f08044098434f0dc6071fb7cf))
* **wiki:** Updated Linking to OpenSSL (markdown) ([c00eb77](https://www.github.com/nodejs/node-gyp/commit/c00eb778fc7dc27e4dab3a9219035ea20458b33b))
* **wiki:** Updated node-levelup to node-leveldown (broken links) ([59668bb](https://www.github.com/nodejs/node-gyp/commit/59668bb0b904feccf3c09afa2fd37378c77af967))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([d314854](https://www.github.com/nodejs/node-gyp/commit/d31485415ef69d46effa6090c95698341965de1b))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([11858b0](https://www.github.com/nodejs/node-gyp/commit/11858b0655d1eee00c62ad628e719d4378803d14))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([33561e9](https://www.github.com/nodejs/node-gyp/commit/33561e9cbf5f4eb46111318503c77df2c6eb484a))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([4a7f2d0](https://www.github.com/nodejs/node-gyp/commit/4a7f2d0d869a65c99a78504976567017edadf657))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([979a706](https://www.github.com/nodejs/node-gyp/commit/979a7063b950c088a7f4896fc3a48e1d00dfd231))
* **wiki:** Updated Updating npm's bundled node gyp (markdown) ([e50e04d](https://www.github.com/nodejs/node-gyp/commit/e50e04d7b6a3754ea0aa11fe8cef491b3bc5bdd4))
## [8.1.0](https://www.github.com/nodejs/node-gyp/compare/v8.0.0...v8.1.0) (2021-05-28)
### Features
* **gyp:** update gyp to v0.9.1 ([#2402](https://www.github.com/nodejs/node-gyp/issues/2402)) ([814b1b0](https://www.github.com/nodejs/node-gyp/commit/814b1b0eda102afb9fc87e81638a9cf5b650bb10))
### Miscellaneous
* add `release-please-action` for automated releases ([#2395](https://www.github.com/nodejs/node-gyp/issues/2395)) ([07e9d7c](https://www.github.com/nodejs/node-gyp/commit/07e9d7c7ee80ba119ea760c635f72fd8e7efe198))
### Core
* fail gracefully if we can't find the username ([#2375](https://www.github.com/nodejs/node-gyp/issues/2375)) ([fca4795](https://www.github.com/nodejs/node-gyp/commit/fca4795512c67dc8420aaa0d913b5b89a4b147f3))
* log as yes/no whether build dir was created ([#2370](https://www.github.com/nodejs/node-gyp/issues/2370)) ([245dee5](https://www.github.com/nodejs/node-gyp/commit/245dee5b62581309946872ae253226ea3a42c0e3))
### Doc
* fix v8.0.0 release date ([4b83c3d](https://www.github.com/nodejs/node-gyp/commit/4b83c3de7300457919d53f26d96ea9ad6f6bedd8))
* remove redundant version info ([#2403](https://www.github.com/nodejs/node-gyp/issues/2403)) ([1423670](https://www.github.com/nodejs/node-gyp/commit/14236709de64b100a424396b91a5115639daa0ef))
* Update README.md Visual Studio Community page polski to auto ([#2371](https://www.github.com/nodejs/node-gyp/issues/2371)) ([1b4697a](https://www.github.com/nodejs/node-gyp/commit/1b4697abf69ef574a48faf832a7098f4c6c224a5))
## v8.0.0 2021-04-03
* [[`0d8a6f1b19`](https://github.com/nodejs/node-gyp/commit/0d8a6f1b19)] - **ci**: update actions/setup-node to v2 (#2302) (Sora Morimoto) [#2302](https://github.com/nodejs/node-gyp/pull/2302)
* [[`15a5c7d45b`](https://github.com/nodejs/node-gyp/commit/15a5c7d45b)] - **ci**: migrate deprecated grammar (#2285) (Jiawen Geng) [#2285](https://github.com/nodejs/node-gyp/pull/2285)
* [[`06ddde27f9`](https://github.com/nodejs/node-gyp/commit/06ddde27f9)] - **deps**: sync mutual dependencies with npm (DeeDeeG) [#2348](https://github.com/nodejs/node-gyp/pull/2348)
* [[`a5fd1f41e3`](https://github.com/nodejs/node-gyp/commit/a5fd1f41e3)] - **doc**: add downloads badge (#2352) (Jiawen Geng) [#2352](https://github.com/nodejs/node-gyp/pull/2352)
* [[`cc1cbce056`](https://github.com/nodejs/node-gyp/commit/cc1cbce056)] - **doc**: update macOS\_Catalina.md (#2293) (iMrLopez) [#2293](https://github.com/nodejs/node-gyp/pull/2293)
* [[`6287118fc4`](https://github.com/nodejs/node-gyp/commit/6287118fc4)] - **doc**: updated README.md to copy easily (#2281) (மனோஜ்குமார் பழனிச்சாமி) [#2281](https://github.com/nodejs/node-gyp/pull/2281)
* [[`66c0f04467`](https://github.com/nodejs/node-gyp/commit/66c0f04467)] - **doc**: add missing `sudo` to Catalina doc (Karl Horky) [#2244](https://github.com/nodejs/node-gyp/pull/2244)
* [[`0da2e0140d`](https://github.com/nodejs/node-gyp/commit/0da2e0140d)] - **gyp**: update gyp to v0.8.1 (#2355) (DeeDeeG) [#2355](https://github.com/nodejs/node-gyp/pull/2355)
* [[`0093ec8646`](https://github.com/nodejs/node-gyp/commit/0093ec8646)] - **gyp**: Improve our flake8 linting tests (Christian Clauss) [#2356](https://github.com/nodejs/node-gyp/pull/2356)
* [[`a78b584236`](https://github.com/nodejs/node-gyp/commit/a78b584236)] - **(SEMVER-MAJOR)** **gyp**: remove support for Python 2 (#2300) (Christian Clauss) [#2300](https://github.com/nodejs/node-gyp/pull/2300)
* [[`c3c510d89e`](https://github.com/nodejs/node-gyp/commit/c3c510d89e)] - **gyp**: update gyp to v0.8.0 (#2318) (Christian Clauss) [#2318](https://github.com/nodejs/node-gyp/pull/2318)
* [[`9e1397c52e`](https://github.com/nodejs/node-gyp/commit/9e1397c52e)] - **(SEMVER-MAJOR)** **gyp**: update gyp to v0.7.0 (#2284) (Jiawen Geng) [#2284](https://github.com/nodejs/node-gyp/pull/2284)
* [[`1bd18f3e77`](https://github.com/nodejs/node-gyp/commit/1bd18f3e77)] - **(SEMVER-MAJOR)** **lib**: drop Python 2 support in find-python.js (#2333) (DeeDeeG) [#2333](https://github.com/nodejs/node-gyp/pull/2333)
* [[`e81602ef55`](https://github.com/nodejs/node-gyp/commit/e81602ef55)] - **(SEMVER-MAJOR)** **lib**: migrate requests to fetch (#2220) (Matias Lopez) [#2220](https://github.com/nodejs/node-gyp/pull/2220)
* [[`392b7760b4`](https://github.com/nodejs/node-gyp/commit/392b7760b4)] - **lib**: avoid changing process.config (#2322) (Michaël Zasso) [#2322](https://github.com/nodejs/node-gyp/pull/2322)
## v7.1.2 2020-10-17
* [[`096e3aded5`](https://github.com/nodejs/node-gyp/commit/096e3aded5)] - **gyp**: update gyp to 0.6.2 (Myles Borins) [#2241](https://github.com/nodejs/node-gyp/pull/2241)
* [[`54f97cd243`](https://github.com/nodejs/node-gyp/commit/54f97cd243)] - **doc**: add cmd to reset `xcode-select` to initial state (Valera Rozuvan) [#2235](https://github.com/nodejs/node-gyp/pull/2235)
## v7.1.1 2020-10-15
This release restores the location of shared library builds to the pre-v7
location. In v7.0.0 until this release, shared library outputs were placed
in a lib.target subdirectory inside the build/{Release,Debug} directory for
builds using `make` (Linux, etc.). This is inconsistent with macOS (Xcode)
behavior and previous node-gyp behavior so has been reverted.
We consider this a bug-fix rather than semver-major change.
* [[`18bf2d1d38`](https://github.com/nodejs/node-gyp/commit/18bf2d1d38)] - **deps**: update deps to match npm@7 (Rod Vagg) [#2240](https://github.com/nodejs/node-gyp/pull/2240)
* [[`ee6a837cb7`](https://github.com/nodejs/node-gyp/commit/ee6a837cb7)] - **gyp**: update gyp to 0.6.1 (Rod Vagg) [#2238](https://github.com/nodejs/node-gyp/pull/2238)
* [[`3e7f8ccafc`](https://github.com/nodejs/node-gyp/commit/3e7f8ccafc)] - **lib**: better log message when ps fails (Martin Midtgaard) [#2229](https://github.com/nodejs/node-gyp/pull/2229)
* [[`7fb314339f`](https://github.com/nodejs/node-gyp/commit/7fb314339f)] - **test**: GitHub Actions: Test on Python 3.9 (Christian Clauss) [#2230](https://github.com/nodejs/node-gyp/pull/2230)
* [[`754996b9ec`](https://github.com/nodejs/node-gyp/commit/754996b9ec)] - **doc**: replace status badges with new Actions badge (Rod Vagg) [#2218](https://github.com/nodejs/node-gyp/pull/2218)
* [[`2317dc400c`](https://github.com/nodejs/node-gyp/commit/2317dc400c)] - **ci**: switch to GitHub Actions (Shelley Vohr) [#2210](https://github.com/nodejs/node-gyp/pull/2210)
* [[`2cca9b74f7`](https://github.com/nodejs/node-gyp/commit/2cca9b74f7)] - **doc**: drop the --production flag for installing windows-build-tools (DeeDeeG) [#2206](https://github.com/nodejs/node-gyp/pull/2206)
## v7.1.0 2020-08-12
* [[`aaf33c3029`](https://github.com/nodejs/node-gyp/commit/aaf33c3029)] - **build**: add update-gyp script (Samuel Attard) [#2167](https://github.com/nodejs/node-gyp/pull/2167)
* * [[`3baa4e4172`](https://github.com/nodejs/node-gyp/commit/3baa4e4172)] - **(SEMVER-MINOR)** **gyp**: update gyp to 0.4.0 (Samuel Attard) [#2165](https://github.com/nodejs/node-gyp/pull/2165)
* * [[`f461d56c53`](https://github.com/nodejs/node-gyp/commit/f461d56c53)] - **(SEMVER-MINOR)** **build**: support apple silicon (arm64 darwin) builds (Samuel Attard) [#2165](https://github.com/nodejs/node-gyp/pull/2165)
* * [[`ee6fa7d3bc`](https://github.com/nodejs/node-gyp/commit/ee6fa7d3bc)] - **docs**: note that node-gyp@7 should solve Catalina CLT issues (Rod Vagg) [#2156](https://github.com/nodejs/node-gyp/pull/2156)
* * [[`4fc8ff179d`](https://github.com/nodejs/node-gyp/commit/4fc8ff179d)] - **doc**: silence curl for macOS Catalina acid test (Chia Wei Ong) [#2150](https://github.com/nodejs/node-gyp/pull/2150)
* * [[`7857cb2eb1`](https://github.com/nodejs/node-gyp/commit/7857cb2eb1)] - **deps**: increase "engines" to "node" : "\>= 10.12.0" (DeeDeeG) [#2153](https://github.com/nodejs/node-gyp/pull/2153)
## v7.0.0 2020-06-03
* [[`e18a61afc1`](https://github.com/nodejs/node-gyp/commit/e18a61afc1)] - **build**: shrink bloated addon binaries on windows (Shelley Vohr) [#2060](https://github.com/nodejs/node-gyp/pull/2060)
* [[`4937722cf5`](https://github.com/nodejs/node-gyp/commit/4937722cf5)] - **(SEMVER-MAJOR)** **deps**: replace mkdirp with {recursive} mkdir (Rod Vagg) [#2123](https://github.com/nodejs/node-gyp/pull/2123)
* [[`d45438a047`](https://github.com/nodejs/node-gyp/commit/d45438a047)] - **(SEMVER-MAJOR)** **deps**: update deps, match to npm@7 (Rod Vagg) [#2126](https://github.com/nodejs/node-gyp/pull/2126)
* [[`ba4f34b7d6`](https://github.com/nodejs/node-gyp/commit/ba4f34b7d6)] - **doc**: update catalina xcode clt download link (Dario Vladovic) [#2133](https://github.com/nodejs/node-gyp/pull/2133)
* [[`f7bfce96ed`](https://github.com/nodejs/node-gyp/commit/f7bfce96ed)] - **doc**: update acid test and introduce curl|bash test script (Dario Vladovic) [#2105](https://github.com/nodejs/node-gyp/pull/2105)
* [[`e529f3309d`](https://github.com/nodejs/node-gyp/commit/e529f3309d)] - **doc**: update README to reflect upgrade to gyp-next (Ujjwal Sharma) [#2092](https://github.com/nodejs/node-gyp/pull/2092)
* [[`9aed6286a3`](https://github.com/nodejs/node-gyp/commit/9aed6286a3)] - **doc**: give more attention to Catalina issues doc (Matheus Marchini) [#2134](https://github.com/nodejs/node-gyp/pull/2134)
* [[`963f2a7b48`](https://github.com/nodejs/node-gyp/commit/963f2a7b48)] - **doc**: improve Catalina discoverability for search engines (Matheus Marchini) [#2135](https://github.com/nodejs/node-gyp/pull/2135)
* [[`7b75af349b`](https://github.com/nodejs/node-gyp/commit/7b75af349b)] - **doc**: add macOS Catalina software update info (Karl Horky) [#2078](https://github.com/nodejs/node-gyp/pull/2078)
* [[`4f23c7bee2`](https://github.com/nodejs/node-gyp/commit/4f23c7bee2)] - **doc**: update link to the code of conduct (#2073) (Michaël Zasso) [#2073](https://github.com/nodejs/node-gyp/pull/2073)
* [[`473cfa283f`](https://github.com/nodejs/node-gyp/commit/473cfa283f)] - **doc**: note in README that Python 3.8 is supported (#2072) (Michaël Zasso) [#2072](https://github.com/nodejs/node-gyp/pull/2072)
* [[`e7402b4a7c`](https://github.com/nodejs/node-gyp/commit/e7402b4a7c)] - **doc**: update catalina xcode cli tools download link (#2044) (Dario Vladović) [#2044](https://github.com/nodejs/node-gyp/pull/2044)
* [[`35de45984f`](https://github.com/nodejs/node-gyp/commit/35de45984f)] - **doc**: update catalina xcode cli tools download link; formatting (Jonathan Hult) [#2034](https://github.com/nodejs/node-gyp/pull/2034)
* [[`48642191f5`](https://github.com/nodejs/node-gyp/commit/48642191f5)] - **doc**: add download link for Command Line Tools for Xcode (Przemysław Bitkowski) [#2029](https://github.com/nodejs/node-gyp/pull/2029)
* [[`ae5b150051`](https://github.com/nodejs/node-gyp/commit/ae5b150051)] - **doc**: Catalina suggestion: remove /Library/Developer/CommandLineTools (Christian Clauss) [#2022](https://github.com/nodejs/node-gyp/pull/2022)
* [[`d1dea13fe4`](https://github.com/nodejs/node-gyp/commit/d1dea13fe4)] - **doc**: fix changelog 6.1.0 release year to be 2020 (Quentin Vernot) [#2021](https://github.com/nodejs/node-gyp/pull/2021)
* [[`6356117b08`](https://github.com/nodejs/node-gyp/commit/6356117b08)] - **doc, bin**: stop suggesting opening node-gyp issues (Bartosz Sosnowski) [#2096](https://github.com/nodejs/node-gyp/pull/2096)
* [[`a6b76a8b48`](https://github.com/nodejs/node-gyp/commit/a6b76a8b48)] - **gyp**: update gyp to 0.2.1 (Ujjwal Sharma) [#2092](https://github.com/nodejs/node-gyp/pull/2092)
* [[`ebc34ec823`](https://github.com/nodejs/node-gyp/commit/ebc34ec823)] - **gyp**: update gyp to 0.2.0 (Ujjwal Sharma) [#2092](https://github.com/nodejs/node-gyp/pull/2092)
* [[`972780bde7`](https://github.com/nodejs/node-gyp/commit/972780bde7)] - **(SEMVER-MAJOR)** **gyp**: sync code base with nodejs repo (#1975) (Michaël Zasso) [#1975](https://github.com/nodejs/node-gyp/pull/1975)
* [[`c255ffbf6a`](https://github.com/nodejs/node-gyp/commit/c255ffbf6a)] - **lib**: drop "-2" flag for "py.exe" launcher (DeeDeeG) [#2131](https://github.com/nodejs/node-gyp/pull/2131)
* [[`1f7e1e93b5`](https://github.com/nodejs/node-gyp/commit/1f7e1e93b5)] - **lib**: ignore VS instances that cause COMExceptions (Andrew Casey) [#2018](https://github.com/nodejs/node-gyp/pull/2018)
* [[`741ab096d5`](https://github.com/nodejs/node-gyp/commit/741ab096d5)] - **test**: remove support for EOL versions of Node.js (Shelley Vohr)
* [[`ca86ef2539`](https://github.com/nodejs/node-gyp/commit/ca86ef2539)] - **test**: bump actions/checkout from v1 to v2 (BSKY) [#2063](https://github.com/nodejs/node-gyp/pull/2063)
## v6.1.0 2020-01-08
* [[`9a7dd16b76`](https://github.com/nodejs/node-gyp/commit/9a7dd16b76)] - **doc**: remove backticks from Python version list (Rod Vagg) [#2011](https://github.com/nodejs/node-gyp/pull/2011)
* [[`26cd6eaea6`](https://github.com/nodejs/node-gyp/commit/26cd6eaea6)] - **doc**: add GitHub Actions badge (#1994) (Rod Vagg) [#1994](https://github.com/nodejs/node-gyp/pull/1994)
* [[`312c12ef4f`](https://github.com/nodejs/node-gyp/commit/312c12ef4f)] - **doc**: update macOS\_Catalina.md (#1992) (James Home) [#1992](https://github.com/nodejs/node-gyp/pull/1992)
* [[`f7b6b6b77b`](https://github.com/nodejs/node-gyp/commit/f7b6b6b77b)] - **doc**: fix typo in README.md (#1985) (Suraneti Rodsuwan) [#1985](https://github.com/nodejs/node-gyp/pull/1985)
* [[`6b8f2652dd`](https://github.com/nodejs/node-gyp/commit/6b8f2652dd)] - **doc**: add travis badge (Rod Vagg) [#1971](https://github.com/nodejs/node-gyp/pull/1971)
* [[`20aa0b44f7`](https://github.com/nodejs/node-gyp/commit/20aa0b44f7)] - **doc**: macOS Catalina add two commands (Christian Clauss) [#1962](https://github.com/nodejs/node-gyp/pull/1962)
* [[`14f2a07a39`](https://github.com/nodejs/node-gyp/commit/14f2a07a39)] - **gyp**: list(dict) so we can del dict(key) while iterating (Christian Clauss) [#2009](https://github.com/nodejs/node-gyp/pull/2009)
* [[`f242ce4d2c`](https://github.com/nodejs/node-gyp/commit/f242ce4d2c)] - **lib**: compatibility with semver ≥ 7 (`new` for semver.Range) (Xavier Guimard) [#2006](https://github.com/nodejs/node-gyp/pull/2006)
* [[`3bcba2a01a`](https://github.com/nodejs/node-gyp/commit/3bcba2a01a)] - **(SEMVER-MINOR)** **lib**: noproxy support, match proxy detection to `request` (Matias Lopez) [#1978](https://github.com/nodejs/node-gyp/pull/1978)
* [[`470cc2178e`](https://github.com/nodejs/node-gyp/commit/470cc2178e)] - **test**: remove old docker test harness (#1993) (Rod Vagg) [#1993](https://github.com/nodejs/node-gyp/pull/1993)
* [[`31ecc8421d`](https://github.com/nodejs/node-gyp/commit/31ecc8421d)] - **test**: add Windows to GitHub Actions testing (#1996) (Christian Clauss) [#1996](https://github.com/nodejs/node-gyp/pull/1996)
* [[`5a729e86ee`](https://github.com/nodejs/node-gyp/commit/5a729e86ee)] - **test**: fix typo in header download test (#2001) (Richard Lau) [#2001](https://github.com/nodejs/node-gyp/pull/2001)
* [[`345c70e56d`](https://github.com/nodejs/node-gyp/commit/345c70e56d)] - **test**: direct python invocation & simpler pyenv (Matias Lopez) [#1979](https://github.com/nodejs/node-gyp/pull/1979)
* [[`d6a7e0e1fb`](https://github.com/nodejs/node-gyp/commit/d6a7e0e1fb)] - **test**: fix macOS Travis on Python 2.7 & 3.7 (Christian Clauss) [#1979](https://github.com/nodejs/node-gyp/pull/1979)
* [[`5a64e9bd32`](https://github.com/nodejs/node-gyp/commit/5a64e9bd32)] - **test**: initial Github Actions with Ubuntu & macOS (Christian Clauss) [#1985](https://github.com/nodejs/node-gyp/pull/1985)
* [[`04da736d38`](https://github.com/nodejs/node-gyp/commit/04da736d38)] - **test**: fix Python unittests (cclauss) [#1961](https://github.com/nodejs/node-gyp/pull/1961)
* [[`0670e5189d`](https://github.com/nodejs/node-gyp/commit/0670e5189d)] - **test**: add header download test (Rod Vagg) [#1796](https://github.com/nodejs/node-gyp/pull/1796)
* [[`c506a6a150`](https://github.com/nodejs/node-gyp/commit/c506a6a150)] - **test**: configure proper devDir for invoking configure() (Rod Vagg) [#1796](https://github.com/nodejs/node-gyp/pull/1796)
## v6.0.1 2019-11-01
* [[`8ec2e681d5`](https://github.com/nodejs/node-gyp/commit/8ec2e681d5)] - **doc**: add macOS\_Catalina.md document (cclauss) [#1940](https://github.com/nodejs/node-gyp/pull/1940)
* [[`1b11be63cc`](https://github.com/nodejs/node-gyp/commit/1b11be63cc)] - **gyp**: python3 fixes: utf8 decode, use of 'None' in eval (Wilfried Goesgens) [#1925](https://github.com/nodejs/node-gyp/pull/1925)
* [[`c0282daa48`](https://github.com/nodejs/node-gyp/commit/c0282daa48)] - **gyp**: iteritems() -\> items() in compile\_commands\_json.py (cclauss) [#1947](https://github.com/nodejs/node-gyp/pull/1947)
* [[`d8e09a1b6a`](https://github.com/nodejs/node-gyp/commit/d8e09a1b6a)] - **gyp**: make cmake python3 compatible (gengjiawen) [#1944](https://github.com/nodejs/node-gyp/pull/1944)
* [[`9c0f3404f0`](https://github.com/nodejs/node-gyp/commit/9c0f3404f0)] - **gyp**: fix TypeError in XcodeVersion() (Christian Clauss) [#1939](https://github.com/nodejs/node-gyp/pull/1939)
* [[`bb2eb72a3f`](https://github.com/nodejs/node-gyp/commit/bb2eb72a3f)] - **gyp**: finish decode stdout on Python 3 (Christian Clauss) [#1937](https://github.com/nodejs/node-gyp/pull/1937)
* [[`f0693413d9`](https://github.com/nodejs/node-gyp/commit/f0693413d9)] - **src,win**: allow 403 errors for arm64 node.lib (Richard Lau) [#1934](https://github.com/nodejs/node-gyp/pull/1934)
* [[`c60c22de58`](https://github.com/nodejs/node-gyp/commit/c60c22de58)] - **deps**: update deps to roughly match current npm@6 (Rod Vagg) [#1920](https://github.com/nodejs/node-gyp/pull/1920)
* [[`b91718eefc`](https://github.com/nodejs/node-gyp/commit/b91718eefc)] - **test**: upgrade Linux Travis CI to Python 3.8 (Christian Clauss) [#1923](https://github.com/nodejs/node-gyp/pull/1923)
* [[`3538a317b6`](https://github.com/nodejs/node-gyp/commit/3538a317b6)] - **doc**: adjustments to the README.md for new users (Dan Pike) [#1919](https://github.com/nodejs/node-gyp/pull/1919)
* [[`4fff8458c0`](https://github.com/nodejs/node-gyp/commit/4fff8458c0)] - **travis**: ignore failed `brew upgrade npm`, update xcode (Christian Clauss) [#1932](https://github.com/nodejs/node-gyp/pull/1932)
* [[`60e4488f08`](https://github.com/nodejs/node-gyp/commit/60e4488f08)] - **build**: avoid bare exceptions in xcode\_emulation.py (Christian Clauss) [#1932](https://github.com/nodejs/node-gyp/pull/1932)
* [[`032db2a2d0`](https://github.com/nodejs/node-gyp/commit/032db2a2d0)] - **lib,install**: always download SHA sums on Windows (Sam Hughes) [#1926](https://github.com/nodejs/node-gyp/pull/1926)
* [[`5a83630c33`](https://github.com/nodejs/node-gyp/commit/5a83630c33)] - **travis**: add Windows + Python 3.8 to the mix (Rod Vagg) [#1921](https://github.com/nodejs/node-gyp/pull/1921)
## v6.0.0 2019-10-04
* [[`dd0e97ef0b`](https://github.com/nodejs/node-gyp/commit/dd0e97ef0b)] - **(SEMVER-MAJOR)** **lib**: try to find `python` after `python3` (Sam Roberts) [#1907](https://github.com/nodejs/node-gyp/pull/1907)
* [[`f60ed47d14`](https://github.com/nodejs/node-gyp/commit/f60ed47d14)] - **travis**: add Python 3.5 and 3.6 tests on Linux (Christian Clauss) [#1903](https://github.com/nodejs/node-gyp/pull/1903)
* [[`c763ca1838`](https://github.com/nodejs/node-gyp/commit/c763ca1838)] - **(SEMVER-MAJOR)** **doc**: Declare that node-gyp is Python 3 compatible (cclauss) [#1811](https://github.com/nodejs/node-gyp/pull/1811)
* [[`3d1c60ab81`](https://github.com/nodejs/node-gyp/commit/3d1c60ab81)] - **(SEMVER-MAJOR)** **lib**: accept Python 3 by default (João Reis) [#1844](https://github.com/nodejs/node-gyp/pull/1844)
* [[`c6e3b65a23`](https://github.com/nodejs/node-gyp/commit/c6e3b65a23)] - **(SEMVER-MAJOR)** **lib**: raise the minimum Python version from 2.6 to 2.7 (cclauss) [#1818](https://github.com/nodejs/node-gyp/pull/1818)
## v5.1.1 2020-05-25
* [[`bdd3a79abe`](https://github.com/nodejs/node-gyp/commit/bdd3a79abe)] - **build**: shrink bloated addon binaries on windows (Shelley Vohr) [#2060](https://github.com/nodejs/node-gyp/pull/2060)
* [[`1f2ba75bc0`](https://github.com/nodejs/node-gyp/commit/1f2ba75bc0)] - **doc**: add macOS Catalina software update info (Karl Horky) [#2078](https://github.com/nodejs/node-gyp/pull/2078)
* [[`c106d915f5`](https://github.com/nodejs/node-gyp/commit/c106d915f5)] - **doc**: update catalina xcode cli tools download link (#2044) (Dario Vladović) [#2044](https://github.com/nodejs/node-gyp/pull/2044)
* [[`9a6fea92e2`](https://github.com/nodejs/node-gyp/commit/9a6fea92e2)] - **doc**: update catalina xcode cli tools download link; formatting (Jonathan Hult) [#2034](https://github.com/nodejs/node-gyp/pull/2034)
* [[`59b0b1add8`](https://github.com/nodejs/node-gyp/commit/59b0b1add8)] - **doc**: add download link for Command Line Tools for Xcode (Przemysław Bitkowski) [#2029](https://github.com/nodejs/node-gyp/pull/2029)
* [[`bb8d0e7b10`](https://github.com/nodejs/node-gyp/commit/bb8d0e7b10)] - **doc**: Catalina suggestion: remove /Library/Developer/CommandLineTools (Christian Clauss) [#2022](https://github.com/nodejs/node-gyp/pull/2022)
* [[`fb2e80d4e3`](https://github.com/nodejs/node-gyp/commit/fb2e80d4e3)] - **doc**: update link to the code of conduct (#2073) (Michaël Zasso) [#2073](https://github.com/nodejs/node-gyp/pull/2073)
* [[`251d9c885c`](https://github.com/nodejs/node-gyp/commit/251d9c885c)] - **doc**: note in README that Python 3.8 is supported (#2072) (Michaël Zasso) [#2072](https://github.com/nodejs/node-gyp/pull/2072)
* [[`2b6fc3c8d6`](https://github.com/nodejs/node-gyp/commit/2b6fc3c8d6)] - **doc, bin**: stop suggesting opening node-gyp issues (Bartosz Sosnowski) [#2096](https://github.com/nodejs/node-gyp/pull/2096)
* [[`a876ae58ad`](https://github.com/nodejs/node-gyp/commit/a876ae58ad)] - **test**: bump actions/checkout from v1 to v2 (BSKY) [#2063](https://github.com/nodejs/node-gyp/pull/2063)
## v5.1.0 2020-02-05
* [[`f37a8b40d0`](https://github.com/nodejs/node-gyp/commit/f37a8b40d0)] - **doc**: add GitHub Actions badge (#1994) (Rod Vagg) [#1994](https://github.com/nodejs/node-gyp/pull/1994)
* [[`cb3f6aae5e`](https://github.com/nodejs/node-gyp/commit/cb3f6aae5e)] - **doc**: update macOS\_Catalina.md (#1992) (James Home) [#1992](https://github.com/nodejs/node-gyp/pull/1992)
* [[`0607596a4c`](https://github.com/nodejs/node-gyp/commit/0607596a4c)] - **doc**: fix typo in README.md (#1985) (Suraneti Rodsuwan) [#1985](https://github.com/nodejs/node-gyp/pull/1985)
* [[`0d5a415a14`](https://github.com/nodejs/node-gyp/commit/0d5a415a14)] - **doc**: add travis badge (Rod Vagg) [#1971](https://github.com/nodejs/node-gyp/pull/1971)
* [[`103740cd95`](https://github.com/nodejs/node-gyp/commit/103740cd95)] - **gyp**: list(dict) so we can del dict(key) while iterating (Christian Clauss) [#2009](https://github.com/nodejs/node-gyp/pull/2009)
* [[`278dcddbdd`](https://github.com/nodejs/node-gyp/commit/278dcddbdd)] - **lib**: ignore VS instances that cause COMExceptions (Andrew Casey) [#2018](https://github.com/nodejs/node-gyp/pull/2018)
* [[`1694907bbf`](https://github.com/nodejs/node-gyp/commit/1694907bbf)] - **lib**: compatibility with semver ≥ 7 (`new` for semver.Range) (Xavier Guimard) [#2006](https://github.com/nodejs/node-gyp/pull/2006)
* [[`a3f1143514`](https://github.com/nodejs/node-gyp/commit/a3f1143514)] - **(SEMVER-MINOR)** **lib**: noproxy support, match proxy detection to `request` (Matias Lopez) [#1978](https://github.com/nodejs/node-gyp/pull/1978)
* [[`52365819c7`](https://github.com/nodejs/node-gyp/commit/52365819c7)] - **test**: remove old docker test harness (#1993) (Rod Vagg) [#1993](https://github.com/nodejs/node-gyp/pull/1993)
* [[`bc509c511d`](https://github.com/nodejs/node-gyp/commit/bc509c511d)] - **test**: add Windows to GitHub Actions testing (#1996) (Christian Clauss) [#1996](https://github.com/nodejs/node-gyp/pull/1996)
* [[`91ee26dd48`](https://github.com/nodejs/node-gyp/commit/91ee26dd48)] - **test**: fix typo in header download test (#2001) (Richard Lau) [#2001](https://github.com/nodejs/node-gyp/pull/2001)
* [[`0923f344c9`](https://github.com/nodejs/node-gyp/commit/0923f344c9)] - **test**: direct python invocation & simpler pyenv (Matias Lopez) [#1979](https://github.com/nodejs/node-gyp/pull/1979)
* [[`32c8744b34`](https://github.com/nodejs/node-gyp/commit/32c8744b34)] - **test**: fix macOS Travis on Python 2.7 & 3.7 (Christian Clauss) [#1979](https://github.com/nodejs/node-gyp/pull/1979)
* [[`fd4b1351e4`](https://github.com/nodejs/node-gyp/commit/fd4b1351e4)] - **test**: initial Github Actions with Ubuntu & macOS (Christian Clauss) [#1985](https://github.com/nodejs/node-gyp/pull/1985)
## v5.0.7 2019-12-16
Republish of v5.0.6 with unnecessary tarball removed from pack file.
## v5.0.6 2019-12-16
* [[`cdec00286f`](https://github.com/nodejs/node-gyp/commit/cdec00286f)] - **doc**: adjustments to the README.md for new users (Dan Pike) [#1919](https://github.com/nodejs/node-gyp/pull/1919)
* [[`b7c8233ef2`](https://github.com/nodejs/node-gyp/commit/b7c8233ef2)] - **test**: fix Python unittests (cclauss) [#1961](https://github.com/nodejs/node-gyp/pull/1961)
* [[`e12b00ab0a`](https://github.com/nodejs/node-gyp/commit/e12b00ab0a)] - **doc**: macOS Catalina add two commands (Christian Clauss) [#1962](https://github.com/nodejs/node-gyp/pull/1962)
* [[`70b9890c0d`](https://github.com/nodejs/node-gyp/commit/70b9890c0d)] - **test**: add header download test (Rod Vagg) [#1796](https://github.com/nodejs/node-gyp/pull/1796)
* [[`4029fa8629`](https://github.com/nodejs/node-gyp/commit/4029fa8629)] - **test**: configure proper devDir for invoking configure() (Rod Vagg) [#1796](https://github.com/nodejs/node-gyp/pull/1796)
* [[`fe8b02cc8b`](https://github.com/nodejs/node-gyp/commit/fe8b02cc8b)] - **doc**: add macOS\_Catalina.md document (cclauss) [#1940](https://github.com/nodejs/node-gyp/pull/1940)
* [[`8ea47ce365`](https://github.com/nodejs/node-gyp/commit/8ea47ce365)] - **gyp**: python3 fixes: utf8 decode, use of 'None' in eval (Wilfried Goesgens) [#1925](https://github.com/nodejs/node-gyp/pull/1925)
* [[`c7229716ba`](https://github.com/nodejs/node-gyp/commit/c7229716ba)] - **gyp**: iteritems() -\> items() in compile\_commands\_json.py (cclauss) [#1947](https://github.com/nodejs/node-gyp/pull/1947)
* [[`2a18b2a0f8`](https://github.com/nodejs/node-gyp/commit/2a18b2a0f8)] - **gyp**: make cmake python3 compatible (gengjiawen) [#1944](https://github.com/nodejs/node-gyp/pull/1944)
* [[`70f391e844`](https://github.com/nodejs/node-gyp/commit/70f391e844)] - **gyp**: fix TypeError in XcodeVersion() (Christian Clauss) [#1939](https://github.com/nodejs/node-gyp/pull/1939)
* [[`9f4f0fa34e`](https://github.com/nodejs/node-gyp/commit/9f4f0fa34e)] - **gyp**: finish decode stdout on Python 3 (Christian Clauss) [#1937](https://github.com/nodejs/node-gyp/pull/1937)
* [[`7cf507906d`](https://github.com/nodejs/node-gyp/commit/7cf507906d)] - **src,win**: allow 403 errors for arm64 node.lib (Richard Lau) [#1934](https://github.com/nodejs/node-gyp/pull/1934)
* [[`ad0d182c01`](https://github.com/nodejs/node-gyp/commit/ad0d182c01)] - **deps**: update deps to roughly match current npm@6 (Rod Vagg) [#1920](https://github.com/nodejs/node-gyp/pull/1920)
* [[`1553081ed6`](https://github.com/nodejs/node-gyp/commit/1553081ed6)] - **test**: upgrade Linux Travis CI to Python 3.8 (Christian Clauss) [#1923](https://github.com/nodejs/node-gyp/pull/1923)
* [[`0705cae9aa`](https://github.com/nodejs/node-gyp/commit/0705cae9aa)] - **travis**: ignore failed `brew upgrade npm`, update xcode (Christian Clauss) [#1932](https://github.com/nodejs/node-gyp/pull/1932)
* [[`7bfdb6f5bf`](https://github.com/nodejs/node-gyp/commit/7bfdb6f5bf)] - **build**: avoid bare exceptions in xcode\_emulation.py (Christian Clauss) [#1932](https://github.com/nodejs/node-gyp/pull/1932)
* [[`7edf7658fa`](https://github.com/nodejs/node-gyp/commit/7edf7658fa)] - **lib,install**: always download SHA sums on Windows (Sam Hughes) [#1926](https://github.com/nodejs/node-gyp/pull/1926)
* [[`69056d04fe`](https://github.com/nodejs/node-gyp/commit/69056d04fe)] - **travis**: add Windows + Python 3.8 to the mix (Rod Vagg) [#1921](https://github.com/nodejs/node-gyp/pull/1921)
## v5.0.5 2019-10-04
* [[`3891391746`](https://github.com/nodejs/node-gyp/commit/3891391746)] - **doc**: reconcile README with Python 3 compat changes (Rod Vagg) [#1911](https://github.com/nodejs/node-gyp/pull/1911)
* [[`07f81f1920`](https://github.com/nodejs/node-gyp/commit/07f81f1920)] - **lib**: accept Python 3 after Python 2 (Sam Roberts) [#1910](https://github.com/nodejs/node-gyp/pull/1910)
* [[`04ce59f4a2`](https://github.com/nodejs/node-gyp/commit/04ce59f4a2)] - **doc**: clarify Python configuration, etc (Sam Roberts) [#1908](https://github.com/nodejs/node-gyp/pull/1908)
* [[`01c46ee3df`](https://github.com/nodejs/node-gyp/commit/01c46ee3df)] - **gyp**: add \_\_lt\_\_ to MSVSSolutionEntry (João Reis) [#1904](https://github.com/nodejs/node-gyp/pull/1904)
* [[`735d961b99`](https://github.com/nodejs/node-gyp/commit/735d961b99)] - **win**: support VS 2017 Desktop Express (João Reis) [#1902](https://github.com/nodejs/node-gyp/pull/1902)
* [[`3834156a92`](https://github.com/nodejs/node-gyp/commit/3834156a92)] - **test**: add Python 3.5 and 3.6 tests on Linux (cclauss) [#1909](https://github.com/nodejs/node-gyp/pull/1909)
* [[`1196e990d8`](https://github.com/nodejs/node-gyp/commit/1196e990d8)] - **src**: update to standard@14 (Rod Vagg) [#1899](https://github.com/nodejs/node-gyp/pull/1899)
* [[`53ee7dfe89`](https://github.com/nodejs/node-gyp/commit/53ee7dfe89)] - **gyp**: fix undefined name: cflags --\> ldflags (Christian Clauss) [#1901](https://github.com/nodejs/node-gyp/pull/1901)
* [[`5871dcf6c9`](https://github.com/nodejs/node-gyp/commit/5871dcf6c9)] - **src,win**: add support for fetching arm64 node.lib (Richard Townsend) [#1875](https://github.com/nodejs/node-gyp/pull/1875)
## v5.0.4 2019-09-27
* [[`1236869ffc`](https://github.com/nodejs/node-gyp/commit/1236869ffc)] - **gyp**: modify XcodeVersion() to convert "4.2" to "0420" and "10.0" to "1000" (Christian Clauss) [#1895](https://github.com/nodejs/node-gyp/pull/1895)
* [[`36638afe48`](https://github.com/nodejs/node-gyp/commit/36638afe48)] - **gyp**: more decode stdout on Python 3 (cclauss) [#1894](https://github.com/nodejs/node-gyp/pull/1894)
* [[`f753c167c5`](https://github.com/nodejs/node-gyp/commit/f753c167c5)] - **gyp**: decode stdout on Python 3 (cclauss) [#1890](https://github.com/nodejs/node-gyp/pull/1890)
* [[`60a4083523`](https://github.com/nodejs/node-gyp/commit/60a4083523)] - **doc**: update xcode install instructions to match Node's BUILDING (Nhan Khong) [#1884](https://github.com/nodejs/node-gyp/pull/1884)
* [[`19dbc9ac32`](https://github.com/nodejs/node-gyp/commit/19dbc9ac32)] - **deps**: update tar to 4.4.12 (Matheus Marchini) [#1889](https://github.com/nodejs/node-gyp/pull/1889)
* [[`5f3ed92181`](https://github.com/nodejs/node-gyp/commit/5f3ed92181)] - **bin**: fix the usage instructions (Halit Ogunc) [#1888](https://github.com/nodejs/node-gyp/pull/1888)
* [[`aab118edf1`](https://github.com/nodejs/node-gyp/commit/aab118edf1)] - **lib**: adding keep-alive header to download requests (Milad Farazmand) [#1863](https://github.com/nodejs/node-gyp/pull/1863)
* [[`1186e89326`](https://github.com/nodejs/node-gyp/commit/1186e89326)] - **lib**: ignore non-critical os.userInfo() failures (Rod Vagg) [#1835](https://github.com/nodejs/node-gyp/pull/1835)
* [[`785e527c3d`](https://github.com/nodejs/node-gyp/commit/785e527c3d)] - **doc**: fix missing argument for setting python path (lagorsse) [#1802](https://github.com/nodejs/node-gyp/pull/1802)
* [[`a97615196c`](https://github.com/nodejs/node-gyp/commit/a97615196c)] - **gyp**: rm semicolons (Python != JavaScript) (MattIPv4) [#1858](https://github.com/nodejs/node-gyp/pull/1858)
* [[`06019bac24`](https://github.com/nodejs/node-gyp/commit/06019bac24)] - **gyp**: assorted typo fixes (XhmikosR) [#1853](https://github.com/nodejs/node-gyp/pull/1853)
* [[`3f4972c1ca`](https://github.com/nodejs/node-gyp/commit/3f4972c1ca)] - **gyp**: use "is" when comparing to None (Vladyslav Burzakovskyy) [#1860](https://github.com/nodejs/node-gyp/pull/1860)
* [[`1cb4708073`](https://github.com/nodejs/node-gyp/commit/1cb4708073)] - **src,win**: improve unmanaged handling (Peter Sabath) [#1852](https://github.com/nodejs/node-gyp/pull/1852)
* [[`5553cd910e`](https://github.com/nodejs/node-gyp/commit/5553cd910e)] - **gyp**: improve Windows+Cygwin compatibility (Jose Quijada) [#1817](https://github.com/nodejs/node-gyp/pull/1817)
* [[`8bcb1fbb43`](https://github.com/nodejs/node-gyp/commit/8bcb1fbb43)] - **gyp**: Python 3 Windows fixes (João Reis) [#1843](https://github.com/nodejs/node-gyp/pull/1843)
* [[`2e24d0a326`](https://github.com/nodejs/node-gyp/commit/2e24d0a326)] - **test**: accept Python 3 in test-find-python.js (João Reis) [#1843](https://github.com/nodejs/node-gyp/pull/1843)
* [[`1267b4dc1c`](https://github.com/nodejs/node-gyp/commit/1267b4dc1c)] - **build**: add test run Python 3.7 on macOS (Christian Clauss) [#1843](https://github.com/nodejs/node-gyp/pull/1843)
* [[`da1b031aa3`](https://github.com/nodejs/node-gyp/commit/da1b031aa3)] - **build**: import StringIO on Python 2 and Python 3 (Christian Clauss) [#1836](https://github.com/nodejs/node-gyp/pull/1836)
* [[`fa0ed4aa42`](https://github.com/nodejs/node-gyp/commit/fa0ed4aa42)] - **build**: more Python 3 compat, replace compile with ast (cclauss) [#1820](https://github.com/nodejs/node-gyp/pull/1820)
* [[`18d5c7c9d0`](https://github.com/nodejs/node-gyp/commit/18d5c7c9d0)] - **win,src**: update win\_delay\_load\_hook.cc to work with /clr (Ivan Petrovic) [#1819](https://github.com/nodejs/node-gyp/pull/1819)
## v5.0.3 2019-07-17
* [[`66ad305775`](https://github.com/nodejs/node-gyp/commit/66ad305775)] - **python**: accept Python 3 conditionally (João Reis) [#1815](https://github.com/nodejs/node-gyp/pull/1815)
* [[`7e7fce3fed`](https://github.com/nodejs/node-gyp/commit/7e7fce3fed)] - **python**: move Python detection to its own file (João Reis) [#1815](https://github.com/nodejs/node-gyp/pull/1815)
* [[`e40c99e283`](https://github.com/nodejs/node-gyp/commit/e40c99e283)] - **src**: implement standard.js linting (Rod Vagg) [#1794](https://github.com/nodejs/node-gyp/pull/1794)
* [[`bb92c761a9`](https://github.com/nodejs/node-gyp/commit/bb92c761a9)] - **test**: add Node.js 6 on Windows to Travis CI (João Reis) [#1812](https://github.com/nodejs/node-gyp/pull/1812)
* [[`7fd924079f`](https://github.com/nodejs/node-gyp/commit/7fd924079f)] - **test**: increase tap timeout (João Reis) [#1812](https://github.com/nodejs/node-gyp/pull/1812)
* [[`7e8127068f`](https://github.com/nodejs/node-gyp/commit/7e8127068f)] - **test**: cover supported node versions with travis (Rod Vagg) [#1809](https://github.com/nodejs/node-gyp/pull/1809)
* [[`24109148df`](https://github.com/nodejs/node-gyp/commit/24109148df)] - **test**: downgrade to tap@^12 for continued Node 6 support (Rod Vagg) [#1808](https://github.com/nodejs/node-gyp/pull/1808)
* [[`656117cc4a`](https://github.com/nodejs/node-gyp/commit/656117cc4a)] - **win**: make VS path match case-insensitive (João Reis) [#1806](https://github.com/nodejs/node-gyp/pull/1806)
## v5.0.2 2019-06-27
* [[`2761afbf73`](https://github.com/nodejs/node-gyp/commit/2761afbf73)] - **build,test**: add duplicate symbol test (Gabriel Schulhof) [#1689](https://github.com/nodejs/node-gyp/pull/1689)
* [[`82f129d6de`](https://github.com/nodejs/node-gyp/commit/82f129d6de)] - **gyp**: replace optparse to argparse (KiYugadgeter) [#1591](https://github.com/nodejs/node-gyp/pull/1591)
* [[`afaaa29c61`](https://github.com/nodejs/node-gyp/commit/afaaa29c61)] - **gyp**: remove from \_\_future\_\_ import with\_statement (cclauss) [#1799](https://github.com/nodejs/node-gyp/pull/1799)
* [[`a991f633d6`](https://github.com/nodejs/node-gyp/commit/a991f633d6)] - **gyp**: fix the remaining Python 3 issues (cclauss) [#1793](https://github.com/nodejs/node-gyp/pull/1793)
* [[`f952b08f84`](https://github.com/nodejs/node-gyp/commit/f952b08f84)] - **gyp**: move from \_\_future\_\_ import to the top of the file (cclauss) [#1789](https://github.com/nodejs/node-gyp/pull/1789)
* [[`4f4a677dfa`](https://github.com/nodejs/node-gyp/commit/4f4a677dfa)] - **gyp**: use different default compiler for z/OS (Shuowang (Wayne) Zhang) [#1768](https://github.com/nodejs/node-gyp/pull/1768)
* [[`03683f09d6`](https://github.com/nodejs/node-gyp/commit/03683f09d6)] - **lib**: code de-duplication (Pavel Medvedev) [#965](https://github.com/nodejs/node-gyp/pull/965)
* [[`611bc3c89f`](https://github.com/nodejs/node-gyp/commit/611bc3c89f)] - **lib**: add .json suffix for explicit require (Rod Vagg) [#1787](https://github.com/nodejs/node-gyp/pull/1787)
* [[`d3478d7b0b`](https://github.com/nodejs/node-gyp/commit/d3478d7b0b)] - **meta**: add to .gitignore (Refael Ackermann) [#1573](https://github.com/nodejs/node-gyp/pull/1573)
* [[`7a9a038e9e`](https://github.com/nodejs/node-gyp/commit/7a9a038e9e)] - **test**: add parallel test runs on macOS and Windows (cclauss) [#1800](https://github.com/nodejs/node-gyp/pull/1800)
* [[`7dd7f2b2a2`](https://github.com/nodejs/node-gyp/commit/7dd7f2b2a2)] - **test**: fix Python syntax error in test-adding.js (cclauss) [#1793](https://github.com/nodejs/node-gyp/pull/1793)
* [[`395f843de0`](https://github.com/nodejs/node-gyp/commit/395f843de0)] - **test**: replace self-signed cert with 'localhost' (Rod Vagg) [#1795](https://github.com/nodejs/node-gyp/pull/1795)
* [[`a52c6eb9e8`](https://github.com/nodejs/node-gyp/commit/a52c6eb9e8)] - **test**: migrate from tape to tap (Rod Vagg) [#1795](https://github.com/nodejs/node-gyp/pull/1795)
* [[`ec2eb44a30`](https://github.com/nodejs/node-gyp/commit/ec2eb44a30)] - **test**: use Nan in duplicate\_symbols (Gabriel Schulhof) [#1689](https://github.com/nodejs/node-gyp/pull/1689)
* [[`1597c84aad`](https://github.com/nodejs/node-gyp/commit/1597c84aad)] - **test**: use Travis CI to run tests on every pull request (cclauss) [#1752](https://github.com/nodejs/node-gyp/pull/1752)
* [[`dd9bf929ac`](https://github.com/nodejs/node-gyp/commit/dd9bf929ac)] - **zos**: update compiler options (Shuowang (Wayne) Zhang) [#1768](https://github.com/nodejs/node-gyp/pull/1768)
## v5.0.1 2019-06-20
* [[`e3861722ed`](https://github.com/nodejs/node-gyp/commit/e3861722ed)] - **doc**: document --jobs max (David Sanders) [#1770](https://github.com/nodejs/node-gyp/pull/1770)
* [[`1cfdb28886`](https://github.com/nodejs/node-gyp/commit/1cfdb28886)] - **lib**: reintroduce support for iojs file naming for releases \>= 1 && \< 4 (Samuel Attard) [#1777](https://github.com/nodejs/node-gyp/pull/1777)
## v5.0.0 2019-06-13
* [[`8a83972743`](https://github.com/nodejs/node-gyp/commit/8a83972743)] - **(SEMVER-MAJOR)** **bin**: follow XDG OS conventions for storing data (Selwyn) [#1570](https://github.com/nodejs/node-gyp/pull/1570)
* [[`9e46872ea3`](https://github.com/nodejs/node-gyp/commit/9e46872ea3)] - **bin,lib**: remove extra comments/lines/spaces (Jon Moss) [#1508](https://github.com/nodejs/node-gyp/pull/1508)
* [[`8098ebdeb4`](https://github.com/nodejs/node-gyp/commit/8098ebdeb4)] - **deps**: replace `osenv` dependency with native `os` (Selwyn)
* [[`f83b457e03`](https://github.com/nodejs/node-gyp/commit/f83b457e03)] - **deps**: bump request to 2.8.7, fixes heok/hawk issues (Rohit Hazra) [#1492](https://github.com/nodejs/node-gyp/pull/1492)
* [[`323cee7323`](https://github.com/nodejs/node-gyp/commit/323cee7323)] - **deps**: pin `request` version range (Refael Ackermann) [#1300](https://github.com/nodejs/node-gyp/pull/1300)
* [[`c515912d08`](https://github.com/nodejs/node-gyp/commit/c515912d08)] - **doc**: improve issue template (Bartosz Sosnowski) [#1618](https://github.com/nodejs/node-gyp/pull/1618)
* [[`cca2d66727`](https://github.com/nodejs/node-gyp/commit/cca2d66727)] - **doc**: python info needs own header (Taylor D. Lee) [#1245](https://github.com/nodejs/node-gyp/pull/1245)
* [[`3e64c780f5`](https://github.com/nodejs/node-gyp/commit/3e64c780f5)] - **doc**: lint README.md (Jon Moss) [#1498](https://github.com/nodejs/node-gyp/pull/1498)
* [[`a20faedc91`](https://github.com/nodejs/node-gyp/commit/a20faedc91)] - **(SEMVER-MAJOR)** **gyp**: enable MARMASM items only on new VS versions (João Reis) [#1762](https://github.com/nodejs/node-gyp/pull/1762)
* [[`721eb691cf`](https://github.com/nodejs/node-gyp/commit/721eb691cf)] - **gyp**: teach MSVS generator about MARMASM Items (Jon Kunkee) [#1679](https://github.com/nodejs/node-gyp/pull/1679)
* [[`91744bfecc`](https://github.com/nodejs/node-gyp/commit/91744bfecc)] - **gyp**: add support for Windows on Arm (Richard Townsend) [#1739](https://github.com/nodejs/node-gyp/pull/1739)
* [[`a6e0a6c7ed`](https://github.com/nodejs/node-gyp/commit/a6e0a6c7ed)] - **gyp**: move compile\_commands\_json (Paul Maréchal) [#1661](https://github.com/nodejs/node-gyp/pull/1661)
* [[`92e8b52cee`](https://github.com/nodejs/node-gyp/commit/92e8b52cee)] - **gyp**: fix target --\> self.target (cclauss)
* [[`febdfa2137`](https://github.com/nodejs/node-gyp/commit/febdfa2137)] - **gyp**: fix sntex error (cclauss) [#1333](https://github.com/nodejs/node-gyp/pull/1333)
* [[`588d333c14`](https://github.com/nodejs/node-gyp/commit/588d333c14)] - **gyp**: \_winreg module was renamed to winreg in Python 3. (Craig Rodrigues)
* [[`98226d198c`](https://github.com/nodejs/node-gyp/commit/98226d198c)] - **gyp**: replace basestring with str, but only on Python 3. (Craig Rodrigues)
* [[`7535e4478e`](https://github.com/nodejs/node-gyp/commit/7535e4478e)] - **gyp**: replace deprecated functions (Craig Rodrigues)
* [[`2040cd21cc`](https://github.com/nodejs/node-gyp/commit/2040cd21cc)] - **gyp**: use print as a function, as specified in PEP 3105. (Craig Rodrigues)
* [[`abef93ded5`](https://github.com/nodejs/node-gyp/commit/abef93ded5)] - **gyp**: get ready for python 3 (cclauss)
* [[`43031fadcb`](https://github.com/nodejs/node-gyp/commit/43031fadcb)] - **python**: clean-up detection (João Reis) [#1582](https://github.com/nodejs/node-gyp/pull/1582)
* [[`49ab79d221`](https://github.com/nodejs/node-gyp/commit/49ab79d221)] - **python**: more informative error (Refael Ackermann) [#1269](https://github.com/nodejs/node-gyp/pull/1269)
* [[`997bc3c748`](https://github.com/nodejs/node-gyp/commit/997bc3c748)] - **readme**: add ARM64 info to MSVC setup instructions (Jon Kunkee) [#1655](https://github.com/nodejs/node-gyp/pull/1655)
* [[`788e767179`](https://github.com/nodejs/node-gyp/commit/788e767179)] - **test**: remove unused variable (João Reis)
* [[`6f5a408934`](https://github.com/nodejs/node-gyp/commit/6f5a408934)] - **tools**: fix usage of inherited -fPIC and -fPIE (Jens) [#1340](https://github.com/nodejs/node-gyp/pull/1340)
* [[`0efb8fb34b`](https://github.com/nodejs/node-gyp/commit/0efb8fb34b)] - **(SEMVER-MAJOR)** **win**: support running in VS Command Prompt (João Reis) [#1762](https://github.com/nodejs/node-gyp/pull/1762)
* [[`360ddbdf3a`](https://github.com/nodejs/node-gyp/commit/360ddbdf3a)] - **(SEMVER-MAJOR)** **win**: add support for Visual Studio 2019 (João Reis) [#1762](https://github.com/nodejs/node-gyp/pull/1762)
* [[`8f43f68275`](https://github.com/nodejs/node-gyp/commit/8f43f68275)] - **(SEMVER-MAJOR)** **win**: detect all VS versions in node-gyp (João Reis) [#1762](https://github.com/nodejs/node-gyp/pull/1762)
* [[`7fe4095974`](https://github.com/nodejs/node-gyp/commit/7fe4095974)] - **(SEMVER-MAJOR)** **win**: generic Visual Studio 2017 detection (João Reis) [#1762](https://github.com/nodejs/node-gyp/pull/1762)
* [[`7a71d68bce`](https://github.com/nodejs/node-gyp/commit/7a71d68bce)] - **win**: use msbuild from the configure stage (Bartosz Sosnowski) [#1654](https://github.com/nodejs/node-gyp/pull/1654)
* [[`d3b21220a0`](https://github.com/nodejs/node-gyp/commit/d3b21220a0)] - **win**: fix delay-load hook for electron 4 (Andy Dill)
* [[`81f3a92338`](https://github.com/nodejs/node-gyp/commit/81f3a92338)] - Update list of Node.js versions to test against. (Ben Noordhuis) [#1670](https://github.com/nodejs/node-gyp/pull/1670)
* [[`4748f6ab75`](https://github.com/nodejs/node-gyp/commit/4748f6ab75)] - Remove deprecated compatibility code. (Ben Noordhuis) [#1670](https://github.com/nodejs/node-gyp/pull/1670)
* [[`45e3221fd4`](https://github.com/nodejs/node-gyp/commit/45e3221fd4)] - Remove an outdated workaround for Python 2.4 (cclauss) [#1650](https://github.com/nodejs/node-gyp/pull/1650)
* [[`721dc7d314`](https://github.com/nodejs/node-gyp/commit/721dc7d314)] - Add ARM64 to MSBuild /Platform logic (Jon Kunkee) [#1655](https://github.com/nodejs/node-gyp/pull/1655)
* [[`a5b7410497`](https://github.com/nodejs/node-gyp/commit/a5b7410497)] - Add ESLint no-unused-vars rule (Jon Moss) [#1497](https://github.com/nodejs/node-gyp/pull/1497)
## v4.0.0 2019-04-24
* [[`ceed5cbe10`](https://github.com/nodejs/node-gyp/commit/ceed5cbe10)] - **deps**: updated tar package version to 4.4.8 (Pobegaylo Maksim) [#1713](https://github.com/nodejs/node-gyp/pull/1713)
* [[`374519e066`](https://github.com/nodejs/node-gyp/commit/374519e066)] - **(SEMVER-MAJOR)** Upgrade to tar v3 (isaacs) [#1212](https://github.com/nodejs/node-gyp/pull/1212)
* [[`e6699d13cd`](https://github.com/nodejs/node-gyp/commit/e6699d13cd)] - **test**: fix addon test for Node.js 12 and V8 7.4 (Richard Lau) [#1705](https://github.com/nodejs/node-gyp/pull/1705)
* [[`0c6bf530a0`](https://github.com/nodejs/node-gyp/commit/0c6bf530a0)] - **lib**: use print() for python version detection (GreenAddress) [#1534](https://github.com/nodejs/node-gyp/pull/1534)
## v3.8.0 2018-08-09
* [[`c5929cb4fe`](https://github.com/nodejs/node-gyp/commit/c5929cb4fe)] - **doc**: update Xcode preferences tab name. (Ivan Daniluk) [#1330](https://github.com/nodejs/node-gyp/pull/1330)
* [[`8b488da8b9`](https://github.com/nodejs/node-gyp/commit/8b488da8b9)] - **doc**: update link to commit guidelines (Jonas Hermsmeier) [#1456](https://github.com/nodejs/node-gyp/pull/1456)
* [[`b4fe8c16f9`](https://github.com/nodejs/node-gyp/commit/b4fe8c16f9)] - **doc**: fix visual studio links (Bartosz Sosnowski) [#1490](https://github.com/nodejs/node-gyp/pull/1490)
* [[`536759c7e9`](https://github.com/nodejs/node-gyp/commit/536759c7e9)] - **configure**: use sys.version\_info to get python version (Yang Guo) [#1504](https://github.com/nodejs/node-gyp/pull/1504)
* [[`94c39c604e`](https://github.com/nodejs/node-gyp/commit/94c39c604e)] - **gyp**: fix ninja build failure (GYP patch) (Daniel Bevenius) [nodejs/node#12484](https://github.com/nodejs/node/pull/12484)
* [[`e8ea74e0fa`](https://github.com/nodejs/node-gyp/commit/e8ea74e0fa)] - **tools**: patch gyp to avoid xcrun errors (Ujjwal Sharma) [nodejs/node#21520](https://github.com/nodejs/node/pull/21520)
* [[`ea9aff44f2`](https://github.com/nodejs/node-gyp/commit/ea9aff44f2)] - **tools**: fix "the the" typos in comments (Masashi Hirano) [nodejs/node#20716](https://github.com/nodejs/node/pull/20716)
* [[`207e5aa4fd`](https://github.com/nodejs/node-gyp/commit/207e5aa4fd)] - **gyp**: implement LD/LDXX for ninja and FIPS (Sam Roberts)
* [[`b416c5f4b7`](https://github.com/nodejs/node-gyp/commit/b416c5f4b7)] - **gyp**: enable cctest to use objects (gyp part) (Daniel Bevenius) [nodejs/node#12450](https://github.com/nodejs/node/pull/12450)
* [[`40692d016b`](https://github.com/nodejs/node-gyp/commit/40692d016b)] - **gyp**: add compile\_commands.json gyp generator (Ben Noordhuis) [nodejs/node#12450](https://github.com/nodejs/node/pull/12450)
* [[`fc3c4e2b10`](https://github.com/nodejs/node-gyp/commit/fc3c4e2b10)] - **gyp**: float gyp patch for long filenames (Anna Henningsen) [nodejs/node#7963](https://github.com/nodejs/node/pull/7963)
* [[`8aedbfdef6`](https://github.com/nodejs/node-gyp/commit/8aedbfdef6)] - **gyp**: backport GYP fix to fix AIX shared suffix (Stewart Addison)
* [[`6cd84b84fc`](https://github.com/nodejs/node-gyp/commit/6cd84b84fc)] - **test**: formatting and minor fixes for execFileSync replacement (Rod Vagg) [#1521](https://github.com/nodejs/node-gyp/pull/1521)
* [[`60e421363f`](https://github.com/nodejs/node-gyp/commit/60e421363f)] - **test**: added test/processExecSync.js for when execFileSync is not available. (Rohit Hazra) [#1492](https://github.com/nodejs/node-gyp/pull/1492)
* [[`969447c5bd`](https://github.com/nodejs/node-gyp/commit/969447c5bd)] - **deps**: bump request to 2.8.7, fixes heok/hawk issues (Rohit Hazra) [#1492](https://github.com/nodejs/node-gyp/pull/1492)
* [[`340403ccfe`](https://github.com/nodejs/node-gyp/commit/340403ccfe)] - **win**: improve parsing of SDK version (Alessandro Vergani) [#1516](https://github.com/nodejs/node-gyp/pull/1516)
## v3.7.0 2018-06-08
* [[`84cea7b30d`](https://github.com/nodejs/node-gyp/commit/84cea7b30d)] - Remove unused gyp test scripts. (Ben Noordhuis) [#1458](https://github.com/nodejs/node-gyp/pull/1458)
* [[`0540e4ec63`](https://github.com/nodejs/node-gyp/commit/0540e4ec63)] - **gyp**: escape spaces in filenames in make generator (Jeff Senn) [#1436](https://github.com/nodejs/node-gyp/pull/1436)
* [[`88fc6fa0ec`](https://github.com/nodejs/node-gyp/commit/88fc6fa0ec)] - Drop dependency on minimatch. (Brian Woodward) [#1158](https://github.com/nodejs/node-gyp/pull/1158)
* [[`1e203c5148`](https://github.com/nodejs/node-gyp/commit/1e203c5148)] - Fix include path when pointing to Node.js source (Richard Lau) [#1055](https://github.com/nodejs/node-gyp/pull/1055)
* [[`53d8cb967c`](https://github.com/nodejs/node-gyp/commit/53d8cb967c)] - Prefix build targets with /t: on Windows (Natalie Wolfe) [#1164](https://github.com/nodejs/node-gyp/pull/1164)
* [[`53a5f8ff38`](https://github.com/nodejs/node-gyp/commit/53a5f8ff38)] - **gyp**: add support for .mm files to msvs generator (Julien Racle) [#1167](https://github.com/nodejs/node-gyp/pull/1167)
* [[`dd8561e528`](https://github.com/nodejs/node-gyp/commit/dd8561e528)] - **zos**: don't use universal-new-lines mode (John Barboza) [#1451](https://github.com/nodejs/node-gyp/pull/1451)
* [[`e5a69010ed`](https://github.com/nodejs/node-gyp/commit/e5a69010ed)] - **zos**: add search locations for libnode.x (John Barboza) [#1451](https://github.com/nodejs/node-gyp/pull/1451)
* [[`79febace53`](https://github.com/nodejs/node-gyp/commit/79febace53)] - **doc**: update macOS information in README (Josh Parnham) [#1323](https://github.com/nodejs/node-gyp/pull/1323)
* [[`9425448945`](https://github.com/nodejs/node-gyp/commit/9425448945)] - **gyp**: don't print xcodebuild not found errors (Gibson Fahnestock) [#1370](https://github.com/nodejs/node-gyp/pull/1370)
* [[`6f1286f5b2`](https://github.com/nodejs/node-gyp/commit/6f1286f5b2)] - Fix infinite install loop. (Ben Noordhuis) [#1384](https://github.com/nodejs/node-gyp/pull/1384)
* [[`2580b9139e`](https://github.com/nodejs/node-gyp/commit/2580b9139e)] - Update `--nodedir` description in README. (Ben Noordhuis) [#1372](https://github.com/nodejs/node-gyp/pull/1372)
* [[`a61360391a`](https://github.com/nodejs/node-gyp/commit/a61360391a)] - Update README with another way to install on windows (JeffAtDeere) [#1352](https://github.com/nodejs/node-gyp/pull/1352)
* [[`47496bf6dc`](https://github.com/nodejs/node-gyp/commit/47496bf6dc)] - Fix IndexError when parsing GYP files. (Ben Noordhuis) [#1267](https://github.com/nodejs/node-gyp/pull/1267)
* [[`b2024dee7b`](https://github.com/nodejs/node-gyp/commit/b2024dee7b)] - **zos**: support platform (John Barboza) [#1276](https://github.com/nodejs/node-gyp/pull/1276)
* [[`90d86512f4`](https://github.com/nodejs/node-gyp/commit/90d86512f4)] - **win**: run PS with `-NoProfile` (Refael Ackermann) [#1292](https://github.com/nodejs/node-gyp/pull/1292)
* [[`2da5f86ef7`](https://github.com/nodejs/node-gyp/commit/2da5f86ef7)] - **doc**: add github PR and Issue templates (Gibson Fahnestock) [#1228](https://github.com/nodejs/node-gyp/pull/1228)
* [[`a46a770d68`](https://github.com/nodejs/node-gyp/commit/a46a770d68)] - **doc**: update proposed DCO and CoC (Mikeal Rogers) [#1229](https://github.com/nodejs/node-gyp/pull/1229)
* [[`7e803d58e0`](https://github.com/nodejs/node-gyp/commit/7e803d58e0)] - **doc**: headerify the Install instructions (Nick Schonning) [#1225](https://github.com/nodejs/node-gyp/pull/1225)
* [[`f27599193a`](https://github.com/nodejs/node-gyp/commit/f27599193a)] - **gyp**: update xml string encoding conversion (Liu Chao) [#1203](https://github.com/nodejs/node-gyp/pull/1203)
* [[`0a07e481f7`](https://github.com/nodejs/node-gyp/commit/0a07e481f7)] - **configure**: don't set ensure if tarball is set (Gibson Fahnestock) [#1220](https://github.com/nodejs/node-gyp/pull/1220)
## v3.6.3 2018-06-08
* [[`90cd2e8da9`](https://github.com/nodejs/node-gyp/commit/90cd2e8da9)] - **gyp**: fix regex to match multi-digit versions (Jonas Hermsmeier) [#1455](https://github.com/nodejs/node-gyp/pull/1455)
* [[`7900122337`](https://github.com/nodejs/node-gyp/commit/7900122337)] - deps: pin `request` version range (Refael Ackerman) [#1300](https://github.com/nodejs/node-gyp/pull/1300)
## v3.6.2 2017-06-01
* [[`72afdd62cd`](https://github.com/nodejs/node-gyp/commit/72afdd62cd)] - **build**: rename copyNodeLib() to doBuild() (Liu Chao) [#1206](https://github.com/nodejs/node-gyp/pull/1206)
* [[`bad903ac70`](https://github.com/nodejs/node-gyp/commit/bad903ac70)] - **win**: more robust parsing of SDK version (Refael Ackermann) [#1198](https://github.com/nodejs/node-gyp/pull/1198)
* [[`241752f381`](https://github.com/nodejs/node-gyp/commit/241752f381)] - Log dist-url. (Ben Noordhuis) [#1170](https://github.com/nodejs/node-gyp/pull/1170)
* [[`386746c7d1`](https://github.com/nodejs/node-gyp/commit/386746c7d1)] - **configure**: use full path in node_lib_file GYP var (Pavel Medvedev) [#964](https://github.com/nodejs/node-gyp/pull/964)
* [[`0913b2dd99`](https://github.com/nodejs/node-gyp/commit/0913b2dd99)] - **build, win**: use target_arch to link with node.lib (Pavel Medvedev) [#964](https://github.com/nodejs/node-gyp/pull/964)
* [[`c307b302f7`](https://github.com/nodejs/node-gyp/commit/c307b302f7)] - **doc**: blorb about setting `npm_config_OPTION_NAME` (Refael Ackermann) [#1185](https://github.com/nodejs/node-gyp/pull/1185)
## v3.6.1 2017-04-30
* [[`49801716c2`](https://github.com/nodejs/node-gyp/commit/49801716c2)] - **test**: fix test-find-python on v0.10.x buildbot. (Ben Noordhuis) [#1172](https://github.com/nodejs/node-gyp/pull/1172)
* [[`a83a3801fc`](https://github.com/nodejs/node-gyp/commit/a83a3801fc)] - **test**: fix test/test-configure-python on AIX (Richard Lau) [#1131](https://github.com/nodejs/node-gyp/pull/1131)
* [[`8a767145c9`](https://github.com/nodejs/node-gyp/commit/8a767145c9)] - **gyp**: Revert quote_cmd workaround (Kunal Pathak) [#1153](https://github.com/nodejs/node-gyp/pull/1153)
* [[`c09cf7671e`](https://github.com/nodejs/node-gyp/commit/c09cf7671e)] - **doc**: add a note for using `configure` on Windows (Vse Mozhet Byt) [#1152](https://github.com/nodejs/node-gyp/pull/1152)
* [[`da9cb5f411`](https://github.com/nodejs/node-gyp/commit/da9cb5f411)] - Delete superfluous .patch files. (Ben Noordhuis) [#1122](https://github.com/nodejs/node-gyp/pull/1122)
## v3.6.0 2017-03-16
* [[`ae141e1906`](https://github.com/nodejs/node-gyp/commit/ae141e1906)] - **win**: find and setup for VS2017 (Refael Ackermann) [#1130](https://github.com/nodejs/node-gyp/pull/1130)
* [[`ec5fc36a80`](https://github.com/nodejs/node-gyp/commit/ec5fc36a80)] - Add support to build node.js with chakracore for ARM. (Kunal Pathak) [#873](https://github.com/nodejs/node-gyp/pull/873)
* [[`a04ea3051a`](https://github.com/nodejs/node-gyp/commit/a04ea3051a)] - Add support to build node.js with chakracore. (Kunal Pathak) [#873](https://github.com/nodejs/node-gyp/pull/873)
* [[`93d7fa83c8`](https://github.com/nodejs/node-gyp/commit/93d7fa83c8)] - Upgrade semver dependency. (Ben Noordhuis) [#1107](https://github.com/nodejs/node-gyp/pull/1107)
* [[`ff9a6fadfd`](https://github.com/nodejs/node-gyp/commit/ff9a6fadfd)] - Update link of gyp as Google code is shutting down (Peter Dave Hello) [#1061](https://github.com/nodejs/node-gyp/pull/1061)
## v3.5.0 2017-01-10
* [[`762d19a39e`](https://github.com/nodejs/node-gyp/commit/762d19a39e)] - \[doc\] merge History.md and CHANGELOG.md (Rod Vagg)
* [[`80fc5c3d31`](https://github.com/nodejs/node-gyp/commit/80fc5c3d31)] - Fix deprecated dependency warning (Simone Primarosa) [#1069](https://github.com/nodejs/node-gyp/pull/1069)
* [[`05c44944fd`](https://github.com/nodejs/node-gyp/commit/05c44944fd)] - Open the build file with universal-newlines mode (Guy Margalit) [#1053](https://github.com/nodejs/node-gyp/pull/1053)
* [[`37ae7be114`](https://github.com/nodejs/node-gyp/commit/37ae7be114)] - Try python launcher when stock python is python 3. (Ben Noordhuis) [#992](https://github.com/nodejs/node-gyp/pull/992)
* [[`e3778d9907`](https://github.com/nodejs/node-gyp/commit/e3778d9907)] - Add lots of findPython() tests. (Ben Noordhuis) [#992](https://github.com/nodejs/node-gyp/pull/992)
* [[`afc766adf6`](https://github.com/nodejs/node-gyp/commit/afc766adf6)] - Unset executable bit for .bat files (Pavel Medvedev) [#969](https://github.com/nodejs/node-gyp/pull/969)
* [[`ddac348991`](https://github.com/nodejs/node-gyp/commit/ddac348991)] - Use push on PYTHONPATH and add tests (Michael Hart) [#990](https://github.com/nodejs/node-gyp/pull/990)
* [[`b182a19042`](https://github.com/nodejs/node-gyp/commit/b182a19042)] - ***Revert*** "add "path-array" dep" (Michael Hart) [#990](https://github.com/nodejs/node-gyp/pull/990)
* [[`7c08b85c5a`](https://github.com/nodejs/node-gyp/commit/7c08b85c5a)] - ***Revert*** "**configure**: use "path-array" for PYTHONPATH" (Michael Hart) [#990](https://github.com/nodejs/node-gyp/pull/990)
* [[`9c8d275526`](https://github.com/nodejs/node-gyp/commit/9c8d275526)] - Add --devdir flag. (Ben Noordhuis) [#916](https://github.com/nodejs/node-gyp/pull/916)
* [[`f6eab1f9e4`](https://github.com/nodejs/node-gyp/commit/f6eab1f9e4)] - **doc**: add windows-build-tools to readme (Felix Rieseberg) [#970](https://github.com/nodejs/node-gyp/pull/970)
## v3.4.0 2016-06-28
* [[`ce5fd04e94`](https://github.com/nodejs/node-gyp/commit/ce5fd04e94)] - **deps**: update minimatch version (delphiactual) [#961](https://github.com/nodejs/node-gyp/pull/961)
* [[`77383ddd85`](https://github.com/nodejs/node-gyp/commit/77383ddd85)] - Replace fs.accessSync call to fs.statSync (Richard Lau) [#955](https://github.com/nodejs/node-gyp/pull/955)
* [[`0dba4bda57`](https://github.com/nodejs/node-gyp/commit/0dba4bda57)] - **test**: add simple addon test (Richard Lau) [#955](https://github.com/nodejs/node-gyp/pull/955)
* [[`c4344b3889`](https://github.com/nodejs/node-gyp/commit/c4344b3889)] - **doc**: add --target option to README (Gibson Fahnestock) [#958](https://github.com/nodejs/node-gyp/pull/958)
* [[`cc778e9215`](https://github.com/nodejs/node-gyp/commit/cc778e9215)] - Override BUILDING_UV_SHARED, BUILDING_V8_SHARED. (Ben Noordhuis) [#915](https://github.com/nodejs/node-gyp/pull/915)
* [[`af35b2ad32`](https://github.com/nodejs/node-gyp/commit/af35b2ad32)] - Move VC++ Build Tools to Build Tools landing page. (Andrew Pardoe) [#953](https://github.com/nodejs/node-gyp/pull/953)
* [[`f31482e226`](https://github.com/nodejs/node-gyp/commit/f31482e226)] - **win**: work around __pfnDliNotifyHook2 type change (Alexis Campailla) [#952](https://github.com/nodejs/node-gyp/pull/952)
* [[`3df8222fa5`](https://github.com/nodejs/node-gyp/commit/3df8222fa5)] - Allow for npmlog@3.x (Rebecca Turner) [#950](https://github.com/nodejs/node-gyp/pull/950)
* [[`a4fa07b390`](https://github.com/nodejs/node-gyp/commit/a4fa07b390)] - More verbose error on locating msbuild.exe failure. (Mateusz Jaworski) [#930](https://github.com/nodejs/node-gyp/pull/930)
* [[`4ee31329e0`](https://github.com/nodejs/node-gyp/commit/4ee31329e0)] - **doc**: add command options to README.md (Gibson Fahnestock) [#937](https://github.com/nodejs/node-gyp/pull/937)
* [[`c8c7ca86b9`](https://github.com/nodejs/node-gyp/commit/c8c7ca86b9)] - Add --silent option for zero output. (Gibson Fahnestock) [#937](https://github.com/nodejs/node-gyp/pull/937)
* [[`ac29d23a7c`](https://github.com/nodejs/node-gyp/commit/ac29d23a7c)] - Upgrade to glob@7.0.3. (Ben Noordhuis) [#943](https://github.com/nodejs/node-gyp/pull/943)
* [[`15fd56be3d`](https://github.com/nodejs/node-gyp/commit/15fd56be3d)] - Enable V8 deprecation warnings for native modules (Matt Loring) [#920](https://github.com/nodejs/node-gyp/pull/920)
* [[`7f1c1b960c`](https://github.com/nodejs/node-gyp/commit/7f1c1b960c)] - **gyp**: improvements for android generator (Robert Chiras) [#935](https://github.com/nodejs/node-gyp/pull/935)
* [[`088082766c`](https://github.com/nodejs/node-gyp/commit/088082766c)] - Update Windows install instructions (Sara Itani) [#867](https://github.com/nodejs/node-gyp/pull/867)
* [[`625c1515f9`](https://github.com/nodejs/node-gyp/commit/625c1515f9)] - **gyp**: inherit CC/CXX for CC/CXX.host (Johan Bergström) [#908](https://github.com/nodejs/node-gyp/pull/908)
* [[`3bcb1720e4`](https://github.com/nodejs/node-gyp/commit/3bcb1720e4)] - Add support for the Python launcher on Windows (Patrick Westerhoff) [#894](https://github.com/nodejs/node-gyp/pull/894
## v3.3.1 2016-03-04
* [[`a981ef847a`](https://github.com/nodejs/node-gyp/commit/a981ef847a)] - **gyp**: fix android generator (Robert Chiras) [#889](https://github.com/nodejs/node-gyp/pull/889)
## v3.3.0 2016-02-16
* [[`818d854a4d`](https://github.com/nodejs/node-gyp/commit/818d854a4d)] - Introduce NODEJS_ORG_MIRROR and IOJS_ORG_MIRROR (Rod Vagg) [#878](https://github.com/nodejs/node-gyp/pull/878)
* [[`d1e4cc4b62`](https://github.com/nodejs/node-gyp/commit/d1e4cc4b62)] - **(SEMVER-MINOR)** Download headers tarball for ~0.12.10 || ~0.10.42 (Rod Vagg) [#877](https://github.com/nodejs/node-gyp/pull/877)
* [[`6e28ad1bea`](https://github.com/nodejs/node-gyp/commit/6e28ad1bea)] - Allow for npmlog@2.x (Rebecca Turner) [#861](https://github.com/nodejs/node-gyp/pull/861)
* [[`07371e5812`](https://github.com/nodejs/node-gyp/commit/07371e5812)] - Use -fPIC for NetBSD. (Marcin Cieślak) [#856](https://github.com/nodejs/node-gyp/pull/856)
* [[`8c4b0ffa50`](https://github.com/nodejs/node-gyp/commit/8c4b0ffa50)] - **(SEMVER-MINOR)** Add --cafile command line option. (Ben Noordhuis) [#837](https://github.com/nodejs/node-gyp/pull/837)
* [[`b3ad43498e`](https://github.com/nodejs/node-gyp/commit/b3ad43498e)] - **(SEMVER-MINOR)** Make download() function testable. (Ben Noordhuis) [#837](https://github.com/nodejs/node-gyp/pull/837)
## v3.2.1 2015-12-03
* [[`ab89b477c4`](https://github.com/nodejs/node-gyp/commit/ab89b477c4)] - Upgrade gyp to b3cef02. (Ben Noordhuis) [#831](https://github.com/nodejs/node-gyp/pull/831)
* [[`90078ecb17`](https://github.com/nodejs/node-gyp/commit/90078ecb17)] - Define WIN32_LEAN_AND_MEAN conditionally. (Ben Noordhuis) [#824](https://github.com/nodejs/node-gyp/pull/824)
## v3.2.0 2015-11-25
* [[`268f1ca4c7`](https://github.com/nodejs/node-gyp/commit/268f1ca4c7)] - Use result of `which` when searching for python. (Refael Ackermann) [#668](https://github.com/nodejs/node-gyp/pull/668)
* [[`817ed9bd78`](https://github.com/nodejs/node-gyp/commit/817ed9bd78)] - Add test for python executable search logic. (Ben Noordhuis) [#756](https://github.com/nodejs/node-gyp/pull/756)
* [[`0e2dfda1f3`](https://github.com/nodejs/node-gyp/commit/0e2dfda1f3)] - Fix test/test-options when run through `npm test`. (Ben Noordhuis) [#755](https://github.com/nodejs/node-gyp/pull/755)
* [[`9bfa0876b4`](https://github.com/nodejs/node-gyp/commit/9bfa0876b4)] - Add support for AIX (Michael Dawson) [#753](https://github.com/nodejs/node-gyp/pull/753)
* [[`a8d441a0a2`](https://github.com/nodejs/node-gyp/commit/a8d441a0a2)] - Update README for Windows 10 support. (Jason Williams) [#766](https://github.com/nodejs/node-gyp/pull/766)
* [[`d1d6015276`](https://github.com/nodejs/node-gyp/commit/d1d6015276)] - Update broken links and switch to HTTPS. (andrew morton)
## v3.1.0 2015-11-14
* [[`9049241f91`](https://github.com/nodejs/node-gyp/commit/9049241f91)] - **gyp**: don't use links at all, just copy the files instead (Nathan Zadoks)
* [[`8ef90348d1`](https://github.com/nodejs/node-gyp/commit/8ef90348d1)] - **gyp**: apply https://codereview.chromium.org/11361103/ (Nathan Rajlich)
* [[`a2ed0df84e`](https://github.com/nodejs/node-gyp/commit/a2ed0df84e)] - **gyp**: always install into $PRODUCT_DIR (Nathan Rajlich)
* [[`cc8b2fa83e`](https://github.com/nodejs/node-gyp/commit/cc8b2fa83e)] - Update gyp to b3cef02. (Imran Iqbal) [#781](https://github.com/nodejs/node-gyp/pull/781)
* [[`f5d86eb84e`](https://github.com/nodejs/node-gyp/commit/f5d86eb84e)] - Update to tar@2.0.0. (Edgar Muentes) [#797](https://github.com/nodejs/node-gyp/pull/797)
* [[`2ac7de02c4`](https://github.com/nodejs/node-gyp/commit/2ac7de02c4)] - Fix infinite loop with zero-length options. (Ben Noordhuis) [#745](https://github.com/nodejs/node-gyp/pull/745)
* [[`101bed639b`](https://github.com/nodejs/node-gyp/commit/101bed639b)] - This platform value came from debian package, and now the value (Jérémy Lal) [#738](https://github.com/nodejs/node-gyp/pull/738)
## v3.0.3 2015-09-14
* [[`ad827cda30`](https://github.com/nodejs/node-gyp/commit/ad827cda30)] - tarballUrl global and && when checking for iojs (Lars-Magnus Skog) [#729](https://github.com/nodejs/node-gyp/pull/729)
## v3.0.2 2015-09-12
* [[`6e8c3bf3c6`](https://github.com/nodejs/node-gyp/commit/6e8c3bf3c6)] - add back support for passing additional cmdline args (Rod Vagg) [#723](https://github.com/nodejs/node-gyp/pull/723)
* [[`ff82f2f3b9`](https://github.com/nodejs/node-gyp/commit/ff82f2f3b9)] - fixed broken link in docs to Visual Studio 2013 download (simon-p-r) [#722](https://github.com/nodejs/node-gyp/pull/722)
## v3.0.1 2015-09-08
* [[`846337e36b`](https://github.com/nodejs/node-gyp/commit/846337e36b)] - normalise versions for target == this comparison (Rod Vagg) [#716](https://github.com/nodejs/node-gyp/pull/716)
## v3.0.0 2015-09-08
* [[`9720d0373c`](https://github.com/nodejs/node-gyp/commit/9720d0373c)] - remove node_modules from tree (Rod Vagg) [#711](https://github.com/nodejs/node-gyp/pull/711)
* [[`6dcf220db7`](https://github.com/nodejs/node-gyp/commit/6dcf220db7)] - test version major directly, don't use semver.satisfies() (Rod Vagg) [#711](https://github.com/nodejs/node-gyp/pull/711)
* [[`938dd18d1c`](https://github.com/nodejs/node-gyp/commit/938dd18d1c)] - refactor for clarity, fix dist-url, add env var dist-url functionality (Rod Vagg) [#711](https://github.com/nodejs/node-gyp/pull/711)
* [[`9e9df66a06`](https://github.com/nodejs/node-gyp/commit/9e9df66a06)] - use process.release, make aware of io.js & node v4 differences (Rod Vagg) [#711](https://github.com/nodejs/node-gyp/pull/711)
* [[`1ea7ed01f4`](https://github.com/nodejs/node-gyp/commit/1ea7ed01f4)] - **deps**: update graceful-fs dependency to the latest (Sakthipriyan Vairamani) [#714](https://github.com/nodejs/node-gyp/pull/714)
* [[`0fbc387b35`](https://github.com/nodejs/node-gyp/commit/0fbc387b35)] - Update repository URLs. (Ben Noordhuis) [#715](https://github.com/nodejs/node-gyp/pull/715)
* [[`bbedb8868b`](https://github.com/nodejs/node-gyp/commit/bbedb8868b)] - **(SEMVER-MAJOR)** **win**: enable delay-load hook by default (Jeremiah Senkpiel) [#708](https://github.com/nodejs/node-gyp/pull/708)
* [[`85ed107565`](https://github.com/nodejs/node-gyp/commit/85ed107565)] - Merge pull request #664 from othiym23/othiym23/allow-semver-5 (Nathan Rajlich)
* [[`0c720d234c`](https://github.com/nodejs/node-gyp/commit/0c720d234c)] - allow semver@5 (Forrest L Norvell)
## 2.0.2 / 2015-07-14
* Use HTTPS for dist url (#656, @SonicHedgehog)
* Merge pull request #648 from nevosegal/master
* Merge pull request #650 from magic890/patch-1
* Updated Installation section on README
* Updated link to gyp user documentation
* Fix download error message spelling (#643, @tomxtobin)
* Merge pull request #637 from lygstate/master
* Set NODE_GYP_DIR for addon.gypi to setting absolute path for
src/win_delay_load_hook.c, and fixes of the long relative path issue on Win32.
Fixes #636 (#637, @lygstate).
## 2.0.1 / 2015-05-28
* configure: try/catch the semver range.test() call
* README: update for visual studio 2013 (#510, @samccone)
## 2.0.0 / 2015-05-24
* configure: check for python2 executable by default, fallback to python
* configure: don't clobber existing $PYTHONPATH
* configure: use "path-array" for PYTHONPATH
* gyp: fix for non-acsii userprofile name on Windows
* gyp: always install into $PRODUCT_DIR
* gyp: apply https://codereview.chromium.org/11361103/
* gyp: don't use links at all, just copy the files instead
* gyp: update gyp to e1c8fcf7
* Updated README.md with updated Windows build info
* Show URL when a download fails
* package: add a "license" field
* move HMODULE m declaration to top
* Only add "-undefined dynamic_lookup" to loadable_module targets
* win: optionally allow node.exe/iojs.exe to be renamed
* Avoid downloading shasums if using tarPath
* Add target name preprocessor define: `NODE_GYP_MODULE_NAME`
* Show better error message in case of bad network settings
node-gyp-9.3.0/CONTRIBUTING.md 0000664 0000000 0000000 00000002547 14321173220 0015501 0 ustar 00root root 0000000 0000000 # Contributing to node-gyp
## Code of Conduct
Please read the
[Code of Conduct](https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md)
which explains the minimum behavior expectations for node-gyp contributors.
## Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
* (a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
* (b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
* (c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
* (d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
node-gyp-9.3.0/LICENSE 0000664 0000000 0000000 00000002116 14321173220 0014245 0 ustar 00root root 0000000 0000000 (The MIT License)
Copyright (c) 2012 Nathan Rajlich
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
node-gyp-9.3.0/README.md 0000664 0000000 0000000 00000024761 14321173220 0014531 0 ustar 00root root 0000000 0000000 # `node-gyp` - Node.js native addon build tool
[](https://github.com/nodejs/node-gyp/actions?query=workflow%3ATests+branch%3Amaster)

`node-gyp` is a cross-platform command-line tool written in Node.js for
compiling native addon modules for Node.js. It contains a vendored copy of the
[gyp-next](https://github.com/nodejs/gyp-next) project that was previously used
by the Chromium team, extended to support the development of Node.js native addons.
Note that `node-gyp` is _not_ used to build Node.js itself.
Multiple target versions of Node.js are supported (i.e. `0.8`, ..., `4`, `5`, `6`,
etc.), regardless of what version of Node.js is actually installed on your system
(`node-gyp` downloads the necessary development files or headers for the target version).
## Features
* The same build commands work on any of the supported platforms
* Supports the targeting of different versions of Node.js
## Installation
You can install `node-gyp` using `npm`:
``` bash
npm install -g node-gyp
```
Depending on your operating system, you will need to install:
### On Unix
* Python v3.7, v3.8, v3.9, or v3.10
* `make`
* A proper C/C++ compiler toolchain, like [GCC](https://gcc.gnu.org)
### On macOS
**ATTENTION**: If your Mac has been _upgraded_ to macOS Catalina (10.15) or higher, please read [macOS_Catalina.md](macOS_Catalina.md).
* Python v3.7, v3.8, v3.9, or v3.10
* `XCode Command Line Tools` which will install `clang`, `clang++`, and `make`.
* Install the `XCode Command Line Tools` standalone by running `xcode-select --install`. -- OR --
* Alternatively, if you already have the [full Xcode installed](https://developer.apple.com/xcode/download/), you can install the Command Line Tools under the menu `Xcode -> Open Developer Tool -> More Developer Tools...`.
### On Windows
Install the current version of Python from the [Microsoft Store package](https://www.microsoft.com/en-us/p/python-310/9pjpw5ldxlz5).
Install tools and configuration manually:
* Install Visual C++ Build Environment: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools)
(using "Visual C++ build tools" workload) or [Visual Studio Community](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community)
(using the "Desktop development with C++" workload)
* Launch cmd, `npm config set msvs_version 2017`
If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips.
To target native ARM64 Node.js on Windows 10 on ARM, add the components "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64".
### Configuring Python Dependency
`node-gyp` requires that you have installed a compatible version of Python, one of: v3.7, v3.8,
v3.9, or v3.10. If you have multiple Python versions installed, you can identify which Python
version `node-gyp` should use in one of the following ways:
1. by setting the `--python` command-line option, e.g.:
``` bash
node-gyp --python /path/to/executable/python
```
2. If `node-gyp` is called by way of `npm`, *and* you have multiple versions of
Python installed, then you can set `npm`'s 'python' config key to the appropriate
value:
``` bash
npm config set python /path/to/executable/python
```
3. If the `PYTHON` environment variable is set to the path of a Python executable,
then that version will be used, if it is a compatible version.
4. If the `NODE_GYP_FORCE_PYTHON` environment variable is set to the path of a
Python executable, it will be used instead of any of the other configured or
builtin Python search paths. If it's not a compatible version, no further
searching will be done.
### Build for Third Party Node.js Runtimes
When building modules for third party Node.js runtimes like Electron, which have
different build configurations from the official Node.js distribution, you
should use `--dist-url` or `--nodedir` flags to specify the headers of the
runtime to build for.
Also when `--dist-url` or `--nodedir` flags are passed, node-gyp will use the
`config.gypi` shipped in the headers distribution to generate build
configurations, which is different from the default mode that would use the
`process.config` object of the running Node.js instance.
Some old versions of Electron shipped malformed `config.gypi` in their headers
distributions, and you might need to pass `--force-process-config` to node-gyp
to work around configuration errors.
## How to Use
To compile your native addon, first go to its root directory:
``` bash
cd my_node_addon
```
The next step is to generate the appropriate project build files for the current
platform. Use `configure` for that:
``` bash
node-gyp configure
```
Auto-detection fails for Visual C++ Build Tools 2015, so `--msvs_version=2015`
needs to be added (not needed when run by npm as configured above):
``` bash
node-gyp configure --msvs_version=2015
```
__Note__: The `configure` step looks for a `binding.gyp` file in the current
directory to process. See below for instructions on creating a `binding.gyp` file.
Now you will have either a `Makefile` (on Unix platforms) or a `vcxproj` file
(on Windows) in the `build/` directory. Next, invoke the `build` command:
``` bash
node-gyp build
```
Now you have your compiled `.node` bindings file! The compiled bindings end up
in `build/Debug/` or `build/Release/`, depending on the build mode. At this point,
you can require the `.node` file with Node.js and run your tests!
__Note:__ To create a _Debug_ build of the bindings file, pass the `--debug` (or
`-d`) switch when running either the `configure`, `build` or `rebuild` commands.
## The `binding.gyp` file
A `binding.gyp` file describes the configuration to build your module, in a
JSON-like format. This file gets placed in the root of your package, alongside
`package.json`.
A barebones `gyp` file appropriate for building a Node.js addon could look like:
```python
{
"targets": [
{
"target_name": "binding",
"sources": [ "src/binding.cc" ]
}
]
}
```
## Further reading
The **[docs](./docs/)** directory contains additional documentation on specific node-gyp topics that may be useful if you are experiencing problems installing or building addons using node-gyp.
Some additional resources for Node.js native addons and writing `gyp` configuration files:
* ["Going Native" a nodeschool.io tutorial](http://nodeschool.io/#goingnative)
* ["Hello World" node addon example](https://github.com/nodejs/node/tree/master/test/addons/hello-world)
* [gyp user documentation](https://gyp.gsrc.io/docs/UserDocumentation.md)
* [gyp input format reference](https://gyp.gsrc.io/docs/InputFormatReference.md)
* [*"binding.gyp" files out in the wild* wiki page](./docs/binding.gyp-files-in-the-wild.md)
## Commands
`node-gyp` responds to the following commands:
| **Command** | **Description**
|:--------------|:---------------------------------------------------------------
| `help` | Shows the help dialog
| `build` | Invokes `make`/`msbuild.exe` and builds the native addon
| `clean` | Removes the `build` directory if it exists
| `configure` | Generates project build files for the current platform
| `rebuild` | Runs `clean`, `configure` and `build` all in a row
| `install` | Installs Node.js header files for the given version
| `list` | Lists the currently installed Node.js header versions
| `remove` | Removes the Node.js header files for the given version
## Command Options
`node-gyp` accepts the following command options:
| **Command** | **Description**
|:----------------------------------|:------------------------------------------
| `-j n`, `--jobs n` | Run `make` in parallel. The value `max` will use all available CPU cores
| `--target=v6.2.1` | Node.js version to build for (default is `process.version`)
| `--silly`, `--loglevel=silly` | Log all progress to console
| `--verbose`, `--loglevel=verbose` | Log most progress to console
| `--silent`, `--loglevel=silent` | Don't log anything to console
| `debug`, `--debug` | Make Debug build (default is `Release`)
| `--release`, `--no-debug` | Make Release build
| `-C $dir`, `--directory=$dir` | Run command in different directory
| `--make=$make` | Override `make` command (e.g. `gmake`)
| `--thin=yes` | Enable thin static libraries
| `--arch=$arch` | Set target architecture (e.g. ia32)
| `--tarball=$path` | Get headers from a local tarball
| `--devdir=$path` | SDK download directory (default is OS cache directory)
| `--ensure` | Don't reinstall headers if already present
| `--dist-url=$url` | Download header tarball from custom URL
| `--proxy=$url` | Set HTTP(S) proxy for downloading header tarball
| `--noproxy=$urls` | Set urls to ignore proxies when downloading header tarball
| `--cafile=$cafile` | Override default CA chain (to download tarball)
| `--nodedir=$path` | Set the path to the node source code
| `--python=$path` | Set path to the Python binary
| `--msvs_version=$version` | Set Visual Studio version (Windows only)
| `--solution=$solution` | Set Visual Studio Solution version (Windows only)
| `--force-process-config` | Force using runtime's `process.config` object to generate `config.gypi` file
## Configuration
### Environment variables
Use the form `npm_config_OPTION_NAME` for any of the command options listed
above (dashes in option names should be replaced by underscores).
For example, to set `devdir` equal to `/tmp/.gyp`, you would:
Run this on Unix:
```bash
export npm_config_devdir=/tmp/.gyp
```
Or this on Windows:
```console
set npm_config_devdir=c:\temp\.gyp
```
### `npm` configuration
Use the form `OPTION_NAME` for any of the command options listed above.
For example, to set `devdir` equal to `/tmp/.gyp`, you would run:
```bash
npm config set [--global] devdir /tmp/.gyp
```
**Note:** Configuration set via `npm` will only be used when `node-gyp`
is run via `npm`, not when `node-gyp` is run directly.
## License
`node-gyp` is available under the MIT license. See the [LICENSE
file](LICENSE) for details.
node-gyp-9.3.0/SECURITY.md 0000664 0000000 0000000 00000000227 14321173220 0015032 0 ustar 00root root 0000000 0000000 If you believe you have found a security issue in the software in this
repository, please consult https://github.com/nodejs/node/blob/HEAD/SECURITY.md. node-gyp-9.3.0/addon.gypi 0000664 0000000 0000000 00000013464 14321173220 0015227 0 ustar 00root root 0000000 0000000 {
'variables' : {
'node_engine_include_dir%': 'deps/v8/include',
'node_host_binary%': 'node',
'node_with_ltcg%': 'true',
},
'target_defaults': {
'type': 'loadable_module',
'win_delay_load_hook': 'true',
'product_prefix': '',
'conditions': [
[ 'node_engine=="chakracore"', {
'variables': {
'node_engine_include_dir%': 'deps/chakrashim/include'
},
}]
],
'include_dirs': [
'<(node_root_dir)/include/node',
'<(node_root_dir)/src',
'<(node_root_dir)/deps/openssl/config',
'<(node_root_dir)/deps/openssl/openssl/include',
'<(node_root_dir)/deps/uv/include',
'<(node_root_dir)/deps/zlib',
'<(node_root_dir)/<(node_engine_include_dir)'
],
'defines!': [
'BUILDING_UV_SHARED=1', # Inherited from common.gypi.
'BUILDING_V8_SHARED=1', # Inherited from common.gypi.
],
'defines': [
'NODE_GYP_MODULE_NAME=>(_target_name)',
'USING_UV_SHARED=1',
'USING_V8_SHARED=1',
# Warn when using deprecated V8 APIs.
'V8_DEPRECATION_WARNINGS=1'
],
'target_conditions': [
['_type=="loadable_module"', {
'product_extension': 'node',
'defines': [
'BUILDING_NODE_EXTENSION'
],
'xcode_settings': {
'OTHER_LDFLAGS': [
'-undefined dynamic_lookup'
],
},
}],
['_type=="static_library"', {
# set to `1` to *disable* the -T thin archive 'ld' flag.
# older linkers don't support this flag.
'standalone_static_library': '<(standalone_static_library)'
}],
['_type!="executable"', {
'conditions': [
[ 'OS=="android"', {
'cflags!': [ '-fPIE' ],
}]
]
}],
['_win_delay_load_hook=="true"', {
# If the addon specifies `'win_delay_load_hook': 'true'` in its
# binding.gyp, link a delay-load hook into the DLL. This hook ensures
# that the addon will work regardless of whether the node/iojs binary
# is named node.exe, iojs.exe, or something else.
'conditions': [
[ 'OS=="win"', {
'defines': [ 'HOST_BINARY=\"<(node_host_binary)<(EXECUTABLE_SUFFIX)\"', ],
'sources': [
'<(node_gyp_dir)/src/win_delay_load_hook.cc',
],
'msvs_settings': {
'VCLinkerTool': {
'DelayLoadDLLs': [ '<(node_host_binary)<(EXECUTABLE_SUFFIX)' ],
# Don't print a linker warning when no imports from either .exe
# are used.
'AdditionalOptions': [ '/ignore:4199' ],
},
},
}],
],
}],
],
'conditions': [
[ 'OS=="mac"', {
'defines': [
'_DARWIN_USE_64_BIT_INODE=1'
],
'xcode_settings': {
'DYLIB_INSTALL_NAME_BASE': '@rpath'
},
}],
[ 'OS=="aix"', {
'ldflags': [
'-Wl,-bimport:<(node_exp_file)'
],
}],
[ 'OS=="os400"', {
'ldflags': [
'-Wl,-bimport:<(node_exp_file)'
],
}],
[ 'OS=="zos"', {
'conditions': [
[ '"'
# needs to have dll-interface to be used by
# clients of class 'node::ObjectWrap'
4251
],
}, {
# OS!="win"
'defines': [
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64'
],
}],
[ 'OS in "freebsd openbsd netbsd solaris android" or \
(OS=="linux" and target_arch!="ia32")', {
'cflags': [ '-fPIC' ],
}],
]
}
}
node-gyp-9.3.0/bin/ 0000775 0000000 0000000 00000000000 14321173220 0014010 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/bin/node-gyp.js 0000775 0000000 0000000 00000006662 14321173220 0016105 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
'use strict'
process.title = 'node-gyp'
const envPaths = require('env-paths')
const gyp = require('../')
const log = require('npmlog')
const os = require('os')
/**
* Process and execute the selected commands.
*/
const prog = gyp()
var completed = false
prog.parseArgv(process.argv)
prog.devDir = prog.opts.devdir
var homeDir = os.homedir()
if (prog.devDir) {
prog.devDir = prog.devDir.replace(/^~/, homeDir)
} else if (homeDir) {
prog.devDir = envPaths('node-gyp', { suffix: '' }).cache
} else {
throw new Error(
"node-gyp requires that the user's home directory is specified " +
'in either of the environmental variables HOME or USERPROFILE. ' +
'Overide with: --devdir /path/to/.node-gyp')
}
if (prog.todo.length === 0) {
if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {
console.log('v%s', prog.version)
} else {
console.log('%s', prog.usage())
}
process.exit(0)
}
log.info('it worked if it ends with', 'ok')
log.verbose('cli', process.argv)
log.info('using', 'node-gyp@%s', prog.version)
log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch)
/**
* Change dir if -C/--directory was passed.
*/
var dir = prog.opts.directory
if (dir) {
var fs = require('fs')
try {
var stat = fs.statSync(dir)
if (stat.isDirectory()) {
log.info('chdir', dir)
process.chdir(dir)
} else {
log.warn('chdir', dir + ' is not a directory')
}
} catch (e) {
if (e.code === 'ENOENT') {
log.warn('chdir', dir + ' is not a directory')
} else {
log.warn('chdir', 'error during chdir() "%s"', e.message)
}
}
}
function run () {
var command = prog.todo.shift()
if (!command) {
// done!
completed = true
log.info('ok')
return
}
prog.commands[command.name](command.args, function (err) {
if (err) {
log.error(command.name + ' error')
log.error('stack', err.stack)
errorMessage()
log.error('not ok')
return process.exit(1)
}
if (command.name === 'list') {
var versions = arguments[1]
if (versions.length > 0) {
versions.forEach(function (version) {
console.log(version)
})
} else {
console.log('No node development files installed. Use `node-gyp install` to install a version.')
}
} else if (arguments.length >= 2) {
console.log.apply(console, [].slice.call(arguments, 1))
}
// now run the next command in the queue
process.nextTick(run)
})
}
process.on('exit', function (code) {
if (!completed && !code) {
log.error('Completion callback never invoked!')
issueMessage()
process.exit(6)
}
})
process.on('uncaughtException', function (err) {
log.error('UNCAUGHT EXCEPTION')
log.error('stack', err.stack)
issueMessage()
process.exit(7)
})
function errorMessage () {
// copied from npm's lib/utils/error-handler.js
var os = require('os')
log.error('System', os.type() + ' ' + os.release())
log.error('command', process.argv
.map(JSON.stringify).join(' '))
log.error('cwd', process.cwd())
log.error('node -v', process.version)
log.error('node-gyp -v', 'v' + prog.package.version)
}
function issueMessage () {
errorMessage()
log.error('', ['Node-gyp failed to build your package.',
'Try to update npm and/or node-gyp and if it does not help file an issue with the package author.'
].join('\n'))
}
// start running the given commands!
run()
node-gyp-9.3.0/docs/ 0000775 0000000 0000000 00000000000 14321173220 0014170 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/docs/Error-pre-versions-of-node-cannot-be-installed.md 0000664 0000000 0000000 00000007403 14321173220 0025407 0 ustar 00root root 0000000 0000000 When using `node-gyp` you might see an error like this when attempting to compile/install a node.js native addon:
```
$ npm install bcrypt
npm http GET https://registry.npmjs.org/bcrypt/0.7.5
npm http 304 https://registry.npmjs.org/bcrypt/0.7.5
npm http GET https://registry.npmjs.org/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0
> bcrypt@0.7.5 install /home/ubuntu/public/song-swap/node_modules/bcrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:69:16)
gyp ERR! stack at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:56:37)
gyp ERR! stack at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:219:20)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:105:9
gyp ERR! stack at ChildProcess.exithandler (child_process.js:630:7)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack at maybeClose (child_process.js:730:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:5)
gyp ERR! System Linux 3.5.0-21-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ubuntu/public/song-swap/node_modules/bcrypt
gyp ERR! node -v v0.11.2-pre
gyp ERR! node-gyp -v v0.9.5
gyp ERR! not ok
npm ERR! bcrypt@0.7.5 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the bcrypt@0.7.5 install script.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.5.0-21-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "bcrypt"
npm ERR! cwd /home/ubuntu/public/song-swap
npm ERR! node -v v0.11.2-pre
npm ERR! npm -v 1.2.18
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ubuntu/public/song-swap/npm-debug.log
npm ERR! not ok code 0
```
The main error here is:
```
Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
```
This error is caused when you attempt to compile a native addon using a version of node.js with `-pre` at the end of the version number:
``` bash
$ node -v
v0.10.4-pre
```
## How to avoid (the short answer)
To avoid this error completely just use a stable release of node.js. i.e. `v0.10.4`, and __not__ `v0.10.4-pre`.
## How to fix (the long answer)
This error happens because `node-gyp` does not know what header files were used to compile your "pre" version of node, and therefore it needs you to specify the node source code directory path using the `--nodedir` flag.
For example, if I compiled my development ("pre") version of node.js using the source code in `/Users/nrajlich/node`, then I could invoke `node-gyp` like:
``` bash
$ node-gyp rebuild --nodedir=/Users/nrajlich/node
```
Or install an native addon through `npm` like:
``` bash
$ npm install bcrypt --nodedir=/Users/nrajlich/node
```
### Always use `--nodedir`
__Note:__ This is for advanced users who use `-pre` versions of node more often than tagged releases.
If you're invoking `node-gyp` through `npm`, then you can leverage `npm`'s configuration system and not have to specify the `--nodedir` flag all the time:
``` bash
$ npm config set nodedir /Users/nrajlich/node
``` node-gyp-9.3.0/docs/Force-npm-to-use-global-node-gyp.md 0000664 0000000 0000000 00000005334 14321173220 0022535 0 ustar 00root root 0000000 0000000 # Force npm to use global installed node-gyp
**Note: These instructions only work with npm 6 or older. For a solution that works with npm 8 (or older), see [Updating-npm-bundled-node-gyp.md](Updating-npm-bundled-node-gyp.md).**
[Many issues](https://github.com/nodejs/node-gyp/labels/ERR%21%20node-gyp%20-v%20%3C%3D%20v5.1.0) are opened by users who are
not running a [current version of node-gyp](https://github.com/nodejs/node-gyp/releases).
npm bundles its own, internal, copy of node-gyp located at `npm/node_modules`, within npm's private dependencies which are separate from *globally* accessible packages. Therefore this internal copy of node-gyp is independent from any globally installed copy of node-gyp that
may have been installed via `npm install -g node-gyp`.
So npm's internal copy of node-gyp **isn't** stored inside *global* `node_modules` and thus isn't available for use as a standalone package. npm uses it's *internal* copy of `node-gyp` to automatically build native addons.
When you install a _new_ version of node-gyp outside of npm, it'll go into your *global* `node_modules`, but not under the `npm/node_modules` (where internal copy of node-gyp is stored). So it will get into your `$PATH` and you will be able to use this globally installed version (**but not internal node-gyp of npm**) as any other globally installed package.
The catch is that npm **won't** use global version unless you tell it to, it'll keep on using the **internal one**. You need to instruct it to by setting the `node_gyp` config variable (which goes into your `~/.npmrc`). You do this by running the `npm config set` command as below. Then npm will use the command in the path you supply whenever it needs to build a native addon.
**Important**: You also need to remember to unset this when you upgrade npm with a newer version of node-gyp, or you have to manually keep your globally installed node-gyp to date. See "Undo" below.
## Linux and macOS
```
npm install --global node-gyp@latest
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
```
`sudo` may be required for the first command if you get a permission error.
## Windows
### Windows Command Prompt
```
npm install --global node-gyp@latest
for /f "delims=" %P in ('npm prefix -g') do npm config set node_gyp "%P\node_modules\node-gyp\bin\node-gyp.js"
```
### Powershell
```
npm install --global node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
```
## Undo
**Beware** if you don't unset the `node_gyp` config option, npm will continue to use the globally installed version of node-gyp rather than the one it ships with, which may end up being newer.
```
npm config delete node_gyp
npm uninstall --global node-gyp
```
node-gyp-9.3.0/docs/Home.md 0000664 0000000 0000000 00000000331 14321173220 0015377 0 ustar 00root root 0000000 0000000 Welcome to the node-gyp wiki!
* [["binding.gyp" files out in the wild]]
* [[Linking to OpenSSL]]
* [[Common Issues]]
* [[Updating npm's bundled node-gyp]]
* [[Error: "pre" versions of node cannot be installed]]
node-gyp-9.3.0/docs/Linking-to-OpenSSL.md 0000664 0000000 0000000 00000007417 14321173220 0020017 0 ustar 00root root 0000000 0000000 A handful of native addons require linking to OpenSSL in one way or another. This introduces a small challenge since node will sometimes bundle OpenSSL statically (the default for node >= v0.8.x), or sometimes dynamically link to the system OpenSSL (default for node <= v0.6.x).
Good native addons should account for both scenarios. It's recommended that you use the `binding.gyp` file provided below as a starting-point for any addon that needs to use OpenSSL:
``` python
{
'variables': {
# node v0.6.x doesn't give us its build variables,
# but on Unix it was only possible to use the system OpenSSL library,
# so default the variable to "true", v0.8.x node and up will overwrite it.
'node_shared_openssl%': 'true'
},
'targets': [
{
'target_name': 'binding',
'sources': [
'src/binding.cc'
],
'conditions': [
['node_shared_openssl=="false"', {
# so when "node_shared_openssl" is "false", then OpenSSL has been
# bundled into the node executable. So we need to include the same
# header files that were used when building node.
'include_dirs': [
'<(node_root_dir)/deps/openssl/openssl/include'
],
"conditions" : [
["target_arch=='ia32'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/piii" ]
}],
["target_arch=='x64'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/k8" ]
}],
["target_arch=='arm'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/arm" ]
}]
]
}]
]
}
]
}
```
This ensures that when OpenSSL is statically linked into `node` then, the bundled OpenSSL headers are included, but when the system OpenSSL is in use, then only those headers will be used.
## Windows?
As you can see this baseline `binding.gyp` file only accounts for the Unix scenario. Currently on Windows the situation is a little less ideal. On Windows, OpenSSL is _always_ statically compiled into the `node` executable, so ideally it would be possible to use that copy of OpenSSL when building native addons.
Unfortunately it doesn't seem like that is possible at the moment, as there would need to be tweaks made to the generated `node.lib` file to include the openssl glue functions, or a new `openssl.lib` file would need to be created during the node build. I'm not sure which is the easiest/most feasible.
In the meantime, one possible solution is using another copy of OpenSSL, which is what [`node-bcrypt`](https://github.com/ncb000gt/node.bcrypt.js) currently does. Adding something like this to your `binding.gyp` file's `"conditions"` block would enable this:
``` python
[ 'OS=="win"', {
'conditions': [
# "openssl_root" is the directory on Windows of the OpenSSL files.
# Check the "target_arch" variable to set good default values for
# both 64-bit and 32-bit builds of the module.
['target_arch=="x64"', {
'variables': {
'openssl_root%': 'C:/OpenSSL-Win64'
},
}, {
'variables': {
'openssl_root%': 'C:/OpenSSL-Win32'
},
}],
],
'libraries': [
'-l<(openssl_root)/lib/libeay32.lib',
],
'include_dirs': [
'<(openssl_root)/include',
],
}]
```
Now you can direct your users to install OpenSSL on Windows from here (be sure to tell them to install the 64-bit version if they're compiling against a 64-bit version of node): http://slproweb.com/products/Win32OpenSSL.html
Also note that both `node-gyp` and `npm` allow you to overwrite that default `openssl_root` variable on the command line:
``` bash
$ node-gyp rebuild --openssl-root="C:\Users\Nathan\Desktop\openssl"
``` node-gyp-9.3.0/docs/README.md 0000664 0000000 0000000 00000002033 14321173220 0015445 0 ustar 00root root 0000000 0000000 ## Versions of `node-gyp` that are earlier than v9.x.x
Please look thru your error log for the string `gyp info using node-gyp@` and if that version number is less than the [current release of node-gyp](https://github.com/nodejs/node-gyp/releases) then __please upgrade__ using [these instructions](https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md) and then try your command again.
## `node-sass` is deprecated
Please be aware that the package [`node-sass` is deprecated](https://github.com/sass/node-sass#node-sass) so you should actively seek alternatives. Please avoid opening new `node-sass` issues on this repo. You can try `npm install --global node-sass@latest` but we [cannot help much](https://github.com/nodejs/node-gyp/issues?q=is%3Aissue+label%3A%22Node+Sass+--%3E+Dart+Sass%22+) here.
## Issues finding the installed Visual Studio
In cmd, [`npm config set msvs_version 20xx`](https://github.com/nodejs/node-gyp#on-windows) with ___xx___ matching your locally installed version of Visual Studio.
node-gyp-9.3.0/docs/Updating-npm-bundled-node-gyp.md 0000664 0000000 0000000 00000005026 14321173220 0022213 0 ustar 00root root 0000000 0000000 # Updating the npm-bundled version of node-gyp
**Note: These instructions are (only) tested and known to work with npm 8 and older.**
**Note: These instructions will be undone if you reinstall or upgrade npm or node! For a more permanent (and simpler) solution, see [Force-npm-to-use-global-node-gyp.md](Force-npm-to-use-global-node-gyp.md). (npm 6 or older only!)**
[Many issues](https://github.com/nodejs/node-gyp/issues?q=label%3A"ERR!+node-gyp+-v+<%3D+v9.x.x") are opened by users who are
not running a [current version of node-gyp](https://github.com/nodejs/node-gyp/releases).
`npm` bundles its own, internal, copy of `node-gyp`. This internal copy is independent of any globally installed copy of node-gyp that
may have been installed via `npm install -g node-gyp`.
This means that while `node-gyp` doesn't get installed into your `$PATH` by default, npm still keeps its own copy to invoke when you
attempt to `npm install` a native add-on.
Sometimes, you may need to update npm's internal node-gyp to a newer version than what is installed. A simple `npm install -g node-gyp`
_won't_ do the trick since npm will still continue to use its internal copy over the global one.
So instead:
## Version of npm
We need to start by knowing your version of `npm`:
```bash
npm --version
```
## Linux, macOS, Solaris, etc.
Unix is easy. Just run the following command.
If your npm is version ___7 or 8___, do:
```bash
$ npm explore npm/node_modules/@npmcli/run-script -g -- npm_config_global=false npm install node-gyp@latest
```
Else if your npm is version ___less than 7___, do:
```bash
$ npm explore npm/node_modules/npm-lifecycle -g -- npm install node-gyp@latest
```
If the command fails with a permissions error, please try `sudo` and then the command.
## Windows
Windows is a bit trickier, since `npm` might be installed to the "Program Files" directory, which needs admin privileges in order to
modify on current Windows. Therefore, run the following commands __inside a `cmd.exe` started with "Run as Administrator"__:
First we need to find the location of `node`. If you don't already know the location that `node.exe` got installed to, then run:
```bash
$ where node
```
Now `cd` to the directory that `node.exe` is contained in e.g.:
```bash
$ cd "C:\Program Files\nodejs"
```
If your npm version is ___7 or 8___, do:
```bash
cd node_modules\npm\node_modules\@npmcli\run-script
```
Else if your npm version is ___less than 7___, do:
```bash
cd node_modules\npm\node_modules\npm-lifecycle
```
Finish by running:
```bash
$ npm install node-gyp@latest
```
node-gyp-9.3.0/docs/binding.gyp-files-in-the-wild.md 0000664 0000000 0000000 00000011213 14321173220 0022137 0 ustar 00root root 0000000 0000000 This page contains links to some examples of existing `binding.gyp` files that other node modules are using. Take a look at them for inspiration.
To add to this page, just add the link to the project's `binding.gyp` file below:
* [ons](https://github.com/XadillaX/aliyun-ons/blob/master/binding.gyp)
* [thmclrx](https://github.com/XadillaX/thmclrx/blob/master/binding.gyp)
* [libxmljs](https://github.com/polotek/libxmljs/blob/master/binding.gyp)
* [node-buffertools](https://github.com/bnoordhuis/node-buffertools/blob/master/binding.gyp)
* [node-canvas](https://github.com/LearnBoost/node-canvas/blob/master/binding.gyp)
* [node-ffi](https://github.com/rbranson/node-ffi/blob/master/binding.gyp) + [libffi](https://github.com/rbranson/node-ffi/blob/master/deps/libffi/libffi.gyp)
* [node-time](https://github.com/TooTallNate/node-time/blob/master/binding.gyp)
* [node-sass](https://github.com/sass/node-sass/blob/master/binding.gyp) + [libsass](https://github.com/sass/node-sass/blob/master/src/libsass.gyp)
* [node-serialport](https://github.com/voodootikigod/node-serialport/blob/master/binding.gyp)
* [node-weak](https://github.com/TooTallNate/node-weak/blob/master/binding.gyp)
* [pty.js](https://github.com/chjj/pty.js/blob/master/binding.gyp)
* [ref](https://github.com/TooTallNate/ref/blob/master/binding.gyp)
* [appjs](https://github.com/milani/appjs/blob/master/binding.gyp)
* [nwm](https://github.com/mixu/nwm/blob/master/binding.gyp)
* [bcrypt](https://github.com/ncb000gt/node.bcrypt.js/blob/master/binding.gyp)
* [nk-mysql](https://github.com/mmod/nodamysql/blob/master/binding.gyp)
* [nk-xrm-installer](https://github.com/mmod/nk-xrm-installer/blob/master/binding.gyp) + [includable.gypi](https://github.com/mmod/nk-xrm-installer/blob/master/includable.gypi) + [unpack.py](https://github.com/mmod/nk-xrm-installer/blob/master/unpack.py) + [disburse.py](https://github.com/mmod/nk-xrm-installer/blob/master/disburse.py)
.py files above provide complete reference for examples of fetching source via http, extracting, and moving files.
* [node-memwatch](https://github.com/lloyd/node-memwatch/blob/master/binding.gyp)
* [node-ip2location](https://github.com/bolgovr/node-ip2location/blob/master/binding.gyp)
* [node-midi](https://github.com/justinlatimer/node-midi/blob/master/binding.gyp)
* [node-sqlite3](https://github.com/developmentseed/node-sqlite3/blob/master/binding.gyp) + [libsqlite3](https://github.com/developmentseed/node-sqlite3/blob/master/deps/sqlite3.gyp)
* [node-zipfile](https://github.com/mapbox/node-zipfile/blob/master/binding.gyp)
* [node-mapnik](https://github.com/mapnik/node-mapnik/blob/master/binding.gyp)
* [node-inotify](https://github.com/c4milo/node-inotify/blob/master/binding.gyp)
* [v8-profiler](https://github.com/c4milo/v8-profiler/blob/master/binding.gyp)
* [airtunes](https://github.com/radioline/node_airtunes/blob/master/binding.gyp)
* [node-fann](https://github.com/c4milo/node-fann/blob/master/binding.gyp)
* [node-talib](https://github.com/oransel/node-talib/blob/master/binding.gyp)
* [node-leveldown](https://github.com/rvagg/node-leveldown/blob/master/binding.gyp) + [leveldb.gyp](https://github.com/rvagg/node-leveldown/blob/master/deps/leveldb/leveldb.gyp) + [snappy.gyp](https://github.com/rvagg/node-leveldown/blob/master/deps/snappy/snappy.gyp)
* [node-expat](https://github.com/astro/node-expat/blob/master/binding.gyp) + [libexpat](https://github.com/astro/node-expat/blob/master/deps/libexpat/libexpat.gyp)
* [node-openvg-canvas](https://github.com/luismreis/node-openvg-canvas/blob/master/binding.gyp) + [node-openvg](https://github.com/luismreis/node-openvg/blob/master/binding.gyp)
* [node-cryptopp](https://github.com/BatikhSouri/node-cryptopp/blob/master/binding.gyp)
* [topcube](https://github.com/creationix/topcube/blob/master/binding.gyp)
* [node-osmium](https://github.com/osmcode/node-osmium/blob/master/binding.gyp)
* [node-osrm](https://github.com/DennisOSRM/node-osrm)
* [node-oracle](https://github.com/joeferner/node-oracle/blob/master/binding.gyp)
* [node-process-list](https://github.com/ReklatsMasters/node-process-list/blob/master/binding.gyp)
* [node-nanomsg](https://github.com/nickdesaulniers/node-nanomsg/blob/master/binding.gyp)
* [Ghostscript4JS](https://github.com/NickNaso/ghostscript4js/blob/master/binding.gyp)
* [nodecv](https://github.com/xudafeng/nodecv/blob/master/binding.gyp)
* [magick-cli](https://github.com/NickNaso/magick-cli/blob/master/binding.gyp)
* [sharp](https://github.com/lovell/sharp/blob/master/binding.gyp)
* [krb5](https://github.com/adaltas/node-krb5/blob/master/binding.gyp)
* [node-heapdump](https://github.com/bnoordhuis/node-heapdump/blob/master/binding.gyp)
node-gyp-9.3.0/gyp/ 0000775 0000000 0000000 00000000000 14321173220 0014037 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/.flake8 0000664 0000000 0000000 00000000171 14321173220 0015211 0 ustar 00root root 0000000 0000000 [flake8]
max-complexity = 101
max-line-length = 88
extend-ignore = E203 # whitespace before ':' to agree with psf/black
node-gyp-9.3.0/gyp/.github/ 0000775 0000000 0000000 00000000000 14321173220 0015377 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/.github/workflows/ 0000775 0000000 0000000 00000000000 14321173220 0017434 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/.github/workflows/Python_tests.yml 0000664 0000000 0000000 00000002166 14321173220 0022667 0 ustar 00root root 0000000 0000000 # TODO: Enable os: windows-latest
# TODO: Enable pytest --doctest-modules
name: Python_tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
Python_tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
max-parallel: 8
matrix:
os: [macos-latest, ubuntu-latest] # , windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install --editable ".[dev]"
- run: ./gyp -V && ./gyp --version && gyp -V && gyp --version
- name: Lint with flake8
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
- name: Test with pytest
run: pytest
# - name: Run doctests with pytest
# run: pytest --doctest-modules
node-gyp-9.3.0/gyp/.github/workflows/node-gyp.yml 0000664 0000000 0000000 00000002072 14321173220 0021702 0 ustar 00root root 0000000 0000000 name: node-gyp integration
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
integration:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python: ["3.7", "3.10"]
runs-on: ${{ matrix.os }}
steps:
- name: Clone gyp-next
uses: actions/checkout@v3
with:
path: gyp-next
- name: Clone nodejs/node-gyp
uses: actions/checkout@v3
with:
repository: nodejs/node-gyp
path: node-gyp
- uses: actions/setup-node@v3
with:
node-version: 14.x
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
cd node-gyp
npm install --no-progress
- name: Replace gyp in node-gyp
shell: bash
run: |
rm -rf node-gyp/gyp
cp -r gyp-next node-gyp/gyp
- name: Run tests
run: |
cd node-gyp
npm test
node-gyp-9.3.0/gyp/.github/workflows/nodejs-windows.yml 0000664 0000000 0000000 00000001303 14321173220 0023126 0 ustar 00root root 0000000 0000000 name: Node.js Windows integration
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build-windows:
runs-on: windows-2019
steps:
- name: Clone gyp-next
uses: actions/checkout@v3
with:
path: gyp-next
- name: Clone nodejs/node
uses: actions/checkout@v3
with:
repository: nodejs/node
path: node
- name: Install deps
run: choco install nasm
- name: Replace gyp in Node.js
run: |
rm -Recurse node/tools/gyp
cp -Recurse gyp-next node/tools/gyp
- name: Build Node.js
run: |
cd node
./vcbuild.bat
node-gyp-9.3.0/gyp/.github/workflows/release-please.yml 0000664 0000000 0000000 00000000530 14321173220 0023044 0 ustar 00root root 0000000 0000000 on:
push:
branches:
- main
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: python
package-name: gyp-next
bump-minor-pre-major: true
node-gyp-9.3.0/gyp/.gitignore 0000664 0000000 0000000 00000004134 14321173220 0016031 0 ustar 00root root 0000000 0000000 # Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# static files generated from Django application using `collectstatic`
media
static
node-gyp-9.3.0/gyp/AUTHORS 0000664 0000000 0000000 00000001002 14321173220 0015100 0 ustar 00root root 0000000 0000000 # Names should be added to this file like so:
# Name or Organization
Google Inc. <*@google.com>
Bloomberg Finance L.P. <*@bloomberg.net>
IBM Inc. <*@*.ibm.com>
Yandex LLC <*@yandex-team.ru>
Steven Knight
Ryan Norton
David J. Sankel
Eric N. Vander Weele
Tom Freudenberg
Julien Brianceau
Refael Ackermann
Ujjwal Sharma
node-gyp-9.3.0/gyp/CHANGELOG.md 0000664 0000000 0000000 00000024513 14321173220 0015655 0 ustar 00root root 0000000 0000000 # Changelog
## [0.14.0](https://github.com/nodejs/gyp-next/compare/v0.13.0...v0.14.0) (2022-10-08)
### Features
* Add command line argument for `gyp --version` ([#164](https://github.com/nodejs/gyp-next/issues/164)) ([5c9f4d0](https://github.com/nodejs/gyp-next/commit/5c9f4d05678dd855e18ed2327219e5d18e5374db))
* ninja build for iOS ([#174](https://github.com/nodejs/gyp-next/issues/174)) ([b6f2714](https://github.com/nodejs/gyp-next/commit/b6f271424e0033d7ed54d437706695af2ba7a1bf))
* **zos:** support IBM Open XL C/C++ & PL/I compilers on z/OS ([#178](https://github.com/nodejs/gyp-next/issues/178)) ([43a7211](https://github.com/nodejs/gyp-next/commit/43a72110ae3fafb13c9625cc7a969624b27cda47))
### Bug Fixes
* lock windows env ([#163](https://github.com/nodejs/gyp-next/issues/163)) ([44bd0dd](https://github.com/nodejs/gyp-next/commit/44bd0ddc93ea0b5770a44dd326a2e4ae62c21442))
* move configuration information into pyproject.toml ([#176](https://github.com/nodejs/gyp-next/issues/176)) ([d69d8ec](https://github.com/nodejs/gyp-next/commit/d69d8ece6dbff7af4f2ea073c9fd170baf8cb7f7))
* node.js debugger adds stderr (but exit code is 0) -> shouldn't throw ([#179](https://github.com/nodejs/gyp-next/issues/179)) ([1a457d9](https://github.com/nodejs/gyp-next/commit/1a457d9ed08cfd30c9fa551bc5cf0d90fb583787))
## [0.13.0](https://www.github.com/nodejs/gyp-next/compare/v0.12.1...v0.13.0) (2022-05-11)
### Features
* add PRODUCT_DIR_ABS variable ([#151](https://www.github.com/nodejs/gyp-next/issues/151)) ([80d2626](https://www.github.com/nodejs/gyp-next/commit/80d26263581db829b61b312a7bdb5cc791df7824))
### Bug Fixes
* execvp: printf: Argument list too long ([#147](https://www.github.com/nodejs/gyp-next/issues/147)) ([c4e14f3](https://www.github.com/nodejs/gyp-next/commit/c4e14f301673fadbac3ab7882d0b5f4d02530cb9))
### [0.12.1](https://www.github.com/nodejs/gyp-next/compare/v0.12.0...v0.12.1) (2022-04-06)
### Bug Fixes
* **msvs:** avoid fixing path for arguments with "=" ([#143](https://www.github.com/nodejs/gyp-next/issues/143)) ([7e8f16e](https://www.github.com/nodejs/gyp-next/commit/7e8f16eb165e042e64bec98fa6c2a0232a42c26b))
## [0.12.0](https://www.github.com/nodejs/gyp-next/compare/v0.11.0...v0.12.0) (2022-04-04)
### Features
* support building shared libraries on z/OS ([#137](https://www.github.com/nodejs/gyp-next/issues/137)) ([293bcfa](https://www.github.com/nodejs/gyp-next/commit/293bcfa4c25c6adb743377adafc45a80fee492c6))
## [0.11.0](https://www.github.com/nodejs/gyp-next/compare/v0.10.1...v0.11.0) (2022-03-04)
### Features
* Add proper support for IBM i ([#140](https://www.github.com/nodejs/gyp-next/issues/140)) ([fdda4a3](https://www.github.com/nodejs/gyp-next/commit/fdda4a3038b8a7042ad960ce7a223687c24a21b1))
### [0.10.1](https://www.github.com/nodejs/gyp-next/compare/v0.10.0...v0.10.1) (2021-11-24)
### Bug Fixes
* **make:** only generate makefile for multiple toolsets if requested ([#133](https://www.github.com/nodejs/gyp-next/issues/133)) ([f463a77](https://www.github.com/nodejs/gyp-next/commit/f463a77705973289ea38fec1b244c922ac438e26))
## [0.10.0](https://www.github.com/nodejs/gyp-next/compare/v0.9.6...v0.10.0) (2021-08-26)
### Features
* **msvs:** add support for Visual Studio 2022 ([#124](https://www.github.com/nodejs/gyp-next/issues/124)) ([4bd9215](https://www.github.com/nodejs/gyp-next/commit/4bd9215c44d300f06e916aec1d6327c22b78272d))
### [0.9.6](https://www.github.com/nodejs/gyp-next/compare/v0.9.5...v0.9.6) (2021-08-23)
### Bug Fixes
* align flake8 test ([#122](https://www.github.com/nodejs/gyp-next/issues/122)) ([f1faa8d](https://www.github.com/nodejs/gyp-next/commit/f1faa8d3081e1a47e917ff910892f00dff16cf8a))
* **msvs:** fix paths again in action command arguments ([#121](https://www.github.com/nodejs/gyp-next/issues/121)) ([7159dfb](https://www.github.com/nodejs/gyp-next/commit/7159dfbc5758c9ec717e215f2c36daf482c846a1))
### [0.9.5](https://www.github.com/nodejs/gyp-next/compare/v0.9.4...v0.9.5) (2021-08-18)
### Bug Fixes
* add python 3.6 to node-gyp integration test ([3462d4c](https://www.github.com/nodejs/gyp-next/commit/3462d4ce3c31cce747513dc7ca9760c81d57c60e))
* revert for windows compatibility ([d078e7d](https://www.github.com/nodejs/gyp-next/commit/d078e7d7ae080ddae243188f6415f940376a7368))
* support msvs_quote_cmd in ninja generator ([#117](https://www.github.com/nodejs/gyp-next/issues/117)) ([46486ac](https://www.github.com/nodejs/gyp-next/commit/46486ac6e9329529d51061e006a5b39631e46729))
### [0.9.4](https://www.github.com/nodejs/gyp-next/compare/v0.9.3...v0.9.4) (2021-08-09)
### Bug Fixes
* .S is an extension for asm file on Windows ([#115](https://www.github.com/nodejs/gyp-next/issues/115)) ([d2fad44](https://www.github.com/nodejs/gyp-next/commit/d2fad44ef3a79ca8900f1307060153ded57053fc))
### [0.9.3](https://www.github.com/nodejs/gyp-next/compare/v0.9.2...v0.9.3) (2021-07-07)
### Bug Fixes
* build failure with ninja and Python 3 on Windows ([#113](https://www.github.com/nodejs/gyp-next/issues/113)) ([c172d10](https://www.github.com/nodejs/gyp-next/commit/c172d105deff5db4244e583942215918fa80dd3c))
### [0.9.2](https://www.github.com/nodejs/gyp-next/compare/v0.9.1...v0.9.2) (2021-05-21)
### Bug Fixes
* add support of utf8 encoding ([#105](https://www.github.com/nodejs/gyp-next/issues/105)) ([4d0f93c](https://www.github.com/nodejs/gyp-next/commit/4d0f93c249286d1f0c0f665f5fe7346119f98cf1))
### [0.9.1](https://www.github.com/nodejs/gyp-next/compare/v0.9.0...v0.9.1) (2021-05-14)
### Bug Fixes
* py lint ([3b6a8ee](https://www.github.com/nodejs/gyp-next/commit/3b6a8ee7a66193a8a6867eba9e1d2b70bdf04402))
## [0.9.0](https://www.github.com/nodejs/gyp-next/compare/v0.8.1...v0.9.0) (2021-05-13)
### Features
* use LDFLAGS_host for host toolset ([#98](https://www.github.com/nodejs/gyp-next/issues/98)) ([bea5c7b](https://www.github.com/nodejs/gyp-next/commit/bea5c7bd67d6ad32acbdce79767a5481c70675a2))
### Bug Fixes
* msvs.py: remove overindentation ([#102](https://www.github.com/nodejs/gyp-next/issues/102)) ([3f83e99](https://www.github.com/nodejs/gyp-next/commit/3f83e99056d004d9579ceb786e06b624ddc36529))
* update gyp.el to change case to cl-case ([#93](https://www.github.com/nodejs/gyp-next/issues/93)) ([13d5b66](https://www.github.com/nodejs/gyp-next/commit/13d5b66aab35985af9c2fb1174fdc6e1c1407ecc))
### [0.8.1](https://www.github.com/nodejs/gyp-next/compare/v0.8.0...v0.8.1) (2021-02-18)
### Bug Fixes
* update shebang lines from python to python3 ([#94](https://www.github.com/nodejs/gyp-next/issues/94)) ([a1b0d41](https://www.github.com/nodejs/gyp-next/commit/a1b0d4171a8049a4ab7a614202063dec332f2df4))
## [0.8.0](https://www.github.com/nodejs/gyp-next/compare/v0.7.0...v0.8.0) (2021-01-15)
### ⚠ BREAKING CHANGES
* remove support for Python 2
### Bug Fixes
* revert posix build job ([#86](https://www.github.com/nodejs/gyp-next/issues/86)) ([39dc34f](https://www.github.com/nodejs/gyp-next/commit/39dc34f0799c074624005fb9bbccf6e028607f9d))
### gyp
* Remove support for Python 2 ([#88](https://www.github.com/nodejs/gyp-next/issues/88)) ([22e4654](https://www.github.com/nodejs/gyp-next/commit/22e465426fd892403c95534229af819a99c3f8dc))
## [0.7.0](https://www.github.com/nodejs/gyp-next/compare/v0.6.2...v0.7.0) (2020-12-17)
### ⚠ BREAKING CHANGES
* **msvs:** On Windows, arguments passed to the "action" commands are no longer transformed to replace slashes with backslashes.
### Features
* **xcode:** --cross-compiling overrides arch-specific settings ([973bae0](https://www.github.com/nodejs/gyp-next/commit/973bae0b7b08be7b680ecae9565fbd04b3e0787d))
### Bug Fixes
* **msvs:** do not fix paths in action command arguments ([fc22f83](https://www.github.com/nodejs/gyp-next/commit/fc22f8335e2016da4aae4f4233074bd651d2faea))
* cmake on python 3 ([fd61f5f](https://www.github.com/nodejs/gyp-next/commit/fd61f5faa5275ec8fc98e3c7868c0dd46f109540))
* ValueError: invalid mode: 'rU' while trying to load binding.gyp ([d0504e6](https://www.github.com/nodejs/gyp-next/commit/d0504e6700ce48f44957a4d5891b142a60be946f))
* xcode cmake parsing ([eefe8d1](https://www.github.com/nodejs/gyp-next/commit/eefe8d10e99863bc4ac7e2ed32facd608d400d4b))
### [0.6.2](https://www.github.com/nodejs/gyp-next/compare/v0.6.1...v0.6.2) (2020-10-16)
### Bug Fixes
* do not rewrite absolute paths to avoid long paths ([#74](https://www.github.com/nodejs/gyp-next/issues/74)) ([c2ccc1a](https://www.github.com/nodejs/gyp-next/commit/c2ccc1a81f7f94433a94f4d01a2e820db4c4331a))
* only include MARMASM when toolset is target ([5a2794a](https://www.github.com/nodejs/gyp-next/commit/5a2794aefb58f0c00404ff042b61740bc8b8d5cd))
### [0.6.1](https://github.com/nodejs/gyp-next/compare/v0.6.0...v0.6.1) (2020-10-14)
### Bug Fixes
* Correctly rename object files for absolute paths in MSVS generator.
## [0.6.0](https://github.com/nodejs/gyp-next/compare/v0.5.0...v0.6.0) (2020-10-13)
### Features
* The Makefile generator will now output shared libraries directly to the product directory on all platforms (previously only macOS).
## [0.5.0](https://github.com/nodejs/gyp-next/compare/v0.4.0...v0.5.0) (2020-09-30)
### Features
* Extended compile_commands_json generator to consider more file extensions than just `c` and `cc`. `cpp` and `cxx` are now supported.
* Source files with duplicate basenames are now supported.
### Removed
* The `--no-duplicate-basename-check` option was removed.
* The `msvs_enable_marmasm` configuration option was removed in favor of auto-inclusion of the "marmasm" sections for Windows on ARM.
## [0.4.0](https://github.com/nodejs/gyp-next/compare/v0.3.0...v0.4.0) (2020-07-14)
### Features
* Added support for passing arbitrary architectures to Xcode builds, enables `arm64` builds.
### Bug Fixes
* Fixed a bug on Solaris where copying archives failed.
## [0.3.0](https://github.com/nodejs/gyp-next/compare/v0.2.1...v0.3.0) (2020-06-06)
### Features
* Added support for MSVC cross-compilation. This allows compilation on x64 for a Windows ARM target.
### Bug Fixes
* Fixed XCode CLT version detection on macOS Catalina.
### [0.2.1](https://github.com/nodejs/gyp-next/compare/v0.2.0...v0.2.1) (2020-05-05)
### Bug Fixes
* Relicensed to Node.js contributors.
* Fixed Windows bug introduced in v0.2.0.
## [0.2.0](https://github.com/nodejs/gyp-next/releases/tag/v0.2.0) (2020-04-06)
This is the first release of this project, based on https://chromium.googlesource.com/external/gyp with changes made over the years in Node.js and node-gyp.
node-gyp-9.3.0/gyp/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000000313 14321173220 0016633 0 ustar 00root root 0000000 0000000 # Code of Conduct
* [Node.js Code of Conduct](https://github.com/nodejs/admin/blob/HEAD/CODE_OF_CONDUCT.md)
* [Node.js Moderation Policy](https://github.com/nodejs/admin/blob/HEAD/Moderation-Policy.md)
node-gyp-9.3.0/gyp/CONTRIBUTING.md 0000664 0000000 0000000 00000002457 14321173220 0016300 0 ustar 00root root 0000000 0000000 # Contributing to gyp-next
## Code of Conduct
This project is bound to the [Node.js Code of Conduct](https://github.com/nodejs/admin/blob/HEAD/CODE_OF_CONDUCT.md).
## Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
* (a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
* (b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
* (c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
* (d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
node-gyp-9.3.0/gyp/LICENSE 0000664 0000000 0000000 00000003001 14321173220 0015036 0 ustar 00root root 0000000 0000000 Copyright (c) 2020 Node.js contributors. All rights reserved.
Copyright (c) 2009 Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
node-gyp-9.3.0/gyp/README.md 0000664 0000000 0000000 00000000662 14321173220 0015322 0 ustar 00root root 0000000 0000000 GYP can Generate Your Projects.
===================================
Documents are available at [gyp.gsrc.io](https://gyp.gsrc.io), or you can check out ```md-pages``` branch to read those documents offline.
__gyp-next__ is [released](https://github.com/nodejs/gyp-next/releases) to the [__Python Packaging Index__](https://pypi.org/project/gyp-next) (PyPI) and can be installed with the command:
* `python3 -m pip install gyp-next`
node-gyp-9.3.0/gyp/data/ 0000775 0000000 0000000 00000000000 14321173220 0014750 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/data/win/ 0000775 0000000 0000000 00000000000 14321173220 0015545 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/data/win/large-pdb-shim.cc 0000664 0000000 0000000 00000001215 14321173220 0020646 0 ustar 00root root 0000000 0000000 // Copyright (c) 2013 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is used to generate an empty .pdb -- with a 4KB pagesize -- that is
// then used during the final link for modules that have large PDBs. Otherwise,
// the linker will generate a pdb with a page size of 1KB, which imposes a limit
// of 1GB on the .pdb. By generating an initial empty .pdb with the compiler
// (rather than the linker), this limit is avoided. With this in place PDBs may
// grow to 2GB.
//
// This file is referenced by the msvs_large_pdb mechanism in MSVSUtil.py.
node-gyp-9.3.0/gyp/gyp 0000775 0000000 0000000 00000000360 14321173220 0014563 0 ustar 00root root 0000000 0000000 #!/bin/sh
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
base=$(dirname "$0")
exec python "${base}/gyp_main.py" "$@"
node-gyp-9.3.0/gyp/gyp.bat 0000775 0000000 0000000 00000000311 14321173220 0015324 0 ustar 00root root 0000000 0000000 @rem Copyright (c) 2009 Google Inc. All rights reserved.
@rem Use of this source code is governed by a BSD-style license that can be
@rem found in the LICENSE file.
@python "%~dp0gyp_main.py" %*
node-gyp-9.3.0/gyp/gyp_main.py 0000775 0000000 0000000 00000002342 14321173220 0016220 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
import subprocess
def IsCygwin():
# Function copied from pylib/gyp/common.py
try:
out = subprocess.Popen(
"uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
stdout, _ = out.communicate()
return "CYGWIN" in stdout.decode("utf-8")
except Exception:
return False
def UnixifyPath(path):
try:
if not IsCygwin():
return path
out = subprocess.Popen(
["cygpath", "-u", path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
stdout, _ = out.communicate()
return stdout.decode("utf-8")
except Exception:
return path
# Make sure we're using the version of pylib in this repo, not one installed
# elsewhere on the system. Also convert to Unix style path on Cygwin systems,
# else the 'gyp' library will not be found
path = UnixifyPath(sys.argv[0])
sys.path.insert(0, os.path.join(os.path.dirname(path), "pylib"))
import gyp # noqa: E402
if __name__ == "__main__":
sys.exit(gyp.script_main())
node-gyp-9.3.0/gyp/pylib/ 0000775 0000000 0000000 00000000000 14321173220 0015156 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/pylib/gyp/ 0000775 0000000 0000000 00000000000 14321173220 0015755 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/pylib/gyp/MSVSNew.py 0000664 0000000 0000000 00000031447 14321173220 0017602 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""New implementation of Visual Studio project generation."""
import hashlib
import os
import random
from operator import attrgetter
import gyp.common
def cmp(x, y):
return (x > y) - (x < y)
# Initialize random number generator
random.seed()
# GUIDs for project types
ENTRY_TYPE_GUIDS = {
"project": "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}",
"folder": "{2150E333-8FDC-42A3-9474-1A3956D46DE8}",
}
# ------------------------------------------------------------------------------
# Helper functions
def MakeGuid(name, seed="msvs_new"):
"""Returns a GUID for the specified target name.
Args:
name: Target name.
seed: Seed for MD5 hash.
Returns:
A GUID-line string calculated from the name and seed.
This generates something which looks like a GUID, but depends only on the
name and seed. This means the same name/seed will always generate the same
GUID, so that projects and solutions which refer to each other can explicitly
determine the GUID to refer to explicitly. It also means that the GUID will
not change when the project for a target is rebuilt.
"""
# Calculate a MD5 signature for the seed and name.
d = hashlib.md5((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
# Convert most of the signature to GUID form (discard the rest)
guid = (
"{"
+ d[:8]
+ "-"
+ d[8:12]
+ "-"
+ d[12:16]
+ "-"
+ d[16:20]
+ "-"
+ d[20:32]
+ "}"
)
return guid
# ------------------------------------------------------------------------------
class MSVSSolutionEntry:
def __cmp__(self, other):
# Sort by name then guid (so things are in order on vs2008).
return cmp((self.name, self.get_guid()), (other.name, other.get_guid()))
class MSVSFolder(MSVSSolutionEntry):
"""Folder in a Visual Studio project or solution."""
def __init__(self, path, name=None, entries=None, guid=None, items=None):
"""Initializes the folder.
Args:
path: Full path to the folder.
name: Name of the folder.
entries: List of folder entries to nest inside this folder. May contain
Folder or Project objects. May be None, if the folder is empty.
guid: GUID to use for folder, if not None.
items: List of solution items to include in the folder project. May be
None, if the folder does not directly contain items.
"""
if name:
self.name = name
else:
# Use last layer.
self.name = os.path.basename(path)
self.path = path
self.guid = guid
# Copy passed lists (or set to empty lists)
self.entries = sorted(entries or [], key=attrgetter("path"))
self.items = list(items or [])
self.entry_type_guid = ENTRY_TYPE_GUIDS["folder"]
def get_guid(self):
if self.guid is None:
# Use consistent guids for folders (so things don't regenerate).
self.guid = MakeGuid(self.path, seed="msvs_folder")
return self.guid
# ------------------------------------------------------------------------------
class MSVSProject(MSVSSolutionEntry):
"""Visual Studio project."""
def __init__(
self,
path,
name=None,
dependencies=None,
guid=None,
spec=None,
build_file=None,
config_platform_overrides=None,
fixpath_prefix=None,
):
"""Initializes the project.
Args:
path: Absolute path to the project file.
name: Name of project. If None, the name will be the same as the base
name of the project file.
dependencies: List of other Project objects this project is dependent
upon, if not None.
guid: GUID to use for project, if not None.
spec: Dictionary specifying how to build this project.
build_file: Filename of the .gyp file that the vcproj file comes from.
config_platform_overrides: optional dict of configuration platforms to
used in place of the default for this target.
fixpath_prefix: the path used to adjust the behavior of _fixpath
"""
self.path = path
self.guid = guid
self.spec = spec
self.build_file = build_file
# Use project filename if name not specified
self.name = name or os.path.splitext(os.path.basename(path))[0]
# Copy passed lists (or set to empty lists)
self.dependencies = list(dependencies or [])
self.entry_type_guid = ENTRY_TYPE_GUIDS["project"]
if config_platform_overrides:
self.config_platform_overrides = config_platform_overrides
else:
self.config_platform_overrides = {}
self.fixpath_prefix = fixpath_prefix
self.msbuild_toolset = None
def set_dependencies(self, dependencies):
self.dependencies = list(dependencies or [])
def get_guid(self):
if self.guid is None:
# Set GUID from path
# TODO(rspangler): This is fragile.
# 1. We can't just use the project filename sans path, since there could
# be multiple projects with the same base name (for example,
# foo/unittest.vcproj and bar/unittest.vcproj).
# 2. The path needs to be relative to $SOURCE_ROOT, so that the project
# GUID is the same whether it's included from base/base.sln or
# foo/bar/baz/baz.sln.
# 3. The GUID needs to be the same each time this builder is invoked, so
# that we don't need to rebuild the solution when the project changes.
# 4. We should be able to handle pre-built project files by reading the
# GUID from the files.
self.guid = MakeGuid(self.name)
return self.guid
def set_msbuild_toolset(self, msbuild_toolset):
self.msbuild_toolset = msbuild_toolset
# ------------------------------------------------------------------------------
class MSVSSolution:
"""Visual Studio solution."""
def __init__(
self, path, version, entries=None, variants=None, websiteProperties=True
):
"""Initializes the solution.
Args:
path: Path to solution file.
version: Format version to emit.
entries: List of entries in solution. May contain Folder or Project
objects. May be None, if the folder is empty.
variants: List of build variant strings. If none, a default list will
be used.
websiteProperties: Flag to decide if the website properties section
is generated.
"""
self.path = path
self.websiteProperties = websiteProperties
self.version = version
# Copy passed lists (or set to empty lists)
self.entries = list(entries or [])
if variants:
# Copy passed list
self.variants = variants[:]
else:
# Use default
self.variants = ["Debug|Win32", "Release|Win32"]
# TODO(rspangler): Need to be able to handle a mapping of solution config
# to project config. Should we be able to handle variants being a dict,
# or add a separate variant_map variable? If it's a dict, we can't
# guarantee the order of variants since dict keys aren't ordered.
# TODO(rspangler): Automatically write to disk for now; should delay until
# node-evaluation time.
self.Write()
def Write(self, writer=gyp.common.WriteOnDiff):
"""Writes the solution file to disk.
Raises:
IndexError: An entry appears multiple times.
"""
# Walk the entry tree and collect all the folders and projects.
all_entries = set()
entries_to_check = self.entries[:]
while entries_to_check:
e = entries_to_check.pop(0)
# If this entry has been visited, nothing to do.
if e in all_entries:
continue
all_entries.add(e)
# If this is a folder, check its entries too.
if isinstance(e, MSVSFolder):
entries_to_check += e.entries
all_entries = sorted(all_entries, key=attrgetter("path"))
# Open file and print header
f = writer(self.path)
f.write(
"Microsoft Visual Studio Solution File, "
"Format Version %s\r\n" % self.version.SolutionVersion()
)
f.write("# %s\r\n" % self.version.Description())
# Project entries
sln_root = os.path.split(self.path)[0]
for e in all_entries:
relative_path = gyp.common.RelativePath(e.path, sln_root)
# msbuild does not accept an empty folder_name.
# use '.' in case relative_path is empty.
folder_name = relative_path.replace("/", "\\") or "."
f.write(
'Project("%s") = "%s", "%s", "%s"\r\n'
% (
e.entry_type_guid, # Entry type GUID
e.name, # Folder name
folder_name, # Folder name (again)
e.get_guid(), # Entry GUID
)
)
# TODO(rspangler): Need a way to configure this stuff
if self.websiteProperties:
f.write(
"\tProjectSection(WebsiteProperties) = preProject\r\n"
'\t\tDebug.AspNetCompiler.Debug = "True"\r\n'
'\t\tRelease.AspNetCompiler.Debug = "False"\r\n'
"\tEndProjectSection\r\n"
)
if isinstance(e, MSVSFolder):
if e.items:
f.write("\tProjectSection(SolutionItems) = preProject\r\n")
for i in e.items:
f.write(f"\t\t{i} = {i}\r\n")
f.write("\tEndProjectSection\r\n")
if isinstance(e, MSVSProject):
if e.dependencies:
f.write("\tProjectSection(ProjectDependencies) = postProject\r\n")
for d in e.dependencies:
f.write(f"\t\t{d.get_guid()} = {d.get_guid()}\r\n")
f.write("\tEndProjectSection\r\n")
f.write("EndProject\r\n")
# Global section
f.write("Global\r\n")
# Configurations (variants)
f.write("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n")
for v in self.variants:
f.write(f"\t\t{v} = {v}\r\n")
f.write("\tEndGlobalSection\r\n")
# Sort config guids for easier diffing of solution changes.
config_guids = []
config_guids_overrides = {}
for e in all_entries:
if isinstance(e, MSVSProject):
config_guids.append(e.get_guid())
config_guids_overrides[e.get_guid()] = e.config_platform_overrides
config_guids.sort()
f.write("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n")
for g in config_guids:
for v in self.variants:
nv = config_guids_overrides[g].get(v, v)
# Pick which project configuration to build for this solution
# configuration.
f.write(
"\t\t%s.%s.ActiveCfg = %s\r\n"
% (
g, # Project GUID
v, # Solution build configuration
nv, # Project build config for that solution config
)
)
# Enable project in this solution configuration.
f.write(
"\t\t%s.%s.Build.0 = %s\r\n"
% (
g, # Project GUID
v, # Solution build configuration
nv, # Project build config for that solution config
)
)
f.write("\tEndGlobalSection\r\n")
# TODO(rspangler): Should be able to configure this stuff too (though I've
# never seen this be any different)
f.write("\tGlobalSection(SolutionProperties) = preSolution\r\n")
f.write("\t\tHideSolutionNode = FALSE\r\n")
f.write("\tEndGlobalSection\r\n")
# Folder mappings
# Omit this section if there are no folders
if any([e.entries for e in all_entries if isinstance(e, MSVSFolder)]):
f.write("\tGlobalSection(NestedProjects) = preSolution\r\n")
for e in all_entries:
if not isinstance(e, MSVSFolder):
continue # Does not apply to projects, only folders
for subentry in e.entries:
f.write(f"\t\t{subentry.get_guid()} = {e.get_guid()}\r\n")
f.write("\tEndGlobalSection\r\n")
f.write("EndGlobal\r\n")
f.close()
node-gyp-9.3.0/gyp/pylib/gyp/MSVSProject.py 0000664 0000000 0000000 00000015127 14321173220 0020454 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Visual Studio project reader/writer."""
import gyp.easy_xml as easy_xml
# ------------------------------------------------------------------------------
class Tool:
"""Visual Studio tool."""
def __init__(self, name, attrs=None):
"""Initializes the tool.
Args:
name: Tool name.
attrs: Dict of tool attributes; may be None.
"""
self._attrs = attrs or {}
self._attrs["Name"] = name
def _GetSpecification(self):
"""Creates an element for the tool.
Returns:
A new xml.dom.Element for the tool.
"""
return ["Tool", self._attrs]
class Filter:
"""Visual Studio filter - that is, a virtual folder."""
def __init__(self, name, contents=None):
"""Initializes the folder.
Args:
name: Filter (folder) name.
contents: List of filenames and/or Filter objects contained.
"""
self.name = name
self.contents = list(contents or [])
# ------------------------------------------------------------------------------
class Writer:
"""Visual Studio XML project writer."""
def __init__(self, project_path, version, name, guid=None, platforms=None):
"""Initializes the project.
Args:
project_path: Path to the project file.
version: Format version to emit.
name: Name of the project.
guid: GUID to use for project, if not None.
platforms: Array of string, the supported platforms. If null, ['Win32']
"""
self.project_path = project_path
self.version = version
self.name = name
self.guid = guid
# Default to Win32 for platforms.
if not platforms:
platforms = ["Win32"]
# Initialize the specifications of the various sections.
self.platform_section = ["Platforms"]
for platform in platforms:
self.platform_section.append(["Platform", {"Name": platform}])
self.tool_files_section = ["ToolFiles"]
self.configurations_section = ["Configurations"]
self.files_section = ["Files"]
# Keep a dict keyed on filename to speed up access.
self.files_dict = dict()
def AddToolFile(self, path):
"""Adds a tool file to the project.
Args:
path: Relative path from project to tool file.
"""
self.tool_files_section.append(["ToolFile", {"RelativePath": path}])
def _GetSpecForConfiguration(self, config_type, config_name, attrs, tools):
"""Returns the specification for a configuration.
Args:
config_type: Type of configuration node.
config_name: Configuration name.
attrs: Dict of configuration attributes; may be None.
tools: List of tools (strings or Tool objects); may be None.
Returns:
"""
# Handle defaults
if not attrs:
attrs = {}
if not tools:
tools = []
# Add configuration node and its attributes
node_attrs = attrs.copy()
node_attrs["Name"] = config_name
specification = [config_type, node_attrs]
# Add tool nodes and their attributes
if tools:
for t in tools:
if isinstance(t, Tool):
specification.append(t._GetSpecification())
else:
specification.append(Tool(t)._GetSpecification())
return specification
def AddConfig(self, name, attrs=None, tools=None):
"""Adds a configuration to the project.
Args:
name: Configuration name.
attrs: Dict of configuration attributes; may be None.
tools: List of tools (strings or Tool objects); may be None.
"""
spec = self._GetSpecForConfiguration("Configuration", name, attrs, tools)
self.configurations_section.append(spec)
def _AddFilesToNode(self, parent, files):
"""Adds files and/or filters to the parent node.
Args:
parent: Destination node
files: A list of Filter objects and/or relative paths to files.
Will call itself recursively, if the files list contains Filter objects.
"""
for f in files:
if isinstance(f, Filter):
node = ["Filter", {"Name": f.name}]
self._AddFilesToNode(node, f.contents)
else:
node = ["File", {"RelativePath": f}]
self.files_dict[f] = node
parent.append(node)
def AddFiles(self, files):
"""Adds files to the project.
Args:
files: A list of Filter objects and/or relative paths to files.
This makes a copy of the file/filter tree at the time of this call. If you
later add files to a Filter object which was passed into a previous call
to AddFiles(), it will not be reflected in this project.
"""
self._AddFilesToNode(self.files_section, files)
# TODO(rspangler) This also doesn't handle adding files to an existing
# filter. That is, it doesn't merge the trees.
def AddFileConfig(self, path, config, attrs=None, tools=None):
"""Adds a configuration to a file.
Args:
path: Relative path to the file.
config: Name of configuration to add.
attrs: Dict of configuration attributes; may be None.
tools: List of tools (strings or Tool objects); may be None.
Raises:
ValueError: Relative path does not match any file added via AddFiles().
"""
# Find the file node with the right relative path
parent = self.files_dict.get(path)
if not parent:
raise ValueError('AddFileConfig: file "%s" not in project.' % path)
# Add the config to the file node
spec = self._GetSpecForConfiguration("FileConfiguration", config, attrs, tools)
parent.append(spec)
def WriteIfChanged(self):
"""Writes the project file."""
# First create XML content definition
content = [
"VisualStudioProject",
{
"ProjectType": "Visual C++",
"Version": self.version.ProjectVersion(),
"Name": self.name,
"ProjectGUID": self.guid,
"RootNamespace": self.name,
"Keyword": "Win32Proj",
},
self.platform_section,
self.tool_files_section,
self.configurations_section,
["References"], # empty section
self.files_section,
["Globals"], # empty section
]
easy_xml.WriteXmlIfChanged(content, self.project_path, encoding="Windows-1252")
node-gyp-9.3.0/gyp/pylib/gyp/MSVSSettings.py 0000664 0000000 0000000 00000130446 14321173220 0020650 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
r"""Code to validate and convert settings of the Microsoft build tools.
This file contains code to validate and convert settings of the Microsoft
build tools. The function ConvertToMSBuildSettings(), ValidateMSVSSettings(),
and ValidateMSBuildSettings() are the entry points.
This file was created by comparing the projects created by Visual Studio 2008
and Visual Studio 2010 for all available settings through the user interface.
The MSBuild schemas were also considered. They are typically found in the
MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild
"""
import re
import sys
# Dictionaries of settings validators. The key is the tool name, the value is
# a dictionary mapping setting names to validation functions.
_msvs_validators = {}
_msbuild_validators = {}
# A dictionary of settings converters. The key is the tool name, the value is
# a dictionary mapping setting names to conversion functions.
_msvs_to_msbuild_converters = {}
# Tool name mapping from MSVS to MSBuild.
_msbuild_name_of_tool = {}
class _Tool:
"""Represents a tool used by MSVS or MSBuild.
Attributes:
msvs_name: The name of the tool in MSVS.
msbuild_name: The name of the tool in MSBuild.
"""
def __init__(self, msvs_name, msbuild_name):
self.msvs_name = msvs_name
self.msbuild_name = msbuild_name
def _AddTool(tool):
"""Adds a tool to the four dictionaries used to process settings.
This only defines the tool. Each setting also needs to be added.
Args:
tool: The _Tool object to be added.
"""
_msvs_validators[tool.msvs_name] = {}
_msbuild_validators[tool.msbuild_name] = {}
_msvs_to_msbuild_converters[tool.msvs_name] = {}
_msbuild_name_of_tool[tool.msvs_name] = tool.msbuild_name
def _GetMSBuildToolSettings(msbuild_settings, tool):
"""Returns an MSBuild tool dictionary. Creates it if needed."""
return msbuild_settings.setdefault(tool.msbuild_name, {})
class _Type:
"""Type of settings (Base class)."""
def ValidateMSVS(self, value):
"""Verifies that the value is legal for MSVS.
Args:
value: the value to check for this type.
Raises:
ValueError if value is not valid for MSVS.
"""
def ValidateMSBuild(self, value):
"""Verifies that the value is legal for MSBuild.
Args:
value: the value to check for this type.
Raises:
ValueError if value is not valid for MSBuild.
"""
def ConvertToMSBuild(self, value):
"""Returns the MSBuild equivalent of the MSVS value given.
Args:
value: the MSVS value to convert.
Returns:
the MSBuild equivalent.
Raises:
ValueError if value is not valid.
"""
return value
class _String(_Type):
"""A setting that's just a string."""
def ValidateMSVS(self, value):
if not isinstance(value, str):
raise ValueError("expected string; got %r" % value)
def ValidateMSBuild(self, value):
if not isinstance(value, str):
raise ValueError("expected string; got %r" % value)
def ConvertToMSBuild(self, value):
# Convert the macros
return ConvertVCMacrosToMSBuild(value)
class _StringList(_Type):
"""A settings that's a list of strings."""
def ValidateMSVS(self, value):
if not isinstance(value, (list, str)):
raise ValueError("expected string list; got %r" % value)
def ValidateMSBuild(self, value):
if not isinstance(value, (list, str)):
raise ValueError("expected string list; got %r" % value)
def ConvertToMSBuild(self, value):
# Convert the macros
if isinstance(value, list):
return [ConvertVCMacrosToMSBuild(i) for i in value]
else:
return ConvertVCMacrosToMSBuild(value)
class _Boolean(_Type):
"""Boolean settings, can have the values 'false' or 'true'."""
def _Validate(self, value):
if value != "true" and value != "false":
raise ValueError("expected bool; got %r" % value)
def ValidateMSVS(self, value):
self._Validate(value)
def ValidateMSBuild(self, value):
self._Validate(value)
def ConvertToMSBuild(self, value):
self._Validate(value)
return value
class _Integer(_Type):
"""Integer settings."""
def __init__(self, msbuild_base=10):
_Type.__init__(self)
self._msbuild_base = msbuild_base
def ValidateMSVS(self, value):
# Try to convert, this will raise ValueError if invalid.
self.ConvertToMSBuild(value)
def ValidateMSBuild(self, value):
# Try to convert, this will raise ValueError if invalid.
int(value, self._msbuild_base)
def ConvertToMSBuild(self, value):
msbuild_format = (self._msbuild_base == 10) and "%d" or "0x%04x"
return msbuild_format % int(value)
class _Enumeration(_Type):
"""Type of settings that is an enumeration.
In MSVS, the values are indexes like '0', '1', and '2'.
MSBuild uses text labels that are more representative, like 'Win32'.
Constructor args:
label_list: an array of MSBuild labels that correspond to the MSVS index.
In the rare cases where MSVS has skipped an index value, None is
used in the array to indicate the unused spot.
new: an array of labels that are new to MSBuild.
"""
def __init__(self, label_list, new=None):
_Type.__init__(self)
self._label_list = label_list
self._msbuild_values = {value for value in label_list if value is not None}
if new is not None:
self._msbuild_values.update(new)
def ValidateMSVS(self, value):
# Try to convert. It will raise an exception if not valid.
self.ConvertToMSBuild(value)
def ValidateMSBuild(self, value):
if value not in self._msbuild_values:
raise ValueError("unrecognized enumerated value %s" % value)
def ConvertToMSBuild(self, value):
index = int(value)
if index < 0 or index >= len(self._label_list):
raise ValueError(
"index value (%d) not in expected range [0, %d)"
% (index, len(self._label_list))
)
label = self._label_list[index]
if label is None:
raise ValueError("converted value for %s not specified." % value)
return label
# Instantiate the various generic types.
_boolean = _Boolean()
_integer = _Integer()
# For now, we don't do any special validation on these types:
_string = _String()
_file_name = _String()
_folder_name = _String()
_file_list = _StringList()
_folder_list = _StringList()
_string_list = _StringList()
# Some boolean settings went from numerical values to boolean. The
# mapping is 0: default, 1: false, 2: true.
_newly_boolean = _Enumeration(["", "false", "true"])
def _Same(tool, name, setting_type):
"""Defines a setting that has the same name in MSVS and MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
_Renamed(tool, name, name, setting_type)
def _Renamed(tool, msvs_name, msbuild_name, setting_type):
"""Defines a setting for which the name has changed.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_name: the name of the MSVS setting.
msbuild_name: the name of the MSBuild setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
msbuild_tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
msbuild_tool_settings[msbuild_name] = setting_type.ConvertToMSBuild(value)
_msvs_validators[tool.msvs_name][msvs_name] = setting_type.ValidateMSVS
_msbuild_validators[tool.msbuild_name][msbuild_name] = setting_type.ValidateMSBuild
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
def _Moved(tool, settings_name, msbuild_tool_name, setting_type):
_MovedAndRenamed(
tool, settings_name, msbuild_tool_name, settings_name, setting_type
)
def _MovedAndRenamed(
tool, msvs_settings_name, msbuild_tool_name, msbuild_settings_name, setting_type
):
"""Defines a setting that may have moved to a new section.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_settings_name: the MSVS name of the setting.
msbuild_tool_name: the name of the MSBuild tool to place the setting under.
msbuild_settings_name: the MSBuild name of the setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
tool_settings = msbuild_settings.setdefault(msbuild_tool_name, {})
tool_settings[msbuild_settings_name] = setting_type.ConvertToMSBuild(value)
_msvs_validators[tool.msvs_name][msvs_settings_name] = setting_type.ValidateMSVS
validator = setting_type.ValidateMSBuild
_msbuild_validators[msbuild_tool_name][msbuild_settings_name] = validator
_msvs_to_msbuild_converters[tool.msvs_name][msvs_settings_name] = _Translate
def _MSVSOnly(tool, name, setting_type):
"""Defines a setting that is only found in MSVS.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
def _Translate(unused_value, unused_msbuild_settings):
# Since this is for MSVS only settings, no translation will happen.
pass
_msvs_validators[tool.msvs_name][name] = setting_type.ValidateMSVS
_msvs_to_msbuild_converters[tool.msvs_name][name] = _Translate
def _MSBuildOnly(tool, name, setting_type):
"""Defines a setting that is only found in MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
# Let msbuild-only properties get translated as-is from msvs_settings.
tool_settings = msbuild_settings.setdefault(tool.msbuild_name, {})
tool_settings[name] = value
_msbuild_validators[tool.msbuild_name][name] = setting_type.ValidateMSBuild
_msvs_to_msbuild_converters[tool.msvs_name][name] = _Translate
def _ConvertedToAdditionalOption(tool, msvs_name, flag):
"""Defines a setting that's handled via a command line option in MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_name: the name of the MSVS setting that if 'true' becomes a flag
flag: the flag to insert at the end of the AdditionalOptions
"""
def _Translate(value, msbuild_settings):
if value == "true":
tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
if "AdditionalOptions" in tool_settings:
new_flags = "{} {}".format(tool_settings["AdditionalOptions"], flag)
else:
new_flags = flag
tool_settings["AdditionalOptions"] = new_flags
_msvs_validators[tool.msvs_name][msvs_name] = _boolean.ValidateMSVS
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
def _CustomGeneratePreprocessedFile(tool, msvs_name):
def _Translate(value, msbuild_settings):
tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
if value == "0":
tool_settings["PreprocessToFile"] = "false"
tool_settings["PreprocessSuppressLineNumbers"] = "false"
elif value == "1": # /P
tool_settings["PreprocessToFile"] = "true"
tool_settings["PreprocessSuppressLineNumbers"] = "false"
elif value == "2": # /EP /P
tool_settings["PreprocessToFile"] = "true"
tool_settings["PreprocessSuppressLineNumbers"] = "true"
else:
raise ValueError("value must be one of [0, 1, 2]; got %s" % value)
# Create a bogus validator that looks for '0', '1', or '2'
msvs_validator = _Enumeration(["a", "b", "c"]).ValidateMSVS
_msvs_validators[tool.msvs_name][msvs_name] = msvs_validator
msbuild_validator = _boolean.ValidateMSBuild
msbuild_tool_validators = _msbuild_validators[tool.msbuild_name]
msbuild_tool_validators["PreprocessToFile"] = msbuild_validator
msbuild_tool_validators["PreprocessSuppressLineNumbers"] = msbuild_validator
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
fix_vc_macro_slashes_regex_list = ("IntDir", "OutDir")
fix_vc_macro_slashes_regex = re.compile(
r"(\$\((?:%s)\))(?:[\\/]+)" % "|".join(fix_vc_macro_slashes_regex_list)
)
# Regular expression to detect keys that were generated by exclusion lists
_EXCLUDED_SUFFIX_RE = re.compile("^(.*)_excluded$")
def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):
"""Verify that 'setting' is valid if it is generated from an exclusion list.
If the setting appears to be generated from an exclusion list, the root name
is checked.
Args:
setting: A string that is the setting name to validate
settings: A dictionary where the keys are valid settings
error_msg: The message to emit in the event of error
stderr: The stream receiving the error messages.
"""
# This may be unrecognized because it's an exclusion list. If the
# setting name has the _excluded suffix, then check the root name.
unrecognized = True
m = re.match(_EXCLUDED_SUFFIX_RE, setting)
if m:
root_setting = m.group(1)
unrecognized = root_setting not in settings
if unrecognized:
# We don't know this setting. Give a warning.
print(error_msg, file=stderr)
def FixVCMacroSlashes(s):
"""Replace macros which have excessive following slashes.
These macros are known to have a built-in trailing slash. Furthermore, many
scripts hiccup on processing paths with extra slashes in the middle.
This list is probably not exhaustive. Add as needed.
"""
if "$" in s:
s = fix_vc_macro_slashes_regex.sub(r"\1", s)
return s
def ConvertVCMacrosToMSBuild(s):
"""Convert the MSVS macros found in the string to the MSBuild equivalent.
This list is probably not exhaustive. Add as needed.
"""
if "$" in s:
replace_map = {
"$(ConfigurationName)": "$(Configuration)",
"$(InputDir)": "%(RelativeDir)",
"$(InputExt)": "%(Extension)",
"$(InputFileName)": "%(Filename)%(Extension)",
"$(InputName)": "%(Filename)",
"$(InputPath)": "%(Identity)",
"$(ParentName)": "$(ProjectFileName)",
"$(PlatformName)": "$(Platform)",
"$(SafeInputName)": "%(Filename)",
}
for old, new in replace_map.items():
s = s.replace(old, new)
s = FixVCMacroSlashes(s)
return s
def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
"""Converts MSVS settings (VS2008 and earlier) to MSBuild settings (VS2010+).
Args:
msvs_settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
Returns:
A dictionary of MSBuild settings. The key is either the MSBuild tool name
or the empty string (for the global settings). The values are themselves
dictionaries of settings and their values.
"""
msbuild_settings = {}
for msvs_tool_name, msvs_tool_settings in msvs_settings.items():
if msvs_tool_name in _msvs_to_msbuild_converters:
msvs_tool = _msvs_to_msbuild_converters[msvs_tool_name]
for msvs_setting, msvs_value in msvs_tool_settings.items():
if msvs_setting in msvs_tool:
# Invoke the translation function.
try:
msvs_tool[msvs_setting](msvs_value, msbuild_settings)
except ValueError as e:
print(
"Warning: while converting %s/%s to MSBuild, "
"%s" % (msvs_tool_name, msvs_setting, e),
file=stderr,
)
else:
_ValidateExclusionSetting(
msvs_setting,
msvs_tool,
(
"Warning: unrecognized setting %s/%s "
"while converting to MSBuild."
% (msvs_tool_name, msvs_setting)
),
stderr,
)
else:
print(
"Warning: unrecognized tool %s while converting to "
"MSBuild." % msvs_tool_name,
file=stderr,
)
return msbuild_settings
def ValidateMSVSSettings(settings, stderr=sys.stderr):
"""Validates that the names of the settings are valid for MSVS.
Args:
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
_ValidateSettings(_msvs_validators, settings, stderr)
def ValidateMSBuildSettings(settings, stderr=sys.stderr):
"""Validates that the names of the settings are valid for MSBuild.
Args:
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
_ValidateSettings(_msbuild_validators, settings, stderr)
def _ValidateSettings(validators, settings, stderr):
"""Validates that the settings are valid for MSBuild or MSVS.
We currently only validate the names of the settings, not their values.
Args:
validators: A dictionary of tools and their validators.
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
for tool_name in settings:
if tool_name in validators:
tool_validators = validators[tool_name]
for setting, value in settings[tool_name].items():
if setting in tool_validators:
try:
tool_validators[setting](value)
except ValueError as e:
print(
f"Warning: for {tool_name}/{setting}, {e}",
file=stderr,
)
else:
_ValidateExclusionSetting(
setting,
tool_validators,
(f"Warning: unrecognized setting {tool_name}/{setting}"),
stderr,
)
else:
print("Warning: unrecognized tool %s" % (tool_name), file=stderr)
# MSVS and MBuild names of the tools.
_compile = _Tool("VCCLCompilerTool", "ClCompile")
_link = _Tool("VCLinkerTool", "Link")
_midl = _Tool("VCMIDLTool", "Midl")
_rc = _Tool("VCResourceCompilerTool", "ResourceCompile")
_lib = _Tool("VCLibrarianTool", "Lib")
_manifest = _Tool("VCManifestTool", "Manifest")
_masm = _Tool("MASM", "MASM")
_armasm = _Tool("ARMASM", "ARMASM")
_AddTool(_compile)
_AddTool(_link)
_AddTool(_midl)
_AddTool(_rc)
_AddTool(_lib)
_AddTool(_manifest)
_AddTool(_masm)
_AddTool(_armasm)
# Add sections only found in the MSBuild settings.
_msbuild_validators[""] = {}
_msbuild_validators["ProjectReference"] = {}
_msbuild_validators["ManifestResourceCompile"] = {}
# Descriptions of the compiler options, i.e. VCCLCompilerTool in MSVS and
# ClCompile in MSBuild.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\cl.xml" for
# the schema of the MSBuild ClCompile settings.
# Options that have the same name in MSVS and MSBuild
_Same(_compile, "AdditionalIncludeDirectories", _folder_list) # /I
_Same(_compile, "AdditionalOptions", _string_list)
_Same(_compile, "AdditionalUsingDirectories", _folder_list) # /AI
_Same(_compile, "AssemblerListingLocation", _file_name) # /Fa
_Same(_compile, "BrowseInformationFile", _file_name)
_Same(_compile, "BufferSecurityCheck", _boolean) # /GS
_Same(_compile, "DisableLanguageExtensions", _boolean) # /Za
_Same(_compile, "DisableSpecificWarnings", _string_list) # /wd
_Same(_compile, "EnableFiberSafeOptimizations", _boolean) # /GT
_Same(_compile, "EnablePREfast", _boolean) # /analyze Visible='false'
_Same(_compile, "ExpandAttributedSource", _boolean) # /Fx
_Same(_compile, "FloatingPointExceptions", _boolean) # /fp:except
_Same(_compile, "ForceConformanceInForLoopScope", _boolean) # /Zc:forScope
_Same(_compile, "ForcedIncludeFiles", _file_list) # /FI
_Same(_compile, "ForcedUsingFiles", _file_list) # /FU
_Same(_compile, "GenerateXMLDocumentationFiles", _boolean) # /doc
_Same(_compile, "IgnoreStandardIncludePath", _boolean) # /X
_Same(_compile, "MinimalRebuild", _boolean) # /Gm
_Same(_compile, "OmitDefaultLibName", _boolean) # /Zl
_Same(_compile, "OmitFramePointers", _boolean) # /Oy
_Same(_compile, "PreprocessorDefinitions", _string_list) # /D
_Same(_compile, "ProgramDataBaseFileName", _file_name) # /Fd
_Same(_compile, "RuntimeTypeInfo", _boolean) # /GR
_Same(_compile, "ShowIncludes", _boolean) # /showIncludes
_Same(_compile, "SmallerTypeCheck", _boolean) # /RTCc
_Same(_compile, "StringPooling", _boolean) # /GF
_Same(_compile, "SuppressStartupBanner", _boolean) # /nologo
_Same(_compile, "TreatWChar_tAsBuiltInType", _boolean) # /Zc:wchar_t
_Same(_compile, "UndefineAllPreprocessorDefinitions", _boolean) # /u
_Same(_compile, "UndefinePreprocessorDefinitions", _string_list) # /U
_Same(_compile, "UseFullPaths", _boolean) # /FC
_Same(_compile, "WholeProgramOptimization", _boolean) # /GL
_Same(_compile, "XMLDocumentationFileName", _file_name)
_Same(_compile, "CompileAsWinRT", _boolean) # /ZW
_Same(
_compile,
"AssemblerOutput",
_Enumeration(
[
"NoListing",
"AssemblyCode", # /FA
"All", # /FAcs
"AssemblyAndMachineCode", # /FAc
"AssemblyAndSourceCode",
]
),
) # /FAs
_Same(
_compile,
"BasicRuntimeChecks",
_Enumeration(
[
"Default",
"StackFrameRuntimeCheck", # /RTCs
"UninitializedLocalUsageCheck", # /RTCu
"EnableFastChecks",
]
),
) # /RTC1
_Same(
_compile, "BrowseInformation", _Enumeration(["false", "true", "true"]) # /FR
) # /Fr
_Same(
_compile,
"CallingConvention",
_Enumeration(["Cdecl", "FastCall", "StdCall", "VectorCall"]), # /Gd # /Gr # /Gz
) # /Gv
_Same(
_compile,
"CompileAs",
_Enumeration(["Default", "CompileAsC", "CompileAsCpp"]), # /TC
) # /TP
_Same(
_compile,
"DebugInformationFormat",
_Enumeration(
[
"", # Disabled
"OldStyle", # /Z7
None,
"ProgramDatabase", # /Zi
"EditAndContinue",
]
),
) # /ZI
_Same(
_compile,
"EnableEnhancedInstructionSet",
_Enumeration(
[
"NotSet",
"StreamingSIMDExtensions", # /arch:SSE
"StreamingSIMDExtensions2", # /arch:SSE2
"AdvancedVectorExtensions", # /arch:AVX (vs2012+)
"NoExtensions", # /arch:IA32 (vs2012+)
# This one only exists in the new msbuild format.
"AdvancedVectorExtensions2", # /arch:AVX2 (vs2013r2+)
]
),
)
_Same(
_compile,
"ErrorReporting",
_Enumeration(
[
"None", # /errorReport:none
"Prompt", # /errorReport:prompt
"Queue",
], # /errorReport:queue
new=["Send"],
),
) # /errorReport:send"
_Same(
_compile,
"ExceptionHandling",
_Enumeration(["false", "Sync", "Async"], new=["SyncCThrow"]), # /EHsc # /EHa
) # /EHs
_Same(
_compile, "FavorSizeOrSpeed", _Enumeration(["Neither", "Speed", "Size"]) # /Ot
) # /Os
_Same(
_compile,
"FloatingPointModel",
_Enumeration(["Precise", "Strict", "Fast"]), # /fp:precise # /fp:strict
) # /fp:fast
_Same(
_compile,
"InlineFunctionExpansion",
_Enumeration(
["Default", "OnlyExplicitInline", "AnySuitable"], # /Ob1 # /Ob2
new=["Disabled"],
),
) # /Ob0
_Same(
_compile,
"Optimization",
_Enumeration(["Disabled", "MinSpace", "MaxSpeed", "Full"]), # /Od # /O1 # /O2
) # /Ox
_Same(
_compile,
"RuntimeLibrary",
_Enumeration(
[
"MultiThreaded", # /MT
"MultiThreadedDebug", # /MTd
"MultiThreadedDLL", # /MD
"MultiThreadedDebugDLL",
]
),
) # /MDd
_Same(
_compile,
"StructMemberAlignment",
_Enumeration(
[
"Default",
"1Byte", # /Zp1
"2Bytes", # /Zp2
"4Bytes", # /Zp4
"8Bytes", # /Zp8
"16Bytes",
]
),
) # /Zp16
_Same(
_compile,
"WarningLevel",
_Enumeration(
[
"TurnOffAllWarnings", # /W0
"Level1", # /W1
"Level2", # /W2
"Level3", # /W3
"Level4",
], # /W4
new=["EnableAllWarnings"],
),
) # /Wall
# Options found in MSVS that have been renamed in MSBuild.
_Renamed(
_compile, "EnableFunctionLevelLinking", "FunctionLevelLinking", _boolean
) # /Gy
_Renamed(_compile, "EnableIntrinsicFunctions", "IntrinsicFunctions", _boolean) # /Oi
_Renamed(_compile, "KeepComments", "PreprocessKeepComments", _boolean) # /C
_Renamed(_compile, "ObjectFile", "ObjectFileName", _file_name) # /Fo
_Renamed(_compile, "OpenMP", "OpenMPSupport", _boolean) # /openmp
_Renamed(
_compile, "PrecompiledHeaderThrough", "PrecompiledHeaderFile", _file_name
) # Used with /Yc and /Yu
_Renamed(
_compile, "PrecompiledHeaderFile", "PrecompiledHeaderOutputFile", _file_name
) # /Fp
_Renamed(
_compile,
"UsePrecompiledHeader",
"PrecompiledHeader",
_Enumeration(
["NotUsing", "Create", "Use"] # VS recognized '' for this value too. # /Yc
),
) # /Yu
_Renamed(_compile, "WarnAsError", "TreatWarningAsError", _boolean) # /WX
_ConvertedToAdditionalOption(_compile, "DefaultCharIsUnsigned", "/J")
# MSVS options not found in MSBuild.
_MSVSOnly(_compile, "Detect64BitPortabilityProblems", _boolean)
_MSVSOnly(_compile, "UseUnicodeResponseFiles", _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_compile, "BuildingInIDE", _boolean)
_MSBuildOnly(
_compile, "CompileAsManaged", _Enumeration([], new=["false", "true"])
) # /clr
_MSBuildOnly(_compile, "CreateHotpatchableImage", _boolean) # /hotpatch
_MSBuildOnly(_compile, "MultiProcessorCompilation", _boolean) # /MP
_MSBuildOnly(_compile, "PreprocessOutputPath", _string) # /Fi
_MSBuildOnly(_compile, "ProcessorNumber", _integer) # the number of processors
_MSBuildOnly(_compile, "TrackerLogDirectory", _folder_name)
_MSBuildOnly(_compile, "TreatSpecificWarningsAsErrors", _string_list) # /we
_MSBuildOnly(_compile, "UseUnicodeForAssemblerListing", _boolean) # /FAu
# Defines a setting that needs very customized processing
_CustomGeneratePreprocessedFile(_compile, "GeneratePreprocessedFile")
# Directives for converting MSVS VCLinkerTool to MSBuild Link.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\link.xml" for
# the schema of the MSBuild Link settings.
# Options that have the same name in MSVS and MSBuild
_Same(_link, "AdditionalDependencies", _file_list)
_Same(_link, "AdditionalLibraryDirectories", _folder_list) # /LIBPATH
# /MANIFESTDEPENDENCY:
_Same(_link, "AdditionalManifestDependencies", _file_list)
_Same(_link, "AdditionalOptions", _string_list)
_Same(_link, "AddModuleNamesToAssembly", _file_list) # /ASSEMBLYMODULE
_Same(_link, "AllowIsolation", _boolean) # /ALLOWISOLATION
_Same(_link, "AssemblyLinkResource", _file_list) # /ASSEMBLYLINKRESOURCE
_Same(_link, "BaseAddress", _string) # /BASE
_Same(_link, "CLRUnmanagedCodeCheck", _boolean) # /CLRUNMANAGEDCODECHECK
_Same(_link, "DelayLoadDLLs", _file_list) # /DELAYLOAD
_Same(_link, "DelaySign", _boolean) # /DELAYSIGN
_Same(_link, "EmbedManagedResourceFile", _file_list) # /ASSEMBLYRESOURCE
_Same(_link, "EnableUAC", _boolean) # /MANIFESTUAC
_Same(_link, "EntryPointSymbol", _string) # /ENTRY
_Same(_link, "ForceSymbolReferences", _file_list) # /INCLUDE
_Same(_link, "FunctionOrder", _file_name) # /ORDER
_Same(_link, "GenerateDebugInformation", _boolean) # /DEBUG
_Same(_link, "GenerateMapFile", _boolean) # /MAP
_Same(_link, "HeapCommitSize", _string)
_Same(_link, "HeapReserveSize", _string) # /HEAP
_Same(_link, "IgnoreAllDefaultLibraries", _boolean) # /NODEFAULTLIB
_Same(_link, "IgnoreEmbeddedIDL", _boolean) # /IGNOREIDL
_Same(_link, "ImportLibrary", _file_name) # /IMPLIB
_Same(_link, "KeyContainer", _file_name) # /KEYCONTAINER
_Same(_link, "KeyFile", _file_name) # /KEYFILE
_Same(_link, "ManifestFile", _file_name) # /ManifestFile
_Same(_link, "MapExports", _boolean) # /MAPINFO:EXPORTS
_Same(_link, "MapFileName", _file_name)
_Same(_link, "MergedIDLBaseFileName", _file_name) # /IDLOUT
_Same(_link, "MergeSections", _string) # /MERGE
_Same(_link, "MidlCommandFile", _file_name) # /MIDL
_Same(_link, "ModuleDefinitionFile", _file_name) # /DEF
_Same(_link, "OutputFile", _file_name) # /OUT
_Same(_link, "PerUserRedirection", _boolean)
_Same(_link, "Profile", _boolean) # /PROFILE
_Same(_link, "ProfileGuidedDatabase", _file_name) # /PGD
_Same(_link, "ProgramDatabaseFile", _file_name) # /PDB
_Same(_link, "RegisterOutput", _boolean)
_Same(_link, "SetChecksum", _boolean) # /RELEASE
_Same(_link, "StackCommitSize", _string)
_Same(_link, "StackReserveSize", _string) # /STACK
_Same(_link, "StripPrivateSymbols", _file_name) # /PDBSTRIPPED
_Same(_link, "SupportUnloadOfDelayLoadedDLL", _boolean) # /DELAY:UNLOAD
_Same(_link, "SuppressStartupBanner", _boolean) # /NOLOGO
_Same(_link, "SwapRunFromCD", _boolean) # /SWAPRUN:CD
_Same(_link, "TurnOffAssemblyGeneration", _boolean) # /NOASSEMBLY
_Same(_link, "TypeLibraryFile", _file_name) # /TLBOUT
_Same(_link, "TypeLibraryResourceID", _integer) # /TLBID
_Same(_link, "UACUIAccess", _boolean) # /uiAccess='true'
_Same(_link, "Version", _string) # /VERSION
_Same(_link, "EnableCOMDATFolding", _newly_boolean) # /OPT:ICF
_Same(_link, "FixedBaseAddress", _newly_boolean) # /FIXED
_Same(_link, "LargeAddressAware", _newly_boolean) # /LARGEADDRESSAWARE
_Same(_link, "OptimizeReferences", _newly_boolean) # /OPT:REF
_Same(_link, "RandomizedBaseAddress", _newly_boolean) # /DYNAMICBASE
_Same(_link, "TerminalServerAware", _newly_boolean) # /TSAWARE
_subsystem_enumeration = _Enumeration(
[
"NotSet",
"Console", # /SUBSYSTEM:CONSOLE
"Windows", # /SUBSYSTEM:WINDOWS
"Native", # /SUBSYSTEM:NATIVE
"EFI Application", # /SUBSYSTEM:EFI_APPLICATION
"EFI Boot Service Driver", # /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER
"EFI ROM", # /SUBSYSTEM:EFI_ROM
"EFI Runtime", # /SUBSYSTEM:EFI_RUNTIME_DRIVER
"WindowsCE",
], # /SUBSYSTEM:WINDOWSCE
new=["POSIX"],
) # /SUBSYSTEM:POSIX
_target_machine_enumeration = _Enumeration(
[
"NotSet",
"MachineX86", # /MACHINE:X86
None,
"MachineARM", # /MACHINE:ARM
"MachineEBC", # /MACHINE:EBC
"MachineIA64", # /MACHINE:IA64
None,
"MachineMIPS", # /MACHINE:MIPS
"MachineMIPS16", # /MACHINE:MIPS16
"MachineMIPSFPU", # /MACHINE:MIPSFPU
"MachineMIPSFPU16", # /MACHINE:MIPSFPU16
None,
None,
None,
"MachineSH4", # /MACHINE:SH4
None,
"MachineTHUMB", # /MACHINE:THUMB
"MachineX64",
]
) # /MACHINE:X64
_Same(
_link, "AssemblyDebug", _Enumeration(["", "true", "false"]) # /ASSEMBLYDEBUG
) # /ASSEMBLYDEBUG:DISABLE
_Same(
_link,
"CLRImageType",
_Enumeration(
[
"Default",
"ForceIJWImage", # /CLRIMAGETYPE:IJW
"ForcePureILImage", # /Switch="CLRIMAGETYPE:PURE
"ForceSafeILImage",
]
),
) # /Switch="CLRIMAGETYPE:SAFE
_Same(
_link,
"CLRThreadAttribute",
_Enumeration(
[
"DefaultThreadingAttribute", # /CLRTHREADATTRIBUTE:NONE
"MTAThreadingAttribute", # /CLRTHREADATTRIBUTE:MTA
"STAThreadingAttribute",
]
),
) # /CLRTHREADATTRIBUTE:STA
_Same(
_link,
"DataExecutionPrevention",
_Enumeration(["", "false", "true"]), # /NXCOMPAT:NO
) # /NXCOMPAT
_Same(
_link,
"Driver",
_Enumeration(["NotSet", "Driver", "UpOnly", "WDM"]), # /Driver # /DRIVER:UPONLY
) # /DRIVER:WDM
_Same(
_link,
"LinkTimeCodeGeneration",
_Enumeration(
[
"Default",
"UseLinkTimeCodeGeneration", # /LTCG
"PGInstrument", # /LTCG:PGInstrument
"PGOptimization", # /LTCG:PGOptimize
"PGUpdate",
]
),
) # /LTCG:PGUpdate
_Same(
_link,
"ShowProgress",
_Enumeration(
["NotSet", "LinkVerbose", "LinkVerboseLib"], # /VERBOSE # /VERBOSE:Lib
new=[
"LinkVerboseICF", # /VERBOSE:ICF
"LinkVerboseREF", # /VERBOSE:REF
"LinkVerboseSAFESEH", # /VERBOSE:SAFESEH
"LinkVerboseCLR",
],
),
) # /VERBOSE:CLR
_Same(_link, "SubSystem", _subsystem_enumeration)
_Same(_link, "TargetMachine", _target_machine_enumeration)
_Same(
_link,
"UACExecutionLevel",
_Enumeration(
[
"AsInvoker", # /level='asInvoker'
"HighestAvailable", # /level='highestAvailable'
"RequireAdministrator",
]
),
) # /level='requireAdministrator'
_Same(_link, "MinimumRequiredVersion", _string)
_Same(_link, "TreatLinkerWarningAsErrors", _boolean) # /WX
# Options found in MSVS that have been renamed in MSBuild.
_Renamed(
_link,
"ErrorReporting",
"LinkErrorReporting",
_Enumeration(
[
"NoErrorReport", # /ERRORREPORT:NONE
"PromptImmediately", # /ERRORREPORT:PROMPT
"QueueForNextLogin",
], # /ERRORREPORT:QUEUE
new=["SendErrorReport"],
),
) # /ERRORREPORT:SEND
_Renamed(
_link, "IgnoreDefaultLibraryNames", "IgnoreSpecificDefaultLibraries", _file_list
) # /NODEFAULTLIB
_Renamed(_link, "ResourceOnlyDLL", "NoEntryPoint", _boolean) # /NOENTRY
_Renamed(_link, "SwapRunFromNet", "SwapRunFromNET", _boolean) # /SWAPRUN:NET
_Moved(_link, "GenerateManifest", "", _boolean)
_Moved(_link, "IgnoreImportLibrary", "", _boolean)
_Moved(_link, "LinkIncremental", "", _newly_boolean)
_Moved(_link, "LinkLibraryDependencies", "ProjectReference", _boolean)
_Moved(_link, "UseLibraryDependencyInputs", "ProjectReference", _boolean)
# MSVS options not found in MSBuild.
_MSVSOnly(_link, "OptimizeForWindows98", _newly_boolean)
_MSVSOnly(_link, "UseUnicodeResponseFiles", _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_link, "BuildingInIDE", _boolean)
_MSBuildOnly(_link, "ImageHasSafeExceptionHandlers", _boolean) # /SAFESEH
_MSBuildOnly(_link, "LinkDLL", _boolean) # /DLL Visible='false'
_MSBuildOnly(_link, "LinkStatus", _boolean) # /LTCG:STATUS
_MSBuildOnly(_link, "PreventDllBinding", _boolean) # /ALLOWBIND
_MSBuildOnly(_link, "SupportNobindOfDelayLoadedDLL", _boolean) # /DELAY:NOBIND
_MSBuildOnly(_link, "TrackerLogDirectory", _folder_name)
_MSBuildOnly(_link, "MSDOSStubFileName", _file_name) # /STUB Visible='false'
_MSBuildOnly(_link, "SectionAlignment", _integer) # /ALIGN
_MSBuildOnly(_link, "SpecifySectionAttributes", _string) # /SECTION
_MSBuildOnly(
_link,
"ForceFileOutput",
_Enumeration(
[],
new=[
"Enabled", # /FORCE
# /FORCE:MULTIPLE
"MultiplyDefinedSymbolOnly",
"UndefinedSymbolOnly",
],
),
) # /FORCE:UNRESOLVED
_MSBuildOnly(
_link,
"CreateHotPatchableImage",
_Enumeration(
[],
new=[
"Enabled", # /FUNCTIONPADMIN
"X86Image", # /FUNCTIONPADMIN:5
"X64Image", # /FUNCTIONPADMIN:6
"ItaniumImage",
],
),
) # /FUNCTIONPADMIN:16
_MSBuildOnly(
_link,
"CLRSupportLastError",
_Enumeration(
[],
new=[
"Enabled", # /CLRSupportLastError
"Disabled", # /CLRSupportLastError:NO
# /CLRSupportLastError:SYSTEMDLL
"SystemDlls",
],
),
)
# Directives for converting VCResourceCompilerTool to ResourceCompile.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\rc.xml" for
# the schema of the MSBuild ResourceCompile settings.
_Same(_rc, "AdditionalOptions", _string_list)
_Same(_rc, "AdditionalIncludeDirectories", _folder_list) # /I
_Same(_rc, "Culture", _Integer(msbuild_base=16))
_Same(_rc, "IgnoreStandardIncludePath", _boolean) # /X
_Same(_rc, "PreprocessorDefinitions", _string_list) # /D
_Same(_rc, "ResourceOutputFileName", _string) # /fo
_Same(_rc, "ShowProgress", _boolean) # /v
# There is no UI in VisualStudio 2008 to set the following properties.
# However they are found in CL and other tools. Include them here for
# completeness, as they are very likely to have the same usage pattern.
_Same(_rc, "SuppressStartupBanner", _boolean) # /nologo
_Same(_rc, "UndefinePreprocessorDefinitions", _string_list) # /u
# MSBuild options not found in MSVS.
_MSBuildOnly(_rc, "NullTerminateStrings", _boolean) # /n
_MSBuildOnly(_rc, "TrackerLogDirectory", _folder_name)
# Directives for converting VCMIDLTool to Midl.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\midl.xml" for
# the schema of the MSBuild Midl settings.
_Same(_midl, "AdditionalIncludeDirectories", _folder_list) # /I
_Same(_midl, "AdditionalOptions", _string_list)
_Same(_midl, "CPreprocessOptions", _string) # /cpp_opt
_Same(_midl, "ErrorCheckAllocations", _boolean) # /error allocation
_Same(_midl, "ErrorCheckBounds", _boolean) # /error bounds_check
_Same(_midl, "ErrorCheckEnumRange", _boolean) # /error enum
_Same(_midl, "ErrorCheckRefPointers", _boolean) # /error ref
_Same(_midl, "ErrorCheckStubData", _boolean) # /error stub_data
_Same(_midl, "GenerateStublessProxies", _boolean) # /Oicf
_Same(_midl, "GenerateTypeLibrary", _boolean)
_Same(_midl, "HeaderFileName", _file_name) # /h
_Same(_midl, "IgnoreStandardIncludePath", _boolean) # /no_def_idir
_Same(_midl, "InterfaceIdentifierFileName", _file_name) # /iid
_Same(_midl, "MkTypLibCompatible", _boolean) # /mktyplib203
_Same(_midl, "OutputDirectory", _string) # /out
_Same(_midl, "PreprocessorDefinitions", _string_list) # /D
_Same(_midl, "ProxyFileName", _file_name) # /proxy
_Same(_midl, "RedirectOutputAndErrors", _file_name) # /o
_Same(_midl, "SuppressStartupBanner", _boolean) # /nologo
_Same(_midl, "TypeLibraryName", _file_name) # /tlb
_Same(_midl, "UndefinePreprocessorDefinitions", _string_list) # /U
_Same(_midl, "WarnAsError", _boolean) # /WX
_Same(
_midl,
"DefaultCharType",
_Enumeration(["Unsigned", "Signed", "Ascii"]), # /char unsigned # /char signed
) # /char ascii7
_Same(
_midl,
"TargetEnvironment",
_Enumeration(
[
"NotSet",
"Win32", # /env win32
"Itanium", # /env ia64
"X64", # /env x64
"ARM64", # /env arm64
]
),
)
_Same(
_midl,
"EnableErrorChecks",
_Enumeration(["EnableCustom", "None", "All"]), # /error none
) # /error all
_Same(
_midl,
"StructMemberAlignment",
_Enumeration(["NotSet", "1", "2", "4", "8"]), # Zp1 # Zp2 # Zp4
) # Zp8
_Same(
_midl,
"WarningLevel",
_Enumeration(["0", "1", "2", "3", "4"]), # /W0 # /W1 # /W2 # /W3
) # /W4
_Renamed(_midl, "DLLDataFileName", "DllDataFileName", _file_name) # /dlldata
_Renamed(_midl, "ValidateParameters", "ValidateAllParameters", _boolean) # /robust
# MSBuild options not found in MSVS.
_MSBuildOnly(_midl, "ApplicationConfigurationMode", _boolean) # /app_config
_MSBuildOnly(_midl, "ClientStubFile", _file_name) # /cstub
_MSBuildOnly(
_midl, "GenerateClientFiles", _Enumeration([], new=["Stub", "None"]) # /client stub
) # /client none
_MSBuildOnly(
_midl, "GenerateServerFiles", _Enumeration([], new=["Stub", "None"]) # /client stub
) # /client none
_MSBuildOnly(_midl, "LocaleID", _integer) # /lcid DECIMAL
_MSBuildOnly(_midl, "ServerStubFile", _file_name) # /sstub
_MSBuildOnly(_midl, "SuppressCompilerWarnings", _boolean) # /no_warn
_MSBuildOnly(_midl, "TrackerLogDirectory", _folder_name)
_MSBuildOnly(
_midl, "TypeLibFormat", _Enumeration([], new=["NewFormat", "OldFormat"]) # /newtlb
) # /oldtlb
# Directives for converting VCLibrarianTool to Lib.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\lib.xml" for
# the schema of the MSBuild Lib settings.
_Same(_lib, "AdditionalDependencies", _file_list)
_Same(_lib, "AdditionalLibraryDirectories", _folder_list) # /LIBPATH
_Same(_lib, "AdditionalOptions", _string_list)
_Same(_lib, "ExportNamedFunctions", _string_list) # /EXPORT
_Same(_lib, "ForceSymbolReferences", _string) # /INCLUDE
_Same(_lib, "IgnoreAllDefaultLibraries", _boolean) # /NODEFAULTLIB
_Same(_lib, "IgnoreSpecificDefaultLibraries", _file_list) # /NODEFAULTLIB
_Same(_lib, "ModuleDefinitionFile", _file_name) # /DEF
_Same(_lib, "OutputFile", _file_name) # /OUT
_Same(_lib, "SuppressStartupBanner", _boolean) # /NOLOGO
_Same(_lib, "UseUnicodeResponseFiles", _boolean)
_Same(_lib, "LinkTimeCodeGeneration", _boolean) # /LTCG
_Same(_lib, "TargetMachine", _target_machine_enumeration)
# TODO(jeanluc) _link defines the same value that gets moved to
# ProjectReference. We may want to validate that they are consistent.
_Moved(_lib, "LinkLibraryDependencies", "ProjectReference", _boolean)
_MSBuildOnly(_lib, "DisplayLibrary", _string) # /LIST Visible='false'
_MSBuildOnly(
_lib,
"ErrorReporting",
_Enumeration(
[],
new=[
"PromptImmediately", # /ERRORREPORT:PROMPT
"QueueForNextLogin", # /ERRORREPORT:QUEUE
"SendErrorReport", # /ERRORREPORT:SEND
"NoErrorReport",
],
),
) # /ERRORREPORT:NONE
_MSBuildOnly(_lib, "MinimumRequiredVersion", _string)
_MSBuildOnly(_lib, "Name", _file_name) # /NAME
_MSBuildOnly(_lib, "RemoveObjects", _file_list) # /REMOVE
_MSBuildOnly(_lib, "SubSystem", _subsystem_enumeration)
_MSBuildOnly(_lib, "TrackerLogDirectory", _folder_name)
_MSBuildOnly(_lib, "TreatLibWarningAsErrors", _boolean) # /WX
_MSBuildOnly(_lib, "Verbose", _boolean)
# Directives for converting VCManifestTool to Mt.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\mt.xml" for
# the schema of the MSBuild Lib settings.
# Options that have the same name in MSVS and MSBuild
_Same(_manifest, "AdditionalManifestFiles", _file_list) # /manifest
_Same(_manifest, "AdditionalOptions", _string_list)
_Same(_manifest, "AssemblyIdentity", _string) # /identity:
_Same(_manifest, "ComponentFileName", _file_name) # /dll
_Same(_manifest, "GenerateCatalogFiles", _boolean) # /makecdfs
_Same(_manifest, "InputResourceManifests", _string) # /inputresource
_Same(_manifest, "OutputManifestFile", _file_name) # /out
_Same(_manifest, "RegistrarScriptFile", _file_name) # /rgs
_Same(_manifest, "ReplacementsFile", _file_name) # /replacements
_Same(_manifest, "SuppressStartupBanner", _boolean) # /nologo
_Same(_manifest, "TypeLibraryFile", _file_name) # /tlb:
_Same(_manifest, "UpdateFileHashes", _boolean) # /hashupdate
_Same(_manifest, "UpdateFileHashesSearchPath", _file_name)
_Same(_manifest, "VerboseOutput", _boolean) # /verbose
# Options that have moved location.
_MovedAndRenamed(
_manifest,
"ManifestResourceFile",
"ManifestResourceCompile",
"ResourceOutputFileName",
_file_name,
)
_Moved(_manifest, "EmbedManifest", "", _boolean)
# MSVS options not found in MSBuild.
_MSVSOnly(_manifest, "DependencyInformationFile", _file_name)
_MSVSOnly(_manifest, "UseFAT32Workaround", _boolean)
_MSVSOnly(_manifest, "UseUnicodeResponseFiles", _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_manifest, "EnableDPIAwareness", _boolean)
_MSBuildOnly(_manifest, "GenerateCategoryTags", _boolean) # /category
_MSBuildOnly(
_manifest, "ManifestFromManagedAssembly", _file_name
) # /managedassemblyname
_MSBuildOnly(_manifest, "OutputResourceManifests", _string) # /outputresource
_MSBuildOnly(_manifest, "SuppressDependencyElement", _boolean) # /nodependency
_MSBuildOnly(_manifest, "TrackerLogDirectory", _folder_name)
# Directives for MASM.
# See "$(VCTargetsPath)\BuildCustomizations\masm.xml" for the schema of the
# MSBuild MASM settings.
# Options that have the same name in MSVS and MSBuild.
_Same(_masm, "UseSafeExceptionHandlers", _boolean) # /safeseh
node-gyp-9.3.0/gyp/pylib/gyp/MSVSSettings_test.py 0000775 0000000 0000000 00000221071 14321173220 0021705 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for the MSVSSettings.py file."""
import unittest
import gyp.MSVSSettings as MSVSSettings
from io import StringIO
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.stderr = StringIO()
def _ExpectedWarnings(self, expected):
"""Compares recorded lines to expected warnings."""
self.stderr.seek(0)
actual = self.stderr.read().split("\n")
actual = [line for line in actual if line]
self.assertEqual(sorted(expected), sorted(actual))
def testValidateMSVSSettings_tool_names(self):
"""Tests that only MSVS tool names are allowed."""
MSVSSettings.ValidateMSVSSettings(
{
"VCCLCompilerTool": {},
"VCLinkerTool": {},
"VCMIDLTool": {},
"foo": {},
"VCResourceCompilerTool": {},
"VCLibrarianTool": {},
"VCManifestTool": {},
"ClCompile": {},
},
self.stderr,
)
self._ExpectedWarnings(
["Warning: unrecognized tool foo", "Warning: unrecognized tool ClCompile"]
)
def testValidateMSVSSettings_settings(self):
"""Tests that for invalid MSVS settings."""
MSVSSettings.ValidateMSVSSettings(
{
"VCCLCompilerTool": {
"AdditionalIncludeDirectories": "folder1;folder2",
"AdditionalOptions": ["string1", "string2"],
"AdditionalUsingDirectories": "folder1;folder2",
"AssemblerListingLocation": "a_file_name",
"AssemblerOutput": "0",
"BasicRuntimeChecks": "5",
"BrowseInformation": "fdkslj",
"BrowseInformationFile": "a_file_name",
"BufferSecurityCheck": "true",
"CallingConvention": "-1",
"CompileAs": "1",
"DebugInformationFormat": "2",
"DefaultCharIsUnsigned": "true",
"Detect64BitPortabilityProblems": "true",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "string1;string2",
"EnableEnhancedInstructionSet": "1",
"EnableFiberSafeOptimizations": "true",
"EnableFunctionLevelLinking": "true",
"EnableIntrinsicFunctions": "true",
"EnablePREfast": "true",
"Enableprefast": "bogus",
"ErrorReporting": "1",
"ExceptionHandling": "1",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "1",
"FloatingPointExceptions": "true",
"FloatingPointModel": "1",
"ForceConformanceInForLoopScope": "true",
"ForcedIncludeFiles": "file1;file2",
"ForcedUsingFiles": "file1;file2",
"GeneratePreprocessedFile": "1",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "1",
"KeepComments": "true",
"MinimalRebuild": "true",
"ObjectFile": "a_file_name",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMP": "true",
"Optimization": "1",
"PrecompiledHeaderFile": "a_file_name",
"PrecompiledHeaderThrough": "a_file_name",
"PreprocessorDefinitions": "string1;string2",
"ProgramDataBaseFileName": "a_file_name",
"RuntimeLibrary": "1",
"RuntimeTypeInfo": "true",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "1",
"SuppressStartupBanner": "true",
"TreatWChar_tAsBuiltInType": "true",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "string1;string2",
"UseFullPaths": "true",
"UsePrecompiledHeader": "1",
"UseUnicodeResponseFiles": "true",
"WarnAsError": "true",
"WarningLevel": "1",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "a_file_name",
"ZZXYZ": "bogus",
},
"VCLinkerTool": {
"AdditionalDependencies": "file1;file2",
"AdditionalDependencies_excluded": "file3",
"AdditionalLibraryDirectories": "folder1;folder2",
"AdditionalManifestDependencies": "file1;file2",
"AdditionalOptions": "a string1",
"AddModuleNamesToAssembly": "file1;file2",
"AllowIsolation": "true",
"AssemblyDebug": "2",
"AssemblyLinkResource": "file1;file2",
"BaseAddress": "a string1",
"CLRImageType": "2",
"CLRThreadAttribute": "2",
"CLRUnmanagedCodeCheck": "true",
"DataExecutionPrevention": "2",
"DelayLoadDLLs": "file1;file2",
"DelaySign": "true",
"Driver": "2",
"EmbedManagedResourceFile": "file1;file2",
"EnableCOMDATFolding": "2",
"EnableUAC": "true",
"EntryPointSymbol": "a string1",
"ErrorReporting": "2",
"FixedBaseAddress": "2",
"ForceSymbolReferences": "file1;file2",
"FunctionOrder": "a_file_name",
"GenerateDebugInformation": "true",
"GenerateManifest": "true",
"GenerateMapFile": "true",
"HeapCommitSize": "a string1",
"HeapReserveSize": "a string1",
"IgnoreAllDefaultLibraries": "true",
"IgnoreDefaultLibraryNames": "file1;file2",
"IgnoreEmbeddedIDL": "true",
"IgnoreImportLibrary": "true",
"ImportLibrary": "a_file_name",
"KeyContainer": "a_file_name",
"KeyFile": "a_file_name",
"LargeAddressAware": "2",
"LinkIncremental": "2",
"LinkLibraryDependencies": "true",
"LinkTimeCodeGeneration": "2",
"ManifestFile": "a_file_name",
"MapExports": "true",
"MapFileName": "a_file_name",
"MergedIDLBaseFileName": "a_file_name",
"MergeSections": "a string1",
"MidlCommandFile": "a_file_name",
"ModuleDefinitionFile": "a_file_name",
"OptimizeForWindows98": "1",
"OptimizeReferences": "2",
"OutputFile": "a_file_name",
"PerUserRedirection": "true",
"Profile": "true",
"ProfileGuidedDatabase": "a_file_name",
"ProgramDatabaseFile": "a_file_name",
"RandomizedBaseAddress": "2",
"RegisterOutput": "true",
"ResourceOnlyDLL": "true",
"SetChecksum": "true",
"ShowProgress": "2",
"StackCommitSize": "a string1",
"StackReserveSize": "a string1",
"StripPrivateSymbols": "a_file_name",
"SubSystem": "2",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "true",
"SwapRunFromCD": "true",
"SwapRunFromNet": "true",
"TargetMachine": "2",
"TerminalServerAware": "2",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "a_file_name",
"TypeLibraryResourceID": "33",
"UACExecutionLevel": "2",
"UACUIAccess": "true",
"UseLibraryDependencyInputs": "true",
"UseUnicodeResponseFiles": "true",
"Version": "a string1",
},
"VCMIDLTool": {
"AdditionalIncludeDirectories": "folder1;folder2",
"AdditionalOptions": "a string1",
"CPreprocessOptions": "a string1",
"DefaultCharType": "1",
"DLLDataFileName": "a_file_name",
"EnableErrorChecks": "1",
"ErrorCheckAllocations": "true",
"ErrorCheckBounds": "true",
"ErrorCheckEnumRange": "true",
"ErrorCheckRefPointers": "true",
"ErrorCheckStubData": "true",
"GenerateStublessProxies": "true",
"GenerateTypeLibrary": "true",
"HeaderFileName": "a_file_name",
"IgnoreStandardIncludePath": "true",
"InterfaceIdentifierFileName": "a_file_name",
"MkTypLibCompatible": "true",
"notgood": "bogus",
"OutputDirectory": "a string1",
"PreprocessorDefinitions": "string1;string2",
"ProxyFileName": "a_file_name",
"RedirectOutputAndErrors": "a_file_name",
"StructMemberAlignment": "1",
"SuppressStartupBanner": "true",
"TargetEnvironment": "1",
"TypeLibraryName": "a_file_name",
"UndefinePreprocessorDefinitions": "string1;string2",
"ValidateParameters": "true",
"WarnAsError": "true",
"WarningLevel": "1",
},
"VCResourceCompilerTool": {
"AdditionalOptions": "a string1",
"AdditionalIncludeDirectories": "folder1;folder2",
"Culture": "1003",
"IgnoreStandardIncludePath": "true",
"notgood2": "bogus",
"PreprocessorDefinitions": "string1;string2",
"ResourceOutputFileName": "a string1",
"ShowProgress": "true",
"SuppressStartupBanner": "true",
"UndefinePreprocessorDefinitions": "string1;string2",
},
"VCLibrarianTool": {
"AdditionalDependencies": "file1;file2",
"AdditionalLibraryDirectories": "folder1;folder2",
"AdditionalOptions": "a string1",
"ExportNamedFunctions": "string1;string2",
"ForceSymbolReferences": "a string1",
"IgnoreAllDefaultLibraries": "true",
"IgnoreSpecificDefaultLibraries": "file1;file2",
"LinkLibraryDependencies": "true",
"ModuleDefinitionFile": "a_file_name",
"OutputFile": "a_file_name",
"SuppressStartupBanner": "true",
"UseUnicodeResponseFiles": "true",
},
"VCManifestTool": {
"AdditionalManifestFiles": "file1;file2",
"AdditionalOptions": "a string1",
"AssemblyIdentity": "a string1",
"ComponentFileName": "a_file_name",
"DependencyInformationFile": "a_file_name",
"GenerateCatalogFiles": "true",
"InputResourceManifests": "a string1",
"ManifestResourceFile": "a_file_name",
"OutputManifestFile": "a_file_name",
"RegistrarScriptFile": "a_file_name",
"ReplacementsFile": "a_file_name",
"SuppressStartupBanner": "true",
"TypeLibraryFile": "a_file_name",
"UpdateFileHashes": "truel",
"UpdateFileHashesSearchPath": "a_file_name",
"UseFAT32Workaround": "true",
"UseUnicodeResponseFiles": "true",
"VerboseOutput": "true",
},
},
self.stderr,
)
self._ExpectedWarnings(
[
"Warning: for VCCLCompilerTool/BasicRuntimeChecks, "
"index value (5) not in expected range [0, 4)",
"Warning: for VCCLCompilerTool/BrowseInformation, "
"invalid literal for int() with base 10: 'fdkslj'",
"Warning: for VCCLCompilerTool/CallingConvention, "
"index value (-1) not in expected range [0, 4)",
"Warning: for VCCLCompilerTool/DebugInformationFormat, "
"converted value for 2 not specified.",
"Warning: unrecognized setting VCCLCompilerTool/Enableprefast",
"Warning: unrecognized setting VCCLCompilerTool/ZZXYZ",
"Warning: for VCLinkerTool/TargetMachine, "
"converted value for 2 not specified.",
"Warning: unrecognized setting VCMIDLTool/notgood",
"Warning: unrecognized setting VCResourceCompilerTool/notgood2",
"Warning: for VCManifestTool/UpdateFileHashes, "
"expected bool; got 'truel'"
"",
]
)
def testValidateMSBuildSettings_settings(self):
"""Tests that for invalid MSBuild settings."""
MSVSSettings.ValidateMSBuildSettings(
{
"ClCompile": {
"AdditionalIncludeDirectories": "folder1;folder2",
"AdditionalOptions": ["string1", "string2"],
"AdditionalUsingDirectories": "folder1;folder2",
"AssemblerListingLocation": "a_file_name",
"AssemblerOutput": "NoListing",
"BasicRuntimeChecks": "StackFrameRuntimeCheck",
"BrowseInformation": "false",
"BrowseInformationFile": "a_file_name",
"BufferSecurityCheck": "true",
"BuildingInIDE": "true",
"CallingConvention": "Cdecl",
"CompileAs": "CompileAsC",
"CompileAsManaged": "true",
"CreateHotpatchableImage": "true",
"DebugInformationFormat": "ProgramDatabase",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "string1;string2",
"EnableEnhancedInstructionSet": "StreamingSIMDExtensions",
"EnableFiberSafeOptimizations": "true",
"EnablePREfast": "true",
"Enableprefast": "bogus",
"ErrorReporting": "Prompt",
"ExceptionHandling": "SyncCThrow",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "Neither",
"FloatingPointExceptions": "true",
"FloatingPointModel": "Precise",
"ForceConformanceInForLoopScope": "true",
"ForcedIncludeFiles": "file1;file2",
"ForcedUsingFiles": "file1;file2",
"FunctionLevelLinking": "false",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "OnlyExplicitInline",
"IntrinsicFunctions": "false",
"MinimalRebuild": "true",
"MultiProcessorCompilation": "true",
"ObjectFileName": "a_file_name",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMPSupport": "true",
"Optimization": "Disabled",
"PrecompiledHeader": "NotUsing",
"PrecompiledHeaderFile": "a_file_name",
"PrecompiledHeaderOutputFile": "a_file_name",
"PreprocessKeepComments": "true",
"PreprocessorDefinitions": "string1;string2",
"PreprocessOutputPath": "a string1",
"PreprocessSuppressLineNumbers": "false",
"PreprocessToFile": "false",
"ProcessorNumber": "33",
"ProgramDataBaseFileName": "a_file_name",
"RuntimeLibrary": "MultiThreaded",
"RuntimeTypeInfo": "true",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "1Byte",
"SuppressStartupBanner": "true",
"TrackerLogDirectory": "a_folder",
"TreatSpecificWarningsAsErrors": "string1;string2",
"TreatWarningAsError": "true",
"TreatWChar_tAsBuiltInType": "true",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "string1;string2",
"UseFullPaths": "true",
"UseUnicodeForAssemblerListing": "true",
"WarningLevel": "TurnOffAllWarnings",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "a_file_name",
"ZZXYZ": "bogus",
},
"Link": {
"AdditionalDependencies": "file1;file2",
"AdditionalLibraryDirectories": "folder1;folder2",
"AdditionalManifestDependencies": "file1;file2",
"AdditionalOptions": "a string1",
"AddModuleNamesToAssembly": "file1;file2",
"AllowIsolation": "true",
"AssemblyDebug": "",
"AssemblyLinkResource": "file1;file2",
"BaseAddress": "a string1",
"BuildingInIDE": "true",
"CLRImageType": "ForceIJWImage",
"CLRSupportLastError": "Enabled",
"CLRThreadAttribute": "MTAThreadingAttribute",
"CLRUnmanagedCodeCheck": "true",
"CreateHotPatchableImage": "X86Image",
"DataExecutionPrevention": "false",
"DelayLoadDLLs": "file1;file2",
"DelaySign": "true",
"Driver": "NotSet",
"EmbedManagedResourceFile": "file1;file2",
"EnableCOMDATFolding": "false",
"EnableUAC": "true",
"EntryPointSymbol": "a string1",
"FixedBaseAddress": "false",
"ForceFileOutput": "Enabled",
"ForceSymbolReferences": "file1;file2",
"FunctionOrder": "a_file_name",
"GenerateDebugInformation": "true",
"GenerateMapFile": "true",
"HeapCommitSize": "a string1",
"HeapReserveSize": "a string1",
"IgnoreAllDefaultLibraries": "true",
"IgnoreEmbeddedIDL": "true",
"IgnoreSpecificDefaultLibraries": "a_file_list",
"ImageHasSafeExceptionHandlers": "true",
"ImportLibrary": "a_file_name",
"KeyContainer": "a_file_name",
"KeyFile": "a_file_name",
"LargeAddressAware": "false",
"LinkDLL": "true",
"LinkErrorReporting": "SendErrorReport",
"LinkStatus": "true",
"LinkTimeCodeGeneration": "UseLinkTimeCodeGeneration",
"ManifestFile": "a_file_name",
"MapExports": "true",
"MapFileName": "a_file_name",
"MergedIDLBaseFileName": "a_file_name",
"MergeSections": "a string1",
"MidlCommandFile": "a_file_name",
"MinimumRequiredVersion": "a string1",
"ModuleDefinitionFile": "a_file_name",
"MSDOSStubFileName": "a_file_name",
"NoEntryPoint": "true",
"OptimizeReferences": "false",
"OutputFile": "a_file_name",
"PerUserRedirection": "true",
"PreventDllBinding": "true",
"Profile": "true",
"ProfileGuidedDatabase": "a_file_name",
"ProgramDatabaseFile": "a_file_name",
"RandomizedBaseAddress": "false",
"RegisterOutput": "true",
"SectionAlignment": "33",
"SetChecksum": "true",
"ShowProgress": "LinkVerboseREF",
"SpecifySectionAttributes": "a string1",
"StackCommitSize": "a string1",
"StackReserveSize": "a string1",
"StripPrivateSymbols": "a_file_name",
"SubSystem": "Console",
"SupportNobindOfDelayLoadedDLL": "true",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "true",
"SwapRunFromCD": "true",
"SwapRunFromNET": "true",
"TargetMachine": "MachineX86",
"TerminalServerAware": "false",
"TrackerLogDirectory": "a_folder",
"TreatLinkerWarningAsErrors": "true",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "a_file_name",
"TypeLibraryResourceID": "33",
"UACExecutionLevel": "AsInvoker",
"UACUIAccess": "true",
"Version": "a string1",
},
"ResourceCompile": {
"AdditionalIncludeDirectories": "folder1;folder2",
"AdditionalOptions": "a string1",
"Culture": "0x236",
"IgnoreStandardIncludePath": "true",
"NullTerminateStrings": "true",
"PreprocessorDefinitions": "string1;string2",
"ResourceOutputFileName": "a string1",
"ShowProgress": "true",
"SuppressStartupBanner": "true",
"TrackerLogDirectory": "a_folder",
"UndefinePreprocessorDefinitions": "string1;string2",
},
"Midl": {
"AdditionalIncludeDirectories": "folder1;folder2",
"AdditionalOptions": "a string1",
"ApplicationConfigurationMode": "true",
"ClientStubFile": "a_file_name",
"CPreprocessOptions": "a string1",
"DefaultCharType": "Signed",
"DllDataFileName": "a_file_name",
"EnableErrorChecks": "EnableCustom",
"ErrorCheckAllocations": "true",
"ErrorCheckBounds": "true",
"ErrorCheckEnumRange": "true",
"ErrorCheckRefPointers": "true",
"ErrorCheckStubData": "true",
"GenerateClientFiles": "Stub",
"GenerateServerFiles": "None",
"GenerateStublessProxies": "true",
"GenerateTypeLibrary": "true",
"HeaderFileName": "a_file_name",
"IgnoreStandardIncludePath": "true",
"InterfaceIdentifierFileName": "a_file_name",
"LocaleID": "33",
"MkTypLibCompatible": "true",
"OutputDirectory": "a string1",
"PreprocessorDefinitions": "string1;string2",
"ProxyFileName": "a_file_name",
"RedirectOutputAndErrors": "a_file_name",
"ServerStubFile": "a_file_name",
"StructMemberAlignment": "NotSet",
"SuppressCompilerWarnings": "true",
"SuppressStartupBanner": "true",
"TargetEnvironment": "Itanium",
"TrackerLogDirectory": "a_folder",
"TypeLibFormat": "NewFormat",
"TypeLibraryName": "a_file_name",
"UndefinePreprocessorDefinitions": "string1;string2",
"ValidateAllParameters": "true",
"WarnAsError": "true",
"WarningLevel": "1",
},
"Lib": {
"AdditionalDependencies": "file1;file2",
"AdditionalLibraryDirectories": "folder1;folder2",
"AdditionalOptions": "a string1",
"DisplayLibrary": "a string1",
"ErrorReporting": "PromptImmediately",
"ExportNamedFunctions": "string1;string2",
"ForceSymbolReferences": "a string1",
"IgnoreAllDefaultLibraries": "true",
"IgnoreSpecificDefaultLibraries": "file1;file2",
"LinkTimeCodeGeneration": "true",
"MinimumRequiredVersion": "a string1",
"ModuleDefinitionFile": "a_file_name",
"Name": "a_file_name",
"OutputFile": "a_file_name",
"RemoveObjects": "file1;file2",
"SubSystem": "Console",
"SuppressStartupBanner": "true",
"TargetMachine": "MachineX86i",
"TrackerLogDirectory": "a_folder",
"TreatLibWarningAsErrors": "true",
"UseUnicodeResponseFiles": "true",
"Verbose": "true",
},
"Manifest": {
"AdditionalManifestFiles": "file1;file2",
"AdditionalOptions": "a string1",
"AssemblyIdentity": "a string1",
"ComponentFileName": "a_file_name",
"EnableDPIAwareness": "fal",
"GenerateCatalogFiles": "truel",
"GenerateCategoryTags": "true",
"InputResourceManifests": "a string1",
"ManifestFromManagedAssembly": "a_file_name",
"notgood3": "bogus",
"OutputManifestFile": "a_file_name",
"OutputResourceManifests": "a string1",
"RegistrarScriptFile": "a_file_name",
"ReplacementsFile": "a_file_name",
"SuppressDependencyElement": "true",
"SuppressStartupBanner": "true",
"TrackerLogDirectory": "a_folder",
"TypeLibraryFile": "a_file_name",
"UpdateFileHashes": "true",
"UpdateFileHashesSearchPath": "a_file_name",
"VerboseOutput": "true",
},
"ProjectReference": {
"LinkLibraryDependencies": "true",
"UseLibraryDependencyInputs": "true",
},
"ManifestResourceCompile": {"ResourceOutputFileName": "a_file_name"},
"": {
"EmbedManifest": "true",
"GenerateManifest": "true",
"IgnoreImportLibrary": "true",
"LinkIncremental": "false",
},
},
self.stderr,
)
self._ExpectedWarnings(
[
"Warning: unrecognized setting ClCompile/Enableprefast",
"Warning: unrecognized setting ClCompile/ZZXYZ",
"Warning: unrecognized setting Manifest/notgood3",
"Warning: for Manifest/GenerateCatalogFiles, "
"expected bool; got 'truel'",
"Warning: for Lib/TargetMachine, unrecognized enumerated value "
"MachineX86i",
"Warning: for Manifest/EnableDPIAwareness, expected bool; got 'fal'",
]
)
def testConvertToMSBuildSettings_empty(self):
"""Tests an empty conversion."""
msvs_settings = {}
expected_msbuild_settings = {}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings, self.stderr
)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_minimal(self):
"""Tests a minimal conversion."""
msvs_settings = {
"VCCLCompilerTool": {
"AdditionalIncludeDirectories": "dir1",
"AdditionalOptions": "/foo",
"BasicRuntimeChecks": "0",
},
"VCLinkerTool": {
"LinkTimeCodeGeneration": "1",
"ErrorReporting": "1",
"DataExecutionPrevention": "2",
},
}
expected_msbuild_settings = {
"ClCompile": {
"AdditionalIncludeDirectories": "dir1",
"AdditionalOptions": "/foo",
"BasicRuntimeChecks": "Default",
},
"Link": {
"LinkTimeCodeGeneration": "UseLinkTimeCodeGeneration",
"LinkErrorReporting": "PromptImmediately",
"DataExecutionPrevention": "true",
},
}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings, self.stderr
)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_warnings(self):
"""Tests conversion that generates warnings."""
msvs_settings = {
"VCCLCompilerTool": {
"AdditionalIncludeDirectories": "1",
"AdditionalOptions": "2",
# These are incorrect values:
"BasicRuntimeChecks": "12",
"BrowseInformation": "21",
"UsePrecompiledHeader": "13",
"GeneratePreprocessedFile": "14",
},
"VCLinkerTool": {
# These are incorrect values:
"Driver": "10",
"LinkTimeCodeGeneration": "31",
"ErrorReporting": "21",
"FixedBaseAddress": "6",
},
"VCResourceCompilerTool": {
# Custom
"Culture": "1003"
},
}
expected_msbuild_settings = {
"ClCompile": {
"AdditionalIncludeDirectories": "1",
"AdditionalOptions": "2",
},
"Link": {},
"ResourceCompile": {
# Custom
"Culture": "0x03eb"
},
}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings, self.stderr
)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings(
[
"Warning: while converting VCCLCompilerTool/BasicRuntimeChecks to "
"MSBuild, index value (12) not in expected range [0, 4)",
"Warning: while converting VCCLCompilerTool/BrowseInformation to "
"MSBuild, index value (21) not in expected range [0, 3)",
"Warning: while converting VCCLCompilerTool/UsePrecompiledHeader to "
"MSBuild, index value (13) not in expected range [0, 3)",
"Warning: while converting "
"VCCLCompilerTool/GeneratePreprocessedFile to "
"MSBuild, value must be one of [0, 1, 2]; got 14",
"Warning: while converting VCLinkerTool/Driver to "
"MSBuild, index value (10) not in expected range [0, 4)",
"Warning: while converting VCLinkerTool/LinkTimeCodeGeneration to "
"MSBuild, index value (31) not in expected range [0, 5)",
"Warning: while converting VCLinkerTool/ErrorReporting to "
"MSBuild, index value (21) not in expected range [0, 3)",
"Warning: while converting VCLinkerTool/FixedBaseAddress to "
"MSBuild, index value (6) not in expected range [0, 3)",
]
)
def testConvertToMSBuildSettings_full_synthetic(self):
"""Tests conversion of all the MSBuild settings."""
msvs_settings = {
"VCCLCompilerTool": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"AdditionalUsingDirectories": "folder1;folder2;folder3",
"AssemblerListingLocation": "a_file_name",
"AssemblerOutput": "0",
"BasicRuntimeChecks": "1",
"BrowseInformation": "2",
"BrowseInformationFile": "a_file_name",
"BufferSecurityCheck": "true",
"CallingConvention": "0",
"CompileAs": "1",
"DebugInformationFormat": "4",
"DefaultCharIsUnsigned": "true",
"Detect64BitPortabilityProblems": "true",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "d1;d2;d3",
"EnableEnhancedInstructionSet": "0",
"EnableFiberSafeOptimizations": "true",
"EnableFunctionLevelLinking": "true",
"EnableIntrinsicFunctions": "true",
"EnablePREfast": "true",
"ErrorReporting": "1",
"ExceptionHandling": "2",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "0",
"FloatingPointExceptions": "true",
"FloatingPointModel": "1",
"ForceConformanceInForLoopScope": "true",
"ForcedIncludeFiles": "file1;file2;file3",
"ForcedUsingFiles": "file1;file2;file3",
"GeneratePreprocessedFile": "1",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "2",
"KeepComments": "true",
"MinimalRebuild": "true",
"ObjectFile": "a_file_name",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMP": "true",
"Optimization": "3",
"PrecompiledHeaderFile": "a_file_name",
"PrecompiledHeaderThrough": "a_file_name",
"PreprocessorDefinitions": "d1;d2;d3",
"ProgramDataBaseFileName": "a_file_name",
"RuntimeLibrary": "0",
"RuntimeTypeInfo": "true",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "1",
"SuppressStartupBanner": "true",
"TreatWChar_tAsBuiltInType": "true",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
"UseFullPaths": "true",
"UsePrecompiledHeader": "1",
"UseUnicodeResponseFiles": "true",
"WarnAsError": "true",
"WarningLevel": "2",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "a_file_name",
},
"VCLinkerTool": {
"AdditionalDependencies": "file1;file2;file3",
"AdditionalLibraryDirectories": "folder1;folder2;folder3",
"AdditionalLibraryDirectories_excluded": "folder1;folder2;folder3",
"AdditionalManifestDependencies": "file1;file2;file3",
"AdditionalOptions": "a_string",
"AddModuleNamesToAssembly": "file1;file2;file3",
"AllowIsolation": "true",
"AssemblyDebug": "0",
"AssemblyLinkResource": "file1;file2;file3",
"BaseAddress": "a_string",
"CLRImageType": "1",
"CLRThreadAttribute": "2",
"CLRUnmanagedCodeCheck": "true",
"DataExecutionPrevention": "0",
"DelayLoadDLLs": "file1;file2;file3",
"DelaySign": "true",
"Driver": "1",
"EmbedManagedResourceFile": "file1;file2;file3",
"EnableCOMDATFolding": "0",
"EnableUAC": "true",
"EntryPointSymbol": "a_string",
"ErrorReporting": "0",
"FixedBaseAddress": "1",
"ForceSymbolReferences": "file1;file2;file3",
"FunctionOrder": "a_file_name",
"GenerateDebugInformation": "true",
"GenerateManifest": "true",
"GenerateMapFile": "true",
"HeapCommitSize": "a_string",
"HeapReserveSize": "a_string",
"IgnoreAllDefaultLibraries": "true",
"IgnoreDefaultLibraryNames": "file1;file2;file3",
"IgnoreEmbeddedIDL": "true",
"IgnoreImportLibrary": "true",
"ImportLibrary": "a_file_name",
"KeyContainer": "a_file_name",
"KeyFile": "a_file_name",
"LargeAddressAware": "2",
"LinkIncremental": "1",
"LinkLibraryDependencies": "true",
"LinkTimeCodeGeneration": "2",
"ManifestFile": "a_file_name",
"MapExports": "true",
"MapFileName": "a_file_name",
"MergedIDLBaseFileName": "a_file_name",
"MergeSections": "a_string",
"MidlCommandFile": "a_file_name",
"ModuleDefinitionFile": "a_file_name",
"OptimizeForWindows98": "1",
"OptimizeReferences": "0",
"OutputFile": "a_file_name",
"PerUserRedirection": "true",
"Profile": "true",
"ProfileGuidedDatabase": "a_file_name",
"ProgramDatabaseFile": "a_file_name",
"RandomizedBaseAddress": "1",
"RegisterOutput": "true",
"ResourceOnlyDLL": "true",
"SetChecksum": "true",
"ShowProgress": "0",
"StackCommitSize": "a_string",
"StackReserveSize": "a_string",
"StripPrivateSymbols": "a_file_name",
"SubSystem": "2",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "true",
"SwapRunFromCD": "true",
"SwapRunFromNet": "true",
"TargetMachine": "3",
"TerminalServerAware": "2",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "a_file_name",
"TypeLibraryResourceID": "33",
"UACExecutionLevel": "1",
"UACUIAccess": "true",
"UseLibraryDependencyInputs": "false",
"UseUnicodeResponseFiles": "true",
"Version": "a_string",
},
"VCResourceCompilerTool": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"Culture": "1003",
"IgnoreStandardIncludePath": "true",
"PreprocessorDefinitions": "d1;d2;d3",
"ResourceOutputFileName": "a_string",
"ShowProgress": "true",
"SuppressStartupBanner": "true",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
},
"VCMIDLTool": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"CPreprocessOptions": "a_string",
"DefaultCharType": "0",
"DLLDataFileName": "a_file_name",
"EnableErrorChecks": "2",
"ErrorCheckAllocations": "true",
"ErrorCheckBounds": "true",
"ErrorCheckEnumRange": "true",
"ErrorCheckRefPointers": "true",
"ErrorCheckStubData": "true",
"GenerateStublessProxies": "true",
"GenerateTypeLibrary": "true",
"HeaderFileName": "a_file_name",
"IgnoreStandardIncludePath": "true",
"InterfaceIdentifierFileName": "a_file_name",
"MkTypLibCompatible": "true",
"OutputDirectory": "a_string",
"PreprocessorDefinitions": "d1;d2;d3",
"ProxyFileName": "a_file_name",
"RedirectOutputAndErrors": "a_file_name",
"StructMemberAlignment": "3",
"SuppressStartupBanner": "true",
"TargetEnvironment": "1",
"TypeLibraryName": "a_file_name",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
"ValidateParameters": "true",
"WarnAsError": "true",
"WarningLevel": "4",
},
"VCLibrarianTool": {
"AdditionalDependencies": "file1;file2;file3",
"AdditionalLibraryDirectories": "folder1;folder2;folder3",
"AdditionalLibraryDirectories_excluded": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"ExportNamedFunctions": "d1;d2;d3",
"ForceSymbolReferences": "a_string",
"IgnoreAllDefaultLibraries": "true",
"IgnoreSpecificDefaultLibraries": "file1;file2;file3",
"LinkLibraryDependencies": "true",
"ModuleDefinitionFile": "a_file_name",
"OutputFile": "a_file_name",
"SuppressStartupBanner": "true",
"UseUnicodeResponseFiles": "true",
},
"VCManifestTool": {
"AdditionalManifestFiles": "file1;file2;file3",
"AdditionalOptions": "a_string",
"AssemblyIdentity": "a_string",
"ComponentFileName": "a_file_name",
"DependencyInformationFile": "a_file_name",
"EmbedManifest": "true",
"GenerateCatalogFiles": "true",
"InputResourceManifests": "a_string",
"ManifestResourceFile": "my_name",
"OutputManifestFile": "a_file_name",
"RegistrarScriptFile": "a_file_name",
"ReplacementsFile": "a_file_name",
"SuppressStartupBanner": "true",
"TypeLibraryFile": "a_file_name",
"UpdateFileHashes": "true",
"UpdateFileHashesSearchPath": "a_file_name",
"UseFAT32Workaround": "true",
"UseUnicodeResponseFiles": "true",
"VerboseOutput": "true",
},
}
expected_msbuild_settings = {
"ClCompile": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string /J",
"AdditionalUsingDirectories": "folder1;folder2;folder3",
"AssemblerListingLocation": "a_file_name",
"AssemblerOutput": "NoListing",
"BasicRuntimeChecks": "StackFrameRuntimeCheck",
"BrowseInformation": "true",
"BrowseInformationFile": "a_file_name",
"BufferSecurityCheck": "true",
"CallingConvention": "Cdecl",
"CompileAs": "CompileAsC",
"DebugInformationFormat": "EditAndContinue",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "d1;d2;d3",
"EnableEnhancedInstructionSet": "NotSet",
"EnableFiberSafeOptimizations": "true",
"EnablePREfast": "true",
"ErrorReporting": "Prompt",
"ExceptionHandling": "Async",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "Neither",
"FloatingPointExceptions": "true",
"FloatingPointModel": "Strict",
"ForceConformanceInForLoopScope": "true",
"ForcedIncludeFiles": "file1;file2;file3",
"ForcedUsingFiles": "file1;file2;file3",
"FunctionLevelLinking": "true",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "AnySuitable",
"IntrinsicFunctions": "true",
"MinimalRebuild": "true",
"ObjectFileName": "a_file_name",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMPSupport": "true",
"Optimization": "Full",
"PrecompiledHeader": "Create",
"PrecompiledHeaderFile": "a_file_name",
"PrecompiledHeaderOutputFile": "a_file_name",
"PreprocessKeepComments": "true",
"PreprocessorDefinitions": "d1;d2;d3",
"PreprocessSuppressLineNumbers": "false",
"PreprocessToFile": "true",
"ProgramDataBaseFileName": "a_file_name",
"RuntimeLibrary": "MultiThreaded",
"RuntimeTypeInfo": "true",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "1Byte",
"SuppressStartupBanner": "true",
"TreatWarningAsError": "true",
"TreatWChar_tAsBuiltInType": "true",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
"UseFullPaths": "true",
"WarningLevel": "Level2",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "a_file_name",
},
"Link": {
"AdditionalDependencies": "file1;file2;file3",
"AdditionalLibraryDirectories": "folder1;folder2;folder3",
"AdditionalManifestDependencies": "file1;file2;file3",
"AdditionalOptions": "a_string",
"AddModuleNamesToAssembly": "file1;file2;file3",
"AllowIsolation": "true",
"AssemblyDebug": "",
"AssemblyLinkResource": "file1;file2;file3",
"BaseAddress": "a_string",
"CLRImageType": "ForceIJWImage",
"CLRThreadAttribute": "STAThreadingAttribute",
"CLRUnmanagedCodeCheck": "true",
"DataExecutionPrevention": "",
"DelayLoadDLLs": "file1;file2;file3",
"DelaySign": "true",
"Driver": "Driver",
"EmbedManagedResourceFile": "file1;file2;file3",
"EnableCOMDATFolding": "",
"EnableUAC": "true",
"EntryPointSymbol": "a_string",
"FixedBaseAddress": "false",
"ForceSymbolReferences": "file1;file2;file3",
"FunctionOrder": "a_file_name",
"GenerateDebugInformation": "true",
"GenerateMapFile": "true",
"HeapCommitSize": "a_string",
"HeapReserveSize": "a_string",
"IgnoreAllDefaultLibraries": "true",
"IgnoreEmbeddedIDL": "true",
"IgnoreSpecificDefaultLibraries": "file1;file2;file3",
"ImportLibrary": "a_file_name",
"KeyContainer": "a_file_name",
"KeyFile": "a_file_name",
"LargeAddressAware": "true",
"LinkErrorReporting": "NoErrorReport",
"LinkTimeCodeGeneration": "PGInstrument",
"ManifestFile": "a_file_name",
"MapExports": "true",
"MapFileName": "a_file_name",
"MergedIDLBaseFileName": "a_file_name",
"MergeSections": "a_string",
"MidlCommandFile": "a_file_name",
"ModuleDefinitionFile": "a_file_name",
"NoEntryPoint": "true",
"OptimizeReferences": "",
"OutputFile": "a_file_name",
"PerUserRedirection": "true",
"Profile": "true",
"ProfileGuidedDatabase": "a_file_name",
"ProgramDatabaseFile": "a_file_name",
"RandomizedBaseAddress": "false",
"RegisterOutput": "true",
"SetChecksum": "true",
"ShowProgress": "NotSet",
"StackCommitSize": "a_string",
"StackReserveSize": "a_string",
"StripPrivateSymbols": "a_file_name",
"SubSystem": "Windows",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "true",
"SwapRunFromCD": "true",
"SwapRunFromNET": "true",
"TargetMachine": "MachineARM",
"TerminalServerAware": "true",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "a_file_name",
"TypeLibraryResourceID": "33",
"UACExecutionLevel": "HighestAvailable",
"UACUIAccess": "true",
"Version": "a_string",
},
"ResourceCompile": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"Culture": "0x03eb",
"IgnoreStandardIncludePath": "true",
"PreprocessorDefinitions": "d1;d2;d3",
"ResourceOutputFileName": "a_string",
"ShowProgress": "true",
"SuppressStartupBanner": "true",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
},
"Midl": {
"AdditionalIncludeDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"CPreprocessOptions": "a_string",
"DefaultCharType": "Unsigned",
"DllDataFileName": "a_file_name",
"EnableErrorChecks": "All",
"ErrorCheckAllocations": "true",
"ErrorCheckBounds": "true",
"ErrorCheckEnumRange": "true",
"ErrorCheckRefPointers": "true",
"ErrorCheckStubData": "true",
"GenerateStublessProxies": "true",
"GenerateTypeLibrary": "true",
"HeaderFileName": "a_file_name",
"IgnoreStandardIncludePath": "true",
"InterfaceIdentifierFileName": "a_file_name",
"MkTypLibCompatible": "true",
"OutputDirectory": "a_string",
"PreprocessorDefinitions": "d1;d2;d3",
"ProxyFileName": "a_file_name",
"RedirectOutputAndErrors": "a_file_name",
"StructMemberAlignment": "4",
"SuppressStartupBanner": "true",
"TargetEnvironment": "Win32",
"TypeLibraryName": "a_file_name",
"UndefinePreprocessorDefinitions": "d1;d2;d3",
"ValidateAllParameters": "true",
"WarnAsError": "true",
"WarningLevel": "4",
},
"Lib": {
"AdditionalDependencies": "file1;file2;file3",
"AdditionalLibraryDirectories": "folder1;folder2;folder3",
"AdditionalOptions": "a_string",
"ExportNamedFunctions": "d1;d2;d3",
"ForceSymbolReferences": "a_string",
"IgnoreAllDefaultLibraries": "true",
"IgnoreSpecificDefaultLibraries": "file1;file2;file3",
"ModuleDefinitionFile": "a_file_name",
"OutputFile": "a_file_name",
"SuppressStartupBanner": "true",
"UseUnicodeResponseFiles": "true",
},
"Manifest": {
"AdditionalManifestFiles": "file1;file2;file3",
"AdditionalOptions": "a_string",
"AssemblyIdentity": "a_string",
"ComponentFileName": "a_file_name",
"GenerateCatalogFiles": "true",
"InputResourceManifests": "a_string",
"OutputManifestFile": "a_file_name",
"RegistrarScriptFile": "a_file_name",
"ReplacementsFile": "a_file_name",
"SuppressStartupBanner": "true",
"TypeLibraryFile": "a_file_name",
"UpdateFileHashes": "true",
"UpdateFileHashesSearchPath": "a_file_name",
"VerboseOutput": "true",
},
"ManifestResourceCompile": {"ResourceOutputFileName": "my_name"},
"ProjectReference": {
"LinkLibraryDependencies": "true",
"UseLibraryDependencyInputs": "false",
},
"": {
"EmbedManifest": "true",
"GenerateManifest": "true",
"IgnoreImportLibrary": "true",
"LinkIncremental": "false",
},
}
self.maxDiff = 9999 # on failure display a long diff
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings, self.stderr
)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_actual(self):
"""Tests the conversion of an actual project.
A VS2008 project with most of the options defined was created through the
VS2008 IDE. It was then converted to VS2010. The tool settings found in
the .vcproj and .vcxproj files were converted to the two dictionaries
msvs_settings and expected_msbuild_settings.
Note that for many settings, the VS2010 converter adds macros like
%(AdditionalIncludeDirectories) to make sure than inherited values are
included. Since the Gyp projects we generate do not use inheritance,
we removed these macros. They were:
ClCompile:
AdditionalIncludeDirectories: ';%(AdditionalIncludeDirectories)'
AdditionalOptions: ' %(AdditionalOptions)'
AdditionalUsingDirectories: ';%(AdditionalUsingDirectories)'
DisableSpecificWarnings: ';%(DisableSpecificWarnings)',
ForcedIncludeFiles: ';%(ForcedIncludeFiles)',
ForcedUsingFiles: ';%(ForcedUsingFiles)',
PreprocessorDefinitions: ';%(PreprocessorDefinitions)',
UndefinePreprocessorDefinitions:
';%(UndefinePreprocessorDefinitions)',
Link:
AdditionalDependencies: ';%(AdditionalDependencies)',
AdditionalLibraryDirectories: ';%(AdditionalLibraryDirectories)',
AdditionalManifestDependencies:
';%(AdditionalManifestDependencies)',
AdditionalOptions: ' %(AdditionalOptions)',
AddModuleNamesToAssembly: ';%(AddModuleNamesToAssembly)',
AssemblyLinkResource: ';%(AssemblyLinkResource)',
DelayLoadDLLs: ';%(DelayLoadDLLs)',
EmbedManagedResourceFile: ';%(EmbedManagedResourceFile)',
ForceSymbolReferences: ';%(ForceSymbolReferences)',
IgnoreSpecificDefaultLibraries:
';%(IgnoreSpecificDefaultLibraries)',
ResourceCompile:
AdditionalIncludeDirectories: ';%(AdditionalIncludeDirectories)',
AdditionalOptions: ' %(AdditionalOptions)',
PreprocessorDefinitions: ';%(PreprocessorDefinitions)',
Manifest:
AdditionalManifestFiles: ';%(AdditionalManifestFiles)',
AdditionalOptions: ' %(AdditionalOptions)',
InputResourceManifests: ';%(InputResourceManifests)',
"""
msvs_settings = {
"VCCLCompilerTool": {
"AdditionalIncludeDirectories": "dir1",
"AdditionalOptions": "/more",
"AdditionalUsingDirectories": "test",
"AssemblerListingLocation": "$(IntDir)\\a",
"AssemblerOutput": "1",
"BasicRuntimeChecks": "3",
"BrowseInformation": "1",
"BrowseInformationFile": "$(IntDir)\\e",
"BufferSecurityCheck": "false",
"CallingConvention": "1",
"CompileAs": "1",
"DebugInformationFormat": "4",
"DefaultCharIsUnsigned": "true",
"Detect64BitPortabilityProblems": "true",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "abc",
"EnableEnhancedInstructionSet": "1",
"EnableFiberSafeOptimizations": "true",
"EnableFunctionLevelLinking": "true",
"EnableIntrinsicFunctions": "true",
"EnablePREfast": "true",
"ErrorReporting": "2",
"ExceptionHandling": "2",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "2",
"FloatingPointExceptions": "true",
"FloatingPointModel": "1",
"ForceConformanceInForLoopScope": "false",
"ForcedIncludeFiles": "def",
"ForcedUsingFiles": "ge",
"GeneratePreprocessedFile": "2",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "1",
"KeepComments": "true",
"MinimalRebuild": "true",
"ObjectFile": "$(IntDir)\\b",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMP": "true",
"Optimization": "3",
"PrecompiledHeaderFile": "$(IntDir)\\$(TargetName).pche",
"PrecompiledHeaderThrough": "StdAfx.hd",
"PreprocessorDefinitions": "WIN32;_DEBUG;_CONSOLE",
"ProgramDataBaseFileName": "$(IntDir)\\vc90b.pdb",
"RuntimeLibrary": "3",
"RuntimeTypeInfo": "false",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "3",
"SuppressStartupBanner": "false",
"TreatWChar_tAsBuiltInType": "false",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "wer",
"UseFullPaths": "true",
"UsePrecompiledHeader": "0",
"UseUnicodeResponseFiles": "false",
"WarnAsError": "true",
"WarningLevel": "3",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "$(IntDir)\\c",
},
"VCLinkerTool": {
"AdditionalDependencies": "zx",
"AdditionalLibraryDirectories": "asd",
"AdditionalManifestDependencies": "s2",
"AdditionalOptions": "/mor2",
"AddModuleNamesToAssembly": "d1",
"AllowIsolation": "false",
"AssemblyDebug": "1",
"AssemblyLinkResource": "d5",
"BaseAddress": "23423",
"CLRImageType": "3",
"CLRThreadAttribute": "1",
"CLRUnmanagedCodeCheck": "true",
"DataExecutionPrevention": "0",
"DelayLoadDLLs": "d4",
"DelaySign": "true",
"Driver": "2",
"EmbedManagedResourceFile": "d2",
"EnableCOMDATFolding": "1",
"EnableUAC": "false",
"EntryPointSymbol": "f5",
"ErrorReporting": "2",
"FixedBaseAddress": "1",
"ForceSymbolReferences": "d3",
"FunctionOrder": "fssdfsd",
"GenerateDebugInformation": "true",
"GenerateManifest": "false",
"GenerateMapFile": "true",
"HeapCommitSize": "13",
"HeapReserveSize": "12",
"IgnoreAllDefaultLibraries": "true",
"IgnoreDefaultLibraryNames": "flob;flok",
"IgnoreEmbeddedIDL": "true",
"IgnoreImportLibrary": "true",
"ImportLibrary": "f4",
"KeyContainer": "f7",
"KeyFile": "f6",
"LargeAddressAware": "2",
"LinkIncremental": "0",
"LinkLibraryDependencies": "false",
"LinkTimeCodeGeneration": "1",
"ManifestFile": "$(IntDir)\\$(TargetFileName).2intermediate.manifest",
"MapExports": "true",
"MapFileName": "d5",
"MergedIDLBaseFileName": "f2",
"MergeSections": "f5",
"MidlCommandFile": "f1",
"ModuleDefinitionFile": "sdsd",
"OptimizeForWindows98": "2",
"OptimizeReferences": "2",
"OutputFile": "$(OutDir)\\$(ProjectName)2.exe",
"PerUserRedirection": "true",
"Profile": "true",
"ProfileGuidedDatabase": "$(TargetDir)$(TargetName).pgdd",
"ProgramDatabaseFile": "Flob.pdb",
"RandomizedBaseAddress": "1",
"RegisterOutput": "true",
"ResourceOnlyDLL": "true",
"SetChecksum": "false",
"ShowProgress": "1",
"StackCommitSize": "15",
"StackReserveSize": "14",
"StripPrivateSymbols": "d3",
"SubSystem": "1",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "false",
"SwapRunFromCD": "true",
"SwapRunFromNet": "true",
"TargetMachine": "1",
"TerminalServerAware": "1",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "f3",
"TypeLibraryResourceID": "12",
"UACExecutionLevel": "2",
"UACUIAccess": "true",
"UseLibraryDependencyInputs": "true",
"UseUnicodeResponseFiles": "false",
"Version": "333",
},
"VCResourceCompilerTool": {
"AdditionalIncludeDirectories": "f3",
"AdditionalOptions": "/more3",
"Culture": "3084",
"IgnoreStandardIncludePath": "true",
"PreprocessorDefinitions": "_UNICODE;UNICODE2",
"ResourceOutputFileName": "$(IntDir)/$(InputName)3.res",
"ShowProgress": "true",
},
"VCManifestTool": {
"AdditionalManifestFiles": "sfsdfsd",
"AdditionalOptions": "afdsdafsd",
"AssemblyIdentity": "sddfdsadfsa",
"ComponentFileName": "fsdfds",
"DependencyInformationFile": "$(IntDir)\\mt.depdfd",
"EmbedManifest": "false",
"GenerateCatalogFiles": "true",
"InputResourceManifests": "asfsfdafs",
"ManifestResourceFile":
"$(IntDir)\\$(TargetFileName).embed.manifest.resfdsf",
"OutputManifestFile": "$(TargetPath).manifestdfs",
"RegistrarScriptFile": "sdfsfd",
"ReplacementsFile": "sdffsd",
"SuppressStartupBanner": "false",
"TypeLibraryFile": "sfsd",
"UpdateFileHashes": "true",
"UpdateFileHashesSearchPath": "sfsd",
"UseFAT32Workaround": "true",
"UseUnicodeResponseFiles": "false",
"VerboseOutput": "true",
},
}
expected_msbuild_settings = {
"ClCompile": {
"AdditionalIncludeDirectories": "dir1",
"AdditionalOptions": "/more /J",
"AdditionalUsingDirectories": "test",
"AssemblerListingLocation": "$(IntDir)a",
"AssemblerOutput": "AssemblyCode",
"BasicRuntimeChecks": "EnableFastChecks",
"BrowseInformation": "true",
"BrowseInformationFile": "$(IntDir)e",
"BufferSecurityCheck": "false",
"CallingConvention": "FastCall",
"CompileAs": "CompileAsC",
"DebugInformationFormat": "EditAndContinue",
"DisableLanguageExtensions": "true",
"DisableSpecificWarnings": "abc",
"EnableEnhancedInstructionSet": "StreamingSIMDExtensions",
"EnableFiberSafeOptimizations": "true",
"EnablePREfast": "true",
"ErrorReporting": "Queue",
"ExceptionHandling": "Async",
"ExpandAttributedSource": "true",
"FavorSizeOrSpeed": "Size",
"FloatingPointExceptions": "true",
"FloatingPointModel": "Strict",
"ForceConformanceInForLoopScope": "false",
"ForcedIncludeFiles": "def",
"ForcedUsingFiles": "ge",
"FunctionLevelLinking": "true",
"GenerateXMLDocumentationFiles": "true",
"IgnoreStandardIncludePath": "true",
"InlineFunctionExpansion": "OnlyExplicitInline",
"IntrinsicFunctions": "true",
"MinimalRebuild": "true",
"ObjectFileName": "$(IntDir)b",
"OmitDefaultLibName": "true",
"OmitFramePointers": "true",
"OpenMPSupport": "true",
"Optimization": "Full",
"PrecompiledHeader": "NotUsing", # Actual conversion gives ''
"PrecompiledHeaderFile": "StdAfx.hd",
"PrecompiledHeaderOutputFile": "$(IntDir)$(TargetName).pche",
"PreprocessKeepComments": "true",
"PreprocessorDefinitions": "WIN32;_DEBUG;_CONSOLE",
"PreprocessSuppressLineNumbers": "true",
"PreprocessToFile": "true",
"ProgramDataBaseFileName": "$(IntDir)vc90b.pdb",
"RuntimeLibrary": "MultiThreadedDebugDLL",
"RuntimeTypeInfo": "false",
"ShowIncludes": "true",
"SmallerTypeCheck": "true",
"StringPooling": "true",
"StructMemberAlignment": "4Bytes",
"SuppressStartupBanner": "false",
"TreatWarningAsError": "true",
"TreatWChar_tAsBuiltInType": "false",
"UndefineAllPreprocessorDefinitions": "true",
"UndefinePreprocessorDefinitions": "wer",
"UseFullPaths": "true",
"WarningLevel": "Level3",
"WholeProgramOptimization": "true",
"XMLDocumentationFileName": "$(IntDir)c",
},
"Link": {
"AdditionalDependencies": "zx",
"AdditionalLibraryDirectories": "asd",
"AdditionalManifestDependencies": "s2",
"AdditionalOptions": "/mor2",
"AddModuleNamesToAssembly": "d1",
"AllowIsolation": "false",
"AssemblyDebug": "true",
"AssemblyLinkResource": "d5",
"BaseAddress": "23423",
"CLRImageType": "ForceSafeILImage",
"CLRThreadAttribute": "MTAThreadingAttribute",
"CLRUnmanagedCodeCheck": "true",
"DataExecutionPrevention": "",
"DelayLoadDLLs": "d4",
"DelaySign": "true",
"Driver": "UpOnly",
"EmbedManagedResourceFile": "d2",
"EnableCOMDATFolding": "false",
"EnableUAC": "false",
"EntryPointSymbol": "f5",
"FixedBaseAddress": "false",
"ForceSymbolReferences": "d3",
"FunctionOrder": "fssdfsd",
"GenerateDebugInformation": "true",
"GenerateMapFile": "true",
"HeapCommitSize": "13",
"HeapReserveSize": "12",
"IgnoreAllDefaultLibraries": "true",
"IgnoreEmbeddedIDL": "true",
"IgnoreSpecificDefaultLibraries": "flob;flok",
"ImportLibrary": "f4",
"KeyContainer": "f7",
"KeyFile": "f6",
"LargeAddressAware": "true",
"LinkErrorReporting": "QueueForNextLogin",
"LinkTimeCodeGeneration": "UseLinkTimeCodeGeneration",
"ManifestFile": "$(IntDir)$(TargetFileName).2intermediate.manifest",
"MapExports": "true",
"MapFileName": "d5",
"MergedIDLBaseFileName": "f2",
"MergeSections": "f5",
"MidlCommandFile": "f1",
"ModuleDefinitionFile": "sdsd",
"NoEntryPoint": "true",
"OptimizeReferences": "true",
"OutputFile": "$(OutDir)$(ProjectName)2.exe",
"PerUserRedirection": "true",
"Profile": "true",
"ProfileGuidedDatabase": "$(TargetDir)$(TargetName).pgdd",
"ProgramDatabaseFile": "Flob.pdb",
"RandomizedBaseAddress": "false",
"RegisterOutput": "true",
"SetChecksum": "false",
"ShowProgress": "LinkVerbose",
"StackCommitSize": "15",
"StackReserveSize": "14",
"StripPrivateSymbols": "d3",
"SubSystem": "Console",
"SupportUnloadOfDelayLoadedDLL": "true",
"SuppressStartupBanner": "false",
"SwapRunFromCD": "true",
"SwapRunFromNET": "true",
"TargetMachine": "MachineX86",
"TerminalServerAware": "false",
"TurnOffAssemblyGeneration": "true",
"TypeLibraryFile": "f3",
"TypeLibraryResourceID": "12",
"UACExecutionLevel": "RequireAdministrator",
"UACUIAccess": "true",
"Version": "333",
},
"ResourceCompile": {
"AdditionalIncludeDirectories": "f3",
"AdditionalOptions": "/more3",
"Culture": "0x0c0c",
"IgnoreStandardIncludePath": "true",
"PreprocessorDefinitions": "_UNICODE;UNICODE2",
"ResourceOutputFileName": "$(IntDir)%(Filename)3.res",
"ShowProgress": "true",
},
"Manifest": {
"AdditionalManifestFiles": "sfsdfsd",
"AdditionalOptions": "afdsdafsd",
"AssemblyIdentity": "sddfdsadfsa",
"ComponentFileName": "fsdfds",
"GenerateCatalogFiles": "true",
"InputResourceManifests": "asfsfdafs",
"OutputManifestFile": "$(TargetPath).manifestdfs",
"RegistrarScriptFile": "sdfsfd",
"ReplacementsFile": "sdffsd",
"SuppressStartupBanner": "false",
"TypeLibraryFile": "sfsd",
"UpdateFileHashes": "true",
"UpdateFileHashesSearchPath": "sfsd",
"VerboseOutput": "true",
},
"ProjectReference": {
"LinkLibraryDependencies": "false",
"UseLibraryDependencyInputs": "true",
},
"": {
"EmbedManifest": "false",
"GenerateManifest": "false",
"IgnoreImportLibrary": "true",
"LinkIncremental": "",
},
"ManifestResourceCompile": {
"ResourceOutputFileName":
"$(IntDir)$(TargetFileName).embed.manifest.resfdsf"
},
}
self.maxDiff = 9999 # on failure display a long diff
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings, self.stderr
)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/MSVSToolFile.py 0000664 0000000 0000000 00000003375 14321173220 0020565 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Visual Studio project reader/writer."""
import gyp.easy_xml as easy_xml
class Writer:
"""Visual Studio XML tool file writer."""
def __init__(self, tool_file_path, name):
"""Initializes the tool file.
Args:
tool_file_path: Path to the tool file.
name: Name of the tool file.
"""
self.tool_file_path = tool_file_path
self.name = name
self.rules_section = ["Rules"]
def AddCustomBuildRule(
self, name, cmd, description, additional_dependencies, outputs, extensions
):
"""Adds a rule to the tool file.
Args:
name: Name of the rule.
description: Description of the rule.
cmd: Command line of the rule.
additional_dependencies: other files which may trigger the rule.
outputs: outputs of the rule.
extensions: extensions handled by the rule.
"""
rule = [
"CustomBuildRule",
{
"Name": name,
"ExecutionDescription": description,
"CommandLine": cmd,
"Outputs": ";".join(outputs),
"FileExtensions": ";".join(extensions),
"AdditionalDependencies": ";".join(additional_dependencies),
},
]
self.rules_section.append(rule)
def WriteIfChanged(self):
"""Writes the tool file."""
content = [
"VisualStudioToolFile",
{"Version": "8.00", "Name": self.name},
self.rules_section,
]
easy_xml.WriteXmlIfChanged(
content, self.tool_file_path, encoding="Windows-1252"
)
node-gyp-9.3.0/gyp/pylib/gyp/MSVSUserFile.py 0000664 0000000 0000000 00000012325 14321173220 0020561 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Visual Studio user preferences file writer."""
import os
import re
import socket # for gethostname
import gyp.easy_xml as easy_xml
# ------------------------------------------------------------------------------
def _FindCommandInPath(command):
"""If there are no slashes in the command given, this function
searches the PATH env to find the given command, and converts it
to an absolute path. We have to do this because MSVS is looking
for an actual file to launch a debugger on, not just a command
line. Note that this happens at GYP time, so anything needing to
be built needs to have a full path."""
if "/" in command or "\\" in command:
# If the command already has path elements (either relative or
# absolute), then assume it is constructed properly.
return command
else:
# Search through the path list and find an existing file that
# we can access.
paths = os.environ.get("PATH", "").split(os.pathsep)
for path in paths:
item = os.path.join(path, command)
if os.path.isfile(item) and os.access(item, os.X_OK):
return item
return command
def _QuoteWin32CommandLineArgs(args):
new_args = []
for arg in args:
# Replace all double-quotes with double-double-quotes to escape
# them for cmd shell, and then quote the whole thing if there
# are any.
if arg.find('"') != -1:
arg = '""'.join(arg.split('"'))
arg = '"%s"' % arg
# Otherwise, if there are any spaces, quote the whole arg.
elif re.search(r"[ \t\n]", arg):
arg = '"%s"' % arg
new_args.append(arg)
return new_args
class Writer:
"""Visual Studio XML user user file writer."""
def __init__(self, user_file_path, version, name):
"""Initializes the user file.
Args:
user_file_path: Path to the user file.
version: Version info.
name: Name of the user file.
"""
self.user_file_path = user_file_path
self.version = version
self.name = name
self.configurations = {}
def AddConfig(self, name):
"""Adds a configuration to the project.
Args:
name: Configuration name.
"""
self.configurations[name] = ["Configuration", {"Name": name}]
def AddDebugSettings(
self, config_name, command, environment={}, working_directory=""
):
"""Adds a DebugSettings node to the user file for a particular config.
Args:
command: command line to run. First element in the list is the
executable. All elements of the command will be quoted if
necessary.
working_directory: other files which may trigger the rule. (optional)
"""
command = _QuoteWin32CommandLineArgs(command)
abs_command = _FindCommandInPath(command[0])
if environment and isinstance(environment, dict):
env_list = [f'{key}="{val}"' for (key, val) in environment.items()]
environment = " ".join(env_list)
else:
environment = ""
n_cmd = [
"DebugSettings",
{
"Command": abs_command,
"WorkingDirectory": working_directory,
"CommandArguments": " ".join(command[1:]),
"RemoteMachine": socket.gethostname(),
"Environment": environment,
"EnvironmentMerge": "true",
# Currently these are all "dummy" values that we're just setting
# in the default manner that MSVS does it. We could use some of
# these to add additional capabilities, I suppose, but they might
# not have parity with other platforms then.
"Attach": "false",
"DebuggerType": "3", # 'auto' debugger
"Remote": "1",
"RemoteCommand": "",
"HttpUrl": "",
"PDBPath": "",
"SQLDebugging": "",
"DebuggerFlavor": "0",
"MPIRunCommand": "",
"MPIRunArguments": "",
"MPIRunWorkingDirectory": "",
"ApplicationCommand": "",
"ApplicationArguments": "",
"ShimCommand": "",
"MPIAcceptMode": "",
"MPIAcceptFilter": "",
},
]
# Find the config, and add it if it doesn't exist.
if config_name not in self.configurations:
self.AddConfig(config_name)
# Add the DebugSettings onto the appropriate config.
self.configurations[config_name].append(n_cmd)
def WriteIfChanged(self):
"""Writes the user file."""
configs = ["Configurations"]
for config, spec in sorted(self.configurations.items()):
configs.append(spec)
content = [
"VisualStudioUserFile",
{"Version": self.version.ProjectVersion(), "Name": self.name},
configs,
]
easy_xml.WriteXmlIfChanged(
content, self.user_file_path, encoding="Windows-1252"
)
node-gyp-9.3.0/gyp/pylib/gyp/MSVSUtil.py 0000664 0000000 0000000 00000023767 14321173220 0017774 0 ustar 00root root 0000000 0000000 # Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utility functions shared amongst the Windows generators."""
import copy
import os
# A dictionary mapping supported target types to extensions.
TARGET_TYPE_EXT = {
"executable": "exe",
"loadable_module": "dll",
"shared_library": "dll",
"static_library": "lib",
"windows_driver": "sys",
}
def _GetLargePdbShimCcPath():
"""Returns the path of the large_pdb_shim.cc file."""
this_dir = os.path.abspath(os.path.dirname(__file__))
src_dir = os.path.abspath(os.path.join(this_dir, "..", ".."))
win_data_dir = os.path.join(src_dir, "data", "win")
large_pdb_shim_cc = os.path.join(win_data_dir, "large-pdb-shim.cc")
return large_pdb_shim_cc
def _DeepCopySomeKeys(in_dict, keys):
"""Performs a partial deep-copy on |in_dict|, only copying the keys in |keys|.
Arguments:
in_dict: The dictionary to copy.
keys: The keys to be copied. If a key is in this list and doesn't exist in
|in_dict| this is not an error.
Returns:
The partially deep-copied dictionary.
"""
d = {}
for key in keys:
if key not in in_dict:
continue
d[key] = copy.deepcopy(in_dict[key])
return d
def _SuffixName(name, suffix):
"""Add a suffix to the end of a target.
Arguments:
name: name of the target (foo#target)
suffix: the suffix to be added
Returns:
Target name with suffix added (foo_suffix#target)
"""
parts = name.rsplit("#", 1)
parts[0] = f"{parts[0]}_{suffix}"
return "#".join(parts)
def _ShardName(name, number):
"""Add a shard number to the end of a target.
Arguments:
name: name of the target (foo#target)
number: shard number
Returns:
Target name with shard added (foo_1#target)
"""
return _SuffixName(name, str(number))
def ShardTargets(target_list, target_dicts):
"""Shard some targets apart to work around the linkers limits.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
Returns:
Tuple of the new sharded versions of the inputs.
"""
# Gather the targets to shard, and how many pieces.
targets_to_shard = {}
for t in target_dicts:
shards = int(target_dicts[t].get("msvs_shard", 0))
if shards:
targets_to_shard[t] = shards
# Shard target_list.
new_target_list = []
for t in target_list:
if t in targets_to_shard:
for i in range(targets_to_shard[t]):
new_target_list.append(_ShardName(t, i))
else:
new_target_list.append(t)
# Shard target_dict.
new_target_dicts = {}
for t in target_dicts:
if t in targets_to_shard:
for i in range(targets_to_shard[t]):
name = _ShardName(t, i)
new_target_dicts[name] = copy.copy(target_dicts[t])
new_target_dicts[name]["target_name"] = _ShardName(
new_target_dicts[name]["target_name"], i
)
sources = new_target_dicts[name].get("sources", [])
new_sources = []
for pos in range(i, len(sources), targets_to_shard[t]):
new_sources.append(sources[pos])
new_target_dicts[name]["sources"] = new_sources
else:
new_target_dicts[t] = target_dicts[t]
# Shard dependencies.
for t in sorted(new_target_dicts):
for deptype in ("dependencies", "dependencies_original"):
dependencies = copy.copy(new_target_dicts[t].get(deptype, []))
new_dependencies = []
for d in dependencies:
if d in targets_to_shard:
for i in range(targets_to_shard[d]):
new_dependencies.append(_ShardName(d, i))
else:
new_dependencies.append(d)
new_target_dicts[t][deptype] = new_dependencies
return (new_target_list, new_target_dicts)
def _GetPdbPath(target_dict, config_name, vars):
"""Returns the path to the PDB file that will be generated by a given
configuration.
The lookup proceeds as follows:
- Look for an explicit path in the VCLinkerTool configuration block.
- Look for an 'msvs_large_pdb_path' variable.
- Use '<(PRODUCT_DIR)/<(product_name).(exe|dll).pdb' if 'product_name' is
specified.
- Use '<(PRODUCT_DIR)/<(target_name).(exe|dll).pdb'.
Arguments:
target_dict: The target dictionary to be searched.
config_name: The name of the configuration of interest.
vars: A dictionary of common GYP variables with generator-specific values.
Returns:
The path of the corresponding PDB file.
"""
config = target_dict["configurations"][config_name]
msvs = config.setdefault("msvs_settings", {})
linker = msvs.get("VCLinkerTool", {})
pdb_path = linker.get("ProgramDatabaseFile")
if pdb_path:
return pdb_path
variables = target_dict.get("variables", {})
pdb_path = variables.get("msvs_large_pdb_path", None)
if pdb_path:
return pdb_path
pdb_base = target_dict.get("product_name", target_dict["target_name"])
pdb_base = "{}.{}.pdb".format(pdb_base, TARGET_TYPE_EXT[target_dict["type"]])
pdb_path = vars["PRODUCT_DIR"] + "/" + pdb_base
return pdb_path
def InsertLargePdbShims(target_list, target_dicts, vars):
"""Insert a shim target that forces the linker to use 4KB pagesize PDBs.
This is a workaround for targets with PDBs greater than 1GB in size, the
limit for the 1KB pagesize PDBs created by the linker by default.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
vars: A dictionary of common GYP variables with generator-specific values.
Returns:
Tuple of the shimmed version of the inputs.
"""
# Determine which targets need shimming.
targets_to_shim = []
for t in target_dicts:
target_dict = target_dicts[t]
# We only want to shim targets that have msvs_large_pdb enabled.
if not int(target_dict.get("msvs_large_pdb", 0)):
continue
# This is intended for executable, shared_library and loadable_module
# targets where every configuration is set up to produce a PDB output.
# If any of these conditions is not true then the shim logic will fail
# below.
targets_to_shim.append(t)
large_pdb_shim_cc = _GetLargePdbShimCcPath()
for t in targets_to_shim:
target_dict = target_dicts[t]
target_name = target_dict.get("target_name")
base_dict = _DeepCopySomeKeys(
target_dict, ["configurations", "default_configuration", "toolset"]
)
# This is the dict for copying the source file (part of the GYP tree)
# to the intermediate directory of the project. This is necessary because
# we can't always build a relative path to the shim source file (on Windows
# GYP and the project may be on different drives), and Ninja hates absolute
# paths (it ends up generating the .obj and .obj.d alongside the source
# file, polluting GYPs tree).
copy_suffix = "large_pdb_copy"
copy_target_name = target_name + "_" + copy_suffix
full_copy_target_name = _SuffixName(t, copy_suffix)
shim_cc_basename = os.path.basename(large_pdb_shim_cc)
shim_cc_dir = vars["SHARED_INTERMEDIATE_DIR"] + "/" + copy_target_name
shim_cc_path = shim_cc_dir + "/" + shim_cc_basename
copy_dict = copy.deepcopy(base_dict)
copy_dict["target_name"] = copy_target_name
copy_dict["type"] = "none"
copy_dict["sources"] = [large_pdb_shim_cc]
copy_dict["copies"] = [
{"destination": shim_cc_dir, "files": [large_pdb_shim_cc]}
]
# This is the dict for the PDB generating shim target. It depends on the
# copy target.
shim_suffix = "large_pdb_shim"
shim_target_name = target_name + "_" + shim_suffix
full_shim_target_name = _SuffixName(t, shim_suffix)
shim_dict = copy.deepcopy(base_dict)
shim_dict["target_name"] = shim_target_name
shim_dict["type"] = "static_library"
shim_dict["sources"] = [shim_cc_path]
shim_dict["dependencies"] = [full_copy_target_name]
# Set up the shim to output its PDB to the same location as the final linker
# target.
for config_name, config in shim_dict.get("configurations").items():
pdb_path = _GetPdbPath(target_dict, config_name, vars)
# A few keys that we don't want to propagate.
for key in ["msvs_precompiled_header", "msvs_precompiled_source", "test"]:
config.pop(key, None)
msvs = config.setdefault("msvs_settings", {})
# Update the compiler directives in the shim target.
compiler = msvs.setdefault("VCCLCompilerTool", {})
compiler["DebugInformationFormat"] = "3"
compiler["ProgramDataBaseFileName"] = pdb_path
# Set the explicit PDB path in the appropriate configuration of the
# original target.
config = target_dict["configurations"][config_name]
msvs = config.setdefault("msvs_settings", {})
linker = msvs.setdefault("VCLinkerTool", {})
linker["GenerateDebugInformation"] = "true"
linker["ProgramDatabaseFile"] = pdb_path
# Add the new targets. They must go to the beginning of the list so that
# the dependency generation works as expected in ninja.
target_list.insert(0, full_copy_target_name)
target_list.insert(0, full_shim_target_name)
target_dicts[full_copy_target_name] = copy_dict
target_dicts[full_shim_target_name] = shim_dict
# Update the original target to depend on the shim target.
target_dict.setdefault("dependencies", []).append(full_shim_target_name)
return (target_list, target_dicts)
node-gyp-9.3.0/gyp/pylib/gyp/MSVSVersion.py 0000664 0000000 0000000 00000046436 14321173220 0020502 0 ustar 00root root 0000000 0000000 # Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Handle version information related to Visual Stuio."""
import errno
import os
import re
import subprocess
import sys
import glob
def JoinPath(*args):
return os.path.normpath(os.path.join(*args))
class VisualStudioVersion:
"""Information regarding a version of Visual Studio."""
def __init__(
self,
short_name,
description,
solution_version,
project_version,
flat_sln,
uses_vcxproj,
path,
sdk_based,
default_toolset=None,
compatible_sdks=None,
):
self.short_name = short_name
self.description = description
self.solution_version = solution_version
self.project_version = project_version
self.flat_sln = flat_sln
self.uses_vcxproj = uses_vcxproj
self.path = path
self.sdk_based = sdk_based
self.default_toolset = default_toolset
compatible_sdks = compatible_sdks or []
compatible_sdks.sort(key=lambda v: float(v.replace("v", "")), reverse=True)
self.compatible_sdks = compatible_sdks
def ShortName(self):
return self.short_name
def Description(self):
"""Get the full description of the version."""
return self.description
def SolutionVersion(self):
"""Get the version number of the sln files."""
return self.solution_version
def ProjectVersion(self):
"""Get the version number of the vcproj or vcxproj files."""
return self.project_version
def FlatSolution(self):
return self.flat_sln
def UsesVcxproj(self):
"""Returns true if this version uses a vcxproj file."""
return self.uses_vcxproj
def ProjectExtension(self):
"""Returns the file extension for the project."""
return self.uses_vcxproj and ".vcxproj" or ".vcproj"
def Path(self):
"""Returns the path to Visual Studio installation."""
return self.path
def ToolPath(self, tool):
"""Returns the path to a given compiler tool. """
return os.path.normpath(os.path.join(self.path, "VC/bin", tool))
def DefaultToolset(self):
"""Returns the msbuild toolset version that will be used in the absence
of a user override."""
return self.default_toolset
def _SetupScriptInternal(self, target_arch):
"""Returns a command (with arguments) to be used to set up the
environment."""
assert target_arch in ("x86", "x64"), "target_arch not supported"
# If WindowsSDKDir is set and SetEnv.Cmd exists then we are using the
# depot_tools build tools and should run SetEnv.Cmd to set up the
# environment. The check for WindowsSDKDir alone is not sufficient because
# this is set by running vcvarsall.bat.
sdk_dir = os.environ.get("WindowsSDKDir", "")
setup_path = JoinPath(sdk_dir, "Bin", "SetEnv.Cmd")
if self.sdk_based and sdk_dir and os.path.exists(setup_path):
return [setup_path, "/" + target_arch]
is_host_arch_x64 = (
os.environ.get("PROCESSOR_ARCHITECTURE") == "AMD64"
or os.environ.get("PROCESSOR_ARCHITEW6432") == "AMD64"
)
# For VS2017 (and newer) it's fairly easy
if self.short_name >= "2017":
script_path = JoinPath(
self.path, "VC", "Auxiliary", "Build", "vcvarsall.bat"
)
# Always use a native executable, cross-compiling if necessary.
host_arch = "amd64" if is_host_arch_x64 else "x86"
msvc_target_arch = "amd64" if target_arch == "x64" else "x86"
arg = host_arch
if host_arch != msvc_target_arch:
arg += "_" + msvc_target_arch
return [script_path, arg]
# We try to find the best version of the env setup batch.
vcvarsall = JoinPath(self.path, "VC", "vcvarsall.bat")
if target_arch == "x86":
if (
self.short_name >= "2013"
and self.short_name[-1] != "e"
and is_host_arch_x64
):
# VS2013 and later, non-Express have a x64-x86 cross that we want
# to prefer.
return [vcvarsall, "amd64_x86"]
else:
# Otherwise, the standard x86 compiler. We don't use VC/vcvarsall.bat
# for x86 because vcvarsall calls vcvars32, which it can only find if
# VS??COMNTOOLS is set, which isn't guaranteed.
return [JoinPath(self.path, "Common7", "Tools", "vsvars32.bat")]
elif target_arch == "x64":
arg = "x86_amd64"
# Use the 64-on-64 compiler if we're not using an express edition and
# we're running on a 64bit OS.
if self.short_name[-1] != "e" and is_host_arch_x64:
arg = "amd64"
return [vcvarsall, arg]
def SetupScript(self, target_arch):
script_data = self._SetupScriptInternal(target_arch)
script_path = script_data[0]
if not os.path.exists(script_path):
raise Exception(
"%s is missing - make sure VC++ tools are installed." % script_path
)
return script_data
def _RegistryQueryBase(sysdir, key, value):
"""Use reg.exe to read a particular key.
While ideally we might use the win32 module, we would like gyp to be
python neutral, so for instance cygwin python lacks this module.
Arguments:
sysdir: The system subdirectory to attempt to launch reg.exe from.
key: The registry key to read from.
value: The particular value to read.
Return:
stdout from reg.exe, or None for failure.
"""
# Skip if not on Windows or Python Win32 setup issue
if sys.platform not in ("win32", "cygwin"):
return None
# Setup params to pass to and attempt to launch reg.exe
cmd = [os.path.join(os.environ.get("WINDIR", ""), sysdir, "reg.exe"), "query", key]
if value:
cmd.extend(["/v", value])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Obtain the stdout from reg.exe, reading to the end so p.returncode is valid
# Note that the error text may be in [1] in some cases
text = p.communicate()[0].decode("utf-8")
# Check return code from reg.exe; officially 0==success and 1==error
if p.returncode:
return None
return text
def _RegistryQuery(key, value=None):
r"""Use reg.exe to read a particular key through _RegistryQueryBase.
First tries to launch from %WinDir%\Sysnative to avoid WoW64 redirection. If
that fails, it falls back to System32. Sysnative is available on Vista and
up and available on Windows Server 2003 and XP through KB patch 942589. Note
that Sysnative will always fail if using 64-bit python due to it being a
virtual directory and System32 will work correctly in the first place.
KB 942589 - http://support.microsoft.com/kb/942589/en-us.
Arguments:
key: The registry key.
value: The particular registry value to read (optional).
Return:
stdout from reg.exe, or None for failure.
"""
text = None
try:
text = _RegistryQueryBase("Sysnative", key, value)
except OSError as e:
if e.errno == errno.ENOENT:
text = _RegistryQueryBase("System32", key, value)
else:
raise
return text
def _RegistryGetValueUsingWinReg(key, value):
"""Use the _winreg module to obtain the value of a registry key.
Args:
key: The registry key.
value: The particular registry value to read.
Return:
contents of the registry key's value, or None on failure. Throws
ImportError if winreg is unavailable.
"""
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
try:
root, subkey = key.split("\\", 1)
assert root == "HKLM" # Only need HKLM for now.
with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey:
return QueryValueEx(hkey, value)[0]
except OSError:
return None
def _RegistryGetValue(key, value):
"""Use _winreg or reg.exe to obtain the value of a registry key.
Using _winreg is preferable because it solves an issue on some corporate
environments where access to reg.exe is locked down. However, we still need
to fallback to reg.exe for the case where the _winreg module is not available
(for example in cygwin python).
Args:
key: The registry key.
value: The particular registry value to read.
Return:
contents of the registry key's value, or None on failure.
"""
try:
return _RegistryGetValueUsingWinReg(key, value)
except ImportError:
pass
# Fallback to reg.exe if we fail to import _winreg.
text = _RegistryQuery(key, value)
if not text:
return None
# Extract value.
match = re.search(r"REG_\w+\s+([^\r]+)\r\n", text)
if not match:
return None
return match.group(1)
def _CreateVersion(name, path, sdk_based=False):
"""Sets up MSVS project generation.
Setup is based off the GYP_MSVS_VERSION environment variable or whatever is
autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is
passed in that doesn't match a value in versions python will throw a error.
"""
if path:
path = os.path.normpath(path)
versions = {
"2022": VisualStudioVersion(
"2022",
"Visual Studio 2022",
solution_version="12.00",
project_version="17.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v143",
compatible_sdks=["v8.1", "v10.0"],
),
"2019": VisualStudioVersion(
"2019",
"Visual Studio 2019",
solution_version="12.00",
project_version="16.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v142",
compatible_sdks=["v8.1", "v10.0"],
),
"2017": VisualStudioVersion(
"2017",
"Visual Studio 2017",
solution_version="12.00",
project_version="15.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v141",
compatible_sdks=["v8.1", "v10.0"],
),
"2015": VisualStudioVersion(
"2015",
"Visual Studio 2015",
solution_version="12.00",
project_version="14.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v140",
),
"2013": VisualStudioVersion(
"2013",
"Visual Studio 2013",
solution_version="13.00",
project_version="12.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v120",
),
"2013e": VisualStudioVersion(
"2013e",
"Visual Studio 2013",
solution_version="13.00",
project_version="12.0",
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v120",
),
"2012": VisualStudioVersion(
"2012",
"Visual Studio 2012",
solution_version="12.00",
project_version="4.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v110",
),
"2012e": VisualStudioVersion(
"2012e",
"Visual Studio 2012",
solution_version="12.00",
project_version="4.0",
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset="v110",
),
"2010": VisualStudioVersion(
"2010",
"Visual Studio 2010",
solution_version="11.00",
project_version="4.0",
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
),
"2010e": VisualStudioVersion(
"2010e",
"Visual C++ Express 2010",
solution_version="11.00",
project_version="4.0",
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
),
"2008": VisualStudioVersion(
"2008",
"Visual Studio 2008",
solution_version="10.00",
project_version="9.00",
flat_sln=False,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based,
),
"2008e": VisualStudioVersion(
"2008e",
"Visual Studio 2008",
solution_version="10.00",
project_version="9.00",
flat_sln=True,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based,
),
"2005": VisualStudioVersion(
"2005",
"Visual Studio 2005",
solution_version="9.00",
project_version="8.00",
flat_sln=False,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based,
),
"2005e": VisualStudioVersion(
"2005e",
"Visual Studio 2005",
solution_version="9.00",
project_version="8.00",
flat_sln=True,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based,
),
}
return versions[str(name)]
def _ConvertToCygpath(path):
"""Convert to cygwin path if we are using cygwin."""
if sys.platform == "cygwin":
p = subprocess.Popen(["cygpath", path], stdout=subprocess.PIPE)
path = p.communicate()[0].decode("utf-8").strip()
return path
def _DetectVisualStudioVersions(versions_to_check, force_express):
"""Collect the list of installed visual studio versions.
Returns:
A list of visual studio versions installed in descending order of
usage preference.
Base this on the registry and a quick check if devenv.exe exists.
Possibilities are:
2005(e) - Visual Studio 2005 (8)
2008(e) - Visual Studio 2008 (9)
2010(e) - Visual Studio 2010 (10)
2012(e) - Visual Studio 2012 (11)
2013(e) - Visual Studio 2013 (12)
2015 - Visual Studio 2015 (14)
2017 - Visual Studio 2017 (15)
2019 - Visual Studio 2019 (16)
2022 - Visual Studio 2022 (17)
Where (e) is e for express editions of MSVS and blank otherwise.
"""
version_to_year = {
"8.0": "2005",
"9.0": "2008",
"10.0": "2010",
"11.0": "2012",
"12.0": "2013",
"14.0": "2015",
"15.0": "2017",
"16.0": "2019",
"17.0": "2022",
}
versions = []
for version in versions_to_check:
# Old method of searching for which VS version is installed
# We don't use the 2010-encouraged-way because we also want to get the
# path to the binaries, which it doesn't offer.
keys = [
r"HKLM\Software\Microsoft\VisualStudio\%s" % version,
r"HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s" % version,
r"HKLM\Software\Microsoft\VCExpress\%s" % version,
r"HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s" % version,
]
for index in range(len(keys)):
path = _RegistryGetValue(keys[index], "InstallDir")
if not path:
continue
path = _ConvertToCygpath(path)
# Check for full.
full_path = os.path.join(path, "devenv.exe")
express_path = os.path.join(path, "*express.exe")
if not force_express and os.path.exists(full_path):
# Add this one.
versions.append(
_CreateVersion(
version_to_year[version], os.path.join(path, "..", "..")
)
)
# Check for express.
elif glob.glob(express_path):
# Add this one.
versions.append(
_CreateVersion(
version_to_year[version] + "e", os.path.join(path, "..", "..")
)
)
# The old method above does not work when only SDK is installed.
keys = [
r"HKLM\Software\Microsoft\VisualStudio\SxS\VC7",
r"HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7",
r"HKLM\Software\Microsoft\VisualStudio\SxS\VS7",
r"HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7",
]
for index in range(len(keys)):
path = _RegistryGetValue(keys[index], version)
if not path:
continue
path = _ConvertToCygpath(path)
if version == "15.0":
if os.path.exists(path):
versions.append(_CreateVersion("2017", path))
elif version != "14.0": # There is no Express edition for 2015.
versions.append(
_CreateVersion(
version_to_year[version] + "e",
os.path.join(path, ".."),
sdk_based=True,
)
)
return versions
def SelectVisualStudioVersion(version="auto", allow_fallback=True):
"""Select which version of Visual Studio projects to generate.
Arguments:
version: Hook to allow caller to force a particular version (vs auto).
Returns:
An object representing a visual studio project format version.
"""
# In auto mode, check environment variable for override.
if version == "auto":
version = os.environ.get("GYP_MSVS_VERSION", "auto")
version_map = {
"auto": ("17.0", "16.0", "15.0", "14.0", "12.0", "10.0", "9.0", "8.0", "11.0"),
"2005": ("8.0",),
"2005e": ("8.0",),
"2008": ("9.0",),
"2008e": ("9.0",),
"2010": ("10.0",),
"2010e": ("10.0",),
"2012": ("11.0",),
"2012e": ("11.0",),
"2013": ("12.0",),
"2013e": ("12.0",),
"2015": ("14.0",),
"2017": ("15.0",),
"2019": ("16.0",),
"2022": ("17.0",),
}
override_path = os.environ.get("GYP_MSVS_OVERRIDE_PATH")
if override_path:
msvs_version = os.environ.get("GYP_MSVS_VERSION")
if not msvs_version:
raise ValueError(
"GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be "
"set to a particular version (e.g. 2010e)."
)
return _CreateVersion(msvs_version, override_path, sdk_based=True)
version = str(version)
versions = _DetectVisualStudioVersions(version_map[version], "e" in version)
if not versions:
if not allow_fallback:
raise ValueError("Could not locate Visual Studio installation.")
if version == "auto":
# Default to 2005 if we couldn't find anything
return _CreateVersion("2005", None)
else:
return _CreateVersion(version, None)
return versions[0]
node-gyp-9.3.0/gyp/pylib/gyp/__init__.py 0000775 0000000 0000000 00000057040 14321173220 0020077 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import gyp.input
import argparse
import os.path
import re
import shlex
import sys
import traceback
from gyp.common import GypError
# Default debug modes for GYP
debug = {}
# List of "official" debug modes, but you can use anything you like.
DEBUG_GENERAL = "general"
DEBUG_VARIABLES = "variables"
DEBUG_INCLUDES = "includes"
def DebugOutput(mode, message, *args):
if "all" in gyp.debug or mode in gyp.debug:
ctx = ("unknown", 0, "unknown")
try:
f = traceback.extract_stack(limit=2)
if f:
ctx = f[0][:3]
except Exception:
pass
if args:
message %= args
print(
"%s:%s:%d:%s %s"
% (mode.upper(), os.path.basename(ctx[0]), ctx[1], ctx[2], message)
)
def FindBuildFiles():
extension = ".gyp"
files = os.listdir(os.getcwd())
build_files = []
for file in files:
if file.endswith(extension):
build_files.append(file)
return build_files
def Load(
build_files,
format,
default_variables={},
includes=[],
depth=".",
params=None,
check=False,
circular_check=True,
):
"""
Loads one or more specified build files.
default_variables and includes will be copied before use.
Returns the generator for the specified format and the
data returned by loading the specified build files.
"""
if params is None:
params = {}
if "-" in format:
format, params["flavor"] = format.split("-", 1)
default_variables = copy.copy(default_variables)
# Default variables provided by this program and its modules should be
# named WITH_CAPITAL_LETTERS to provide a distinct "best practice" namespace,
# avoiding collisions with user and automatic variables.
default_variables["GENERATOR"] = format
default_variables["GENERATOR_FLAVOR"] = params.get("flavor", "")
# Format can be a custom python file, or by default the name of a module
# within gyp.generator.
if format.endswith(".py"):
generator_name = os.path.splitext(format)[0]
path, generator_name = os.path.split(generator_name)
# Make sure the path to the custom generator is in sys.path
# Don't worry about removing it once we are done. Keeping the path
# to each generator that is used in sys.path is likely harmless and
# arguably a good idea.
path = os.path.abspath(path)
if path not in sys.path:
sys.path.insert(0, path)
else:
generator_name = "gyp.generator." + format
# These parameters are passed in order (as opposed to by key)
# because ActivePython cannot handle key parameters to __import__.
generator = __import__(generator_name, globals(), locals(), generator_name)
for (key, val) in generator.generator_default_variables.items():
default_variables.setdefault(key, val)
output_dir = params["options"].generator_output or params["options"].toplevel_dir
if default_variables["GENERATOR"] == "ninja":
default_variables.setdefault(
"PRODUCT_DIR_ABS",
os.path.join(output_dir, "out", default_variables["build_type"]),
)
else:
default_variables.setdefault(
"PRODUCT_DIR_ABS",
os.path.join(output_dir, default_variables["CONFIGURATION_NAME"]),
)
# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
if getattr(generator, "CalculateVariables", None):
generator.CalculateVariables(default_variables, params)
# Give the generator the opportunity to set generator_input_info based on
# the params it will receive in the output phase.
if getattr(generator, "CalculateGeneratorInputInfo", None):
generator.CalculateGeneratorInputInfo(params)
# Fetch the generator specific info that gets fed to input, we use getattr
# so we can default things and the generators only have to provide what
# they need.
generator_input_info = {
"non_configuration_keys": getattr(
generator, "generator_additional_non_configuration_keys", []
),
"path_sections": getattr(generator, "generator_additional_path_sections", []),
"extra_sources_for_rules": getattr(
generator, "generator_extra_sources_for_rules", []
),
"generator_supports_multiple_toolsets": getattr(
generator, "generator_supports_multiple_toolsets", False
),
"generator_wants_static_library_dependencies_adjusted": getattr(
generator, "generator_wants_static_library_dependencies_adjusted", True
),
"generator_wants_sorted_dependencies": getattr(
generator, "generator_wants_sorted_dependencies", False
),
"generator_filelist_paths": getattr(
generator, "generator_filelist_paths", None
),
}
# Process the input specific to this generator.
result = gyp.input.Load(
build_files,
default_variables,
includes[:],
depth,
generator_input_info,
check,
circular_check,
params["parallel"],
params["root_targets"],
)
return [generator] + result
def NameValueListToDict(name_value_list):
"""
Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
of the pairs. If a string is simply NAME, then the value in the dictionary
is set to True. If VALUE can be converted to an integer, it is.
"""
result = {}
for item in name_value_list:
tokens = item.split("=", 1)
if len(tokens) == 2:
# If we can make it an int, use that, otherwise, use the string.
try:
token_value = int(tokens[1])
except ValueError:
token_value = tokens[1]
# Set the variable to the supplied value.
result[tokens[0]] = token_value
else:
# No value supplied, treat it as a boolean and set it.
result[tokens[0]] = True
return result
def ShlexEnv(env_name):
flags = os.environ.get(env_name, [])
if flags:
flags = shlex.split(flags)
return flags
def FormatOpt(opt, value):
if opt.startswith("--"):
return f"{opt}={value}"
return opt + value
def RegenerateAppendFlag(flag, values, predicate, env_name, options):
"""Regenerate a list of command line flags, for an option of action='append'.
The |env_name|, if given, is checked in the environment and used to generate
an initial list of options, then the options that were specified on the
command line (given in |values|) are appended. This matches the handling of
environment variables and command line flags where command line flags override
the environment, while not requiring the environment to be set when the flags
are used again.
"""
flags = []
if options.use_environment and env_name:
for flag_value in ShlexEnv(env_name):
value = FormatOpt(flag, predicate(flag_value))
if value in flags:
flags.remove(value)
flags.append(value)
if values:
for flag_value in values:
flags.append(FormatOpt(flag, predicate(flag_value)))
return flags
def RegenerateFlags(options):
"""Given a parsed options object, and taking the environment variables into
account, returns a list of flags that should regenerate an equivalent options
object (even in the absence of the environment variables.)
Any path options will be normalized relative to depth.
The format flag is not included, as it is assumed the calling generator will
set that as appropriate.
"""
def FixPath(path):
path = gyp.common.FixIfRelativePath(path, options.depth)
if not path:
return os.path.curdir
return path
def Noop(value):
return value
# We always want to ignore the environment when regenerating, to avoid
# duplicate or changed flags in the environment at the time of regeneration.
flags = ["--ignore-environment"]
for name, metadata in options._regeneration_metadata.items():
opt = metadata["opt"]
value = getattr(options, name)
value_predicate = metadata["type"] == "path" and FixPath or Noop
action = metadata["action"]
env_name = metadata["env_name"]
if action == "append":
flags.extend(
RegenerateAppendFlag(opt, value, value_predicate, env_name, options)
)
elif action in ("store", None): # None is a synonym for 'store'.
if value:
flags.append(FormatOpt(opt, value_predicate(value)))
elif options.use_environment and env_name and os.environ.get(env_name):
flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name))))
elif action in ("store_true", "store_false"):
if (action == "store_true" and value) or (
action == "store_false" and not value
):
flags.append(opt)
elif options.use_environment and env_name:
print(
"Warning: environment regeneration unimplemented "
"for %s flag %r env_name %r" % (action, opt, env_name),
file=sys.stderr,
)
else:
print(
"Warning: regeneration unimplemented for action %r "
"flag %r" % (action, opt),
file=sys.stderr,
)
return flags
class RegeneratableOptionParser(argparse.ArgumentParser):
def __init__(self, usage):
self.__regeneratable_options = {}
argparse.ArgumentParser.__init__(self, usage=usage)
def add_argument(self, *args, **kw):
"""Add an option to the parser.
This accepts the same arguments as ArgumentParser.add_argument, plus the
following:
regenerate: can be set to False to prevent this option from being included
in regeneration.
env_name: name of environment variable that additional values for this
option come from.
type: adds type='path', to tell the regenerator that the values of
this option need to be made relative to options.depth
"""
env_name = kw.pop("env_name", None)
if "dest" in kw and kw.pop("regenerate", True):
dest = kw["dest"]
# The path type is needed for regenerating, for optparse we can just treat
# it as a string.
type = kw.get("type")
if type == "path":
kw["type"] = str
self.__regeneratable_options[dest] = {
"action": kw.get("action"),
"type": type,
"env_name": env_name,
"opt": args[0],
}
argparse.ArgumentParser.add_argument(self, *args, **kw)
def parse_args(self, *args):
values, args = argparse.ArgumentParser.parse_known_args(self, *args)
values._regeneration_metadata = self.__regeneratable_options
return values, args
def gyp_main(args):
my_name = os.path.basename(sys.argv[0])
usage = "usage: %(prog)s [options ...] [build_file ...]"
parser = RegeneratableOptionParser(usage=usage.replace("%s", "%(prog)s"))
parser.add_argument(
"--build",
dest="configs",
action="append",
help="configuration for build after project generation",
)
parser.add_argument(
"--check", dest="check", action="store_true", help="check format of gyp files"
)
parser.add_argument(
"--config-dir",
dest="config_dir",
action="store",
env_name="GYP_CONFIG_DIR",
default=None,
help="The location for configuration files like " "include.gypi.",
)
parser.add_argument(
"-d",
"--debug",
dest="debug",
metavar="DEBUGMODE",
action="append",
default=[],
help="turn on a debugging "
'mode for debugging GYP. Supported modes are "variables", '
'"includes" and "general" or "all" for all of them.',
)
parser.add_argument(
"-D",
dest="defines",
action="append",
metavar="VAR=VAL",
env_name="GYP_DEFINES",
help="sets variable VAR to value VAL",
)
parser.add_argument(
"--depth",
dest="depth",
metavar="PATH",
type="path",
help="set DEPTH gyp variable to a relative path to PATH",
)
parser.add_argument(
"-f",
"--format",
dest="formats",
action="append",
env_name="GYP_GENERATORS",
regenerate=False,
help="output formats to generate",
)
parser.add_argument(
"-G",
dest="generator_flags",
action="append",
default=[],
metavar="FLAG=VAL",
env_name="GYP_GENERATOR_FLAGS",
help="sets generator flag FLAG to VAL",
)
parser.add_argument(
"--generator-output",
dest="generator_output",
action="store",
default=None,
metavar="DIR",
type="path",
env_name="GYP_GENERATOR_OUTPUT",
help="puts generated build files under DIR",
)
parser.add_argument(
"--ignore-environment",
dest="use_environment",
action="store_false",
default=True,
regenerate=False,
help="do not read options from environment variables",
)
parser.add_argument(
"-I",
"--include",
dest="includes",
action="append",
metavar="INCLUDE",
type="path",
help="files to include in all loaded .gyp files",
)
# --no-circular-check disables the check for circular relationships between
# .gyp files. These relationships should not exist, but they've only been
# observed to be harmful with the Xcode generator. Chromium's .gyp files
# currently have some circular relationships on non-Mac platforms, so this
# option allows the strict behavior to be used on Macs and the lenient
# behavior to be used elsewhere.
# TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
parser.add_argument(
"--no-circular-check",
dest="circular_check",
action="store_false",
default=True,
regenerate=False,
help="don't check for circular relationships between files",
)
parser.add_argument(
"--no-parallel",
action="store_true",
default=False,
help="Disable multiprocessing",
)
parser.add_argument(
"-S",
"--suffix",
dest="suffix",
default="",
help="suffix to add to generated files",
)
parser.add_argument(
"--toplevel-dir",
dest="toplevel_dir",
action="store",
default=None,
metavar="DIR",
type="path",
help="directory to use as the root of the source tree",
)
parser.add_argument(
"-R",
"--root-target",
dest="root_targets",
action="append",
metavar="TARGET",
help="include only TARGET and its deep dependencies",
)
parser.add_argument(
"-V",
"--version",
dest="version",
action="store_true",
help="Show the version and exit.",
)
options, build_files_arg = parser.parse_args(args)
if options.version:
import pkg_resources
print(f"v{pkg_resources.get_distribution('gyp-next').version}")
return 0
build_files = build_files_arg
# Set up the configuration directory (defaults to ~/.gyp)
if not options.config_dir:
home = None
home_dot_gyp = None
if options.use_environment:
home_dot_gyp = os.environ.get("GYP_CONFIG_DIR", None)
if home_dot_gyp:
home_dot_gyp = os.path.expanduser(home_dot_gyp)
if not home_dot_gyp:
home_vars = ["HOME"]
if sys.platform in ("cygwin", "win32"):
home_vars.append("USERPROFILE")
for home_var in home_vars:
home = os.getenv(home_var)
if home:
home_dot_gyp = os.path.join(home, ".gyp")
if not os.path.exists(home_dot_gyp):
home_dot_gyp = None
else:
break
else:
home_dot_gyp = os.path.expanduser(options.config_dir)
if home_dot_gyp and not os.path.exists(home_dot_gyp):
home_dot_gyp = None
if not options.formats:
# If no format was given on the command line, then check the env variable.
generate_formats = []
if options.use_environment:
generate_formats = os.environ.get("GYP_GENERATORS", [])
if generate_formats:
generate_formats = re.split(r"[\s,]", generate_formats)
if generate_formats:
options.formats = generate_formats
else:
# Nothing in the variable, default based on platform.
if sys.platform == "darwin":
options.formats = ["xcode"]
elif sys.platform in ("win32", "cygwin"):
options.formats = ["msvs"]
else:
options.formats = ["make"]
if not options.generator_output and options.use_environment:
g_o = os.environ.get("GYP_GENERATOR_OUTPUT")
if g_o:
options.generator_output = g_o
options.parallel = not options.no_parallel
for mode in options.debug:
gyp.debug[mode] = 1
# Do an extra check to avoid work when we're not debugging.
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, "running with these options:")
for option, value in sorted(options.__dict__.items()):
if option[0] == "_":
continue
if isinstance(value, str):
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
else:
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
if not build_files:
build_files = FindBuildFiles()
if not build_files:
raise GypError((usage + "\n\n%s: error: no build_file") % (my_name, my_name))
# TODO(mark): Chromium-specific hack!
# For Chromium, the gyp "depth" variable should always be a relative path
# to Chromium's top-level "src" directory. If no depth variable was set
# on the command line, try to find a "src" directory by looking at the
# absolute path to each build file's directory. The first "src" component
# found will be treated as though it were the path used for --depth.
if not options.depth:
for build_file in build_files:
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in range(components_len - 1, -1, -1):
if build_file_dir_components[index] == "src":
options.depth = os.path.sep.join(build_file_dir_components)
break
del build_file_dir_components[index]
# If the inner loop found something, break without advancing to another
# build file.
if options.depth:
break
if not options.depth:
raise GypError(
"Could not automatically locate src directory. This is"
"a temporary Chromium feature that will be removed. Use"
"--depth as a workaround."
)
# If toplevel-dir is not set, we assume that depth is the root of our source
# tree.
if not options.toplevel_dir:
options.toplevel_dir = options.depth
# -D on the command line sets variable defaults - D isn't just for define,
# it's for default. Perhaps there should be a way to force (-F?) a
# variable's value so that it can't be overridden by anything else.
cmdline_default_variables = {}
defines = []
if options.use_environment:
defines += ShlexEnv("GYP_DEFINES")
if options.defines:
defines += options.defines
cmdline_default_variables = NameValueListToDict(defines)
if DEBUG_GENERAL in gyp.debug:
DebugOutput(
DEBUG_GENERAL, "cmdline_default_variables: %s", cmdline_default_variables
)
# Set up includes.
includes = []
# If ~/.gyp/include.gypi exists, it'll be forcibly included into every
# .gyp file that's loaded, before anything else is included.
if home_dot_gyp:
default_include = os.path.join(home_dot_gyp, "include.gypi")
if os.path.exists(default_include):
print("Using overrides found in " + default_include)
includes.append(default_include)
# Command-line --include files come after the default include.
if options.includes:
includes.extend(options.includes)
# Generator flags should be prefixed with the target generator since they
# are global across all generator runs.
gen_flags = []
if options.use_environment:
gen_flags += ShlexEnv("GYP_GENERATOR_FLAGS")
if options.generator_flags:
gen_flags += options.generator_flags
generator_flags = NameValueListToDict(gen_flags)
if DEBUG_GENERAL in gyp.debug.keys():
DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)
# Generate all requested formats (use a set in case we got one format request
# twice)
for format in set(options.formats):
params = {
"options": options,
"build_files": build_files,
"generator_flags": generator_flags,
"cwd": os.getcwd(),
"build_files_arg": build_files_arg,
"gyp_binary": sys.argv[0],
"home_dot_gyp": home_dot_gyp,
"parallel": options.parallel,
"root_targets": options.root_targets,
"target_arch": cmdline_default_variables.get("target_arch", ""),
}
# Start with the default variables from the command line.
[generator, flat_list, targets, data] = Load(
build_files,
format,
cmdline_default_variables,
includes,
options.depth,
params,
options.check,
options.circular_check,
)
# TODO(mark): Pass |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
# a list, and not the whole data dict.
# NOTE: flat_list is the flattened dependency graph specifying the order
# that targets may be built. Build systems that operate serially or that
# need to have dependencies defined before dependents reference them should
# generate targets in the order specified in flat_list.
generator.GenerateOutput(flat_list, targets, data, params)
if options.configs:
valid_configs = targets[flat_list[0]]["configurations"]
for conf in options.configs:
if conf not in valid_configs:
raise GypError("Invalid config specified via --build: %s" % conf)
generator.PerformBuild(data, options.configs, params)
# Done
return 0
def main(args):
try:
return gyp_main(args)
except GypError as e:
sys.stderr.write("gyp: %s\n" % e)
return 1
# NOTE: setuptools generated console_scripts calls function with no arguments
def script_main():
return main(sys.argv[1:])
if __name__ == "__main__":
sys.exit(script_main())
node-gyp-9.3.0/gyp/pylib/gyp/common.py 0000664 0000000 0000000 00000054336 14321173220 0017632 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import errno
import filecmp
import os.path
import re
import tempfile
import sys
import subprocess
from collections.abc import MutableSet
# A minimal memoizing decorator. It'll blow up if the args aren't immutable,
# among other "problems".
class memoize:
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
try:
return self.cache[args]
except KeyError:
result = self.func(*args)
self.cache[args] = result
return result
class GypError(Exception):
"""Error class representing an error, which is to be presented
to the user. The main entry point will catch and display this.
"""
pass
def ExceptionAppend(e, msg):
"""Append a message to the given exception's message."""
if not e.args:
e.args = (msg,)
elif len(e.args) == 1:
e.args = (str(e.args[0]) + " " + msg,)
else:
e.args = (str(e.args[0]) + " " + msg,) + e.args[1:]
def FindQualifiedTargets(target, qualified_list):
"""
Given a list of qualified targets, return the qualified targets for the
specified |target|.
"""
return [t for t in qualified_list if ParseQualifiedTarget(t)[1] == target]
def ParseQualifiedTarget(target):
# Splits a qualified target into a build file, target name and toolset.
# NOTE: rsplit is used to disambiguate the Windows drive letter separator.
target_split = target.rsplit(":", 1)
if len(target_split) == 2:
[build_file, target] = target_split
else:
build_file = None
target_split = target.rsplit("#", 1)
if len(target_split) == 2:
[target, toolset] = target_split
else:
toolset = None
return [build_file, target, toolset]
def ResolveTarget(build_file, target, toolset):
# This function resolves a target into a canonical form:
# - a fully defined build file, either absolute or relative to the current
# directory
# - a target name
# - a toolset
#
# build_file is the file relative to which 'target' is defined.
# target is the qualified target.
# toolset is the default toolset for that target.
[parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
if parsed_build_file:
if build_file:
# If a relative path, parsed_build_file is relative to the directory
# containing build_file. If build_file is not in the current directory,
# parsed_build_file is not a usable path as-is. Resolve it by
# interpreting it as relative to build_file. If parsed_build_file is
# absolute, it is usable as a path regardless of the current directory,
# and os.path.join will return it as-is.
build_file = os.path.normpath(
os.path.join(os.path.dirname(build_file), parsed_build_file)
)
# Further (to handle cases like ../cwd), make it relative to cwd)
if not os.path.isabs(build_file):
build_file = RelativePath(build_file, ".")
else:
build_file = parsed_build_file
if parsed_toolset:
toolset = parsed_toolset
return [build_file, target, toolset]
def BuildFile(fully_qualified_target):
# Extracts the build file from the fully qualified target.
return ParseQualifiedTarget(fully_qualified_target)[0]
def GetEnvironFallback(var_list, default):
"""Look up a key in the environment, with fallback to secondary keys
and finally falling back to a default value."""
for var in var_list:
if var in os.environ:
return os.environ[var]
return default
def QualifiedTarget(build_file, target, toolset):
# "Qualified" means the file that a target was defined in and the target
# name, separated by a colon, suffixed by a # and the toolset name:
# /path/to/file.gyp:target_name#toolset
fully_qualified = build_file + ":" + target
if toolset:
fully_qualified = fully_qualified + "#" + toolset
return fully_qualified
@memoize
def RelativePath(path, relative_to, follow_path_symlink=True):
# Assuming both |path| and |relative_to| are relative to the current
# directory, returns a relative path that identifies path relative to
# relative_to.
# If |follow_symlink_path| is true (default) and |path| is a symlink, then
# this method returns a path to the real file represented by |path|. If it is
# false, this method returns a path to the symlink. If |path| is not a
# symlink, this option has no effect.
# Convert to normalized (and therefore absolute paths).
if follow_path_symlink:
path = os.path.realpath(path)
else:
path = os.path.abspath(path)
relative_to = os.path.realpath(relative_to)
# On Windows, we can't create a relative path to a different drive, so just
# use the absolute path.
if sys.platform == "win32":
if (
os.path.splitdrive(path)[0].lower()
!= os.path.splitdrive(relative_to)[0].lower()
):
return path
# Split the paths into components.
path_split = path.split(os.path.sep)
relative_to_split = relative_to.split(os.path.sep)
# Determine how much of the prefix the two paths share.
prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
# Put enough ".." components to back up out of relative_to to the common
# prefix, and then append the part of path_split after the common prefix.
relative_split = [os.path.pardir] * (
len(relative_to_split) - prefix_len
) + path_split[prefix_len:]
if len(relative_split) == 0:
# The paths were the same.
return ""
# Turn it back into a string and we're done.
return os.path.join(*relative_split)
@memoize
def InvertRelativePath(path, toplevel_dir=None):
"""Given a path like foo/bar that is relative to toplevel_dir, return
the inverse relative path back to the toplevel_dir.
E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path)))
should always produce the empty string, unless the path contains symlinks.
"""
if not path:
return path
toplevel_dir = "." if toplevel_dir is None else toplevel_dir
return RelativePath(toplevel_dir, os.path.join(toplevel_dir, path))
def FixIfRelativePath(path, relative_to):
# Like RelativePath but returns |path| unchanged if it is absolute.
if os.path.isabs(path):
return path
return RelativePath(path, relative_to)
def UnrelativePath(path, relative_to):
# Assuming that |relative_to| is relative to the current directory, and |path|
# is a path relative to the dirname of |relative_to|, returns a path that
# identifies |path| relative to the current directory.
rel_dir = os.path.dirname(relative_to)
return os.path.normpath(os.path.join(rel_dir, path))
# re objects used by EncodePOSIXShellArgument. See IEEE 1003.1 XCU.2.2 at
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02
# and the documentation for various shells.
# _quote is a pattern that should match any argument that needs to be quoted
# with double-quotes by EncodePOSIXShellArgument. It matches the following
# characters appearing anywhere in an argument:
# \t, \n, space parameter separators
# # comments
# $ expansions (quoted to always expand within one argument)
# % called out by IEEE 1003.1 XCU.2.2
# & job control
# ' quoting
# (, ) subshell execution
# *, ?, [ pathname expansion
# ; command delimiter
# <, >, | redirection
# = assignment
# {, } brace expansion (bash)
# ~ tilde expansion
# It also matches the empty string, because "" (or '') is the only way to
# represent an empty string literal argument to a POSIX shell.
#
# This does not match the characters in _escape, because those need to be
# backslash-escaped regardless of whether they appear in a double-quoted
# string.
_quote = re.compile("[\t\n #$%&'()*;<=>?[{|}~]|^$")
# _escape is a pattern that should match any character that needs to be
# escaped with a backslash, whether or not the argument matched the _quote
# pattern. _escape is used with re.sub to backslash anything in _escape's
# first match group, hence the (parentheses) in the regular expression.
#
# _escape matches the following characters appearing anywhere in an argument:
# " to prevent POSIX shells from interpreting this character for quoting
# \ to prevent POSIX shells from interpreting this character for escaping
# ` to prevent POSIX shells from interpreting this character for command
# substitution
# Missing from this list is $, because the desired behavior of
# EncodePOSIXShellArgument is to permit parameter (variable) expansion.
#
# Also missing from this list is !, which bash will interpret as the history
# expansion character when history is enabled. bash does not enable history
# by default in non-interactive shells, so this is not thought to be a problem.
# ! was omitted from this list because bash interprets "\!" as a literal string
# including the backslash character (avoiding history expansion but retaining
# the backslash), which would not be correct for argument encoding. Handling
# this case properly would also be problematic because bash allows the history
# character to be changed with the histchars shell variable. Fortunately,
# as history is not enabled in non-interactive shells and
# EncodePOSIXShellArgument is only expected to encode for non-interactive
# shells, there is no room for error here by ignoring !.
_escape = re.compile(r'(["\\`])')
def EncodePOSIXShellArgument(argument):
"""Encodes |argument| suitably for consumption by POSIX shells.
argument may be quoted and escaped as necessary to ensure that POSIX shells
treat the returned value as a literal representing the argument passed to
this function. Parameter (variable) expansions beginning with $ are allowed
to remain intact without escaping the $, to allow the argument to contain
references to variables to be expanded by the shell.
"""
if not isinstance(argument, str):
argument = str(argument)
if _quote.search(argument):
quote = '"'
else:
quote = ""
encoded = quote + re.sub(_escape, r"\\\1", argument) + quote
return encoded
def EncodePOSIXShellList(list):
"""Encodes |list| suitably for consumption by POSIX shells.
Returns EncodePOSIXShellArgument for each item in list, and joins them
together using the space character as an argument separator.
"""
encoded_arguments = []
for argument in list:
encoded_arguments.append(EncodePOSIXShellArgument(argument))
return " ".join(encoded_arguments)
def DeepDependencyTargets(target_dicts, roots):
"""Returns the recursive list of target dependencies."""
dependencies = set()
pending = set(roots)
while pending:
# Pluck out one.
r = pending.pop()
# Skip if visited already.
if r in dependencies:
continue
# Add it.
dependencies.add(r)
# Add its children.
spec = target_dicts[r]
pending.update(set(spec.get("dependencies", [])))
pending.update(set(spec.get("dependencies_original", [])))
return list(dependencies - set(roots))
def BuildFileTargets(target_list, build_file):
"""From a target_list, returns the subset from the specified build_file.
"""
return [p for p in target_list if BuildFile(p) == build_file]
def AllTargets(target_list, target_dicts, build_file):
"""Returns all targets (direct and dependencies) for the specified build_file.
"""
bftargets = BuildFileTargets(target_list, build_file)
deptargets = DeepDependencyTargets(target_dicts, bftargets)
return bftargets + deptargets
def WriteOnDiff(filename):
"""Write to a file only if the new contents differ.
Arguments:
filename: name of the file to potentially write to.
Returns:
A file like object which will write to temporary file and only overwrite
the target if it differs (on close).
"""
class Writer:
"""Wrapper around file which only covers the target if it differs."""
def __init__(self):
# On Cygwin remove the "dir" argument
# `C:` prefixed paths are treated as relative,
# consequently ending up with current dir "/cygdrive/c/..."
# being prefixed to those, which was
# obviously a non-existent path,
# for example: "/cygdrive/c//C:\".
# For more details see:
# https://docs.python.org/2/library/tempfile.html#tempfile.mkstemp
base_temp_dir = "" if IsCygwin() else os.path.dirname(filename)
# Pick temporary file.
tmp_fd, self.tmp_path = tempfile.mkstemp(
suffix=".tmp",
prefix=os.path.split(filename)[1] + ".gyp.",
dir=base_temp_dir,
)
try:
self.tmp_file = os.fdopen(tmp_fd, "wb")
except Exception:
# Don't leave turds behind.
os.unlink(self.tmp_path)
raise
def __getattr__(self, attrname):
# Delegate everything else to self.tmp_file
return getattr(self.tmp_file, attrname)
def close(self):
try:
# Close tmp file.
self.tmp_file.close()
# Determine if different.
same = False
try:
same = filecmp.cmp(self.tmp_path, filename, False)
except OSError as e:
if e.errno != errno.ENOENT:
raise
if same:
# The new file is identical to the old one, just get rid of the new
# one.
os.unlink(self.tmp_path)
else:
# The new file is different from the old one,
# or there is no old one.
# Rename the new file to the permanent name.
#
# tempfile.mkstemp uses an overly restrictive mode, resulting in a
# file that can only be read by the owner, regardless of the umask.
# There's no reason to not respect the umask here,
# which means that an extra hoop is required
# to fetch it and reset the new file's mode.
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(0o77)
os.umask(umask)
os.chmod(self.tmp_path, 0o666 & ~umask)
if sys.platform == "win32" and os.path.exists(filename):
# NOTE: on windows (but not cygwin) rename will not replace an
# existing file, so it must be preceded with a remove.
# Sadly there is no way to make the switch atomic.
os.remove(filename)
os.rename(self.tmp_path, filename)
except Exception:
# Don't leave turds behind.
os.unlink(self.tmp_path)
raise
def write(self, s):
self.tmp_file.write(s.encode("utf-8"))
return Writer()
def EnsureDirExists(path):
"""Make sure the directory for |path| exists."""
try:
os.makedirs(os.path.dirname(path))
except OSError:
pass
def GetFlavor(params):
"""Returns |params.flavor| if it's set, the system's default flavor else."""
flavors = {
"cygwin": "win",
"win32": "win",
"darwin": "mac",
}
if "flavor" in params:
return params["flavor"]
if sys.platform in flavors:
return flavors[sys.platform]
if sys.platform.startswith("sunos"):
return "solaris"
if sys.platform.startswith(("dragonfly", "freebsd")):
return "freebsd"
if sys.platform.startswith("openbsd"):
return "openbsd"
if sys.platform.startswith("netbsd"):
return "netbsd"
if sys.platform.startswith("aix"):
return "aix"
if sys.platform.startswith(("os390", "zos")):
return "zos"
if sys.platform == "os400":
return "os400"
return "linux"
def CopyTool(flavor, out_path, generator_flags={}):
"""Finds (flock|mac|win)_tool.gyp in the gyp directory and copies it
to |out_path|."""
# aix and solaris just need flock emulation. mac and win use more complicated
# support scripts.
prefix = {
"aix": "flock",
"os400": "flock",
"solaris": "flock",
"mac": "mac",
"ios": "mac",
"win": "win",
}.get(flavor, None)
if not prefix:
return
# Slurp input file.
source_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "%s_tool.py" % prefix
)
with open(source_path) as source_file:
source = source_file.readlines()
# Set custom header flags.
header = "# Generated by gyp. Do not edit.\n"
mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
if flavor == "mac" and mac_toolchain_dir:
header += "import os;\nos.environ['DEVELOPER_DIR']='%s'\n" % mac_toolchain_dir
# Add header and write it out.
tool_path = os.path.join(out_path, "gyp-%s-tool" % prefix)
with open(tool_path, "w") as tool_file:
tool_file.write("".join([source[0], header] + source[1:]))
# Make file executable.
os.chmod(tool_path, 0o755)
# From Alex Martelli,
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
# ASPN: Python Cookbook: Remove duplicates from a sequence
# First comment, dated 2001/10/13.
# (Also in the printed Python Cookbook.)
def uniquer(seq, idfun=lambda x: x):
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen:
continue
seen[marker] = 1
result.append(item)
return result
# Based on http://code.activestate.com/recipes/576694/.
class OrderedSet(MutableSet):
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
self |= iterable
def __len__(self):
return len(self.map)
def __contains__(self, key):
return key in self.map
def add(self, key):
if key not in self.map:
end = self.end
curr = end[1]
curr[2] = end[1] = self.map[key] = [key, curr, end]
def discard(self, key):
if key in self.map:
key, prev_item, next_item = self.map.pop(key)
prev_item[2] = next_item
next_item[1] = prev_item
def __iter__(self):
end = self.end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]
def __reversed__(self):
end = self.end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]
# The second argument is an addition that causes a pylint warning.
def pop(self, last=True): # pylint: disable=W0221
if not self:
raise KeyError("set is empty")
key = self.end[1][0] if last else self.end[2][0]
self.discard(key)
return key
def __repr__(self):
if not self:
return f"{self.__class__.__name__}()"
return f"{self.__class__.__name__}({list(self)!r})"
def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return set(self) == set(other)
# Extensions to the recipe.
def update(self, iterable):
for i in iterable:
if i not in self:
self.add(i)
class CycleError(Exception):
"""An exception raised when an unexpected cycle is detected."""
def __init__(self, nodes):
self.nodes = nodes
def __str__(self):
return "CycleError: cycle involving: " + str(self.nodes)
def TopologicallySorted(graph, get_edges):
r"""Topologically sort based on a user provided edge definition.
Args:
graph: A list of node names.
get_edges: A function mapping from node name to a hashable collection
of node names which this node has outgoing edges to.
Returns:
A list containing all of the node in graph in topological order.
It is assumed that calling get_edges once for each node and caching is
cheaper than repeatedly calling get_edges.
Raises:
CycleError in the event of a cycle.
Example:
graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
def GetEdges(node):
return re.findall(r'\$\(([^))]\)', graph[node])
print TopologicallySorted(graph.keys(), GetEdges)
==>
['a', 'c', b']
"""
get_edges = memoize(get_edges)
visited = set()
visiting = set()
ordered_nodes = []
def Visit(node):
if node in visiting:
raise CycleError(visiting)
if node in visited:
return
visited.add(node)
visiting.add(node)
for neighbor in get_edges(node):
Visit(neighbor)
visiting.remove(node)
ordered_nodes.insert(0, node)
for node in sorted(graph):
Visit(node)
return ordered_nodes
def CrossCompileRequested():
# TODO: figure out how to not build extra host objects in the
# non-cross-compile case when this is enabled, and enable unconditionally.
return (
os.environ.get("GYP_CROSSCOMPILE")
or os.environ.get("AR_host")
or os.environ.get("CC_host")
or os.environ.get("CXX_host")
or os.environ.get("AR_target")
or os.environ.get("CC_target")
or os.environ.get("CXX_target")
)
def IsCygwin():
try:
out = subprocess.Popen(
"uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
stdout = out.communicate()[0].decode("utf-8")
return "CYGWIN" in str(stdout)
except Exception:
return False
node-gyp-9.3.0/gyp/pylib/gyp/common_test.py 0000775 0000000 0000000 00000004162 14321173220 0020664 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for the common.py file."""
import gyp.common
import unittest
import sys
class TestTopologicallySorted(unittest.TestCase):
def test_Valid(self):
"""Test that sorting works on a valid graph with one possible order."""
graph = {
"a": ["b", "c"],
"b": [],
"c": ["d"],
"d": ["b"],
}
def GetEdge(node):
return tuple(graph[node])
self.assertEqual(
gyp.common.TopologicallySorted(graph.keys(), GetEdge), ["a", "c", "d", "b"]
)
def test_Cycle(self):
"""Test that an exception is thrown on a cyclic graph."""
graph = {
"a": ["b"],
"b": ["c"],
"c": ["d"],
"d": ["a"],
}
def GetEdge(node):
return tuple(graph[node])
self.assertRaises(
gyp.common.CycleError, gyp.common.TopologicallySorted, graph.keys(), GetEdge
)
class TestGetFlavor(unittest.TestCase):
"""Test that gyp.common.GetFlavor works as intended"""
original_platform = ""
def setUp(self):
self.original_platform = sys.platform
def tearDown(self):
sys.platform = self.original_platform
def assertFlavor(self, expected, argument, param):
sys.platform = argument
self.assertEqual(expected, gyp.common.GetFlavor(param))
def test_platform_default(self):
self.assertFlavor("freebsd", "freebsd9", {})
self.assertFlavor("freebsd", "freebsd10", {})
self.assertFlavor("openbsd", "openbsd5", {})
self.assertFlavor("solaris", "sunos5", {})
self.assertFlavor("solaris", "sunos", {})
self.assertFlavor("linux", "linux2", {})
self.assertFlavor("linux", "linux3", {})
self.assertFlavor("linux", "linux", {})
def test_param(self):
self.assertFlavor("foobar", "linux2", {"flavor": "foobar"})
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/easy_xml.py 0000664 0000000 0000000 00000012247 14321173220 0020156 0 ustar 00root root 0000000 0000000 # Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
import re
import os
import locale
from functools import reduce
def XmlToString(content, encoding="utf-8", pretty=False):
""" Writes the XML content to disk, touching the file only if it has changed.
Visual Studio files have a lot of pre-defined structures. This function makes
it easy to represent these structures as Python data structures, instead of
having to create a lot of function calls.
Each XML element of the content is represented as a list composed of:
1. The name of the element, a string,
2. The attributes of the element, a dictionary (optional), and
3+. The content of the element, if any. Strings are simple text nodes and
lists are child elements.
Example 1:
becomes
['test']
Example 2:
This is
it!
becomes
['myelement', {'a':'value1', 'b':'value2'},
['childtype', 'This is'],
['childtype', 'it!'],
]
Args:
content: The structured content to be converted.
encoding: The encoding to report on the first XML line.
pretty: True if we want pretty printing with indents and new lines.
Returns:
The XML content as a string.
"""
# We create a huge list of all the elements of the file.
xml_parts = ['' % encoding]
if pretty:
xml_parts.append("\n")
_ConstructContentList(xml_parts, content, pretty)
# Convert it to a string
return "".join(xml_parts)
def _ConstructContentList(xml_parts, specification, pretty, level=0):
""" Appends the XML parts corresponding to the specification.
Args:
xml_parts: A list of XML parts to be appended to.
specification: The specification of the element. See EasyXml docs.
pretty: True if we want pretty printing with indents and new lines.
level: Indentation level.
"""
# The first item in a specification is the name of the element.
if pretty:
indentation = " " * level
new_line = "\n"
else:
indentation = ""
new_line = ""
name = specification[0]
if not isinstance(name, str):
raise Exception(
"The first item of an EasyXml specification should be "
"a string. Specification was " + str(specification)
)
xml_parts.append(indentation + "<" + name)
# Optionally in second position is a dictionary of the attributes.
rest = specification[1:]
if rest and isinstance(rest[0], dict):
for at, val in sorted(rest[0].items()):
xml_parts.append(f' {at}="{_XmlEscape(val, attr=True)}"')
rest = rest[1:]
if rest:
xml_parts.append(">")
all_strings = reduce(lambda x, y: x and isinstance(y, str), rest, True)
multi_line = not all_strings
if multi_line and new_line:
xml_parts.append(new_line)
for child_spec in rest:
# If it's a string, append a text node.
# Otherwise recurse over that child definition
if isinstance(child_spec, str):
xml_parts.append(_XmlEscape(child_spec))
else:
_ConstructContentList(xml_parts, child_spec, pretty, level + 1)
if multi_line and indentation:
xml_parts.append(indentation)
xml_parts.append(f"{name}>{new_line}")
else:
xml_parts.append("/>%s" % new_line)
def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False,
win32=(sys.platform == "win32")):
""" Writes the XML content to disk, touching the file only if it has changed.
Args:
content: The structured content to be written.
path: Location of the file.
encoding: The encoding to report on the first line of the XML file.
pretty: True if we want pretty printing with indents and new lines.
"""
xml_string = XmlToString(content, encoding, pretty)
if win32 and os.linesep != "\r\n":
xml_string = xml_string.replace("\n", "\r\n")
default_encoding = locale.getdefaultlocale()[1]
if default_encoding and default_encoding.upper() != encoding.upper():
xml_string = xml_string.encode(encoding)
# Get the old content
try:
with open(path) as file:
existing = file.read()
except OSError:
existing = None
# It has changed, write it
if existing != xml_string:
with open(path, "wb") as file:
file.write(xml_string)
_xml_escape_map = {
'"': """,
"'": "'",
"<": "<",
">": ">",
"&": "&",
"\n": "
",
"\r": "
",
}
_xml_escape_re = re.compile("(%s)" % "|".join(map(re.escape, _xml_escape_map.keys())))
def _XmlEscape(value, attr=False):
""" Escape a string for inclusion in XML."""
def replace(match):
m = match.string[match.start() : match.end()]
# don't replace single quotes in attrs
if attr and m == "'":
return m
return _xml_escape_map[m]
return _xml_escape_re.sub(replace, value)
node-gyp-9.3.0/gyp/pylib/gyp/easy_xml_test.py 0000775 0000000 0000000 00000007175 14321173220 0021224 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the easy_xml.py file. """
import gyp.easy_xml as easy_xml
import unittest
from io import StringIO
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.stderr = StringIO()
def test_EasyXml_simple(self):
self.assertEqual(
easy_xml.XmlToString(["test"]),
'',
)
self.assertEqual(
easy_xml.XmlToString(["test"], encoding="Windows-1252"),
'',
)
def test_EasyXml_simple_with_attributes(self):
self.assertEqual(
easy_xml.XmlToString(["test2", {"a": "value1", "b": "value2"}]),
'',
)
def test_EasyXml_escaping(self):
original = "'\"\r&\nfoo"
converted = "<test>'"
&
foo"
converted_apos = converted.replace("'", "'")
self.assertEqual(
easy_xml.XmlToString(["test3", {"a": original}, original]),
'%s'
% (converted, converted_apos),
)
def test_EasyXml_pretty(self):
self.assertEqual(
easy_xml.XmlToString(
["test3", ["GrandParent", ["Parent1", ["Child"]], ["Parent2"]]],
pretty=True,
),
'\n'
"\n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
"\n",
)
def test_EasyXml_complex(self):
# We want to create:
target = (
''
""
''
"{D2250C20-3A94-4FB9-AF73-11BC5B73884B}"
"Win32Proj"
"automated_ui_tests"
""
''
"'
"Application"
"Unicode"
""
""
)
xml = easy_xml.XmlToString(
[
"Project",
[
"PropertyGroup",
{"Label": "Globals"},
["ProjectGuid", "{D2250C20-3A94-4FB9-AF73-11BC5B73884B}"],
["Keyword", "Win32Proj"],
["RootNamespace", "automated_ui_tests"],
],
["Import", {"Project": "$(VCTargetsPath)\\Microsoft.Cpp.props"}],
[
"PropertyGroup",
{
"Condition": "'$(Configuration)|$(Platform)'=='Debug|Win32'",
"Label": "Configuration",
},
["ConfigurationType", "Application"],
["CharacterSet", "Unicode"],
],
]
)
self.assertEqual(xml, target)
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/flock_tool.py 0000775 0000000 0000000 00000003536 14321173220 0020474 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""These functions are executed via gyp-flock-tool when using the Makefile
generator. Used on systems that don't have a built-in flock."""
import fcntl
import os
import struct
import subprocess
import sys
def main(args):
executor = FlockTool()
executor.Dispatch(args)
class FlockTool:
"""This class emulates the 'flock' command."""
def Dispatch(self, args):
"""Dispatches a string command to a method."""
if len(args) < 1:
raise Exception("Not enough arguments")
method = "Exec%s" % self._CommandifyName(args[0])
getattr(self, method)(*args[1:])
def _CommandifyName(self, name_string):
"""Transforms a tool name like copy-info-plist to CopyInfoPlist"""
return name_string.title().replace("-", "")
def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
# Note that the stock python on SunOS has a bug
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
if sys.platform.startswith("aix") or sys.platform == "os400":
# Python on AIX is compiled with LARGEFILE support, which changes the
# struct size.
op = struct.pack("hhIllqq", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
else:
op = struct.pack("hhllhhl", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
fcntl.fcntl(fd, fcntl.F_SETLK, op)
return subprocess.call(cmd_list)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
node-gyp-9.3.0/gyp/pylib/gyp/generator/ 0000775 0000000 0000000 00000000000 14321173220 0017743 5 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/pylib/gyp/generator/__init__.py 0000664 0000000 0000000 00000000000 14321173220 0022042 0 ustar 00root root 0000000 0000000 node-gyp-9.3.0/gyp/pylib/gyp/generator/analyzer.py 0000664 0000000 0000000 00000075704 14321173220 0022157 0 ustar 00root root 0000000 0000000 # Copyright (c) 2014 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This script is intended for use as a GYP_GENERATOR. It takes as input (by way of
the generator flag config_path) the path of a json file that dictates the files
and targets to search for. The following keys are supported:
files: list of paths (relative) of the files to search for.
test_targets: unqualified target names to search for. Any target in this list
that depends upon a file in |files| is output regardless of the type of target
or chain of dependencies.
additional_compile_targets: Unqualified targets to search for in addition to
test_targets. Targets in the combined list that depend upon a file in |files|
are not necessarily output. For example, if the target is of type none then the
target is not output (but one of the descendants of the target will be).
The following is output:
error: only supplied if there is an error.
compile_targets: minimal set of targets that directly or indirectly (for
targets of type none) depend on the files in |files| and is one of the
supplied targets or a target that one of the supplied targets depends on.
The expectation is this set of targets is passed into a build step. This list
always contains the output of test_targets as well.
test_targets: set of targets from the supplied |test_targets| that either
directly or indirectly depend upon a file in |files|. This list if useful
if additional processing needs to be done for certain targets after the
build, such as running tests.
status: outputs one of three values: none of the supplied files were found,
one of the include files changed so that it should be assumed everything
changed (in this case test_targets and compile_targets are not output) or at
least one file was found.
invalid_targets: list of supplied targets that were not found.
Example:
Consider a graph like the following:
A D
/ \
B C
A depends upon both B and C, A is of type none and B and C are executables.
D is an executable, has no dependencies and nothing depends on it.
If |additional_compile_targets| = ["A"], |test_targets| = ["B", "C"] and
files = ["b.cc", "d.cc"] (B depends upon b.cc and D depends upon d.cc), then
the following is output:
|compile_targets| = ["B"] B must built as it depends upon the changed file b.cc
and the supplied target A depends upon it. A is not output as a build_target
as it is of type none with no rules and actions.
|test_targets| = ["B"] B directly depends upon the change file b.cc.
Even though the file d.cc, which D depends upon, has changed D is not output
as it was not supplied by way of |additional_compile_targets| or |test_targets|.
If the generator flag analyzer_output_path is specified, output is written
there. Otherwise output is written to stdout.
In Gyp the "all" target is shorthand for the root targets in the files passed
to gyp. For example, if file "a.gyp" contains targets "a1" and
"a2", and file "b.gyp" contains targets "b1" and "b2" and "a2" has a dependency
on "b2" and gyp is supplied "a.gyp" then "all" consists of "a1" and "a2".
Notice that "b1" and "b2" are not in the "all" target as "b.gyp" was not
directly supplied to gyp. OTOH if both "a.gyp" and "b.gyp" are supplied to gyp
then the "all" target includes "b1" and "b2".
"""
import gyp.common
import json
import os
import posixpath
debug = False
found_dependency_string = "Found dependency"
no_dependency_string = "No dependencies"
# Status when it should be assumed that everything has changed.
all_changed_string = "Found dependency (all)"
# MatchStatus is used indicate if and how a target depends upon the supplied
# sources.
# The target's sources contain one of the supplied paths.
MATCH_STATUS_MATCHES = 1
# The target has a dependency on another target that contains one of the
# supplied paths.
MATCH_STATUS_MATCHES_BY_DEPENDENCY = 2
# The target's sources weren't in the supplied paths and none of the target's
# dependencies depend upon a target that matched.
MATCH_STATUS_DOESNT_MATCH = 3
# The target doesn't contain the source, but the dependent targets have not yet
# been visited to determine a more specific status yet.
MATCH_STATUS_TBD = 4
generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
generator_wants_static_library_dependencies_adjusted = False
generator_default_variables = {}
for dirname in [
"INTERMEDIATE_DIR",
"SHARED_INTERMEDIATE_DIR",
"PRODUCT_DIR",
"LIB_DIR",
"SHARED_LIB_DIR",
]:
generator_default_variables[dirname] = "!!!"
for unused in [
"RULE_INPUT_PATH",
"RULE_INPUT_ROOT",
"RULE_INPUT_NAME",
"RULE_INPUT_DIRNAME",
"RULE_INPUT_EXT",
"EXECUTABLE_PREFIX",
"EXECUTABLE_SUFFIX",
"STATIC_LIB_PREFIX",
"STATIC_LIB_SUFFIX",
"SHARED_LIB_PREFIX",
"SHARED_LIB_SUFFIX",
"CONFIGURATION_NAME",
]:
generator_default_variables[unused] = ""
def _ToGypPath(path):
"""Converts a path to the format used by gyp."""
if os.sep == "\\" and os.altsep == "/":
return path.replace("\\", "/")
return path
def _ResolveParent(path, base_path_components):
"""Resolves |path|, which starts with at least one '../'. Returns an empty
string if the path shouldn't be considered. See _AddSources() for a
description of |base_path_components|."""
depth = 0
while path.startswith("../"):
depth += 1
path = path[3:]
# Relative includes may go outside the source tree. For example, an action may
# have inputs in /usr/include, which are not in the source tree.
if depth > len(base_path_components):
return ""
if depth == len(base_path_components):
return path
return (
"/".join(base_path_components[0 : len(base_path_components) - depth])
+ "/"
+ path
)
def _AddSources(sources, base_path, base_path_components, result):
"""Extracts valid sources from |sources| and adds them to |result|. Each
source file is relative to |base_path|, but may contain '..'. To make
resolving '..' easier |base_path_components| contains each of the
directories in |base_path|. Additionally each source may contain variables.
Such sources are ignored as it is assumed dependencies on them are expressed
and tracked in some other means."""
# NOTE: gyp paths are always posix style.
for source in sources:
if not len(source) or source.startswith("!!!") or source.startswith("$"):
continue
# variable expansion may lead to //.
org_source = source
source = source[0] + source[1:].replace("//", "/")
if source.startswith("../"):
source = _ResolveParent(source, base_path_components)
if len(source):
result.append(source)
continue
result.append(base_path + source)
if debug:
print("AddSource", org_source, result[len(result) - 1])
def _ExtractSourcesFromAction(action, base_path, base_path_components, results):
if "inputs" in action:
_AddSources(action["inputs"], base_path, base_path_components, results)
def _ToLocalPath(toplevel_dir, path):
"""Converts |path| to a path relative to |toplevel_dir|."""
if path == toplevel_dir:
return ""
if path.startswith(toplevel_dir + "/"):
return path[len(toplevel_dir) + len("/") :]
return path
def _ExtractSources(target, target_dict, toplevel_dir):
# |target| is either absolute or relative and in the format of the OS. Gyp
# source paths are always posix. Convert |target| to a posix path relative to
# |toplevel_dir_|. This is done to make it easy to build source paths.
base_path = posixpath.dirname(_ToLocalPath(toplevel_dir, _ToGypPath(target)))
base_path_components = base_path.split("/")
# Add a trailing '/' so that _AddSources() can easily build paths.
if len(base_path):
base_path += "/"
if debug:
print("ExtractSources", target, base_path)
results = []
if "sources" in target_dict:
_AddSources(target_dict["sources"], base_path, base_path_components, results)
# Include the inputs from any actions. Any changes to these affect the
# resulting output.
if "actions" in target_dict:
for action in target_dict["actions"]:
_ExtractSourcesFromAction(action, base_path, base_path_components, results)
if "rules" in target_dict:
for rule in target_dict["rules"]:
_ExtractSourcesFromAction(rule, base_path, base_path_components, results)
return results
class Target:
"""Holds information about a particular target:
deps: set of Targets this Target depends upon. This is not recursive, only the
direct dependent Targets.
match_status: one of the MatchStatus values.
back_deps: set of Targets that have a dependency on this Target.
visited: used during iteration to indicate whether we've visited this target.
This is used for two iterations, once in building the set of Targets and
again in _GetBuildTargets().
name: fully qualified name of the target.
requires_build: True if the target type is such that it needs to be built.
See _DoesTargetTypeRequireBuild for details.
added_to_compile_targets: used when determining if the target was added to the
set of targets that needs to be built.
in_roots: true if this target is a descendant of one of the root nodes.
is_executable: true if the type of target is executable.
is_static_library: true if the type of target is static_library.
is_or_has_linked_ancestor: true if the target does a link (eg executable), or
if there is a target in back_deps that does a link."""
def __init__(self, name):
self.deps = set()
self.match_status = MATCH_STATUS_TBD
self.back_deps = set()
self.name = name
# TODO(sky): I don't like hanging this off Target. This state is specific
# to certain functions and should be isolated there.
self.visited = False
self.requires_build = False
self.added_to_compile_targets = False
self.in_roots = False
self.is_executable = False
self.is_static_library = False
self.is_or_has_linked_ancestor = False
class Config:
"""Details what we're looking for
files: set of files to search for
targets: see file description for details."""
def __init__(self):
self.files = []
self.targets = set()
self.additional_compile_target_names = set()
self.test_target_names = set()
def Init(self, params):
"""Initializes Config. This is a separate method as it raises an exception
if there is a parse error."""
generator_flags = params.get("generator_flags", {})
config_path = generator_flags.get("config_path", None)
if not config_path:
return
try:
f = open(config_path)
config = json.load(f)
f.close()
except OSError:
raise Exception("Unable to open file " + config_path)
except ValueError as e:
raise Exception("Unable to parse config file " + config_path + str(e))
if not isinstance(config, dict):
raise Exception("config_path must be a JSON file containing a dictionary")
self.files = config.get("files", [])
self.additional_compile_target_names = set(
config.get("additional_compile_targets", [])
)
self.test_target_names = set(config.get("test_targets", []))
def _WasBuildFileModified(build_file, data, files, toplevel_dir):
"""Returns true if the build file |build_file| is either in |files| or
one of the files included by |build_file| is in |files|. |toplevel_dir| is
the root of the source tree."""
if _ToLocalPath(toplevel_dir, _ToGypPath(build_file)) in files:
if debug:
print("gyp file modified", build_file)
return True
# First element of included_files is the file itself.
if len(data[build_file]["included_files"]) <= 1:
return False
for include_file in data[build_file]["included_files"][1:]:
# |included_files| are relative to the directory of the |build_file|.
rel_include_file = _ToGypPath(
gyp.common.UnrelativePath(include_file, build_file)
)
if _ToLocalPath(toplevel_dir, rel_include_file) in files:
if debug:
print(
"included gyp file modified, gyp_file=",
build_file,
"included file=",
rel_include_file,
)
return True
return False
def _GetOrCreateTargetByName(targets, target_name):
"""Creates or returns the Target at targets[target_name]. If there is no
Target for |target_name| one is created. Returns a tuple of whether a new
Target was created and the Target."""
if target_name in targets:
return False, targets[target_name]
target = Target(target_name)
targets[target_name] = target
return True, target
def _DoesTargetTypeRequireBuild(target_dict):
"""Returns true if the target type is such that it needs to be built."""
# If a 'none' target has rules or actions we assume it requires a build.
return bool(
target_dict["type"] != "none"
or target_dict.get("actions")
or target_dict.get("rules")
)
def _GenerateTargets(data, target_list, target_dicts, toplevel_dir, files, build_files):
"""Returns a tuple of the following:
. A dictionary mapping from fully qualified name to Target.
. A list of the targets that have a source file in |files|.
. Targets that constitute the 'all' target. See description at top of file
for details on the 'all' target.
This sets the |match_status| of the targets that contain any of the source
files in |files| to MATCH_STATUS_MATCHES.
|toplevel_dir| is the root of the source tree."""
# Maps from target name to Target.
name_to_target = {}
# Targets that matched.
matching_targets = []
# Queue of targets to visit.
targets_to_visit = target_list[:]
# Maps from build file to a boolean indicating whether the build file is in
# |files|.
build_file_in_files = {}
# Root targets across all files.
roots = set()
# Set of Targets in |build_files|.
build_file_targets = set()
while len(targets_to_visit) > 0:
target_name = targets_to_visit.pop()
created_target, target = _GetOrCreateTargetByName(name_to_target, target_name)
if created_target:
roots.add(target)
elif target.visited:
continue
target.visited = True
target.requires_build = _DoesTargetTypeRequireBuild(target_dicts[target_name])
target_type = target_dicts[target_name]["type"]
target.is_executable = target_type == "executable"
target.is_static_library = target_type == "static_library"
target.is_or_has_linked_ancestor = (
target_type == "executable" or target_type == "shared_library"
)
build_file = gyp.common.ParseQualifiedTarget(target_name)[0]
if build_file not in build_file_in_files:
build_file_in_files[build_file] = _WasBuildFileModified(
build_file, data, files, toplevel_dir
)
if build_file in build_files:
build_file_targets.add(target)
# If a build file (or any of its included files) is modified we assume all
# targets in the file are modified.
if build_file_in_files[build_file]:
print("matching target from modified build file", target_name)
target.match_status = MATCH_STATUS_MATCHES
matching_targets.append(target)
else:
sources = _ExtractSources(
target_name, target_dicts[target_name], toplevel_dir
)
for source in sources:
if _ToGypPath(os.path.normpath(source)) in files:
print("target", target_name, "matches", source)
target.match_status = MATCH_STATUS_MATCHES
matching_targets.append(target)
break
# Add dependencies to visit as well as updating back pointers for deps.
for dep in target_dicts[target_name].get("dependencies", []):
targets_to_visit.append(dep)
created_dep_target, dep_target = _GetOrCreateTargetByName(
name_to_target, dep
)
if not created_dep_target:
roots.discard(dep_target)
target.deps.add(dep_target)
dep_target.back_deps.add(target)
return name_to_target, matching_targets, roots & build_file_targets
def _GetUnqualifiedToTargetMapping(all_targets, to_find):
"""Returns a tuple of the following:
. mapping (dictionary) from unqualified name to Target for all the
Targets in |to_find|.
. any target names not found. If this is empty all targets were found."""
result = {}
if not to_find:
return {}, []
to_find = set(to_find)
for target_name in all_targets.keys():
extracted = gyp.common.ParseQualifiedTarget(target_name)
if len(extracted) > 1 and extracted[1] in to_find:
to_find.remove(extracted[1])
result[extracted[1]] = all_targets[target_name]
if not to_find:
return result, []
return result, [x for x in to_find]
def _DoesTargetDependOnMatchingTargets(target):
"""Returns true if |target| or any of its dependencies is one of the
targets containing the files supplied as input to analyzer. This updates
|matches| of the Targets as it recurses.
target: the Target to look for."""
if target.match_status == MATCH_STATUS_DOESNT_MATCH:
return False
if (
target.match_status == MATCH_STATUS_MATCHES
or target.match_status == MATCH_STATUS_MATCHES_BY_DEPENDENCY
):
return True
for dep in target.deps:
if _DoesTargetDependOnMatchingTargets(dep):
target.match_status = MATCH_STATUS_MATCHES_BY_DEPENDENCY
print("\t", target.name, "matches by dep", dep.name)
return True
target.match_status = MATCH_STATUS_DOESNT_MATCH
return False
def _GetTargetsDependingOnMatchingTargets(possible_targets):
"""Returns the list of Targets in |possible_targets| that depend (either
directly on indirectly) on at least one of the targets containing the files
supplied as input to analyzer.
possible_targets: targets to search from."""
found = []
print("Targets that matched by dependency:")
for target in possible_targets:
if _DoesTargetDependOnMatchingTargets(target):
found.append(target)
return found
def _AddCompileTargets(target, roots, add_if_no_ancestor, result):
"""Recurses through all targets that depend on |target|, adding all targets
that need to be built (and are in |roots|) to |result|.
roots: set of root targets.
add_if_no_ancestor: If true and there are no ancestors of |target| then add
|target| to |result|. |target| must still be in |roots|.
result: targets that need to be built are added here."""
if target.visited:
return
target.visited = True
target.in_roots = target in roots
for back_dep_target in target.back_deps:
_AddCompileTargets(back_dep_target, roots, False, result)
target.added_to_compile_targets |= back_dep_target.added_to_compile_targets
target.in_roots |= back_dep_target.in_roots
target.is_or_has_linked_ancestor |= back_dep_target.is_or_has_linked_ancestor
# Always add 'executable' targets. Even though they may be built by other
# targets that depend upon them it makes detection of what is going to be
# built easier.
# And always add static_libraries that have no dependencies on them from
# linkables. This is necessary as the other dependencies on them may be
# static libraries themselves, which are not compile time dependencies.
if target.in_roots and (
target.is_executable
or (
not target.added_to_compile_targets
and (add_if_no_ancestor or target.requires_build)
)
or (
target.is_static_library
and add_if_no_ancestor
and not target.is_or_has_linked_ancestor
)
):
print(
"\t\tadding to compile targets",
target.name,
"executable",
target.is_executable,
"added_to_compile_targets",
target.added_to_compile_targets,
"add_if_no_ancestor",
add_if_no_ancestor,
"requires_build",
target.requires_build,
"is_static_library",
target.is_static_library,
"is_or_has_linked_ancestor",
target.is_or_has_linked_ancestor,
)
result.add(target)
target.added_to_compile_targets = True
def _GetCompileTargets(matching_targets, supplied_targets):
"""Returns the set of Targets that require a build.
matching_targets: targets that changed and need to be built.
supplied_targets: set of targets supplied to analyzer to search from."""
result = set()
for target in matching_targets:
print("finding compile targets for match", target.name)
_AddCompileTargets(target, supplied_targets, True, result)
return result
def _WriteOutput(params, **values):
"""Writes the output, either to stdout or a file is specified."""
if "error" in values:
print("Error:", values["error"])
if "status" in values:
print(values["status"])
if "targets" in values:
values["targets"].sort()
print("Supplied targets that depend on changed files:")
for target in values["targets"]:
print("\t", target)
if "invalid_targets" in values:
values["invalid_targets"].sort()
print("The following targets were not found:")
for target in values["invalid_targets"]:
print("\t", target)
if "build_targets" in values:
values["build_targets"].sort()
print("Targets that require a build:")
for target in values["build_targets"]:
print("\t", target)
if "compile_targets" in values:
values["compile_targets"].sort()
print("Targets that need to be built:")
for target in values["compile_targets"]:
print("\t", target)
if "test_targets" in values:
values["test_targets"].sort()
print("Test targets:")
for target in values["test_targets"]:
print("\t", target)
output_path = params.get("generator_flags", {}).get("analyzer_output_path", None)
if not output_path:
print(json.dumps(values))
return
try:
f = open(output_path, "w")
f.write(json.dumps(values) + "\n")
f.close()
except OSError as e:
print("Error writing to output file", output_path, str(e))
def _WasGypIncludeFileModified(params, files):
"""Returns true if one of the files in |files| is in the set of included
files."""
if params["options"].includes:
for include in params["options"].includes:
if _ToGypPath(os.path.normpath(include)) in files:
print("Include file modified, assuming all changed", include)
return True
return False
def _NamesNotIn(names, mapping):
"""Returns a list of the values in |names| that are not in |mapping|."""
return [name for name in names if name not in mapping]
def _LookupTargets(names, mapping):
"""Returns a list of the mapping[name] for each value in |names| that is in
|mapping|."""
return [mapping[name] for name in names if name in mapping]
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
flavor = gyp.common.GetFlavor(params)
if flavor == "mac":
default_variables.setdefault("OS", "mac")
elif flavor == "win":
default_variables.setdefault("OS", "win")
gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
else:
operating_system = flavor
if flavor == "android":
operating_system = "linux" # Keep this legacy behavior for now.
default_variables.setdefault("OS", operating_system)
class TargetCalculator:
"""Calculates the matching test_targets and matching compile_targets."""
def __init__(
self,
files,
additional_compile_target_names,
test_target_names,
data,
target_list,
target_dicts,
toplevel_dir,
build_files,
):
self._additional_compile_target_names = set(additional_compile_target_names)
self._test_target_names = set(test_target_names)
(
self._name_to_target,
self._changed_targets,
self._root_targets,
) = _GenerateTargets(
data, target_list, target_dicts, toplevel_dir, frozenset(files), build_files
)
(
self._unqualified_mapping,
self.invalid_targets,
) = _GetUnqualifiedToTargetMapping(
self._name_to_target, self._supplied_target_names_no_all()
)
def _supplied_target_names(self):
return self._additional_compile_target_names | self._test_target_names
def _supplied_target_names_no_all(self):
"""Returns the supplied test targets without 'all'."""
result = self._supplied_target_names()
result.discard("all")
return result
def is_build_impacted(self):
"""Returns true if the supplied files impact the build at all."""
return self._changed_targets
def find_matching_test_target_names(self):
"""Returns the set of output test targets."""
assert self.is_build_impacted()
# Find the test targets first. 'all' is special cased to mean all the
# root targets. To deal with all the supplied |test_targets| are expanded
# to include the root targets during lookup. If any of the root targets
# match, we remove it and replace it with 'all'.
test_target_names_no_all = set(self._test_target_names)
test_target_names_no_all.discard("all")
test_targets_no_all = _LookupTargets(
test_target_names_no_all, self._unqualified_mapping
)
test_target_names_contains_all = "all" in self._test_target_names
if test_target_names_contains_all:
test_targets = [
x for x in (set(test_targets_no_all) | set(self._root_targets))
]
else:
test_targets = [x for x in test_targets_no_all]
print("supplied test_targets")
for target_name in self._test_target_names:
print("\t", target_name)
print("found test_targets")
for target in test_targets:
print("\t", target.name)
print("searching for matching test targets")
matching_test_targets = _GetTargetsDependingOnMatchingTargets(test_targets)
matching_test_targets_contains_all = test_target_names_contains_all and set(
matching_test_targets
) & set(self._root_targets)
if matching_test_targets_contains_all:
# Remove any of the targets for all that were not explicitly supplied,
# 'all' is subsequentely added to the matching names below.
matching_test_targets = [
x for x in (set(matching_test_targets) & set(test_targets_no_all))
]
print("matched test_targets")
for target in matching_test_targets:
print("\t", target.name)
matching_target_names = [
gyp.common.ParseQualifiedTarget(target.name)[1]
for target in matching_test_targets
]
if matching_test_targets_contains_all:
matching_target_names.append("all")
print("\tall")
return matching_target_names
def find_matching_compile_target_names(self):
"""Returns the set of output compile targets."""
assert self.is_build_impacted()
# Compile targets are found by searching up from changed targets.
# Reset the visited status for _GetBuildTargets.
for target in self._name_to_target.values():
target.visited = False
supplied_targets = _LookupTargets(
self._supplied_target_names_no_all(), self._unqualified_mapping
)
if "all" in self._supplied_target_names():
supplied_targets = [
x for x in (set(supplied_targets) | set(self._root_targets))
]
print("Supplied test_targets & compile_targets")
for target in supplied_targets:
print("\t", target.name)
print("Finding compile targets")
compile_targets = _GetCompileTargets(self._changed_targets, supplied_targets)
return [
gyp.common.ParseQualifiedTarget(target.name)[1]
for target in compile_targets
]
def GenerateOutput(target_list, target_dicts, data, params):
"""Called by gyp as the final stage. Outputs results."""
config = Config()
try:
config.Init(params)
if not config.files:
raise Exception(
"Must specify files to analyze via config_path generator " "flag"
)
toplevel_dir = _ToGypPath(os.path.abspath(params["options"].toplevel_dir))
if debug:
print("toplevel_dir", toplevel_dir)
if _WasGypIncludeFileModified(params, config.files):
result_dict = {
"status": all_changed_string,
"test_targets": list(config.test_target_names),
"compile_targets": list(
config.additional_compile_target_names | config.test_target_names
),
}
_WriteOutput(params, **result_dict)
return
calculator = TargetCalculator(
config.files,
config.additional_compile_target_names,
config.test_target_names,
data,
target_list,
target_dicts,
toplevel_dir,
params["build_files"],
)
if not calculator.is_build_impacted():
result_dict = {
"status": no_dependency_string,
"test_targets": [],
"compile_targets": [],
}
if calculator.invalid_targets:
result_dict["invalid_targets"] = calculator.invalid_targets
_WriteOutput(params, **result_dict)
return
test_target_names = calculator.find_matching_test_target_names()
compile_target_names = calculator.find_matching_compile_target_names()
found_at_least_one_target = compile_target_names or test_target_names
result_dict = {
"test_targets": test_target_names,
"status": found_dependency_string
if found_at_least_one_target
else no_dependency_string,
"compile_targets": list(set(compile_target_names) | set(test_target_names)),
}
if calculator.invalid_targets:
result_dict["invalid_targets"] = calculator.invalid_targets
_WriteOutput(params, **result_dict)
except Exception as e:
_WriteOutput(params, error=str(e))
node-gyp-9.3.0/gyp/pylib/gyp/generator/android.py 0000664 0000000 0000000 00000141456 14321173220 0021750 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Notes:
#
# This generates makefiles suitable for inclusion into the Android build system
# via an Android.mk file. It is based on make.py, the standard makefile
# generator.
#
# The code below generates a separate .mk file for each target, but
# all are sourced by the top-level GypAndroid.mk. This means that all
# variables in .mk-files clobber one another, and furthermore that any
# variables set potentially clash with other Android build system variables.
# Try to avoid setting global variables where possible.
import gyp
import gyp.common
import gyp.generator.make as make # Reuse global functions from make backend.
import os
import re
import subprocess
generator_default_variables = {
"OS": "android",
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"STATIC_LIB_PREFIX": "lib",
"SHARED_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
"SHARED_LIB_SUFFIX": ".so",
"INTERMEDIATE_DIR": "$(gyp_intermediate_dir)",
"SHARED_INTERMEDIATE_DIR": "$(gyp_shared_intermediate_dir)",
"PRODUCT_DIR": "$(gyp_shared_intermediate_dir)",
"SHARED_LIB_DIR": "$(builddir)/lib.$(TOOLSET)",
"LIB_DIR": "$(obj).$(TOOLSET)",
"RULE_INPUT_ROOT": "%(INPUT_ROOT)s", # This gets expanded by Python.
"RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s", # This gets expanded by Python.
"RULE_INPUT_PATH": "$(RULE_SOURCES)",
"RULE_INPUT_EXT": "$(suffix $<)",
"RULE_INPUT_NAME": "$(notdir $<)",
"CONFIGURATION_NAME": "$(GYP_CONFIGURATION)",
}
# Make supports multiple toolsets
generator_supports_multiple_toolsets = True
# Generator-specific gyp specs.
generator_additional_non_configuration_keys = [
# Boolean to declare that this target does not want its name mangled.
"android_unmangled_name",
# Map of android build system variables to set.
"aosp_build_settings",
]
generator_additional_path_sections = []
generator_extra_sources_for_rules = []
ALL_MODULES_FOOTER = """\
# "gyp_all_modules" is a concatenation of the "gyp_all_modules" targets from
# all the included sub-makefiles. This is just here to clarify.
gyp_all_modules:
"""
header = """\
# This file is generated by gyp; do not edit.
"""
# Map gyp target types to Android module classes.
MODULE_CLASSES = {
"static_library": "STATIC_LIBRARIES",
"shared_library": "SHARED_LIBRARIES",
"executable": "EXECUTABLES",
}
def IsCPPExtension(ext):
return make.COMPILABLE_EXTENSIONS.get(ext) == "cxx"
def Sourceify(path):
"""Convert a path to its source directory form. The Android backend does not
support options.generator_output, so this function is a noop."""
return path
# Map from qualified target to path to output.
# For Android, the target of these maps is a tuple ('static', 'modulename'),
# ('dynamic', 'modulename'), or ('path', 'some/path') instead of a string,
# since we link by module.
target_outputs = {}
# Map from qualified target to any linkable output. A subset
# of target_outputs. E.g. when mybinary depends on liba, we want to
# include liba in the linker line; when otherbinary depends on
# mybinary, we just want to build mybinary first.
target_link_deps = {}
class AndroidMkWriter:
"""AndroidMkWriter packages up the writing of one target-specific Android.mk.
Its only real entry point is Write(), and is mostly used for namespacing.
"""
def __init__(self, android_top_dir):
self.android_top_dir = android_top_dir
def Write(
self,
qualified_target,
relative_target,
base_path,
output_filename,
spec,
configs,
part_of_all,
write_alias_target,
sdk_version,
):
"""The main entry point: writes a .mk file for a single target.
Arguments:
qualified_target: target we're generating
relative_target: qualified target name relative to the root
base_path: path relative to source root we're building in, used to resolve
target-relative paths
output_filename: output .mk file name to write
spec, configs: gyp info
part_of_all: flag indicating this target is part of 'all'
write_alias_target: flag indicating whether to create short aliases for
this target
sdk_version: what to emit for LOCAL_SDK_VERSION in output
"""
gyp.common.EnsureDirExists(output_filename)
self.fp = open(output_filename, "w")
self.fp.write(header)
self.qualified_target = qualified_target
self.relative_target = relative_target
self.path = base_path
self.target = spec["target_name"]
self.type = spec["type"]
self.toolset = spec["toolset"]
deps, link_deps = self.ComputeDeps(spec)
# Some of the generation below can add extra output, sources, or
# link dependencies. All of the out params of the functions that
# follow use names like extra_foo.
extra_outputs = []
extra_sources = []
self.android_class = MODULE_CLASSES.get(self.type, "GYP")
self.android_module = self.ComputeAndroidModule(spec)
(self.android_stem, self.android_suffix) = self.ComputeOutputParts(spec)
self.output = self.output_binary = self.ComputeOutput(spec)
# Standard header.
self.WriteLn("include $(CLEAR_VARS)\n")
# Module class and name.
self.WriteLn("LOCAL_MODULE_CLASS := " + self.android_class)
self.WriteLn("LOCAL_MODULE := " + self.android_module)
# Only emit LOCAL_MODULE_STEM if it's different to LOCAL_MODULE.
# The library module classes fail if the stem is set. ComputeOutputParts
# makes sure that stem == modulename in these cases.
if self.android_stem != self.android_module:
self.WriteLn("LOCAL_MODULE_STEM := " + self.android_stem)
self.WriteLn("LOCAL_MODULE_SUFFIX := " + self.android_suffix)
if self.toolset == "host":
self.WriteLn("LOCAL_IS_HOST_MODULE := true")
self.WriteLn("LOCAL_MULTILIB := $(GYP_HOST_MULTILIB)")
elif sdk_version > 0:
self.WriteLn(
"LOCAL_MODULE_TARGET_ARCH := " "$(TARGET_$(GYP_VAR_PREFIX)ARCH)"
)
self.WriteLn("LOCAL_SDK_VERSION := %s" % sdk_version)
# Grab output directories; needed for Actions and Rules.
if self.toolset == "host":
self.WriteLn(
"gyp_intermediate_dir := "
"$(call local-intermediates-dir,,$(GYP_HOST_VAR_PREFIX))"
)
else:
self.WriteLn(
"gyp_intermediate_dir := "
"$(call local-intermediates-dir,,$(GYP_VAR_PREFIX))"
)
self.WriteLn(
"gyp_shared_intermediate_dir := "
"$(call intermediates-dir-for,GYP,shared,,,$(GYP_VAR_PREFIX))"
)
self.WriteLn()
# List files this target depends on so that actions/rules/copies/sources
# can depend on the list.
# TODO: doesn't pull in things through transitive link deps; needed?
target_dependencies = [x[1] for x in deps if x[0] == "path"]
self.WriteLn("# Make sure our deps are built first.")
self.WriteList(
target_dependencies, "GYP_TARGET_DEPENDENCIES", local_pathify=True
)
# Actions must come first, since they can generate more OBJs for use below.
if "actions" in spec:
self.WriteActions(spec["actions"], extra_sources, extra_outputs)
# Rules must be early like actions.
if "rules" in spec:
self.WriteRules(spec["rules"], extra_sources, extra_outputs)
if "copies" in spec:
self.WriteCopies(spec["copies"], extra_outputs)
# GYP generated outputs.
self.WriteList(extra_outputs, "GYP_GENERATED_OUTPUTS", local_pathify=True)
# Set LOCAL_ADDITIONAL_DEPENDENCIES so that Android's build rules depend
# on both our dependency targets and our generated files.
self.WriteLn("# Make sure our deps and generated files are built first.")
self.WriteLn(
"LOCAL_ADDITIONAL_DEPENDENCIES := $(GYP_TARGET_DEPENDENCIES) "
"$(GYP_GENERATED_OUTPUTS)"
)
self.WriteLn()
# Sources.
if spec.get("sources", []) or extra_sources:
self.WriteSources(spec, configs, extra_sources)
self.WriteTarget(
spec, configs, deps, link_deps, part_of_all, write_alias_target
)
# Update global list of target outputs, used in dependency tracking.
target_outputs[qualified_target] = ("path", self.output_binary)
# Update global list of link dependencies.
if self.type == "static_library":
target_link_deps[qualified_target] = ("static", self.android_module)
elif self.type == "shared_library":
target_link_deps[qualified_target] = ("shared", self.android_module)
self.fp.close()
return self.android_module
def WriteActions(self, actions, extra_sources, extra_outputs):
"""Write Makefile code for any 'actions' from the gyp input.
extra_sources: a list that will be filled in with newly generated source
files, if any
extra_outputs: a list that will be filled in with any outputs of these
actions (used to make other pieces dependent on these
actions)
"""
for action in actions:
name = make.StringToMakefileVariable(
"{}_{}".format(self.relative_target, action["action_name"])
)
self.WriteLn('### Rules for action "%s":' % action["action_name"])
inputs = action["inputs"]
outputs = action["outputs"]
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = set()
for out in outputs:
if not out.startswith("$"):
print(
'WARNING: Action for target "%s" writes output to local path '
'"%s".' % (self.target, out)
)
dir = os.path.split(out)[0]
if dir:
dirs.add(dir)
if int(action.get("process_outputs_as_sources", False)):
extra_sources += outputs
# Prepare the actual command.
command = gyp.common.EncodePOSIXShellList(action["action"])
if "message" in action:
quiet_cmd = "Gyp action: %s ($@)" % action["message"]
else:
quiet_cmd = "Gyp action: %s ($@)" % name
if len(dirs) > 0:
command = "mkdir -p %s" % " ".join(dirs) + "; " + command
cd_action = "cd $(gyp_local_path)/%s; " % self.path
command = cd_action + command
# The makefile rules are all relative to the top dir, but the gyp actions
# are defined relative to their containing dir. This replaces the gyp_*
# variables for the action rule with an absolute version so that the
# output goes in the right place.
# Only write the gyp_* rules for the "primary" output (:1);
# it's superfluous for the "extra outputs", and this avoids accidentally
# writing duplicate dummy rules for those outputs.
main_output = make.QuoteSpaces(self.LocalPathify(outputs[0]))
self.WriteLn("%s: gyp_local_path := $(LOCAL_PATH)" % main_output)
self.WriteLn("%s: gyp_var_prefix := $(GYP_VAR_PREFIX)" % main_output)
self.WriteLn(
"%s: gyp_intermediate_dir := "
"$(abspath $(gyp_intermediate_dir))" % main_output
)
self.WriteLn(
"%s: gyp_shared_intermediate_dir := "
"$(abspath $(gyp_shared_intermediate_dir))" % main_output
)
# Android's envsetup.sh adds a number of directories to the path including
# the built host binary directory. This causes actions/rules invoked by
# gyp to sometimes use these instead of system versions, e.g. bison.
# The built host binaries may not be suitable, and can cause errors.
# So, we remove them from the PATH using the ANDROID_BUILD_PATHS variable
# set by envsetup.
self.WriteLn(
"%s: export PATH := $(subst $(ANDROID_BUILD_PATHS),,$(PATH))"
% main_output
)
# Don't allow spaces in input/output filenames, but make an exception for
# filenames which start with '$(' since it's okay for there to be spaces
# inside of make function/macro invocations.
for input in inputs:
if not input.startswith("$(") and " " in input:
raise gyp.common.GypError(
'Action input filename "%s" in target %s contains a space'
% (input, self.target)
)
for output in outputs:
if not output.startswith("$(") and " " in output:
raise gyp.common.GypError(
'Action output filename "%s" in target %s contains a space'
% (output, self.target)
)
self.WriteLn(
"%s: %s $(GYP_TARGET_DEPENDENCIES)"
% (main_output, " ".join(map(self.LocalPathify, inputs)))
)
self.WriteLn('\t@echo "%s"' % quiet_cmd)
self.WriteLn("\t$(hide)%s\n" % command)
for output in outputs[1:]:
# Make each output depend on the main output, with an empty command
# to force make to notice that the mtime has changed.
self.WriteLn(f"{self.LocalPathify(output)}: {main_output} ;")
extra_outputs += outputs
self.WriteLn()
self.WriteLn()
def WriteRules(self, rules, extra_sources, extra_outputs):
"""Write Makefile code for any 'rules' from the gyp input.
extra_sources: a list that will be filled in with newly generated source
files, if any
extra_outputs: a list that will be filled in with any outputs of these
rules (used to make other pieces dependent on these rules)
"""
if len(rules) == 0:
return
for rule in rules:
if len(rule.get("rule_sources", [])) == 0:
continue
name = make.StringToMakefileVariable(
"{}_{}".format(self.relative_target, rule["rule_name"])
)
self.WriteLn('\n### Generated for rule "%s":' % name)
self.WriteLn('# "%s":' % rule)
inputs = rule.get("inputs")
for rule_source in rule.get("rule_sources", []):
(rule_source_dirname, rule_source_basename) = os.path.split(rule_source)
(rule_source_root, rule_source_ext) = os.path.splitext(
rule_source_basename
)
outputs = [
self.ExpandInputRoot(out, rule_source_root, rule_source_dirname)
for out in rule["outputs"]
]
dirs = set()
for out in outputs:
if not out.startswith("$"):
print(
"WARNING: Rule for target %s writes output to local path %s"
% (self.target, out)
)
dir = os.path.dirname(out)
if dir:
dirs.add(dir)
extra_outputs += outputs
if int(rule.get("process_outputs_as_sources", False)):
extra_sources.extend(outputs)
components = []
for component in rule["action"]:
component = self.ExpandInputRoot(
component, rule_source_root, rule_source_dirname
)
if "$(RULE_SOURCES)" in component:
component = component.replace("$(RULE_SOURCES)", rule_source)
components.append(component)
command = gyp.common.EncodePOSIXShellList(components)
cd_action = "cd $(gyp_local_path)/%s; " % self.path
command = cd_action + command
if dirs:
command = "mkdir -p %s" % " ".join(dirs) + "; " + command
# We set up a rule to build the first output, and then set up
# a rule for each additional output to depend on the first.
outputs = map(self.LocalPathify, outputs)
main_output = outputs[0]
self.WriteLn("%s: gyp_local_path := $(LOCAL_PATH)" % main_output)
self.WriteLn("%s: gyp_var_prefix := $(GYP_VAR_PREFIX)" % main_output)
self.WriteLn(
"%s: gyp_intermediate_dir := "
"$(abspath $(gyp_intermediate_dir))" % main_output
)
self.WriteLn(
"%s: gyp_shared_intermediate_dir := "
"$(abspath $(gyp_shared_intermediate_dir))" % main_output
)
# See explanation in WriteActions.
self.WriteLn(
"%s: export PATH := "
"$(subst $(ANDROID_BUILD_PATHS),,$(PATH))" % main_output
)
main_output_deps = self.LocalPathify(rule_source)
if inputs:
main_output_deps += " "
main_output_deps += " ".join([self.LocalPathify(f) for f in inputs])
self.WriteLn(
"%s: %s $(GYP_TARGET_DEPENDENCIES)"
% (main_output, main_output_deps)
)
self.WriteLn("\t%s\n" % command)
for output in outputs[1:]:
# Make each output depend on the main output, with an empty command
# to force make to notice that the mtime has changed.
self.WriteLn(f"{output}: {main_output} ;")
self.WriteLn()
self.WriteLn()
def WriteCopies(self, copies, extra_outputs):
"""Write Makefile code for any 'copies' from the gyp input.
extra_outputs: a list that will be filled in with any outputs of this action
(used to make other pieces dependent on this action)
"""
self.WriteLn("### Generated for copy rule.")
variable = make.StringToMakefileVariable(self.relative_target + "_copies")
outputs = []
for copy in copies:
for path in copy["files"]:
# The Android build system does not allow generation of files into the
# source tree. The destination should start with a variable, which will
# typically be $(gyp_intermediate_dir) or
# $(gyp_shared_intermediate_dir). Note that we can't use an assertion
# because some of the gyp tests depend on this.
if not copy["destination"].startswith("$"):
print(
"WARNING: Copy rule for target %s writes output to "
"local path %s" % (self.target, copy["destination"])
)
# LocalPathify() calls normpath, stripping trailing slashes.
path = Sourceify(self.LocalPathify(path))
filename = os.path.split(path)[1]
output = Sourceify(
self.LocalPathify(os.path.join(copy["destination"], filename))
)
self.WriteLn(f"{output}: {path} $(GYP_TARGET_DEPENDENCIES) | $(ACP)")
self.WriteLn("\t@echo Copying: $@")
self.WriteLn("\t$(hide) mkdir -p $(dir $@)")
self.WriteLn("\t$(hide) $(ACP) -rpf $< $@")
self.WriteLn()
outputs.append(output)
self.WriteLn(
"{} = {}".format(variable, " ".join(map(make.QuoteSpaces, outputs)))
)
extra_outputs.append("$(%s)" % variable)
self.WriteLn()
def WriteSourceFlags(self, spec, configs):
"""Write out the flags and include paths used to compile source files for
the current target.
Args:
spec, configs: input from gyp.
"""
for configname, config in sorted(configs.items()):
extracted_includes = []
self.WriteLn("\n# Flags passed to both C and C++ files.")
cflags, includes_from_cflags = self.ExtractIncludesFromCFlags(
config.get("cflags", []) + config.get("cflags_c", [])
)
extracted_includes.extend(includes_from_cflags)
self.WriteList(cflags, "MY_CFLAGS_%s" % configname)
self.WriteList(
config.get("defines"),
"MY_DEFS_%s" % configname,
prefix="-D",
quoter=make.EscapeCppDefine,
)
self.WriteLn("\n# Include paths placed before CFLAGS/CPPFLAGS")
includes = list(config.get("include_dirs", []))
includes.extend(extracted_includes)
includes = map(Sourceify, map(self.LocalPathify, includes))
includes = self.NormalizeIncludePaths(includes)
self.WriteList(includes, "LOCAL_C_INCLUDES_%s" % configname)
self.WriteLn("\n# Flags passed to only C++ (and not C) files.")
self.WriteList(config.get("cflags_cc"), "LOCAL_CPPFLAGS_%s" % configname)
self.WriteLn(
"\nLOCAL_CFLAGS := $(MY_CFLAGS_$(GYP_CONFIGURATION)) "
"$(MY_DEFS_$(GYP_CONFIGURATION))"
)
# Undefine ANDROID for host modules
# TODO: the source code should not use macro ANDROID to tell if it's host
# or target module.
if self.toolset == "host":
self.WriteLn("# Undefine ANDROID for host modules")
self.WriteLn("LOCAL_CFLAGS += -UANDROID")
self.WriteLn(
"LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) "
"$(LOCAL_C_INCLUDES_$(GYP_CONFIGURATION))"
)
self.WriteLn("LOCAL_CPPFLAGS := $(LOCAL_CPPFLAGS_$(GYP_CONFIGURATION))")
# Android uses separate flags for assembly file invocations, but gyp expects
# the same CFLAGS to be applied:
self.WriteLn("LOCAL_ASFLAGS := $(LOCAL_CFLAGS)")
def WriteSources(self, spec, configs, extra_sources):
"""Write Makefile code for any 'sources' from the gyp input.
These are source files necessary to build the current target.
We need to handle shared_intermediate directory source files as
a special case by copying them to the intermediate directory and
treating them as a generated sources. Otherwise the Android build
rules won't pick them up.
Args:
spec, configs: input from gyp.
extra_sources: Sources generated from Actions or Rules.
"""
sources = filter(make.Compilable, spec.get("sources", []))
generated_not_sources = [x for x in extra_sources if not make.Compilable(x)]
extra_sources = filter(make.Compilable, extra_sources)
# Determine and output the C++ extension used by these sources.
# We simply find the first C++ file and use that extension.
all_sources = sources + extra_sources
local_cpp_extension = ".cpp"
for source in all_sources:
(root, ext) = os.path.splitext(source)
if IsCPPExtension(ext):
local_cpp_extension = ext
break
if local_cpp_extension != ".cpp":
self.WriteLn("LOCAL_CPP_EXTENSION := %s" % local_cpp_extension)
# We need to move any non-generated sources that are coming from the
# shared intermediate directory out of LOCAL_SRC_FILES and put them
# into LOCAL_GENERATED_SOURCES. We also need to move over any C++ files
# that don't match our local_cpp_extension, since Android will only
# generate Makefile rules for a single LOCAL_CPP_EXTENSION.
local_files = []
for source in sources:
(root, ext) = os.path.splitext(source)
if "$(gyp_shared_intermediate_dir)" in source:
extra_sources.append(source)
elif "$(gyp_intermediate_dir)" in source:
extra_sources.append(source)
elif IsCPPExtension(ext) and ext != local_cpp_extension:
extra_sources.append(source)
else:
local_files.append(os.path.normpath(os.path.join(self.path, source)))
# For any generated source, if it is coming from the shared intermediate
# directory then we add a Make rule to copy them to the local intermediate
# directory first. This is because the Android LOCAL_GENERATED_SOURCES
# must be in the local module intermediate directory for the compile rules
# to work properly. If the file has the wrong C++ extension, then we add
# a rule to copy that to intermediates and use the new version.
final_generated_sources = []
# If a source file gets copied, we still need to add the original source
# directory as header search path, for GCC searches headers in the
# directory that contains the source file by default.
origin_src_dirs = []
for source in extra_sources:
local_file = source
if "$(gyp_intermediate_dir)/" not in local_file:
basename = os.path.basename(local_file)
local_file = "$(gyp_intermediate_dir)/" + basename
(root, ext) = os.path.splitext(local_file)
if IsCPPExtension(ext) and ext != local_cpp_extension:
local_file = root + local_cpp_extension
if local_file != source:
self.WriteLn(f"{local_file}: {self.LocalPathify(source)}")
self.WriteLn("\tmkdir -p $(@D); cp $< $@")
origin_src_dirs.append(os.path.dirname(source))
final_generated_sources.append(local_file)
# We add back in all of the non-compilable stuff to make sure that the
# make rules have dependencies on them.
final_generated_sources.extend(generated_not_sources)
self.WriteList(final_generated_sources, "LOCAL_GENERATED_SOURCES")
origin_src_dirs = gyp.common.uniquer(origin_src_dirs)
origin_src_dirs = map(Sourceify, map(self.LocalPathify, origin_src_dirs))
self.WriteList(origin_src_dirs, "GYP_COPIED_SOURCE_ORIGIN_DIRS")
self.WriteList(local_files, "LOCAL_SRC_FILES")
# Write out the flags used to compile the source; this must be done last
# so that GYP_COPIED_SOURCE_ORIGIN_DIRS can be used as an include path.
self.WriteSourceFlags(spec, configs)
def ComputeAndroidModule(self, spec):
"""Return the Android module name used for a gyp spec.
We use the complete qualified target name to avoid collisions between
duplicate targets in different directories. We also add a suffix to
distinguish gyp-generated module names.
"""
if int(spec.get("android_unmangled_name", 0)):
assert self.type != "shared_library" or self.target.startswith("lib")
return self.target
if self.type == "shared_library":
# For reasons of convention, the Android build system requires that all
# shared library modules are named 'libfoo' when generating -l flags.
prefix = "lib_"
else:
prefix = ""
if spec["toolset"] == "host":
suffix = "_$(TARGET_$(GYP_VAR_PREFIX)ARCH)_host_gyp"
else:
suffix = "_gyp"
if self.path:
middle = make.StringToMakefileVariable(f"{self.path}_{self.target}")
else:
middle = make.StringToMakefileVariable(self.target)
return "".join([prefix, middle, suffix])
def ComputeOutputParts(self, spec):
"""Return the 'output basename' of a gyp spec, split into filename + ext.
Android libraries must be named the same thing as their module name,
otherwise the linker can't find them, so product_name and so on must be
ignored if we are building a library, and the "lib" prepending is
not done for Android.
"""
assert self.type != "loadable_module" # TODO: not supported?
target = spec["target_name"]
target_prefix = ""
target_ext = ""
if self.type == "static_library":
target = self.ComputeAndroidModule(spec)
target_ext = ".a"
elif self.type == "shared_library":
target = self.ComputeAndroidModule(spec)
target_ext = ".so"
elif self.type == "none":
target_ext = ".stamp"
elif self.type != "executable":
print(
"ERROR: What output file should be generated?",
"type",
self.type,
"target",
target,
)
if self.type != "static_library" and self.type != "shared_library":
target_prefix = spec.get("product_prefix", target_prefix)
target = spec.get("product_name", target)
product_ext = spec.get("product_extension")
if product_ext:
target_ext = "." + product_ext
target_stem = target_prefix + target
return (target_stem, target_ext)
def ComputeOutputBasename(self, spec):
"""Return the 'output basename' of a gyp spec.
E.g., the loadable module 'foobar' in directory 'baz' will produce
'libfoobar.so'
"""
return "".join(self.ComputeOutputParts(spec))
def ComputeOutput(self, spec):
"""Return the 'output' (full output path) of a gyp spec.
E.g., the loadable module 'foobar' in directory 'baz' will produce
'$(obj)/baz/libfoobar.so'
"""
if self.type == "executable":
# We install host executables into shared_intermediate_dir so they can be
# run by gyp rules that refer to PRODUCT_DIR.
path = "$(gyp_shared_intermediate_dir)"
elif self.type == "shared_library":
if self.toolset == "host":
path = "$($(GYP_HOST_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES)"
else:
path = "$($(GYP_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)"
else:
# Other targets just get built into their intermediate dir.
if self.toolset == "host":
path = (
"$(call intermediates-dir-for,%s,%s,true,,"
"$(GYP_HOST_VAR_PREFIX))"
% (self.android_class, self.android_module)
)
else:
path = "$(call intermediates-dir-for,{},{},,,$(GYP_VAR_PREFIX))".format(
self.android_class,
self.android_module,
)
assert spec.get("product_dir") is None # TODO: not supported?
return os.path.join(path, self.ComputeOutputBasename(spec))
def NormalizeIncludePaths(self, include_paths):
"""Normalize include_paths.
Convert absolute paths to relative to the Android top directory.
Args:
include_paths: A list of unprocessed include paths.
Returns:
A list of normalized include paths.
"""
normalized = []
for path in include_paths:
if path[0] == "/":
path = gyp.common.RelativePath(path, self.android_top_dir)
normalized.append(path)
return normalized
def ExtractIncludesFromCFlags(self, cflags):
"""Extract includes "-I..." out from cflags
Args:
cflags: A list of compiler flags, which may be mixed with "-I.."
Returns:
A tuple of lists: (clean_clfags, include_paths). "-I.." is trimmed.
"""
clean_cflags = []
include_paths = []
for flag in cflags:
if flag.startswith("-I"):
include_paths.append(flag[2:])
else:
clean_cflags.append(flag)
return (clean_cflags, include_paths)
def FilterLibraries(self, libraries):
"""Filter the 'libraries' key to separate things that shouldn't be ldflags.
Library entries that look like filenames should be converted to android
module names instead of being passed to the linker as flags.
Args:
libraries: the value of spec.get('libraries')
Returns:
A tuple (static_lib_modules, dynamic_lib_modules, ldflags)
"""
static_lib_modules = []
dynamic_lib_modules = []
ldflags = []
for libs in libraries:
# Libs can have multiple words.
for lib in libs.split():
# Filter the system libraries, which are added by default by the Android
# build system.
if (
lib == "-lc"
or lib == "-lstdc++"
or lib == "-lm"
or lib.endswith("libgcc.a")
):
continue
match = re.search(r"([^/]+)\.a$", lib)
if match:
static_lib_modules.append(match.group(1))
continue
match = re.search(r"([^/]+)\.so$", lib)
if match:
dynamic_lib_modules.append(match.group(1))
continue
if lib.startswith("-l"):
ldflags.append(lib)
return (static_lib_modules, dynamic_lib_modules, ldflags)
def ComputeDeps(self, spec):
"""Compute the dependencies of a gyp spec.
Returns a tuple (deps, link_deps), where each is a list of
filenames that will need to be put in front of make for either
building (deps) or linking (link_deps).
"""
deps = []
link_deps = []
if "dependencies" in spec:
deps.extend(
[
target_outputs[dep]
for dep in spec["dependencies"]
if target_outputs[dep]
]
)
for dep in spec["dependencies"]:
if dep in target_link_deps:
link_deps.append(target_link_deps[dep])
deps.extend(link_deps)
return (gyp.common.uniquer(deps), gyp.common.uniquer(link_deps))
def WriteTargetFlags(self, spec, configs, link_deps):
"""Write Makefile code to specify the link flags and library dependencies.
spec, configs: input from gyp.
link_deps: link dependency list; see ComputeDeps()
"""
# Libraries (i.e. -lfoo)
# These must be included even for static libraries as some of them provide
# implicit include paths through the build system.
libraries = gyp.common.uniquer(spec.get("libraries", []))
static_libs, dynamic_libs, ldflags_libs = self.FilterLibraries(libraries)
if self.type != "static_library":
for configname, config in sorted(configs.items()):
ldflags = list(config.get("ldflags", []))
self.WriteLn("")
self.WriteList(ldflags, "LOCAL_LDFLAGS_%s" % configname)
self.WriteList(ldflags_libs, "LOCAL_GYP_LIBS")
self.WriteLn(
"LOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION)) "
"$(LOCAL_GYP_LIBS)"
)
# Link dependencies (i.e. other gyp targets this target depends on)
# These need not be included for static libraries as within the gyp build
# we do not use the implicit include path mechanism.
if self.type != "static_library":
static_link_deps = [x[1] for x in link_deps if x[0] == "static"]
shared_link_deps = [x[1] for x in link_deps if x[0] == "shared"]
else:
static_link_deps = []
shared_link_deps = []
# Only write the lists if they are non-empty.
if static_libs or static_link_deps:
self.WriteLn("")
self.WriteList(static_libs + static_link_deps, "LOCAL_STATIC_LIBRARIES")
self.WriteLn("# Enable grouping to fix circular references")
self.WriteLn("LOCAL_GROUP_STATIC_LIBRARIES := true")
if dynamic_libs or shared_link_deps:
self.WriteLn("")
self.WriteList(dynamic_libs + shared_link_deps, "LOCAL_SHARED_LIBRARIES")
def WriteTarget(
self, spec, configs, deps, link_deps, part_of_all, write_alias_target
):
"""Write Makefile code to produce the final target of the gyp spec.
spec, configs: input from gyp.
deps, link_deps: dependency lists; see ComputeDeps()
part_of_all: flag indicating this target is part of 'all'
write_alias_target: flag indicating whether to create short aliases for this
target
"""
self.WriteLn("### Rules for final target.")
if self.type != "none":
self.WriteTargetFlags(spec, configs, link_deps)
settings = spec.get("aosp_build_settings", {})
if settings:
self.WriteLn("### Set directly by aosp_build_settings.")
for k, v in settings.items():
if isinstance(v, list):
self.WriteList(v, k)
else:
self.WriteLn(f"{k} := {make.QuoteIfNecessary(v)}")
self.WriteLn("")
# Add to the set of targets which represent the gyp 'all' target. We use the
# name 'gyp_all_modules' as the Android build system doesn't allow the use
# of the Make target 'all' and because 'all_modules' is the equivalent of
# the Make target 'all' on Android.
if part_of_all and write_alias_target:
self.WriteLn('# Add target alias to "gyp_all_modules" target.')
self.WriteLn(".PHONY: gyp_all_modules")
self.WriteLn("gyp_all_modules: %s" % self.android_module)
self.WriteLn("")
# Add an alias from the gyp target name to the Android module name. This
# simplifies manual builds of the target, and is required by the test
# framework.
if self.target != self.android_module and write_alias_target:
self.WriteLn("# Alias gyp target name.")
self.WriteLn(".PHONY: %s" % self.target)
self.WriteLn(f"{self.target}: {self.android_module}")
self.WriteLn("")
# Add the command to trigger build of the target type depending
# on the toolset. Ex: BUILD_STATIC_LIBRARY vs. BUILD_HOST_STATIC_LIBRARY
# NOTE: This has to come last!
modifier = ""
if self.toolset == "host":
modifier = "HOST_"
if self.type == "static_library":
self.WriteLn("include $(BUILD_%sSTATIC_LIBRARY)" % modifier)
elif self.type == "shared_library":
self.WriteLn("LOCAL_PRELINK_MODULE := false")
self.WriteLn("include $(BUILD_%sSHARED_LIBRARY)" % modifier)
elif self.type == "executable":
self.WriteLn("LOCAL_CXX_STL := libc++_static")
# Executables are for build and test purposes only, so they're installed
# to a directory that doesn't get included in the system image.
self.WriteLn("LOCAL_MODULE_PATH := $(gyp_shared_intermediate_dir)")
self.WriteLn("include $(BUILD_%sEXECUTABLE)" % modifier)
else:
self.WriteLn("LOCAL_MODULE_PATH := $(PRODUCT_OUT)/gyp_stamp")
self.WriteLn("LOCAL_UNINSTALLABLE_MODULE := true")
if self.toolset == "target":
self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_VAR_PREFIX)")
else:
self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_HOST_VAR_PREFIX)")
self.WriteLn()
self.WriteLn("include $(BUILD_SYSTEM)/base_rules.mk")
self.WriteLn()
self.WriteLn("$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES)")
self.WriteLn('\t$(hide) echo "Gyp timestamp: $@"')
self.WriteLn("\t$(hide) mkdir -p $(dir $@)")
self.WriteLn("\t$(hide) touch $@")
self.WriteLn()
self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX :=")
def WriteList(
self,
value_list,
variable=None,
prefix="",
quoter=make.QuoteIfNecessary,
local_pathify=False,
):
"""Write a variable definition that is a list of values.
E.g. WriteList(['a','b'], 'foo', prefix='blah') writes out
foo = blaha blahb
but in a pretty-printed style.
"""
values = ""
if value_list:
value_list = [quoter(prefix + value) for value in value_list]
if local_pathify:
value_list = [self.LocalPathify(value) for value in value_list]
values = " \\\n\t" + " \\\n\t".join(value_list)
self.fp.write(f"{variable} :={values}\n\n")
def WriteLn(self, text=""):
self.fp.write(text + "\n")
def LocalPathify(self, path):
"""Convert a subdirectory-relative path into a normalized path which starts
with the make variable $(LOCAL_PATH) (i.e. the top of the project tree).
Absolute paths, or paths that contain variables, are just normalized."""
if "$(" in path or os.path.isabs(path):
# path is not a file in the project tree in this case, but calling
# normpath is still important for trimming trailing slashes.
return os.path.normpath(path)
local_path = os.path.join("$(LOCAL_PATH)", self.path, path)
local_path = os.path.normpath(local_path)
# Check that normalizing the path didn't ../ itself out of $(LOCAL_PATH)
# - i.e. that the resulting path is still inside the project tree. The
# path may legitimately have ended up containing just $(LOCAL_PATH), though,
# so we don't look for a slash.
assert local_path.startswith(
"$(LOCAL_PATH)"
), f"Path {path} attempts to escape from gyp path {self.path} !)"
return local_path
def ExpandInputRoot(self, template, expansion, dirname):
if "%(INPUT_ROOT)s" not in template and "%(INPUT_DIRNAME)s" not in template:
return template
path = template % {
"INPUT_ROOT": expansion,
"INPUT_DIRNAME": dirname,
}
return os.path.normpath(path)
def PerformBuild(data, configurations, params):
# The android backend only supports the default configuration.
options = params["options"]
makefile = os.path.abspath(os.path.join(options.toplevel_dir, "GypAndroid.mk"))
env = dict(os.environ)
env["ONE_SHOT_MAKEFILE"] = makefile
arguments = ["make", "-C", os.environ["ANDROID_BUILD_TOP"], "gyp_all_modules"]
print("Building: %s" % arguments)
subprocess.check_call(arguments, env=env)
def GenerateOutput(target_list, target_dicts, data, params):
options = params["options"]
generator_flags = params.get("generator_flags", {})
limit_to_target_all = generator_flags.get("limit_to_target_all", False)
write_alias_targets = generator_flags.get("write_alias_targets", True)
sdk_version = generator_flags.get("aosp_sdk_version", 0)
android_top_dir = os.environ.get("ANDROID_BUILD_TOP")
assert android_top_dir, "$ANDROID_BUILD_TOP not set; you need to run lunch."
def CalculateMakefilePath(build_file, base_name):
"""Determine where to write a Makefile for a given gyp file."""
# Paths in gyp files are relative to the .gyp file, but we want
# paths relative to the source root for the master makefile. Grab
# the path of the .gyp file as the base to relativize against.
# E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
base_path = gyp.common.RelativePath(os.path.dirname(build_file), options.depth)
# We write the file in the base_path directory.
output_file = os.path.join(options.depth, base_path, base_name)
assert (
not options.generator_output
), "The Android backend does not support options.generator_output."
base_path = gyp.common.RelativePath(
os.path.dirname(build_file), options.toplevel_dir
)
return base_path, output_file
# TODO: search for the first non-'Default' target. This can go
# away when we add verification that all targets have the
# necessary configurations.
default_configuration = None
for target in target_list:
spec = target_dicts[target]
if spec["default_configuration"] != "Default":
default_configuration = spec["default_configuration"]
break
if not default_configuration:
default_configuration = "Default"
makefile_name = "GypAndroid" + options.suffix + ".mk"
makefile_path = os.path.join(options.toplevel_dir, makefile_name)
assert (
not options.generator_output
), "The Android backend does not support options.generator_output."
gyp.common.EnsureDirExists(makefile_path)
root_makefile = open(makefile_path, "w")
root_makefile.write(header)
# We set LOCAL_PATH just once, here, to the top of the project tree. This
# allows all the other paths we use to be relative to the Android.mk file,
# as the Android build system expects.
root_makefile.write("\nLOCAL_PATH := $(call my-dir)\n")
# Find the list of targets that derive from the gyp file(s) being built.
needed_targets = set()
for build_file in params["build_files"]:
for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
needed_targets.add(target)
build_files = set()
include_list = set()
android_modules = {}
for qualified_target in target_list:
build_file, target, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
relative_build_file = gyp.common.RelativePath(build_file, options.toplevel_dir)
build_files.add(relative_build_file)
included_files = data[build_file]["included_files"]
for included_file in included_files:
# The included_files entries are relative to the dir of the build file
# that included them, so we have to undo that and then make them relative
# to the root dir.
relative_include_file = gyp.common.RelativePath(
gyp.common.UnrelativePath(included_file, build_file),
options.toplevel_dir,
)
abs_include_file = os.path.abspath(relative_include_file)
# If the include file is from the ~/.gyp dir, we should use absolute path
# so that relocating the src dir doesn't break the path.
if params["home_dot_gyp"] and abs_include_file.startswith(
params["home_dot_gyp"]
):
build_files.add(abs_include_file)
else:
build_files.add(relative_include_file)
base_path, output_file = CalculateMakefilePath(
build_file, target + "." + toolset + options.suffix + ".mk"
)
spec = target_dicts[qualified_target]
configs = spec["configurations"]
part_of_all = qualified_target in needed_targets
if limit_to_target_all and not part_of_all:
continue
relative_target = gyp.common.QualifiedTarget(
relative_build_file, target, toolset
)
writer = AndroidMkWriter(android_top_dir)
android_module = writer.Write(
qualified_target,
relative_target,
base_path,
output_file,
spec,
configs,
part_of_all=part_of_all,
write_alias_target=write_alias_targets,
sdk_version=sdk_version,
)
if android_module in android_modules:
print(
"ERROR: Android module names must be unique. The following "
"targets both generate Android module name %s.\n %s\n %s"
% (android_module, android_modules[android_module], qualified_target)
)
return
android_modules[android_module] = qualified_target
# Our root_makefile lives at the source root. Compute the relative path
# from there to the output_file for including.
mkfile_rel_path = gyp.common.RelativePath(
output_file, os.path.dirname(makefile_path)
)
include_list.add(mkfile_rel_path)
root_makefile.write("GYP_CONFIGURATION ?= %s\n" % default_configuration)
root_makefile.write("GYP_VAR_PREFIX ?=\n")
root_makefile.write("GYP_HOST_VAR_PREFIX ?=\n")
root_makefile.write("GYP_HOST_MULTILIB ?= first\n")
# Write out the sorted list of includes.
root_makefile.write("\n")
for include_file in sorted(include_list):
root_makefile.write("include $(LOCAL_PATH)/" + include_file + "\n")
root_makefile.write("\n")
if write_alias_targets:
root_makefile.write(ALL_MODULES_FOOTER)
root_makefile.close()
node-gyp-9.3.0/gyp/pylib/gyp/generator/cmake.py 0000664 0000000 0000000 00000140140 14321173220 0021375 0 ustar 00root root 0000000 0000000 # Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""cmake output module
This module is under development and should be considered experimental.
This module produces cmake (2.8.8+) input as its output. One CMakeLists.txt is
created for each configuration.
This module's original purpose was to support editing in IDEs like KDevelop
which use CMake for project management. It is also possible to use CMake to
generate projects for other IDEs such as eclipse cdt and code::blocks. QtCreator
will convert the CMakeLists.txt to a code::blocks cbp for the editor to read,
but build using CMake. As a result QtCreator editor is unaware of compiler
defines. The generated CMakeLists.txt can also be used to build on Linux. There
is currently no support for building on platforms other than Linux.
The generated CMakeLists.txt should properly compile all projects. However,
there is a mismatch between gyp and cmake with regard to linking. All attempts
are made to work around this, but CMake sometimes sees -Wl,--start-group as a
library and incorrectly repeats it. As a result the output of this generator
should not be relied on for building.
When using with kdevelop, use version 4.4+. Previous versions of kdevelop will
not be able to find the header file directories described in the generated
CMakeLists.txt file.
"""
import multiprocessing
import os
import signal
import subprocess
import gyp.common
import gyp.xcode_emulation
_maketrans = str.maketrans
generator_default_variables = {
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"STATIC_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
"SHARED_LIB_PREFIX": "lib",
"SHARED_LIB_SUFFIX": ".so",
"SHARED_LIB_DIR": "${builddir}/lib.${TOOLSET}",
"LIB_DIR": "${obj}.${TOOLSET}",
"INTERMEDIATE_DIR": "${obj}.${TOOLSET}/${TARGET}/geni",
"SHARED_INTERMEDIATE_DIR": "${obj}/gen",
"PRODUCT_DIR": "${builddir}",
"RULE_INPUT_PATH": "${RULE_INPUT_PATH}",
"RULE_INPUT_DIRNAME": "${RULE_INPUT_DIRNAME}",
"RULE_INPUT_NAME": "${RULE_INPUT_NAME}",
"RULE_INPUT_ROOT": "${RULE_INPUT_ROOT}",
"RULE_INPUT_EXT": "${RULE_INPUT_EXT}",
"CONFIGURATION_NAME": "${configuration}",
}
FULL_PATH_VARS = ("${CMAKE_CURRENT_LIST_DIR}", "${builddir}", "${obj}")
generator_supports_multiple_toolsets = True
generator_wants_static_library_dependencies_adjusted = True
COMPILABLE_EXTENSIONS = {
".c": "cc",
".cc": "cxx",
".cpp": "cxx",
".cxx": "cxx",
".s": "s", # cc
".S": "s", # cc
}
def RemovePrefix(a, prefix):
"""Returns 'a' without 'prefix' if it starts with 'prefix'."""
return a[len(prefix) :] if a.startswith(prefix) else a
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
default_variables.setdefault("OS", gyp.common.GetFlavor(params))
def Compilable(filename):
"""Return true if the file is compilable (should be in OBJS)."""
return any(filename.endswith(e) for e in COMPILABLE_EXTENSIONS)
def Linkable(filename):
"""Return true if the file is linkable (should be on the link line)."""
return filename.endswith(".o")
def NormjoinPathForceCMakeSource(base_path, rel_path):
"""Resolves rel_path against base_path and returns the result.
If rel_path is an absolute path it is returned unchanged.
Otherwise it is resolved against base_path and normalized.
If the result is a relative path, it is forced to be relative to the
CMakeLists.txt.
"""
if os.path.isabs(rel_path):
return rel_path
if any([rel_path.startswith(var) for var in FULL_PATH_VARS]):
return rel_path
# TODO: do we need to check base_path for absolute variables as well?
return os.path.join(
"${CMAKE_CURRENT_LIST_DIR}", os.path.normpath(os.path.join(base_path, rel_path))
)
def NormjoinPath(base_path, rel_path):
"""Resolves rel_path against base_path and returns the result.
TODO: what is this really used for?
If rel_path begins with '$' it is returned unchanged.
Otherwise it is resolved against base_path if relative, then normalized.
"""
if rel_path.startswith("$") and not rel_path.startswith("${configuration}"):
return rel_path
return os.path.normpath(os.path.join(base_path, rel_path))
def CMakeStringEscape(a):
"""Escapes the string 'a' for use inside a CMake string.
This means escaping
'\' otherwise it may be seen as modifying the next character
'"' otherwise it will end the string
';' otherwise the string becomes a list
The following do not need to be escaped
'#' when the lexer is in string state, this does not start a comment
The following are yet unknown
'$' generator variables (like ${obj}) must not be escaped,
but text $ should be escaped
what is wanted is to know which $ come from generator variables
"""
return a.replace("\\", "\\\\").replace(";", "\\;").replace('"', '\\"')
def SetFileProperty(output, source_name, property_name, values, sep):
"""Given a set of source file, sets the given property on them."""
output.write("set_source_files_properties(")
output.write(source_name)
output.write(" PROPERTIES ")
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetFilesProperty(output, variable, property_name, values, sep):
"""Given a set of source files, sets the given property on them."""
output.write("set_source_files_properties(")
WriteVariable(output, variable)
output.write(" PROPERTIES ")
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetTargetProperty(output, target_name, property_name, values, sep=""):
"""Given a target, sets the given property."""
output.write("set_target_properties(")
output.write(target_name)
output.write(" PROPERTIES ")
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetVariable(output, variable_name, value):
"""Sets a CMake variable."""
output.write("set(")
output.write(variable_name)
output.write(' "')
output.write(CMakeStringEscape(value))
output.write('")\n')
def SetVariableList(output, variable_name, values):
"""Sets a CMake variable to a list."""
if not values:
return SetVariable(output, variable_name, "")
if len(values) == 1:
return SetVariable(output, variable_name, values[0])
output.write("list(APPEND ")
output.write(variable_name)
output.write('\n "')
output.write('"\n "'.join([CMakeStringEscape(value) for value in values]))
output.write('")\n')
def UnsetVariable(output, variable_name):
"""Unsets a CMake variable."""
output.write("unset(")
output.write(variable_name)
output.write(")\n")
def WriteVariable(output, variable_name, prepend=None):
if prepend:
output.write(prepend)
output.write("${")
output.write(variable_name)
output.write("}")
class CMakeTargetType:
def __init__(self, command, modifier, property_modifier):
self.command = command
self.modifier = modifier
self.property_modifier = property_modifier
cmake_target_type_from_gyp_target_type = {
"executable": CMakeTargetType("add_executable", None, "RUNTIME"),
"static_library": CMakeTargetType("add_library", "STATIC", "ARCHIVE"),
"shared_library": CMakeTargetType("add_library", "SHARED", "LIBRARY"),
"loadable_module": CMakeTargetType("add_library", "MODULE", "LIBRARY"),
"none": CMakeTargetType("add_custom_target", "SOURCES", None),
}
def StringToCMakeTargetName(a):
"""Converts the given string 'a' to a valid CMake target name.
All invalid characters are replaced by '_'.
Invalid for cmake: ' ', '/', '(', ')', '"'
Invalid for make: ':'
Invalid for unknown reasons but cause failures: '.'
"""
return a.translate(_maketrans(' /():."', "_______"))
def WriteActions(target_name, actions, extra_sources, extra_deps, path_to_gyp, output):
"""Write CMake for the 'actions' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_sources: [(, )] to append with generated source files.
extra_deps: [] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
for action in actions:
action_name = StringToCMakeTargetName(action["action_name"])
action_target_name = f"{target_name}__{action_name}"
inputs = action["inputs"]
inputs_name = action_target_name + "__input"
SetVariableList(
output,
inputs_name,
[NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs],
)
outputs = action["outputs"]
cmake_outputs = [
NormjoinPathForceCMakeSource(path_to_gyp, out) for out in outputs
]
outputs_name = action_target_name + "__output"
SetVariableList(output, outputs_name, cmake_outputs)
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = {dir for dir in (os.path.dirname(o) for o in outputs) if dir}
if int(action.get("process_outputs_as_sources", False)):
extra_sources.extend(zip(cmake_outputs, outputs))
# add_custom_command
output.write("add_custom_command(OUTPUT ")
WriteVariable(output, outputs_name)
output.write("\n")
if len(dirs) > 0:
for directory in dirs:
output.write(" COMMAND ${CMAKE_COMMAND} -E make_directory ")
output.write(directory)
output.write("\n")
output.write(" COMMAND ")
output.write(gyp.common.EncodePOSIXShellList(action["action"]))
output.write("\n")
output.write(" DEPENDS ")
WriteVariable(output, inputs_name)
output.write("\n")
output.write(" WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/")
output.write(path_to_gyp)
output.write("\n")
output.write(" COMMENT ")
if "message" in action:
output.write(action["message"])
else:
output.write(action_target_name)
output.write("\n")
output.write(" VERBATIM\n")
output.write(")\n")
# add_custom_target
output.write("add_custom_target(")
output.write(action_target_name)
output.write("\n DEPENDS ")
WriteVariable(output, outputs_name)
output.write("\n SOURCES ")
WriteVariable(output, inputs_name)
output.write("\n)\n")
extra_deps.append(action_target_name)
def NormjoinRulePathForceCMakeSource(base_path, rel_path, rule_source):
if rel_path.startswith(("${RULE_INPUT_PATH}", "${RULE_INPUT_DIRNAME}")):
if any([rule_source.startswith(var) for var in FULL_PATH_VARS]):
return rel_path
return NormjoinPathForceCMakeSource(base_path, rel_path)
def WriteRules(target_name, rules, extra_sources, extra_deps, path_to_gyp, output):
"""Write CMake for the 'rules' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_sources: [(, )] to append with generated source files.
extra_deps: [] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
for rule in rules:
rule_name = StringToCMakeTargetName(target_name + "__" + rule["rule_name"])
inputs = rule.get("inputs", [])
inputs_name = rule_name + "__input"
SetVariableList(
output,
inputs_name,
[NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs],
)
outputs = rule["outputs"]
var_outputs = []
for count, rule_source in enumerate(rule.get("rule_sources", [])):
action_name = rule_name + "_" + str(count)
rule_source_dirname, rule_source_basename = os.path.split(rule_source)
rule_source_root, rule_source_ext = os.path.splitext(rule_source_basename)
SetVariable(output, "RULE_INPUT_PATH", rule_source)
SetVariable(output, "RULE_INPUT_DIRNAME", rule_source_dirname)
SetVariable(output, "RULE_INPUT_NAME", rule_source_basename)
SetVariable(output, "RULE_INPUT_ROOT", rule_source_root)
SetVariable(output, "RULE_INPUT_EXT", rule_source_ext)
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = {dir for dir in (os.path.dirname(o) for o in outputs) if dir}
# Create variables for the output, as 'local' variable will be unset.
these_outputs = []
for output_index, out in enumerate(outputs):
output_name = action_name + "_" + str(output_index)
SetVariable(
output,
output_name,
NormjoinRulePathForceCMakeSource(path_to_gyp, out, rule_source),
)
if int(rule.get("process_outputs_as_sources", False)):
extra_sources.append(("${" + output_name + "}", out))
these_outputs.append("${" + output_name + "}")
var_outputs.append("${" + output_name + "}")
# add_custom_command
output.write("add_custom_command(OUTPUT\n")
for out in these_outputs:
output.write(" ")
output.write(out)
output.write("\n")
for directory in dirs:
output.write(" COMMAND ${CMAKE_COMMAND} -E make_directory ")
output.write(directory)
output.write("\n")
output.write(" COMMAND ")
output.write(gyp.common.EncodePOSIXShellList(rule["action"]))
output.write("\n")
output.write(" DEPENDS ")
WriteVariable(output, inputs_name)
output.write(" ")
output.write(NormjoinPath(path_to_gyp, rule_source))
output.write("\n")
# CMAKE_CURRENT_LIST_DIR is where the CMakeLists.txt lives.
# The cwd is the current build directory.
output.write(" WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/")
output.write(path_to_gyp)
output.write("\n")
output.write(" COMMENT ")
if "message" in rule:
output.write(rule["message"])
else:
output.write(action_name)
output.write("\n")
output.write(" VERBATIM\n")
output.write(")\n")
UnsetVariable(output, "RULE_INPUT_PATH")
UnsetVariable(output, "RULE_INPUT_DIRNAME")
UnsetVariable(output, "RULE_INPUT_NAME")
UnsetVariable(output, "RULE_INPUT_ROOT")
UnsetVariable(output, "RULE_INPUT_EXT")
# add_custom_target
output.write("add_custom_target(")
output.write(rule_name)
output.write(" DEPENDS\n")
for out in var_outputs:
output.write(" ")
output.write(out)
output.write("\n")
output.write("SOURCES ")
WriteVariable(output, inputs_name)
output.write("\n")
for rule_source in rule.get("rule_sources", []):
output.write(" ")
output.write(NormjoinPath(path_to_gyp, rule_source))
output.write("\n")
output.write(")\n")
extra_deps.append(rule_name)
def WriteCopies(target_name, copies, extra_deps, path_to_gyp, output):
"""Write CMake for the 'copies' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_deps: [] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
copy_name = target_name + "__copies"
# CMake gets upset with custom targets with OUTPUT which specify no output.
have_copies = any(copy["files"] for copy in copies)
if not have_copies:
output.write("add_custom_target(")
output.write(copy_name)
output.write(")\n")
extra_deps.append(copy_name)
return
class Copy:
def __init__(self, ext, command):
self.cmake_inputs = []
self.cmake_outputs = []
self.gyp_inputs = []
self.gyp_outputs = []
self.ext = ext
self.inputs_name = None
self.outputs_name = None
self.command = command
file_copy = Copy("", "copy")
dir_copy = Copy("_dirs", "copy_directory")
for copy in copies:
files = copy["files"]
destination = copy["destination"]
for src in files:
path = os.path.normpath(src)
basename = os.path.split(path)[1]
dst = os.path.join(destination, basename)
copy = file_copy if os.path.basename(src) else dir_copy
copy.cmake_inputs.append(NormjoinPathForceCMakeSource(path_to_gyp, src))
copy.cmake_outputs.append(NormjoinPathForceCMakeSource(path_to_gyp, dst))
copy.gyp_inputs.append(src)
copy.gyp_outputs.append(dst)
for copy in (file_copy, dir_copy):
if copy.cmake_inputs:
copy.inputs_name = copy_name + "__input" + copy.ext
SetVariableList(output, copy.inputs_name, copy.cmake_inputs)
copy.outputs_name = copy_name + "__output" + copy.ext
SetVariableList(output, copy.outputs_name, copy.cmake_outputs)
# add_custom_command
output.write("add_custom_command(\n")
output.write("OUTPUT")
for copy in (file_copy, dir_copy):
if copy.outputs_name:
WriteVariable(output, copy.outputs_name, " ")
output.write("\n")
for copy in (file_copy, dir_copy):
for src, dst in zip(copy.gyp_inputs, copy.gyp_outputs):
# 'cmake -E copy src dst' will create the 'dst' directory if needed.
output.write("COMMAND ${CMAKE_COMMAND} -E %s " % copy.command)
output.write(src)
output.write(" ")
output.write(dst)
output.write("\n")
output.write("DEPENDS")
for copy in (file_copy, dir_copy):
if copy.inputs_name:
WriteVariable(output, copy.inputs_name, " ")
output.write("\n")
output.write("WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/")
output.write(path_to_gyp)
output.write("\n")
output.write("COMMENT Copying for ")
output.write(target_name)
output.write("\n")
output.write("VERBATIM\n")
output.write(")\n")
# add_custom_target
output.write("add_custom_target(")
output.write(copy_name)
output.write("\n DEPENDS")
for copy in (file_copy, dir_copy):
if copy.outputs_name:
WriteVariable(output, copy.outputs_name, " ")
output.write("\n SOURCES")
if file_copy.inputs_name:
WriteVariable(output, file_copy.inputs_name, " ")
output.write("\n)\n")
extra_deps.append(copy_name)
def CreateCMakeTargetBaseName(qualified_target):
"""This is the name we would like the target to have."""
_, gyp_target_name, gyp_target_toolset = gyp.common.ParseQualifiedTarget(
qualified_target
)
cmake_target_base_name = gyp_target_name
if gyp_target_toolset and gyp_target_toolset != "target":
cmake_target_base_name += "_" + gyp_target_toolset
return StringToCMakeTargetName(cmake_target_base_name)
def CreateCMakeTargetFullName(qualified_target):
"""An unambiguous name for the target."""
gyp_file, gyp_target_name, gyp_target_toolset = gyp.common.ParseQualifiedTarget(
qualified_target
)
cmake_target_full_name = gyp_file + ":" + gyp_target_name
if gyp_target_toolset and gyp_target_toolset != "target":
cmake_target_full_name += "_" + gyp_target_toolset
return StringToCMakeTargetName(cmake_target_full_name)
class CMakeNamer:
"""Converts Gyp target names into CMake target names.
CMake requires that target names be globally unique. One way to ensure
this is to fully qualify the names of the targets. Unfortunately, this
ends up with all targets looking like "chrome_chrome_gyp_chrome" instead
of just "chrome". If this generator were only interested in building, it
would be possible to fully qualify all target names, then create
unqualified target names which depend on all qualified targets which
should have had that name. This is more or less what the 'make' generator
does with aliases. However, one goal of this generator is to create CMake
files for use with IDEs, and fully qualified names are not as user
friendly.
Since target name collision is rare, we do the above only when required.
Toolset variants are always qualified from the base, as this is required for
building. However, it also makes sense for an IDE, as it is possible for
defines to be different.
"""
def __init__(self, target_list):
self.cmake_target_base_names_conficting = set()
cmake_target_base_names_seen = set()
for qualified_target in target_list:
cmake_target_base_name = CreateCMakeTargetBaseName(qualified_target)
if cmake_target_base_name not in cmake_target_base_names_seen:
cmake_target_base_names_seen.add(cmake_target_base_name)
else:
self.cmake_target_base_names_conficting.add(cmake_target_base_name)
def CreateCMakeTargetName(self, qualified_target):
base_name = CreateCMakeTargetBaseName(qualified_target)
if base_name in self.cmake_target_base_names_conficting:
return CreateCMakeTargetFullName(qualified_target)
return base_name
def WriteTarget(
namer,
qualified_target,
target_dicts,
build_dir,
config_to_use,
options,
generator_flags,
all_qualified_targets,
flavor,
output,
):
# The make generator does this always.
# TODO: It would be nice to be able to tell CMake all dependencies.
circular_libs = generator_flags.get("circular", True)
if not generator_flags.get("standalone", False):
output.write("\n#")
output.write(qualified_target)
output.write("\n")
gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
rel_gyp_file = gyp.common.RelativePath(gyp_file, options.toplevel_dir)
rel_gyp_dir = os.path.dirname(rel_gyp_file)
# Relative path from build dir to top dir.
build_to_top = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
# Relative path from build dir to gyp dir.
build_to_gyp = os.path.join(build_to_top, rel_gyp_dir)
path_from_cmakelists_to_gyp = build_to_gyp
spec = target_dicts.get(qualified_target, {})
config = spec.get("configurations", {}).get(config_to_use, {})
xcode_settings = None
if flavor == "mac":
xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
target_name = spec.get("target_name", "")
target_type = spec.get("type", "")
target_toolset = spec.get("toolset")
cmake_target_type = cmake_target_type_from_gyp_target_type.get(target_type)
if cmake_target_type is None:
print(
"Target %s has unknown target type %s, skipping."
% (target_name, target_type)
)
return
SetVariable(output, "TARGET", target_name)
SetVariable(output, "TOOLSET", target_toolset)
cmake_target_name = namer.CreateCMakeTargetName(qualified_target)
extra_sources = []
extra_deps = []
# Actions must come first, since they can generate more OBJs for use below.
if "actions" in spec:
WriteActions(
cmake_target_name,
spec["actions"],
extra_sources,
extra_deps,
path_from_cmakelists_to_gyp,
output,
)
# Rules must be early like actions.
if "rules" in spec:
WriteRules(
cmake_target_name,
spec["rules"],
extra_sources,
extra_deps,
path_from_cmakelists_to_gyp,
output,
)
# Copies
if "copies" in spec:
WriteCopies(
cmake_target_name,
spec["copies"],
extra_deps,
path_from_cmakelists_to_gyp,
output,
)
# Target and sources
srcs = spec.get("sources", [])
# Gyp separates the sheep from the goats based on file extensions.
# A full separation is done here because of flag handing (see below).
s_sources = []
c_sources = []
cxx_sources = []
linkable_sources = []
other_sources = []
for src in srcs:
_, ext = os.path.splitext(src)
src_type = COMPILABLE_EXTENSIONS.get(ext, None)
src_norm_path = NormjoinPath(path_from_cmakelists_to_gyp, src)
if src_type == "s":
s_sources.append(src_norm_path)
elif src_type == "cc":
c_sources.append(src_norm_path)
elif src_type == "cxx":
cxx_sources.append(src_norm_path)
elif Linkable(ext):
linkable_sources.append(src_norm_path)
else:
other_sources.append(src_norm_path)
for extra_source in extra_sources:
src, real_source = extra_source
_, ext = os.path.splitext(real_source)
src_type = COMPILABLE_EXTENSIONS.get(ext, None)
if src_type == "s":
s_sources.append(src)
elif src_type == "cc":
c_sources.append(src)
elif src_type == "cxx":
cxx_sources.append(src)
elif Linkable(ext):
linkable_sources.append(src)
else:
other_sources.append(src)
s_sources_name = None
if s_sources:
s_sources_name = cmake_target_name + "__asm_srcs"
SetVariableList(output, s_sources_name, s_sources)
c_sources_name = None
if c_sources:
c_sources_name = cmake_target_name + "__c_srcs"
SetVariableList(output, c_sources_name, c_sources)
cxx_sources_name = None
if cxx_sources:
cxx_sources_name = cmake_target_name + "__cxx_srcs"
SetVariableList(output, cxx_sources_name, cxx_sources)
linkable_sources_name = None
if linkable_sources:
linkable_sources_name = cmake_target_name + "__linkable_srcs"
SetVariableList(output, linkable_sources_name, linkable_sources)
other_sources_name = None
if other_sources:
other_sources_name = cmake_target_name + "__other_srcs"
SetVariableList(output, other_sources_name, other_sources)
# CMake gets upset when executable targets provide no sources.
# http://www.cmake.org/pipermail/cmake/2010-July/038461.html
dummy_sources_name = None
has_sources = (
s_sources_name
or c_sources_name
or cxx_sources_name
or linkable_sources_name
or other_sources_name
)
if target_type == "executable" and not has_sources:
dummy_sources_name = cmake_target_name + "__dummy_srcs"
SetVariable(
output, dummy_sources_name, "${obj}.${TOOLSET}/${TARGET}/genc/dummy.c"
)
output.write('if(NOT EXISTS "')
WriteVariable(output, dummy_sources_name)
output.write('")\n')
output.write(' file(WRITE "')
WriteVariable(output, dummy_sources_name)
output.write('" "")\n')
output.write("endif()\n")
# CMake is opposed to setting linker directories and considers the practice
# of setting linker directories dangerous. Instead, it favors the use of
# find_library and passing absolute paths to target_link_libraries.
# However, CMake does provide the command link_directories, which adds
# link directories to targets defined after it is called.
# As a result, link_directories must come before the target definition.
# CMake unfortunately has no means of removing entries from LINK_DIRECTORIES.
library_dirs = config.get("library_dirs")
if library_dirs is not None:
output.write("link_directories(")
for library_dir in library_dirs:
output.write(" ")
output.write(NormjoinPath(path_from_cmakelists_to_gyp, library_dir))
output.write("\n")
output.write(")\n")
output.write(cmake_target_type.command)
output.write("(")
output.write(cmake_target_name)
if cmake_target_type.modifier is not None:
output.write(" ")
output.write(cmake_target_type.modifier)
if s_sources_name:
WriteVariable(output, s_sources_name, " ")
if c_sources_name:
WriteVariable(output, c_sources_name, " ")
if cxx_sources_name:
WriteVariable(output, cxx_sources_name, " ")
if linkable_sources_name:
WriteVariable(output, linkable_sources_name, " ")
if other_sources_name:
WriteVariable(output, other_sources_name, " ")
if dummy_sources_name:
WriteVariable(output, dummy_sources_name, " ")
output.write(")\n")
# Let CMake know if the 'all' target should depend on this target.
exclude_from_all = (
"TRUE" if qualified_target not in all_qualified_targets else "FALSE"
)
SetTargetProperty(output, cmake_target_name, "EXCLUDE_FROM_ALL", exclude_from_all)
for extra_target_name in extra_deps:
SetTargetProperty(
output, extra_target_name, "EXCLUDE_FROM_ALL", exclude_from_all
)
# Output name and location.
if target_type != "none":
# Link as 'C' if there are no other files
if not c_sources and not cxx_sources:
SetTargetProperty(output, cmake_target_name, "LINKER_LANGUAGE", ["C"])
# Mark uncompiled sources as uncompiled.
if other_sources_name:
output.write("set_source_files_properties(")
WriteVariable(output, other_sources_name, "")
output.write(' PROPERTIES HEADER_FILE_ONLY "TRUE")\n')
# Mark object sources as linkable.
if linkable_sources_name:
output.write("set_source_files_properties(")
WriteVariable(output, other_sources_name, "")
output.write(' PROPERTIES EXTERNAL_OBJECT "TRUE")\n')
# Output directory
target_output_directory = spec.get("product_dir")
if target_output_directory is None:
if target_type in ("executable", "loadable_module"):
target_output_directory = generator_default_variables["PRODUCT_DIR"]
elif target_type == "shared_library":
target_output_directory = "${builddir}/lib.${TOOLSET}"
elif spec.get("standalone_static_library", False):
target_output_directory = generator_default_variables["PRODUCT_DIR"]
else:
base_path = gyp.common.RelativePath(
os.path.dirname(gyp_file), options.toplevel_dir
)
target_output_directory = "${obj}.${TOOLSET}"
target_output_directory = os.path.join(
target_output_directory, base_path
)
cmake_target_output_directory = NormjoinPathForceCMakeSource(
path_from_cmakelists_to_gyp, target_output_directory
)
SetTargetProperty(
output,
cmake_target_name,
cmake_target_type.property_modifier + "_OUTPUT_DIRECTORY",
cmake_target_output_directory,
)
# Output name
default_product_prefix = ""
default_product_name = target_name
default_product_ext = ""
if target_type == "static_library":
static_library_prefix = generator_default_variables["STATIC_LIB_PREFIX"]
default_product_name = RemovePrefix(
default_product_name, static_library_prefix
)
default_product_prefix = static_library_prefix
default_product_ext = generator_default_variables["STATIC_LIB_SUFFIX"]
elif target_type in ("loadable_module", "shared_library"):
shared_library_prefix = generator_default_variables["SHARED_LIB_PREFIX"]
default_product_name = RemovePrefix(
default_product_name, shared_library_prefix
)
default_product_prefix = shared_library_prefix
default_product_ext = generator_default_variables["SHARED_LIB_SUFFIX"]
elif target_type != "executable":
print(
"ERROR: What output file should be generated?",
"type",
target_type,
"target",
target_name,
)
product_prefix = spec.get("product_prefix", default_product_prefix)
product_name = spec.get("product_name", default_product_name)
product_ext = spec.get("product_extension")
if product_ext:
product_ext = "." + product_ext
else:
product_ext = default_product_ext
SetTargetProperty(output, cmake_target_name, "PREFIX", product_prefix)
SetTargetProperty(
output,
cmake_target_name,
cmake_target_type.property_modifier + "_OUTPUT_NAME",
product_name,
)
SetTargetProperty(output, cmake_target_name, "SUFFIX", product_ext)
# Make the output of this target referenceable as a source.
cmake_target_output_basename = product_prefix + product_name + product_ext
cmake_target_output = os.path.join(
cmake_target_output_directory, cmake_target_output_basename
)
SetFileProperty(output, cmake_target_output, "GENERATED", ["TRUE"], "")
# Includes
includes = config.get("include_dirs")
if includes:
# This (target include directories) is what requires CMake 2.8.8
includes_name = cmake_target_name + "__include_dirs"
SetVariableList(
output,
includes_name,
[
NormjoinPathForceCMakeSource(path_from_cmakelists_to_gyp, include)
for include in includes
],
)
output.write("set_property(TARGET ")
output.write(cmake_target_name)
output.write(" APPEND PROPERTY INCLUDE_DIRECTORIES ")
WriteVariable(output, includes_name, "")
output.write(")\n")
# Defines
defines = config.get("defines")
if defines is not None:
SetTargetProperty(
output, cmake_target_name, "COMPILE_DEFINITIONS", defines, ";"
)
# Compile Flags - http://www.cmake.org/Bug/view.php?id=6493
# CMake currently does not have target C and CXX flags.
# So, instead of doing...
# cflags_c = config.get('cflags_c')
# if cflags_c is not None:
# SetTargetProperty(output, cmake_target_name,
# 'C_COMPILE_FLAGS', cflags_c, ' ')
# cflags_cc = config.get('cflags_cc')
# if cflags_cc is not None:
# SetTargetProperty(output, cmake_target_name,
# 'CXX_COMPILE_FLAGS', cflags_cc, ' ')
# Instead we must...
cflags = config.get("cflags", [])
cflags_c = config.get("cflags_c", [])
cflags_cxx = config.get("cflags_cc", [])
if xcode_settings:
cflags = xcode_settings.GetCflags(config_to_use)
cflags_c = xcode_settings.GetCflagsC(config_to_use)
cflags_cxx = xcode_settings.GetCflagsCC(config_to_use)
# cflags_objc = xcode_settings.GetCflagsObjC(config_to_use)
# cflags_objcc = xcode_settings.GetCflagsObjCC(config_to_use)
if (not cflags_c or not c_sources) and (not cflags_cxx or not cxx_sources):
SetTargetProperty(output, cmake_target_name, "COMPILE_FLAGS", cflags, " ")
elif c_sources and not (s_sources or cxx_sources):
flags = []
flags.extend(cflags)
flags.extend(cflags_c)
SetTargetProperty(output, cmake_target_name, "COMPILE_FLAGS", flags, " ")
elif cxx_sources and not (s_sources or c_sources):
flags = []
flags.extend(cflags)
flags.extend(cflags_cxx)
SetTargetProperty(output, cmake_target_name, "COMPILE_FLAGS", flags, " ")
else:
# TODO: This is broken, one cannot generally set properties on files,
# as other targets may require different properties on the same files.
if s_sources and cflags:
SetFilesProperty(output, s_sources_name, "COMPILE_FLAGS", cflags, " ")
if c_sources and (cflags or cflags_c):
flags = []
flags.extend(cflags)
flags.extend(cflags_c)
SetFilesProperty(output, c_sources_name, "COMPILE_FLAGS", flags, " ")
if cxx_sources and (cflags or cflags_cxx):
flags = []
flags.extend(cflags)
flags.extend(cflags_cxx)
SetFilesProperty(output, cxx_sources_name, "COMPILE_FLAGS", flags, " ")
# Linker flags
ldflags = config.get("ldflags")
if ldflags is not None:
SetTargetProperty(output, cmake_target_name, "LINK_FLAGS", ldflags, " ")
# XCode settings
xcode_settings = config.get("xcode_settings", {})
for xcode_setting, xcode_value in xcode_settings.items():
SetTargetProperty(
output,
cmake_target_name,
"XCODE_ATTRIBUTE_%s" % xcode_setting,
xcode_value,
"" if isinstance(xcode_value, str) else " ",
)
# Note on Dependencies and Libraries:
# CMake wants to handle link order, resolving the link line up front.
# Gyp does not retain or enforce specifying enough information to do so.
# So do as other gyp generators and use --start-group and --end-group.
# Give CMake as little information as possible so that it doesn't mess it up.
# Dependencies
rawDeps = spec.get("dependencies", [])
static_deps = []
shared_deps = []
other_deps = []
for rawDep in rawDeps:
dep_cmake_name = namer.CreateCMakeTargetName(rawDep)
dep_spec = target_dicts.get(rawDep, {})
dep_target_type = dep_spec.get("type", None)
if dep_target_type == "static_library":
static_deps.append(dep_cmake_name)
elif dep_target_type == "shared_library":
shared_deps.append(dep_cmake_name)
else:
other_deps.append(dep_cmake_name)
# ensure all external dependencies are complete before internal dependencies
# extra_deps currently only depend on their own deps, so otherwise run early
if static_deps or shared_deps or other_deps:
for extra_dep in extra_deps:
output.write("add_dependencies(")
output.write(extra_dep)
output.write("\n")
for deps in (static_deps, shared_deps, other_deps):
for dep in gyp.common.uniquer(deps):
output.write(" ")
output.write(dep)
output.write("\n")
output.write(")\n")
linkable = target_type in ("executable", "loadable_module", "shared_library")
other_deps.extend(extra_deps)
if other_deps or (not linkable and (static_deps or shared_deps)):
output.write("add_dependencies(")
output.write(cmake_target_name)
output.write("\n")
for dep in gyp.common.uniquer(other_deps):
output.write(" ")
output.write(dep)
output.write("\n")
if not linkable:
for deps in (static_deps, shared_deps):
for lib_dep in gyp.common.uniquer(deps):
output.write(" ")
output.write(lib_dep)
output.write("\n")
output.write(")\n")
# Libraries
if linkable:
external_libs = [lib for lib in spec.get("libraries", []) if len(lib) > 0]
if external_libs or static_deps or shared_deps:
output.write("target_link_libraries(")
output.write(cmake_target_name)
output.write("\n")
if static_deps:
write_group = circular_libs and len(static_deps) > 1 and flavor != "mac"
if write_group:
output.write("-Wl,--start-group\n")
for dep in gyp.common.uniquer(static_deps):
output.write(" ")
output.write(dep)
output.write("\n")
if write_group:
output.write("-Wl,--end-group\n")
if shared_deps:
for dep in gyp.common.uniquer(shared_deps):
output.write(" ")
output.write(dep)
output.write("\n")
if external_libs:
for lib in gyp.common.uniquer(external_libs):
output.write(' "')
output.write(RemovePrefix(lib, "$(SDKROOT)"))
output.write('"\n')
output.write(")\n")
UnsetVariable(output, "TOOLSET")
UnsetVariable(output, "TARGET")
def GenerateOutputForConfig(target_list, target_dicts, data, params, config_to_use):
options = params["options"]
generator_flags = params["generator_flags"]
flavor = gyp.common.GetFlavor(params)
# generator_dir: relative path from pwd to where make puts build files.
# Makes migrating from make to cmake easier, cmake doesn't put anything here.
# Each Gyp configuration creates a different CMakeLists.txt file
# to avoid incompatibilities between Gyp and CMake configurations.
generator_dir = os.path.relpath(options.generator_output or ".")
# output_dir: relative path from generator_dir to the build directory.
output_dir = generator_flags.get("output_dir", "out")
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.normpath(os.path.join(generator_dir, output_dir, config_to_use))
toplevel_build = os.path.join(options.toplevel_dir, build_dir)
output_file = os.path.join(toplevel_build, "CMakeLists.txt")
gyp.common.EnsureDirExists(output_file)
output = open(output_file, "w")
output.write("cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n")
output.write("cmake_policy(VERSION 2.8.8)\n")
gyp_file, project_target, _ = gyp.common.ParseQualifiedTarget(target_list[-1])
output.write("project(")
output.write(project_target)
output.write(")\n")
SetVariable(output, "configuration", config_to_use)
ar = None
cc = None
cxx = None
make_global_settings = data[gyp_file].get("make_global_settings", [])
build_to_top = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
for key, value in make_global_settings:
if key == "AR":
ar = os.path.join(build_to_top, value)
if key == "CC":
cc = os.path.join(build_to_top, value)
if key == "CXX":
cxx = os.path.join(build_to_top, value)
ar = gyp.common.GetEnvironFallback(["AR_target", "AR"], ar)
cc = gyp.common.GetEnvironFallback(["CC_target", "CC"], cc)
cxx = gyp.common.GetEnvironFallback(["CXX_target", "CXX"], cxx)
if ar:
SetVariable(output, "CMAKE_AR", ar)
if cc:
SetVariable(output, "CMAKE_C_COMPILER", cc)
if cxx:
SetVariable(output, "CMAKE_CXX_COMPILER", cxx)
# The following appears to be as-yet undocumented.
# http://public.kitware.com/Bug/view.php?id=8392
output.write("enable_language(ASM)\n")
# ASM-ATT does not support .S files.
# output.write('enable_language(ASM-ATT)\n')
if cc:
SetVariable(output, "CMAKE_ASM_COMPILER", cc)
SetVariable(output, "builddir", "${CMAKE_CURRENT_BINARY_DIR}")
SetVariable(output, "obj", "${builddir}/obj")
output.write("\n")
# TODO: Undocumented/unsupported (the CMake Java generator depends on it).
# CMake by default names the object resulting from foo.c to be foo.c.o.
# Gyp traditionally names the object resulting from foo.c foo.o.
# This should be irrelevant, but some targets extract .o files from .a
# and depend on the name of the extracted .o files.
output.write("set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)\n")
output.write("set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)\n")
output.write("\n")
# Force ninja to use rsp files. Otherwise link and ar lines can get too long,
# resulting in 'Argument list too long' errors.
# However, rsp files don't work correctly on Mac.
if flavor != "mac":
output.write("set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1)\n")
output.write("\n")
namer = CMakeNamer(target_list)
# The list of targets upon which the 'all' target should depend.
# CMake has it's own implicit 'all' target, one is not created explicitly.
all_qualified_targets = set()
for build_file in params["build_files"]:
for qualified_target in gyp.common.AllTargets(
target_list, target_dicts, os.path.normpath(build_file)
):
all_qualified_targets.add(qualified_target)
for qualified_target in target_list:
if flavor == "mac":
gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
spec = target_dicts[qualified_target]
gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[gyp_file], spec)
WriteTarget(
namer,
qualified_target,
target_dicts,
build_dir,
config_to_use,
options,
generator_flags,
all_qualified_targets,
flavor,
output,
)
output.close()
def PerformBuild(data, configurations, params):
options = params["options"]
generator_flags = params["generator_flags"]
# generator_dir: relative path from pwd to where make puts build files.
# Makes migrating from make to cmake easier, cmake doesn't put anything here.
generator_dir = os.path.relpath(options.generator_output or ".")
# output_dir: relative path from generator_dir to the build directory.
output_dir = generator_flags.get("output_dir", "out")
for config_name in configurations:
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.normpath(
os.path.join(generator_dir, output_dir, config_name)
)
arguments = ["cmake", "-G", "Ninja"]
print(f"Generating [{config_name}]: {arguments}")
subprocess.check_call(arguments, cwd=build_dir)
arguments = ["ninja", "-C", build_dir]
print(f"Building [{config_name}]: {arguments}")
subprocess.check_call(arguments)
def CallGenerateOutputForConfig(arglist):
# Ignore the interrupt signal so that the parent process catches it and
# kills all multiprocessing children.
signal.signal(signal.SIGINT, signal.SIG_IGN)
target_list, target_dicts, data, params, config_name = arglist
GenerateOutputForConfig(target_list, target_dicts, data, params, config_name)
def GenerateOutput(target_list, target_dicts, data, params):
user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
if params["parallel"]:
try:
pool = multiprocessing.Pool(len(config_names))
arglists = []
for config_name in config_names:
arglists.append(
(target_list, target_dicts, data, params, config_name)
)
pool.map(CallGenerateOutputForConfig, arglists)
except KeyboardInterrupt as e:
pool.terminate()
raise e
else:
for config_name in config_names:
GenerateOutputForConfig(
target_list, target_dicts, data, params, config_name
)
node-gyp-9.3.0/gyp/pylib/gyp/generator/compile_commands_json.py 0000664 0000000 0000000 00000010757 14321173220 0024671 0 ustar 00root root 0000000 0000000 # Copyright (c) 2016 Ben Noordhuis . All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import gyp.common
import gyp.xcode_emulation
import json
import os
generator_additional_non_configuration_keys = []
generator_additional_path_sections = []
generator_extra_sources_for_rules = []
generator_filelist_paths = None
generator_supports_multiple_toolsets = True
generator_wants_sorted_dependencies = False
# Lifted from make.py. The actual values don't matter much.
generator_default_variables = {
"CONFIGURATION_NAME": "$(BUILDTYPE)",
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"INTERMEDIATE_DIR": "$(obj).$(TOOLSET)/$(TARGET)/geni",
"PRODUCT_DIR": "$(builddir)",
"RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s",
"RULE_INPUT_EXT": "$(suffix $<)",
"RULE_INPUT_NAME": "$(notdir $<)",
"RULE_INPUT_PATH": "$(abspath $<)",
"RULE_INPUT_ROOT": "%(INPUT_ROOT)s",
"SHARED_INTERMEDIATE_DIR": "$(obj)/gen",
"SHARED_LIB_PREFIX": "lib",
"STATIC_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
}
def IsMac(params):
return "mac" == gyp.common.GetFlavor(params)
def CalculateVariables(default_variables, params):
default_variables.setdefault("OS", gyp.common.GetFlavor(params))
def AddCommandsForTarget(cwd, target, params, per_config_commands):
output_dir = params["generator_flags"].get("output_dir", "out")
for configuration_name, configuration in target["configurations"].items():
if IsMac(params):
xcode_settings = gyp.xcode_emulation.XcodeSettings(target)
cflags = xcode_settings.GetCflags(configuration_name)
cflags_c = xcode_settings.GetCflagsC(configuration_name)
cflags_cc = xcode_settings.GetCflagsCC(configuration_name)
else:
cflags = configuration.get("cflags", [])
cflags_c = configuration.get("cflags_c", [])
cflags_cc = configuration.get("cflags_cc", [])
cflags_c = cflags + cflags_c
cflags_cc = cflags + cflags_cc
defines = configuration.get("defines", [])
defines = ["-D" + s for s in defines]
# TODO(bnoordhuis) Handle generated source files.
extensions = (".c", ".cc", ".cpp", ".cxx")
sources = [s for s in target.get("sources", []) if s.endswith(extensions)]
def resolve(filename):
return os.path.abspath(os.path.join(cwd, filename))
# TODO(bnoordhuis) Handle generated header files.
include_dirs = configuration.get("include_dirs", [])
include_dirs = [s for s in include_dirs if not s.startswith("$(obj)")]
includes = ["-I" + resolve(s) for s in include_dirs]
defines = gyp.common.EncodePOSIXShellList(defines)
includes = gyp.common.EncodePOSIXShellList(includes)
cflags_c = gyp.common.EncodePOSIXShellList(cflags_c)
cflags_cc = gyp.common.EncodePOSIXShellList(cflags_cc)
commands = per_config_commands.setdefault(configuration_name, [])
for source in sources:
file = resolve(source)
isc = source.endswith(".c")
cc = "cc" if isc else "c++"
cflags = cflags_c if isc else cflags_cc
command = " ".join(
(
cc,
defines,
includes,
cflags,
"-c",
gyp.common.EncodePOSIXShellArgument(file),
)
)
commands.append(dict(command=command, directory=output_dir, file=file))
def GenerateOutput(target_list, target_dicts, data, params):
per_config_commands = {}
for qualified_target, target in target_dicts.items():
build_file, target_name, toolset = gyp.common.ParseQualifiedTarget(
qualified_target
)
if IsMac(params):
settings = data[build_file]
gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(settings, target)
cwd = os.path.dirname(build_file)
AddCommandsForTarget(cwd, target, params, per_config_commands)
output_dir = params["generator_flags"].get("output_dir", "out")
for configuration_name, commands in per_config_commands.items():
filename = os.path.join(output_dir, configuration_name, "compile_commands.json")
gyp.common.EnsureDirExists(filename)
fp = open(filename, "w")
json.dump(commands, fp=fp, indent=0, check_circular=False)
def PerformBuild(data, configurations, params):
pass
node-gyp-9.3.0/gyp/pylib/gyp/generator/dump_dependency_json.py 0000664 0000000 0000000 00000006035 14321173220 0024515 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import gyp
import gyp.common
import gyp.msvs_emulation
import json
generator_supports_multiple_toolsets = True
generator_wants_static_library_dependencies_adjusted = False
generator_filelist_paths = {}
generator_default_variables = {}
for dirname in [
"INTERMEDIATE_DIR",
"SHARED_INTERMEDIATE_DIR",
"PRODUCT_DIR",
"LIB_DIR",
"SHARED_LIB_DIR",
]:
# Some gyp steps fail if these are empty(!).
generator_default_variables[dirname] = "dir"
for unused in [
"RULE_INPUT_PATH",
"RULE_INPUT_ROOT",
"RULE_INPUT_NAME",
"RULE_INPUT_DIRNAME",
"RULE_INPUT_EXT",
"EXECUTABLE_PREFIX",
"EXECUTABLE_SUFFIX",
"STATIC_LIB_PREFIX",
"STATIC_LIB_SUFFIX",
"SHARED_LIB_PREFIX",
"SHARED_LIB_SUFFIX",
"CONFIGURATION_NAME",
]:
generator_default_variables[unused] = ""
def CalculateVariables(default_variables, params):
generator_flags = params.get("generator_flags", {})
for key, val in generator_flags.items():
default_variables.setdefault(key, val)
default_variables.setdefault("OS", gyp.common.GetFlavor(params))
flavor = gyp.common.GetFlavor(params)
if flavor == "win":
gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
def CalculateGeneratorInputInfo(params):
"""Calculate the generator specific info that gets fed to input (called by
gyp)."""
generator_flags = params.get("generator_flags", {})
if generator_flags.get("adjust_static_libraries", False):
global generator_wants_static_library_dependencies_adjusted
generator_wants_static_library_dependencies_adjusted = True
toplevel = params["options"].toplevel_dir
generator_dir = os.path.relpath(params["options"].generator_output or ".")
# output_dir: relative path from generator_dir to the build directory.
output_dir = generator_flags.get("output_dir", "out")
qualified_out_dir = os.path.normpath(
os.path.join(toplevel, generator_dir, output_dir, "gypfiles")
)
global generator_filelist_paths
generator_filelist_paths = {
"toplevel": toplevel,
"qualified_out_dir": qualified_out_dir,
}
def GenerateOutput(target_list, target_dicts, data, params):
# Map of target -> list of targets it depends on.
edges = {}
# Queue of targets to visit.
targets_to_visit = target_list[:]
while len(targets_to_visit) > 0:
target = targets_to_visit.pop()
if target in edges:
continue
edges[target] = []
for dep in target_dicts[target].get("dependencies", []):
edges[target].append(dep)
targets_to_visit.append(dep)
try:
filepath = params["generator_flags"]["output_dir"]
except KeyError:
filepath = "."
filename = os.path.join(filepath, "dump.json")
f = open(filename, "w")
json.dump(edges, f)
f.close()
print("Wrote json to %s." % filename)
node-gyp-9.3.0/gyp/pylib/gyp/generator/eclipse.py 0000664 0000000 0000000 00000042222 14321173220 0021743 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""GYP backend that generates Eclipse CDT settings files.
This backend DOES NOT generate Eclipse CDT projects. Instead, it generates XML
files that can be imported into an Eclipse CDT project. The XML file contains a
list of include paths and symbols (i.e. defines).
Because a full .cproject definition is not created by this generator, it's not
possible to properly define the include dirs and symbols for each file
individually. Instead, one set of includes/symbols is generated for the entire
project. This works fairly well (and is a vast improvement in general), but may
still result in a few indexer issues here and there.
This generator has no automated tests, so expect it to be broken.
"""
from xml.sax.saxutils import escape
import os.path
import subprocess
import gyp
import gyp.common
import gyp.msvs_emulation
import shlex
import xml.etree.cElementTree as ET
generator_wants_static_library_dependencies_adjusted = False
generator_default_variables = {}
for dirname in ["INTERMEDIATE_DIR", "PRODUCT_DIR", "LIB_DIR", "SHARED_LIB_DIR"]:
# Some gyp steps fail if these are empty(!), so we convert them to variables
generator_default_variables[dirname] = "$" + dirname
for unused in [
"RULE_INPUT_PATH",
"RULE_INPUT_ROOT",
"RULE_INPUT_NAME",
"RULE_INPUT_DIRNAME",
"RULE_INPUT_EXT",
"EXECUTABLE_PREFIX",
"EXECUTABLE_SUFFIX",
"STATIC_LIB_PREFIX",
"STATIC_LIB_SUFFIX",
"SHARED_LIB_PREFIX",
"SHARED_LIB_SUFFIX",
"CONFIGURATION_NAME",
]:
generator_default_variables[unused] = ""
# Include dirs will occasionally use the SHARED_INTERMEDIATE_DIR variable as
# part of the path when dealing with generated headers. This value will be
# replaced dynamically for each configuration.
generator_default_variables["SHARED_INTERMEDIATE_DIR"] = "$SHARED_INTERMEDIATE_DIR"
def CalculateVariables(default_variables, params):
generator_flags = params.get("generator_flags", {})
for key, val in generator_flags.items():
default_variables.setdefault(key, val)
flavor = gyp.common.GetFlavor(params)
default_variables.setdefault("OS", flavor)
if flavor == "win":
gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
def CalculateGeneratorInputInfo(params):
"""Calculate the generator specific info that gets fed to input (called by
gyp)."""
generator_flags = params.get("generator_flags", {})
if generator_flags.get("adjust_static_libraries", False):
global generator_wants_static_library_dependencies_adjusted
generator_wants_static_library_dependencies_adjusted = True
def GetAllIncludeDirectories(
target_list,
target_dicts,
shared_intermediate_dirs,
config_name,
params,
compiler_path,
):
"""Calculate the set of include directories to be used.
Returns:
A list including all the include_dir's specified for every target followed
by any include directories that were added as cflag compiler options.
"""
gyp_includes_set = set()
compiler_includes_list = []
# Find compiler's default include dirs.
if compiler_path:
command = shlex.split(compiler_path)
command.extend(["-E", "-xc++", "-v", "-"])
proc = subprocess.Popen(
args=command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output = proc.communicate()[1].decode("utf-8")
# Extract the list of include dirs from the output, which has this format:
# ...
# #include "..." search starts here:
# #include <...> search starts here:
# /usr/include/c++/4.6
# /usr/local/include
# End of search list.
# ...
in_include_list = False
for line in output.splitlines():
if line.startswith("#include"):
in_include_list = True
continue
if line.startswith("End of search list."):
break
if in_include_list:
include_dir = line.strip()
if include_dir not in compiler_includes_list:
compiler_includes_list.append(include_dir)
flavor = gyp.common.GetFlavor(params)
if flavor == "win":
generator_flags = params.get("generator_flags", {})
for target_name in target_list:
target = target_dicts[target_name]
if config_name in target["configurations"]:
config = target["configurations"][config_name]
# Look for any include dirs that were explicitly added via cflags. This
# may be done in gyp files to force certain includes to come at the end.
# TODO(jgreenwald): Change the gyp files to not abuse cflags for this, and
# remove this.
if flavor == "win":
msvs_settings = gyp.msvs_emulation.MsvsSettings(target, generator_flags)
cflags = msvs_settings.GetCflags(config_name)
else:
cflags = config["cflags"]
for cflag in cflags:
if cflag.startswith("-I"):
include_dir = cflag[2:]
if include_dir not in compiler_includes_list:
compiler_includes_list.append(include_dir)
# Find standard gyp include dirs.
if "include_dirs" in config:
include_dirs = config["include_dirs"]
for shared_intermediate_dir in shared_intermediate_dirs:
for include_dir in include_dirs:
include_dir = include_dir.replace(
"$SHARED_INTERMEDIATE_DIR", shared_intermediate_dir
)
if not os.path.isabs(include_dir):
base_dir = os.path.dirname(target_name)
include_dir = base_dir + "/" + include_dir
include_dir = os.path.abspath(include_dir)
gyp_includes_set.add(include_dir)
# Generate a list that has all the include dirs.
all_includes_list = list(gyp_includes_set)
all_includes_list.sort()
for compiler_include in compiler_includes_list:
if compiler_include not in gyp_includes_set:
all_includes_list.append(compiler_include)
# All done.
return all_includes_list
def GetCompilerPath(target_list, data, options):
"""Determine a command that can be used to invoke the compiler.
Returns:
If this is a gyp project that has explicit make settings, try to determine
the compiler from that. Otherwise, see if a compiler was specified via the
CC_target environment variable.
"""
# First, see if the compiler is configured in make's settings.
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
make_global_settings_dict = data[build_file].get("make_global_settings", {})
for key, value in make_global_settings_dict:
if key in ["CC", "CXX"]:
return os.path.join(options.toplevel_dir, value)
# Check to see if the compiler was specified as an environment variable.
for key in ["CC_target", "CC", "CXX"]:
compiler = os.environ.get(key)
if compiler:
return compiler
return "gcc"
def GetAllDefines(target_list, target_dicts, data, config_name, params, compiler_path):
"""Calculate the defines for a project.
Returns:
A dict that includes explicit defines declared in gyp files along with all
of the default defines that the compiler uses.
"""
# Get defines declared in the gyp files.
all_defines = {}
flavor = gyp.common.GetFlavor(params)
if flavor == "win":
generator_flags = params.get("generator_flags", {})
for target_name in target_list:
target = target_dicts[target_name]
if flavor == "win":
msvs_settings = gyp.msvs_emulation.MsvsSettings(target, generator_flags)
extra_defines = msvs_settings.GetComputedDefines(config_name)
else:
extra_defines = []
if config_name in target["configurations"]:
config = target["configurations"][config_name]
target_defines = config["defines"]
else:
target_defines = []
for define in target_defines + extra_defines:
split_define = define.split("=", 1)
if len(split_define) == 1:
split_define.append("1")
if split_define[0].strip() in all_defines:
# Already defined
continue
all_defines[split_define[0].strip()] = split_define[1].strip()
# Get default compiler defines (if possible).
if flavor == "win":
return all_defines # Default defines already processed in the loop above.
if compiler_path:
command = shlex.split(compiler_path)
command.extend(["-E", "-dM", "-"])
cpp_proc = subprocess.Popen(
args=command, cwd=".", stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
cpp_output = cpp_proc.communicate()[0].decode("utf-8")
cpp_lines = cpp_output.split("\n")
for cpp_line in cpp_lines:
if not cpp_line.strip():
continue
cpp_line_parts = cpp_line.split(" ", 2)
key = cpp_line_parts[1]
if len(cpp_line_parts) >= 3:
val = cpp_line_parts[2]
else:
val = "1"
all_defines[key] = val
return all_defines
def WriteIncludePaths(out, eclipse_langs, include_dirs):
"""Write the includes section of a CDT settings export file."""
out.write(
' \n'
)
out.write(' \n')
for lang in eclipse_langs:
out.write(' \n' % lang)
for include_dir in include_dirs:
out.write(
' %s\n'
% include_dir
)
out.write(" \n")
out.write(" \n")
def WriteMacros(out, eclipse_langs, defines):
"""Write the macros section of a CDT settings export file."""
out.write(
' \n'
)
out.write(' \n')
for lang in eclipse_langs:
out.write(' \n' % lang)
for key in sorted(defines):
out.write(
" %s%s\n"
% (escape(key), escape(defines[key]))
)
out.write(" \n")
out.write(" \n")
def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name):
options = params["options"]
generator_flags = params.get("generator_flags", {})
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.join(generator_flags.get("output_dir", "out"), config_name)
toplevel_build = os.path.join(options.toplevel_dir, build_dir)
# Ninja uses out/Debug/gen while make uses out/Debug/obj/gen as the
# SHARED_INTERMEDIATE_DIR. Include both possible locations.
shared_intermediate_dirs = [
os.path.join(toplevel_build, "obj", "gen"),
os.path.join(toplevel_build, "gen"),
]
GenerateCdtSettingsFile(
target_list,
target_dicts,
data,
params,
config_name,
os.path.join(toplevel_build, "eclipse-cdt-settings.xml"),
options,
shared_intermediate_dirs,
)
GenerateClasspathFile(
target_list,
target_dicts,
options.toplevel_dir,
toplevel_build,
os.path.join(toplevel_build, "eclipse-classpath.xml"),
)
def GenerateCdtSettingsFile(
target_list,
target_dicts,
data,
params,
config_name,
out_name,
options,
shared_intermediate_dirs,
):
gyp.common.EnsureDirExists(out_name)
with open(out_name, "w") as out:
out.write('\n')
out.write("\n")
eclipse_langs = [
"C++ Source File",
"C Source File",
"Assembly Source File",
"GNU C++",
"GNU C",
"Assembly",
]
compiler_path = GetCompilerPath(target_list, data, options)
include_dirs = GetAllIncludeDirectories(
target_list,
target_dicts,
shared_intermediate_dirs,
config_name,
params,
compiler_path,
)
WriteIncludePaths(out, eclipse_langs, include_dirs)
defines = GetAllDefines(
target_list, target_dicts, data, config_name, params, compiler_path
)
WriteMacros(out, eclipse_langs, defines)
out.write("\n")
def GenerateClasspathFile(
target_list, target_dicts, toplevel_dir, toplevel_build, out_name
):
"""Generates a classpath file suitable for symbol navigation and code
completion of Java code (such as in Android projects) by finding all
.java and .jar files used as action inputs."""
gyp.common.EnsureDirExists(out_name)
result = ET.Element("classpath")
def AddElements(kind, paths):
# First, we need to normalize the paths so they are all relative to the
# toplevel dir.
rel_paths = set()
for path in paths:
if os.path.isabs(path):
rel_paths.add(os.path.relpath(path, toplevel_dir))
else:
rel_paths.add(path)
for path in sorted(rel_paths):
entry_element = ET.SubElement(result, "classpathentry")
entry_element.set("kind", kind)
entry_element.set("path", path)
AddElements("lib", GetJavaJars(target_list, target_dicts, toplevel_dir))
AddElements("src", GetJavaSourceDirs(target_list, target_dicts, toplevel_dir))
# Include the standard JRE container and a dummy out folder
AddElements("con", ["org.eclipse.jdt.launching.JRE_CONTAINER"])
# Include a dummy out folder so that Eclipse doesn't use the default /bin
# folder in the root of the project.
AddElements("output", [os.path.join(toplevel_build, ".eclipse-java-build")])
ET.ElementTree(result).write(out_name)
def GetJavaJars(target_list, target_dicts, toplevel_dir):
"""Generates a sequence of all .jars used as inputs."""
for target_name in target_list:
target = target_dicts[target_name]
for action in target.get("actions", []):
for input_ in action["inputs"]:
if os.path.splitext(input_)[1] == ".jar" and not input_.startswith("$"):
if os.path.isabs(input_):
yield input_
else:
yield os.path.join(os.path.dirname(target_name), input_)
def GetJavaSourceDirs(target_list, target_dicts, toplevel_dir):
"""Generates a sequence of all likely java package root directories."""
for target_name in target_list:
target = target_dicts[target_name]
for action in target.get("actions", []):
for input_ in action["inputs"]:
if os.path.splitext(input_)[1] == ".java" and not input_.startswith(
"$"
):
dir_ = os.path.dirname(
os.path.join(os.path.dirname(target_name), input_)
)
# If there is a parent 'src' or 'java' folder, navigate up to it -
# these are canonical package root names in Chromium. This will
# break if 'src' or 'java' exists in the package structure. This
# could be further improved by inspecting the java file for the
# package name if this proves to be too fragile in practice.
parent_search = dir_
while os.path.basename(parent_search) not in ["src", "java"]:
parent_search, _ = os.path.split(parent_search)
if not parent_search or parent_search == toplevel_dir:
# Didn't find a known root, just return the original path
yield dir_
break
else:
yield parent_search
def GenerateOutput(target_list, target_dicts, data, params):
"""Generate an XML settings file that can be imported into a CDT project."""
if params["options"].generator_output:
raise NotImplementedError("--generator_output not implemented for eclipse")
user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
for config_name in config_names:
GenerateOutputForConfig(
target_list, target_dicts, data, params, config_name
)
node-gyp-9.3.0/gyp/pylib/gyp/generator/gypd.py 0000664 0000000 0000000 00000006661 14321173220 0021271 0 ustar 00root root 0000000 0000000 # Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""gypd output module
This module produces gyp input as its output. Output files are given the
.gypd extension to avoid overwriting the .gyp files that they are generated
from. Internal references to .gyp files (such as those found in
"dependencies" sections) are not adjusted to point to .gypd files instead;
unlike other paths, which are relative to the .gyp or .gypd file, such paths
are relative to the directory from which gyp was run to create the .gypd file.
This generator module is intended to be a sample and a debugging aid, hence
the "d" for "debug" in .gypd. It is useful to inspect the results of the
various merges, expansions, and conditional evaluations performed by gyp
and to see a representation of what would be fed to a generator module.
It's not advisable to rename .gypd files produced by this module to .gyp,
because they will have all merges, expansions, and evaluations already
performed and the relevant constructs not present in the output; paths to
dependencies may be wrong; and various sections that do not belong in .gyp
files such as such as "included_files" and "*_excluded" will be present.
Output will also be stripped of comments. This is not intended to be a
general-purpose gyp pretty-printer; for that, you probably just want to
run "pprint.pprint(eval(open('source.gyp').read()))", which will still strip
comments but won't do all of the other things done to this module's output.
The specific formatting of the output generated by this module is subject
to change.
"""
import gyp.common
import pprint
# These variables should just be spit back out as variable references.
_generator_identity_variables = [
"CONFIGURATION_NAME",
"EXECUTABLE_PREFIX",
"EXECUTABLE_SUFFIX",
"INTERMEDIATE_DIR",
"LIB_DIR",
"PRODUCT_DIR",
"RULE_INPUT_ROOT",
"RULE_INPUT_DIRNAME",
"RULE_INPUT_EXT",
"RULE_INPUT_NAME",
"RULE_INPUT_PATH",
"SHARED_INTERMEDIATE_DIR",
"SHARED_LIB_DIR",
"SHARED_LIB_PREFIX",
"SHARED_LIB_SUFFIX",
"STATIC_LIB_PREFIX",
"STATIC_LIB_SUFFIX",
]
# gypd doesn't define a default value for OS like many other generator
# modules. Specify "-D OS=whatever" on the command line to provide a value.
generator_default_variables = {}
# gypd supports multiple toolsets
generator_supports_multiple_toolsets = True
# TODO(mark): This always uses <, which isn't right. The input module should
# notify the generator to tell it which phase it is operating in, and this
# module should use < for the early phase and then switch to > for the late
# phase. Bonus points for carrying @ back into the output too.
for v in _generator_identity_variables:
generator_default_variables[v] = "<(%s)" % v
def GenerateOutput(target_list, target_dicts, data, params):
output_files = {}
for qualified_target in target_list:
[input_file, target] = gyp.common.ParseQualifiedTarget(qualified_target)[0:2]
if input_file[-4:] != ".gyp":
continue
input_file_stem = input_file[:-4]
output_file = input_file_stem + params["options"].suffix + ".gypd"
output_files[output_file] = output_files.get(output_file, input_file)
for output_file, input_file in output_files.items():
output = open(output_file, "w")
pprint.pprint(data[input_file], output)
output.close()
node-gyp-9.3.0/gyp/pylib/gyp/generator/gypsh.py 0000664 0000000 0000000 00000003261 14321173220 0021451 0 ustar 00root root 0000000 0000000 # Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""gypsh output module
gypsh is a GYP shell. It's not really a generator per se. All it does is
fire up an interactive Python session with a few local variables set to the
variables passed to the generator. Like gypd, it's intended as a debugging
aid, to facilitate the exploration of .gyp structures after being processed
by the input module.
The expected usage is "gyp -f gypsh -D OS=desired_os".
"""
import code
import sys
# All of this stuff about generator variables was lovingly ripped from gypd.py.
# That module has a much better description of what's going on and why.
_generator_identity_variables = [
"EXECUTABLE_PREFIX",
"EXECUTABLE_SUFFIX",
"INTERMEDIATE_DIR",
"PRODUCT_DIR",
"RULE_INPUT_ROOT",
"RULE_INPUT_DIRNAME",
"RULE_INPUT_EXT",
"RULE_INPUT_NAME",
"RULE_INPUT_PATH",
"SHARED_INTERMEDIATE_DIR",
]
generator_default_variables = {}
for v in _generator_identity_variables:
generator_default_variables[v] = "<(%s)" % v
def GenerateOutput(target_list, target_dicts, data, params):
locals = {
"target_list": target_list,
"target_dicts": target_dicts,
"data": data,
}
# Use a banner that looks like the stock Python one and like what
# code.interact uses by default, but tack on something to indicate what
# locals are available, and identify gypsh.
banner = "Python {} on {}\nlocals.keys() = {}\ngypsh".format(
sys.version,
sys.platform,
repr(sorted(locals.keys())),
)
code.interact(banner, local=locals)
node-gyp-9.3.0/gyp/pylib/gyp/generator/make.py 0000664 0000000 0000000 00000327506 14321173220 0021247 0 ustar 00root root 0000000 0000000 # Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Notes:
#
# This is all roughly based on the Makefile system used by the Linux
# kernel, but is a non-recursive make -- we put the entire dependency
# graph in front of make and let it figure it out.
#
# The code below generates a separate .mk file for each target, but
# all are sourced by the top-level Makefile. This means that all
# variables in .mk-files clobber one another. Be careful to use :=
# where appropriate for immediate evaluation, and similarly to watch
# that you're not relying on a variable value to last between different
# .mk files.
#
# TODOs:
#
# Global settings and utility functions are currently stuffed in the
# toplevel Makefile. It may make sense to generate some .mk files on
# the side to keep the files readable.
import os
import re
import subprocess
import gyp
import gyp.common
import gyp.xcode_emulation
from gyp.common import GetEnvironFallback
import hashlib
generator_default_variables = {
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"STATIC_LIB_PREFIX": "lib",
"SHARED_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
"INTERMEDIATE_DIR": "$(obj).$(TOOLSET)/$(TARGET)/geni",
"SHARED_INTERMEDIATE_DIR": "$(obj)/gen",
"PRODUCT_DIR": "$(builddir)",
"RULE_INPUT_ROOT": "%(INPUT_ROOT)s", # This gets expanded by Python.
"RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s", # This gets expanded by Python.
"RULE_INPUT_PATH": "$(abspath $<)",
"RULE_INPUT_EXT": "$(suffix $<)",
"RULE_INPUT_NAME": "$(notdir $<)",
"CONFIGURATION_NAME": "$(BUILDTYPE)",
}
# Make supports multiple toolsets
generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
# Request sorted dependencies in the order from dependents to dependencies.
generator_wants_sorted_dependencies = False
# Placates pylint.
generator_additional_non_configuration_keys = []
generator_additional_path_sections = []
generator_extra_sources_for_rules = []
generator_filelist_paths = None
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
flavor = gyp.common.GetFlavor(params)
if flavor == "mac":
default_variables.setdefault("OS", "mac")
default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
default_variables.setdefault(
"SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
)
default_variables.setdefault(
"LIB_DIR", generator_default_variables["PRODUCT_DIR"]
)
# Copy additional generator configuration data from Xcode, which is shared
# by the Mac Make generator.
import gyp.generator.xcode as xcode_generator
global generator_additional_non_configuration_keys
generator_additional_non_configuration_keys = getattr(
xcode_generator, "generator_additional_non_configuration_keys", []
)
global generator_additional_path_sections
generator_additional_path_sections = getattr(
xcode_generator, "generator_additional_path_sections", []
)
global generator_extra_sources_for_rules
generator_extra_sources_for_rules = getattr(
xcode_generator, "generator_extra_sources_for_rules", []
)
COMPILABLE_EXTENSIONS.update({".m": "objc", ".mm": "objcxx"})
else:
operating_system = flavor
if flavor == "android":
operating_system = "linux" # Keep this legacy behavior for now.
default_variables.setdefault("OS", operating_system)
if flavor == "aix":
default_variables.setdefault("SHARED_LIB_SUFFIX", ".a")
elif flavor == "zos":
default_variables.setdefault("SHARED_LIB_SUFFIX", ".x")
COMPILABLE_EXTENSIONS.update({".pli": "pli"})
else:
default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
default_variables.setdefault("SHARED_LIB_DIR", "$(builddir)/lib.$(TOOLSET)")
default_variables.setdefault("LIB_DIR", "$(obj).$(TOOLSET)")
def CalculateGeneratorInputInfo(params):
"""Calculate the generator specific info that gets fed to input (called by
gyp)."""
generator_flags = params.get("generator_flags", {})
android_ndk_version = generator_flags.get("android_ndk_version", None)
# Android NDK requires a strict link order.
if android_ndk_version:
global generator_wants_sorted_dependencies
generator_wants_sorted_dependencies = True
output_dir = params["options"].generator_output or params["options"].toplevel_dir
builddir_name = generator_flags.get("output_dir", "out")
qualified_out_dir = os.path.normpath(
os.path.join(output_dir, builddir_name, "gypfiles")
)
global generator_filelist_paths
generator_filelist_paths = {
"toplevel": params["options"].toplevel_dir,
"qualified_out_dir": qualified_out_dir,
}
# The .d checking code below uses these functions:
# wildcard, sort, foreach, shell, wordlist
# wildcard can handle spaces, the rest can't.
# Since I could find no way to make foreach work with spaces in filenames
# correctly, the .d files have spaces replaced with another character. The .d
# file for
# Chromium\ Framework.framework/foo
# is for example
# out/Release/.deps/out/Release/Chromium?Framework.framework/foo
# This is the replacement character.
SPACE_REPLACEMENT = "?"
LINK_COMMANDS_LINUX = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
# Due to circular dependencies between libraries :(, we wrap the
# special "figure out circular dependencies" flags around the entire
# input list during linking.
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
# Note: this does not handle spaces in paths
define xargs
$(1) $(word 1,$(2))
$(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
endef
define write-to-file
@: >$(1)
$(call xargs,@printf "%s\\n" >>$(1),$(2))
endef
OBJ_FILE_LIST := ar-file-list
define create_archive
rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
$(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
$(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
endef
define create_thin_archive
rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
$(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
$(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
endef
# We support two kinds of shared objects (.so):
# 1) shared_library, which is just bundling together many dependent libraries
# into a link line.
# 2) loadable_module, which is generating a module intended for dlopen().
#
# They differ only slightly:
# In the former case, we want to package all dependent code into the .so.
# In the latter case, we want to package just the API exposed by the
# outermost module.
# This means shared_library uses --whole-archive, while loadable_module doesn't.
# (Note that --whole-archive is incompatible with the --start-group used in
# normal linking.)
# Other shared-object link notes:
# - Set SONAME to the library filename so our binaries don't reference
# the local, absolute paths used on the link command-line.
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
""" # noqa: E501
LINK_COMMANDS_MAC = """\
quiet_cmd_alink = LIBTOOL-STATIC $@
cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
LINK_COMMANDS_ANDROID = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
# Note: this does not handle spaces in paths
define xargs
$(1) $(word 1,$(2))
$(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
endef
define write-to-file
@: >$(1)
$(call xargs,@printf "%s\\n" >>$(1),$(2))
endef
OBJ_FILE_LIST := ar-file-list
define create_archive
rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
$(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
$(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
endef
define create_thin_archive
rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
$(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
$(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
endef
# Due to circular dependencies between libraries :(, we wrap the
# special "figure out circular dependencies" flags around the entire
# input list during linking.
quiet_cmd_link = LINK($(TOOLSET)) $@
quiet_cmd_link_host = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
# Other shared-object link notes:
# - Set SONAME to the library filename so our binaries don't reference
# the local, absolute paths used on the link command-line.
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
quiet_cmd_solink_module_host = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module_host = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
LINK_COMMANDS_AIX = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
LINK_COMMANDS_OS400 = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) -X64 crs $@ $(filter %.o,$^)
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) -X64 crs $@ $(filter %.o,$^)
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
LINK_COMMANDS_OS390 = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
cmd_solink = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
# Header of toplevel Makefile.
# This should go into the build tree, but it's easier to keep it here for now.
SHARED_HEADER = (
"""\
# We borrow heavily from the kernel build setup, though we are simpler since
# we don't have Kconfig tweaking settings on us.
# The implicit make rules have it looking for RCS files, among other things.
# We instead explicitly write all the rules we care about.
# It's even quicker (saves ~200ms) to pass -r on the command line.
MAKEFLAGS=-r
# The source directory tree.
srcdir := %(srcdir)s
abs_srcdir := $(abspath $(srcdir))
# The name of the builddir.
builddir_name ?= %(builddir)s
# The V=1 flag on command line makes us verbosely print command lines.
ifdef V
quiet=
else
quiet=quiet_
endif
# Specify BUILDTYPE=Release on the command line for a release build.
BUILDTYPE ?= %(default_configuration)s
# Directory all our build output goes into.
# Note that this must be two directories beneath src/ for unit tests to pass,
# as they reach into the src/ directory for data with relative paths.
builddir ?= $(builddir_name)/$(BUILDTYPE)
abs_builddir := $(abspath $(builddir))
depsdir := $(builddir)/.deps
# Object output directory.
obj := $(builddir)/obj
abs_obj := $(abspath $(obj))
# We build up a list of every single one of the targets so we can slurp in the
# generated dependency rule Makefiles in one pass.
all_deps :=
%(make_global_settings)s
CC.target ?= %(CC.target)s
CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS)
CXX.target ?= %(CXX.target)s
CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS)
LINK.target ?= %(LINK.target)s
LDFLAGS.target ?= $(LDFLAGS)
AR.target ?= $(AR)
PLI.target ?= %(PLI.target)s
# C++ apps need to be linked with g++.
LINK ?= $(CXX.target)
# TODO(evan): move all cross-compilation logic to gyp-time so we don't need
# to replicate this environment fallback in make as well.
CC.host ?= %(CC.host)s
CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
CXX.host ?= %(CXX.host)s
CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
LINK.host ?= %(LINK.host)s
LDFLAGS.host ?= $(LDFLAGS_host)
AR.host ?= %(AR.host)s
PLI.host ?= %(PLI.host)s
# Define a dir function that can handle spaces.
# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
# "leading spaces cannot appear in the text of the first argument as written.
# These characters can be put into the argument value by variable substitution."
empty :=
space := $(empty) $(empty)
# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
replace_spaces = $(subst $(space),"""
+ SPACE_REPLACEMENT
+ """,$1)
unreplace_spaces = $(subst """
+ SPACE_REPLACEMENT
+ """,$(space),$1)
dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
# Flags to make gcc output dependency info. Note that you need to be
# careful here to use the flags that ccache and distcc can understand.
# We write to a dep file on the side first and then rename at the end
# so we can't end up with a broken dep file.
depfile = $(depsdir)/$(call replace_spaces,$@).d
DEPFLAGS = %(makedep_args)s -MF $(depfile).raw
# We have to fixup the deps output in a few ways.
# (1) the file output should mention the proper .o file.
# ccache or distcc lose the path to the target, so we convert a rule of
# the form:
# foobar.o: DEP1 DEP2
# into
# path/to/foobar.o: DEP1 DEP2
# (2) we want missing files not to cause us to fail to build.
# We want to rewrite
# foobar.o: DEP1 DEP2 \\
# DEP3
# to
# DEP1:
# DEP2:
# DEP3:
# so if the files are missing, they're just considered phony rules.
# We have to do some pretty insane escaping to get those backslashes
# and dollar signs past make, the shell, and sed at the same time.
# Doesn't work with spaces, but that's fine: .d files have spaces in
# their names replaced with other characters."""
r"""
define fixup_dep
# The depfile may not exist if the input file didn't have any #includes.
touch $(depfile).raw
# Fixup path as in (1).
sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
# Add extra rules as in (2).
# We remove slashes and replace spaces with new lines;
# remove blank lines;
# delete the first line and append a colon to the remaining lines.
sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
grep -v '^$$' |\
sed -e 1d -e 's|$$|:|' \
>> $(depfile)
rm $(depfile).raw
endef
"""
"""
# Command definitions:
# - cmd_foo is the actual command to run;
# - quiet_cmd_foo is the brief-output summary of the command.
quiet_cmd_cc = CC($(TOOLSET)) $@
cmd_cc = $(CC.$(TOOLSET)) -o $@ $< $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c
quiet_cmd_cxx = CXX($(TOOLSET)) $@
cmd_cxx = $(CXX.$(TOOLSET)) -o $@ $< $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c
%(extra_commands)s
quiet_cmd_touch = TOUCH $@
cmd_touch = touch $@
quiet_cmd_copy = COPY $@
# send stderr to /dev/null to ignore messages when linking directories.
cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp %(copy_archive_args)s "$<" "$@")
quiet_cmd_symlink = SYMLINK $@
cmd_symlink = ln -sf "$<" "$@"
%(link_commands)s
""" # noqa: E501
r"""
# Define an escape_quotes function to escape single quotes.
# This allows us to handle quotes properly as long as we always use
# use single quotes and escape_quotes.
escape_quotes = $(subst ','\'',$(1))
# This comment is here just to include a ' to unconfuse syntax highlighting.
# Define an escape_vars function to escape '$' variable syntax.
# This allows us to read/write command lines with shell variables (e.g.
# $LD_LIBRARY_PATH), without triggering make substitution.
escape_vars = $(subst $$,$$$$,$(1))
# Helper that expands to a shell command to echo a string exactly as it is in
# make. This uses printf instead of echo because printf's behaviour with respect
# to escape sequences is more portable than echo's across different shells
# (e.g., dash, bash).
exact_echo = printf '%%s\n' '$(call escape_quotes,$(1))'
"""
"""
# Helper to compare the command we're about to run against the command
# we logged the last time we ran the command. Produces an empty
# string (false) when the commands match.
# Tricky point: Make has no string-equality test function.
# The kernel uses the following, but it seems like it would have false
# positives, where one string reordered its arguments.
# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \\
# $(filter-out $(cmd_$@), $(cmd_$(1))))
# We instead substitute each for the empty string into the other, and
# say they're equal if both substitutions produce the empty string.
# .d files contain """
+ SPACE_REPLACEMENT
+ """ instead of spaces, take that into account.
command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\\
$(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
# Helper that is non-empty when a prerequisite changes.
# Normally make does this implicitly, but we force rules to always run
# so we can check their command lines.
# $? -- new prerequisites
# $| -- order-only dependencies
prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
# Helper that executes all postbuilds until one fails.
define do_postbuilds
@E=0;\\
for p in $(POSTBUILDS); do\\
eval $$p;\\
E=$$?;\\
if [ $$E -ne 0 ]; then\\
break;\\
fi;\\
done;\\
if [ $$E -ne 0 ]; then\\
rm -rf "$@";\\
exit $$E;\\
fi
endef
# do_cmd: run a command via the above cmd_foo names, if necessary.
# Should always run for a given target to handle command-line changes.
# Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
# Third argument, if non-zero, makes it do POSTBUILDS processing.
# Note: We intentionally do NOT call dirx for depfile, since it contains """
+ SPACE_REPLACEMENT
+ """ for
# spaces already and dirx strips the """
+ SPACE_REPLACEMENT
+ """ characters.
define do_cmd
$(if $(or $(command_changed),$(prereq_changed)),
@$(call exact_echo, $($(quiet)cmd_$(1)))
@mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
$(if $(findstring flock,$(word %(flock_index)d,$(cmd_$1))),
@$(cmd_$(1))
@echo " $(quiet_cmd_$(1)): Finished",
@$(cmd_$(1))
)
@$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
@$(if $(2),$(fixup_dep))
$(if $(and $(3), $(POSTBUILDS)),
$(call do_postbuilds)
)
)
endef
# Declare the "%(default_target)s" target first so it is the default,
# even though we don't have the deps yet.
.PHONY: %(default_target)s
%(default_target)s:
# make looks for ways to re-generate included makefiles, but in our case, we
# don't have a direct way. Explicitly telling make that it has nothing to do
# for them makes it go faster.
%%.d: ;
# Use FORCE_DO_CMD to force a target to run. Should be coupled with
# do_cmd.
.PHONY: FORCE_DO_CMD
FORCE_DO_CMD:
""" # noqa: E501
)
SHARED_HEADER_MAC_COMMANDS = """
quiet_cmd_objc = CXX($(TOOLSET)) $@
cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
quiet_cmd_objcxx = CXX($(TOOLSET)) $@
cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
# Commands for precompiled header files.
quiet_cmd_pch_c = CXX($(TOOLSET)) $@
cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
quiet_cmd_pch_cc = CXX($(TOOLSET)) $@
cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
quiet_cmd_pch_m = CXX($(TOOLSET)) $@
cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
quiet_cmd_pch_mm = CXX($(TOOLSET)) $@
cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
# gyp-mac-tool is written next to the root Makefile by gyp.
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
# already.
quiet_cmd_mac_tool = MACTOOL $(4) $<
cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
quiet_cmd_infoplist = INFOPLIST $@
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
""" # noqa: E501
def WriteRootHeaderSuffixRules(writer):
extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
writer.write("# Suffix rules, putting all outputs into $(obj).\n")
for ext in extensions:
writer.write("$(obj).$(TOOLSET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD\n" % ext)
writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
writer.write("\n# Try building from generated source, too.\n")
for ext in extensions:
writer.write(
"$(obj).$(TOOLSET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD\n" % ext
)
writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
writer.write("\n")
for ext in extensions:
writer.write("$(obj).$(TOOLSET)/%%.o: $(obj)/%%%s FORCE_DO_CMD\n" % ext)
writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
writer.write("\n")
SHARED_HEADER_OS390_COMMANDS = """
PLIFLAGS.target ?= -qlp=64 -qlimits=extname=31 $(PLIFLAGS)
PLIFLAGS.host ?= -qlp=64 -qlimits=extname=31 $(PLIFLAGS)
quiet_cmd_pli = PLI($(TOOLSET)) $@
cmd_pli = $(PLI.$(TOOLSET)) $(GYP_PLIFLAGS) $(PLIFLAGS.$(TOOLSET)) -c $< && \
if [ -f $(notdir $@) ]; then /bin/cp $(notdir $@) $@; else true; fi
"""
SHARED_HEADER_SUFFIX_RULES_COMMENT1 = """\
# Suffix rules, putting all outputs into $(obj).
"""
SHARED_HEADER_SUFFIX_RULES_COMMENT2 = """\
# Try building from generated source, too.
"""
SHARED_FOOTER = """\
# "all" is a concatenation of the "all" targets from all the included
# sub-makefiles. This is just here to clarify.
all:
# Add in dependency-tracking rules. $(all_deps) is the list of every single
# target in our tree. Only consider the ones with .d (dependency) info:
d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
ifneq ($(d_files),)
include $(d_files)
endif
"""
header = """\
# This file is generated by gyp; do not edit.
"""
# Maps every compilable file extension to the do_cmd that compiles it.
COMPILABLE_EXTENSIONS = {
".c": "cc",
".cc": "cxx",
".cpp": "cxx",
".cxx": "cxx",
".s": "cc",
".S": "cc",
}
def Compilable(filename):
"""Return true if the file is compilable (should be in OBJS)."""
for res in (filename.endswith(e) for e in COMPILABLE_EXTENSIONS):
if res:
return True
return False
def Linkable(filename):
"""Return true if the file is linkable (should be on the link line)."""
return filename.endswith(".o")
def Target(filename):
"""Translate a compilable filename to its .o target."""
return os.path.splitext(filename)[0] + ".o"
def EscapeShellArgument(s):
"""Quotes an argument so that it will be interpreted literally by a POSIX
shell. Taken from
http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python
"""
return "'" + s.replace("'", "'\\''") + "'"
def EscapeMakeVariableExpansion(s):
"""Make has its own variable expansion syntax using $. We must escape it for
string to be interpreted literally."""
return s.replace("$", "$$")
def EscapeCppDefine(s):
"""Escapes a CPP define so that it will reach the compiler unaltered."""
s = EscapeShellArgument(s)
s = EscapeMakeVariableExpansion(s)
# '#' characters must be escaped even embedded in a string, else Make will
# treat it as the start of a comment.
return s.replace("#", r"\#")
def QuoteIfNecessary(string):
"""TODO: Should this ideally be replaced with one or more of the above
functions?"""
if '"' in string:
string = '"' + string.replace('"', '\\"') + '"'
return string
def StringToMakefileVariable(string):
"""Convert a string to a value that is acceptable as a make variable name."""
return re.sub("[^a-zA-Z0-9_]", "_", string)
srcdir_prefix = ""
def Sourceify(path):
"""Convert a path to its source directory form."""
if "$(" in path:
return path
if os.path.isabs(path):
return path
return srcdir_prefix + path
def QuoteSpaces(s, quote=r"\ "):
return s.replace(" ", quote)
def SourceifyAndQuoteSpaces(path):
"""Convert a path to its source directory form and quote spaces."""
return QuoteSpaces(Sourceify(path))
# Map from qualified target to path to output.
target_outputs = {}
# Map from qualified target to any linkable output. A subset
# of target_outputs. E.g. when mybinary depends on liba, we want to
# include liba in the linker line; when otherbinary depends on
# mybinary, we just want to build mybinary first.
target_link_deps = {}
class MakefileWriter:
"""MakefileWriter packages up the writing of one target-specific foobar.mk.
Its only real entry point is Write(), and is mostly used for namespacing.
"""
def __init__(self, generator_flags, flavor):
self.generator_flags = generator_flags
self.flavor = flavor
self.suffix_rules_srcdir = {}
self.suffix_rules_objdir1 = {}
self.suffix_rules_objdir2 = {}
# Generate suffix rules for all compilable extensions.
for ext in COMPILABLE_EXTENSIONS.keys():
# Suffix rules for source folder.
self.suffix_rules_srcdir.update(
{
ext: (
"""\
$(obj).$(TOOLSET)/$(TARGET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD
\t@$(call do_cmd,%s,1)
"""
% (ext, COMPILABLE_EXTENSIONS[ext])
)
}
)
# Suffix rules for generated source files.
self.suffix_rules_objdir1.update(
{
ext: (
"""\
$(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD
\t@$(call do_cmd,%s,1)
"""
% (ext, COMPILABLE_EXTENSIONS[ext])
)
}
)
self.suffix_rules_objdir2.update(
{
ext: (
"""\
$(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD
\t@$(call do_cmd,%s,1)
"""
% (ext, COMPILABLE_EXTENSIONS[ext])
)
}
)
def Write(
self, qualified_target, base_path, output_filename, spec, configs, part_of_all
):
"""The main entry point: writes a .mk file for a single target.
Arguments:
qualified_target: target we're generating
base_path: path relative to source root we're building in, used to resolve
target-relative paths
output_filename: output .mk file name to write
spec, configs: gyp info
part_of_all: flag indicating this target is part of 'all'
"""
gyp.common.EnsureDirExists(output_filename)
self.fp = open(output_filename, "w")
self.fp.write(header)
self.qualified_target = qualified_target
self.path = base_path
self.target = spec["target_name"]
self.type = spec["type"]
self.toolset = spec["toolset"]
self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
if self.flavor == "mac":
self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
else:
self.xcode_settings = None
deps, link_deps = self.ComputeDeps(spec)
# Some of the generation below can add extra output, sources, or
# link dependencies. All of the out params of the functions that
# follow use names like extra_foo.
extra_outputs = []
extra_sources = []
extra_link_deps = []
extra_mac_bundle_resources = []
mac_bundle_deps = []
if self.is_mac_bundle:
self.output = self.ComputeMacBundleOutput(spec)
self.output_binary = self.ComputeMacBundleBinaryOutput(spec)
else:
self.output = self.output_binary = self.ComputeOutput(spec)
self.is_standalone_static_library = bool(
spec.get("standalone_static_library", 0)
)
self._INSTALLABLE_TARGETS = ("executable", "loadable_module", "shared_library")
if self.is_standalone_static_library or self.type in self._INSTALLABLE_TARGETS:
self.alias = os.path.basename(self.output)
install_path = self._InstallableTargetInstallPath()
else:
self.alias = self.output
install_path = self.output
self.WriteLn("TOOLSET := " + self.toolset)
self.WriteLn("TARGET := " + self.target)
# Actions must come first, since they can generate more OBJs for use below.
if "actions" in spec:
self.WriteActions(
spec["actions"],
extra_sources,
extra_outputs,
extra_mac_bundle_resources,
part_of_all,
)
# Rules must be early like actions.
if "rules" in spec:
self.WriteRules(
spec["rules"],
extra_sources,
extra_outputs,
extra_mac_bundle_resources,
part_of_all,
)
if "copies" in spec:
self.WriteCopies(spec["copies"], extra_outputs, part_of_all)
# Bundle resources.
if self.is_mac_bundle:
all_mac_bundle_resources = (
spec.get("mac_bundle_resources", []) + extra_mac_bundle_resources
)
self.WriteMacBundleResources(all_mac_bundle_resources, mac_bundle_deps)
self.WriteMacInfoPlist(mac_bundle_deps)
# Sources.
all_sources = spec.get("sources", []) + extra_sources
if all_sources:
self.WriteSources(
configs,
deps,
all_sources,
extra_outputs,
extra_link_deps,
part_of_all,
gyp.xcode_emulation.MacPrefixHeader(
self.xcode_settings,
lambda p: Sourceify(self.Absolutify(p)),
self.Pchify,
),
)
sources = [x for x in all_sources if Compilable(x)]
if sources:
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
extensions = {os.path.splitext(s)[1] for s in sources}
for ext in extensions:
if ext in self.suffix_rules_srcdir:
self.WriteLn(self.suffix_rules_srcdir[ext])
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT2)
for ext in extensions:
if ext in self.suffix_rules_objdir1:
self.WriteLn(self.suffix_rules_objdir1[ext])
for ext in extensions:
if ext in self.suffix_rules_objdir2:
self.WriteLn(self.suffix_rules_objdir2[ext])
self.WriteLn("# End of this set of suffix rules")
# Add dependency from bundle to bundle binary.
if self.is_mac_bundle:
mac_bundle_deps.append(self.output_binary)
self.WriteTarget(
spec,
configs,
deps,
extra_link_deps + link_deps,
mac_bundle_deps,
extra_outputs,
part_of_all,
)
# Update global list of target outputs, used in dependency tracking.
target_outputs[qualified_target] = install_path
# Update global list of link dependencies.
if self.type in ("static_library", "shared_library"):
target_link_deps[qualified_target] = self.output_binary
# Currently any versions have the same effect, but in future the behavior
# could be different.
if self.generator_flags.get("android_ndk_version", None):
self.WriteAndroidNdkModuleRule(self.target, all_sources, link_deps)
self.fp.close()
def WriteSubMake(self, output_filename, makefile_path, targets, build_dir):
"""Write a "sub-project" Makefile.
This is a small, wrapper Makefile that calls the top-level Makefile to build
the targets from a single gyp file (i.e. a sub-project).
Arguments:
output_filename: sub-project Makefile name to write
makefile_path: path to the top-level Makefile
targets: list of "all" targets for this sub-project
build_dir: build output directory, relative to the sub-project
"""
gyp.common.EnsureDirExists(output_filename)
self.fp = open(output_filename, "w")
self.fp.write(header)
# For consistency with other builders, put sub-project build output in the
# sub-project dir (see test/subdirectory/gyptest-subdir-all.py).
self.WriteLn(
"export builddir_name ?= %s"
% os.path.join(os.path.dirname(output_filename), build_dir)
)
self.WriteLn(".PHONY: all")
self.WriteLn("all:")
if makefile_path:
makefile_path = " -C " + makefile_path
self.WriteLn("\t$(MAKE){} {}".format(makefile_path, " ".join(targets)))
self.fp.close()
def WriteActions(
self,
actions,
extra_sources,
extra_outputs,
extra_mac_bundle_resources,
part_of_all,
):
"""Write Makefile code for any 'actions' from the gyp input.
extra_sources: a list that will be filled in with newly generated source
files, if any
extra_outputs: a list that will be filled in with any outputs of these
actions (used to make other pieces dependent on these
actions)
part_of_all: flag indicating this target is part of 'all'
"""
env = self.GetSortedXcodeEnv()
for action in actions:
name = StringToMakefileVariable(
"{}_{}".format(self.qualified_target, action["action_name"])
)
self.WriteLn('### Rules for action "%s":' % action["action_name"])
inputs = action["inputs"]
outputs = action["outputs"]
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = set()
for out in outputs:
dir = os.path.split(out)[0]
if dir:
dirs.add(dir)
if int(action.get("process_outputs_as_sources", False)):
extra_sources += outputs
if int(action.get("process_outputs_as_mac_bundle_resources", False)):
extra_mac_bundle_resources += outputs
# Write the actual command.
action_commands = action["action"]
if self.flavor == "mac":
action_commands = [
gyp.xcode_emulation.ExpandEnvVars(command, env)
for command in action_commands
]
command = gyp.common.EncodePOSIXShellList(action_commands)
if "message" in action:
self.WriteLn(
"quiet_cmd_{} = ACTION {} $@".format(name, action["message"])
)
else:
self.WriteLn(f"quiet_cmd_{name} = ACTION {name} $@")
if len(dirs) > 0:
command = "mkdir -p %s" % " ".join(dirs) + "; " + command
cd_action = "cd %s; " % Sourceify(self.path or ".")
# command and cd_action get written to a toplevel variable called
# cmd_foo. Toplevel variables can't handle things that change per
# makefile like $(TARGET), so hardcode the target.
command = command.replace("$(TARGET)", self.target)
cd_action = cd_action.replace("$(TARGET)", self.target)
# Set LD_LIBRARY_PATH in case the action runs an executable from this
# build which links to shared libs from this build.
# actions run on the host, so they should in theory only use host
# libraries, but until everything is made cross-compile safe, also use
# target libraries.
# TODO(piman): when everything is cross-compile safe, remove lib.target
if self.flavor == "zos" or self.flavor == "aix":
self.WriteLn(
"cmd_%s = LIBPATH=$(builddir)/lib.host:"
"$(builddir)/lib.target:$$LIBPATH; "
"export LIBPATH; "
"%s%s" % (name, cd_action, command)
)
else:
self.WriteLn(
"cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:"
"$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
"export LD_LIBRARY_PATH; "
"%s%s" % (name, cd_action, command)
)
self.WriteLn()
outputs = [self.Absolutify(o) for o in outputs]
# The makefile rules are all relative to the top dir, but the gyp actions
# are defined relative to their containing dir. This replaces the obj
# variable for the action rule with an absolute version so that the output
# goes in the right place.
# Only write the 'obj' and 'builddir' rules for the "primary" output (:1);
# it's superfluous for the "extra outputs", and this avoids accidentally
# writing duplicate dummy rules for those outputs.
# Same for environment.
self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0]))
self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0]))
self.WriteSortedXcodeEnv(outputs[0], self.GetSortedXcodeEnv())
for input in inputs:
assert " " not in input, (
"Spaces in action input filenames not supported (%s)" % input
)
for output in outputs:
assert " " not in output, (
"Spaces in action output filenames not supported (%s)" % output
)
# See the comment in WriteCopies about expanding env vars.
outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
self.WriteDoCmd(
outputs,
[Sourceify(self.Absolutify(i)) for i in inputs],
part_of_all=part_of_all,
command=name,
)
# Stuff the outputs in a variable so we can refer to them later.
outputs_variable = "action_%s_outputs" % name
self.WriteLn("{} := {}".format(outputs_variable, " ".join(outputs)))
extra_outputs.append("$(%s)" % outputs_variable)
self.WriteLn()
self.WriteLn()
def WriteRules(
self,
rules,
extra_sources,
extra_outputs,
extra_mac_bundle_resources,
part_of_all,
):
"""Write Makefile code for any 'rules' from the gyp input.
extra_sources: a list that will be filled in with newly generated source
files, if any
extra_outputs: a list that will be filled in with any outputs of these
rules (used to make other pieces dependent on these rules)
part_of_all: flag indicating this target is part of 'all'
"""
env = self.GetSortedXcodeEnv()
for rule in rules:
name = StringToMakefileVariable(
"{}_{}".format(self.qualified_target, rule["rule_name"])
)
count = 0
self.WriteLn("### Generated for rule %s:" % name)
all_outputs = []
for rule_source in rule.get("rule_sources", []):
dirs = set()
(rule_source_dirname, rule_source_basename) = os.path.split(rule_source)
(rule_source_root, rule_source_ext) = os.path.splitext(
rule_source_basename
)
outputs = [
self.ExpandInputRoot(out, rule_source_root, rule_source_dirname)
for out in rule["outputs"]
]
for out in outputs:
dir = os.path.dirname(out)
if dir:
dirs.add(dir)
if int(rule.get("process_outputs_as_sources", False)):
extra_sources += outputs
if int(rule.get("process_outputs_as_mac_bundle_resources", False)):
extra_mac_bundle_resources += outputs
inputs = [
Sourceify(self.Absolutify(i))
for i in [rule_source] + rule.get("inputs", [])
]
actions = ["$(call do_cmd,%s_%d)" % (name, count)]
if name == "resources_grit":
# HACK: This is ugly. Grit intentionally doesn't touch the
# timestamp of its output file when the file doesn't change,
# which is fine in hash-based dependency systems like scons
# and forge, but not kosher in the make world. After some
# discussion, hacking around it here seems like the least
# amount of pain.
actions += ["@touch --no-create $@"]
# See the comment in WriteCopies about expanding env vars.
outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
outputs = [self.Absolutify(o) for o in outputs]
all_outputs += outputs
# Only write the 'obj' and 'builddir' rules for the "primary" output
# (:1); it's superfluous for the "extra outputs", and this avoids
# accidentally writing duplicate dummy rules for those outputs.
self.WriteLn("%s: obj := $(abs_obj)" % outputs[0])
self.WriteLn("%s: builddir := $(abs_builddir)" % outputs[0])
self.WriteMakeRule(
outputs, inputs, actions, command="%s_%d" % (name, count)
)
# Spaces in rule filenames are not supported, but rule variables have
# spaces in them (e.g. RULE_INPUT_PATH expands to '$(abspath $<)').
# The spaces within the variables are valid, so remove the variables
# before checking.
variables_with_spaces = re.compile(r"\$\([^ ]* \$<\)")
for output in outputs:
output = re.sub(variables_with_spaces, "", output)
assert " " not in output, (
"Spaces in rule filenames not yet supported (%s)" % output
)
self.WriteLn("all_deps += %s" % " ".join(outputs))
action = [
self.ExpandInputRoot(ac, rule_source_root, rule_source_dirname)
for ac in rule["action"]
]
mkdirs = ""
if len(dirs) > 0:
mkdirs = "mkdir -p %s; " % " ".join(dirs)
cd_action = "cd %s; " % Sourceify(self.path or ".")
# action, cd_action, and mkdirs get written to a toplevel variable
# called cmd_foo. Toplevel variables can't handle things that change
# per makefile like $(TARGET), so hardcode the target.
if self.flavor == "mac":
action = [
gyp.xcode_emulation.ExpandEnvVars(command, env)
for command in action
]
action = gyp.common.EncodePOSIXShellList(action)
action = action.replace("$(TARGET)", self.target)
cd_action = cd_action.replace("$(TARGET)", self.target)
mkdirs = mkdirs.replace("$(TARGET)", self.target)
# Set LD_LIBRARY_PATH in case the rule runs an executable from this
# build which links to shared libs from this build.
# rules run on the host, so they should in theory only use host
# libraries, but until everything is made cross-compile safe, also use
# target libraries.
# TODO(piman): when everything is cross-compile safe, remove lib.target
self.WriteLn(
"cmd_%(name)s_%(count)d = LD_LIBRARY_PATH="
"$(builddir)/lib.host:$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
"export LD_LIBRARY_PATH; "
"%(cd_action)s%(mkdirs)s%(action)s"
% {
"action": action,
"cd_action": cd_action,
"count": count,
"mkdirs": mkdirs,
"name": name,
}
)
self.WriteLn(
"quiet_cmd_%(name)s_%(count)d = RULE %(name)s_%(count)d $@"
% {"count": count, "name": name}
)
self.WriteLn()
count += 1
outputs_variable = "rule_%s_outputs" % name
self.WriteList(all_outputs, outputs_variable)
extra_outputs.append("$(%s)" % outputs_variable)
self.WriteLn("### Finished generating for rule: %s" % name)
self.WriteLn()
self.WriteLn("### Finished generating for all rules")
self.WriteLn("")
def WriteCopies(self, copies, extra_outputs, part_of_all):
"""Write Makefile code for any 'copies' from the gyp input.
extra_outputs: a list that will be filled in with any outputs of this action
(used to make other pieces dependent on this action)
part_of_all: flag indicating this target is part of 'all'
"""
self.WriteLn("### Generated for copy rule.")
variable = StringToMakefileVariable(self.qualified_target + "_copies")
outputs = []
for copy in copies:
for path in copy["files"]:
# Absolutify() may call normpath, and will strip trailing slashes.
path = Sourceify(self.Absolutify(path))
filename = os.path.split(path)[1]
output = Sourceify(
self.Absolutify(os.path.join(copy["destination"], filename))
)
# If the output path has variables in it, which happens in practice for
# 'copies', writing the environment as target-local doesn't work,
# because the variables are already needed for the target name.
# Copying the environment variables into global make variables doesn't
# work either, because then the .d files will potentially contain spaces
# after variable expansion, and .d file handling cannot handle spaces.
# As a workaround, manually expand variables at gyp time. Since 'copies'
# can't run scripts, there's no need to write the env then.
# WriteDoCmd() will escape spaces for .d files.
env = self.GetSortedXcodeEnv()
output = gyp.xcode_emulation.ExpandEnvVars(output, env)
path = gyp.xcode_emulation.ExpandEnvVars(path, env)
self.WriteDoCmd([output], [path], "copy", part_of_all)
outputs.append(output)
self.WriteLn(
"{} = {}".format(variable, " ".join(QuoteSpaces(o) for o in outputs))
)
extra_outputs.append("$(%s)" % variable)
self.WriteLn()
def WriteMacBundleResources(self, resources, bundle_deps):
"""Writes Makefile code for 'mac_bundle_resources'."""
self.WriteLn("### Generated for mac_bundle_resources")
for output, res in gyp.xcode_emulation.GetMacBundleResources(
generator_default_variables["PRODUCT_DIR"],
self.xcode_settings,
[Sourceify(self.Absolutify(r)) for r in resources],
):
_, ext = os.path.splitext(output)
if ext != ".xcassets":
# Make does not supports '.xcassets' emulation.
self.WriteDoCmd(
[output], [res], "mac_tool,,,copy-bundle-resource", part_of_all=True
)
bundle_deps.append(output)
def WriteMacInfoPlist(self, bundle_deps):
"""Write Makefile code for bundle Info.plist files."""
info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
generator_default_variables["PRODUCT_DIR"],
self.xcode_settings,
lambda p: Sourceify(self.Absolutify(p)),
)
if not info_plist:
return
if defines:
# Create an intermediate file to store preprocessed results.
intermediate_plist = "$(obj).$(TOOLSET)/$(TARGET)/" + os.path.basename(
info_plist
)
self.WriteList(
defines,
intermediate_plist + ": INFOPLIST_DEFINES",
"-D",
quoter=EscapeCppDefine,
)
self.WriteMakeRule(
[intermediate_plist],
[info_plist],
[
"$(call do_cmd,infoplist)",
# "Convert" the plist so that any weird whitespace changes from the
# preprocessor do not affect the XML parser in mac_tool.
"@plutil -convert xml1 $@ $@",
],
)
info_plist = intermediate_plist
# plists can contain envvars and substitute them into the file.
self.WriteSortedXcodeEnv(
out, self.GetSortedXcodeEnv(additional_settings=extra_env)
)
self.WriteDoCmd(
[out], [info_plist], "mac_tool,,,copy-info-plist", part_of_all=True
)
bundle_deps.append(out)
def WriteSources(
self,
configs,
deps,
sources,
extra_outputs,
extra_link_deps,
part_of_all,
precompiled_header,
):
"""Write Makefile code for any 'sources' from the gyp input.
These are source files necessary to build the current target.
configs, deps, sources: input from gyp.
extra_outputs: a list of extra outputs this action should be dependent on;
used to serialize action/rules before compilation
extra_link_deps: a list that will be filled in with any outputs of
compilation (to be used in link lines)
part_of_all: flag indicating this target is part of 'all'
"""
# Write configuration-specific variables for CFLAGS, etc.
for configname in sorted(configs.keys()):
config = configs[configname]
self.WriteList(
config.get("defines"),
"DEFS_%s" % configname,
prefix="-D",
quoter=EscapeCppDefine,
)
if self.flavor == "mac":
cflags = self.xcode_settings.GetCflags(
configname, arch=config.get("xcode_configuration_platform")
)
cflags_c = self.xcode_settings.GetCflagsC(configname)
cflags_cc = self.xcode_settings.GetCflagsCC(configname)
cflags_objc = self.xcode_settings.GetCflagsObjC(configname)
cflags_objcc = self.xcode_settings.GetCflagsObjCC(configname)
else:
cflags = config.get("cflags")
cflags_c = config.get("cflags_c")
cflags_cc = config.get("cflags_cc")
self.WriteLn("# Flags passed to all source files.")
self.WriteList(cflags, "CFLAGS_%s" % configname)
self.WriteLn("# Flags passed to only C files.")
self.WriteList(cflags_c, "CFLAGS_C_%s" % configname)
self.WriteLn("# Flags passed to only C++ files.")
self.WriteList(cflags_cc, "CFLAGS_CC_%s" % configname)
if self.flavor == "mac":
self.WriteLn("# Flags passed to only ObjC files.")
self.WriteList(cflags_objc, "CFLAGS_OBJC_%s" % configname)
self.WriteLn("# Flags passed to only ObjC++ files.")
self.WriteList(cflags_objcc, "CFLAGS_OBJCC_%s" % configname)
includes = config.get("include_dirs")
if includes:
includes = [Sourceify(self.Absolutify(i)) for i in includes]
self.WriteList(includes, "INCS_%s" % configname, prefix="-I")
compilable = list(filter(Compilable, sources))
objs = [self.Objectify(self.Absolutify(Target(c))) for c in compilable]
self.WriteList(objs, "OBJS")
for obj in objs:
assert " " not in obj, "Spaces in object filenames not supported (%s)" % obj
self.WriteLn(
"# Add to the list of files we specially track " "dependencies for."
)
self.WriteLn("all_deps += $(OBJS)")
self.WriteLn()
# Make sure our dependencies are built first.
if deps:
self.WriteMakeRule(
["$(OBJS)"],
deps,
comment="Make sure our dependencies are built " "before any of us.",
order_only=True,
)
# Make sure the actions and rules run first.
# If they generate any extra headers etc., the per-.o file dep tracking
# will catch the proper rebuilds, so order only is still ok here.
if extra_outputs:
self.WriteMakeRule(
["$(OBJS)"],
extra_outputs,
comment="Make sure our actions/rules run " "before any of us.",
order_only=True,
)
pchdeps = precompiled_header.GetObjDependencies(compilable, objs)
if pchdeps:
self.WriteLn("# Dependencies from obj files to their precompiled headers")
for source, obj, gch in pchdeps:
self.WriteLn(f"{obj}: {gch}")
self.WriteLn("# End precompiled header dependencies")
if objs:
extra_link_deps.append("$(OBJS)")
self.WriteLn(
"""\
# CFLAGS et al overrides must be target-local.
# See "Target-specific Variable Values" in the GNU Make manual."""
)
self.WriteLn("$(OBJS): TOOLSET := $(TOOLSET)")
self.WriteLn(
"$(OBJS): GYP_CFLAGS := "
"$(DEFS_$(BUILDTYPE)) "
"$(INCS_$(BUILDTYPE)) "
"%s " % precompiled_header.GetInclude("c") + "$(CFLAGS_$(BUILDTYPE)) "
"$(CFLAGS_C_$(BUILDTYPE))"
)
self.WriteLn(
"$(OBJS): GYP_CXXFLAGS := "
"$(DEFS_$(BUILDTYPE)) "
"$(INCS_$(BUILDTYPE)) "
"%s " % precompiled_header.GetInclude("cc") + "$(CFLAGS_$(BUILDTYPE)) "
"$(CFLAGS_CC_$(BUILDTYPE))"
)
if self.flavor == "mac":
self.WriteLn(
"$(OBJS): GYP_OBJCFLAGS := "
"$(DEFS_$(BUILDTYPE)) "
"$(INCS_$(BUILDTYPE)) "
"%s " % precompiled_header.GetInclude("m")
+ "$(CFLAGS_$(BUILDTYPE)) "
"$(CFLAGS_C_$(BUILDTYPE)) "
"$(CFLAGS_OBJC_$(BUILDTYPE))"
)
self.WriteLn(
"$(OBJS): GYP_OBJCXXFLAGS := "
"$(DEFS_$(BUILDTYPE)) "
"$(INCS_$(BUILDTYPE)) "
"%s " % precompiled_header.GetInclude("mm")
+ "$(CFLAGS_$(BUILDTYPE)) "
"$(CFLAGS_CC_$(BUILDTYPE)) "
"$(CFLAGS_OBJCC_$(BUILDTYPE))"
)
self.WritePchTargets(precompiled_header.GetPchBuildCommands())
# If there are any object files in our input file list, link them into our
# output.
extra_link_deps += [source for source in sources if Linkable(source)]
self.WriteLn()
def WritePchTargets(self, pch_commands):
"""Writes make rules to compile prefix headers."""
if not pch_commands:
return
for gch, lang_flag, lang, input in pch_commands:
extra_flags = {
"c": "$(CFLAGS_C_$(BUILDTYPE))",
"cc": "$(CFLAGS_CC_$(BUILDTYPE))",
"m": "$(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE))",
"mm": "$(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE))",
}[lang]
var_name = {
"c": "GYP_PCH_CFLAGS",
"cc": "GYP_PCH_CXXFLAGS",
"m": "GYP_PCH_OBJCFLAGS",
"mm": "GYP_PCH_OBJCXXFLAGS",
}[lang]
self.WriteLn(
f"{gch}: {var_name} := {lang_flag} " + "$(DEFS_$(BUILDTYPE)) "
"$(INCS_$(BUILDTYPE)) "
"$(CFLAGS_$(BUILDTYPE)) " + extra_flags
)
self.WriteLn(f"{gch}: {input} FORCE_DO_CMD")
self.WriteLn("\t@$(call do_cmd,pch_%s,1)" % lang)
self.WriteLn("")
assert " " not in gch, "Spaces in gch filenames not supported (%s)" % gch
self.WriteLn("all_deps += %s" % gch)
self.WriteLn("")
def ComputeOutputBasename(self, spec):
"""Return the 'output basename' of a gyp spec.
E.g., the loadable module 'foobar' in directory 'baz' will produce
'libfoobar.so'
"""
assert not self.is_mac_bundle
if self.flavor == "mac" and self.type in (
"static_library",
"executable",
"shared_library",
"loadable_module",
):
return self.xcode_settings.GetExecutablePath()
target = spec["target_name"]
target_prefix = ""
target_ext = ""
if self.type == "static_library":
if target[:3] == "lib":
target = target[3:]
target_prefix = "lib"
target_ext = ".a"
elif self.type in ("loadable_module", "shared_library"):
if target[:3] == "lib":
target = target[3:]
target_prefix = "lib"
if self.flavor == "aix":
target_ext = ".a"
elif self.flavor == "zos":
target_ext = ".x"
else:
target_ext = ".so"
elif self.type == "none":
target = "%s.stamp" % target
elif self.type != "executable":
print(
"ERROR: What output file should be generated?",
"type",
self.type,
"target",
target,
)
target_prefix = spec.get("product_prefix", target_prefix)
target = spec.get("product_name", target)
product_ext = spec.get("product_extension")
if product_ext:
target_ext = "." + product_ext
return target_prefix + target + target_ext
def _InstallImmediately(self):
return (
self.toolset == "target"
and self.flavor == "mac"
and self.type
in ("static_library", "executable", "shared_library", "loadable_module")
)
def ComputeOutput(self, spec):
"""Return the 'output' (full output path) of a gyp spec.
E.g., the loadable module 'foobar' in directory 'baz' will produce
'$(obj)/baz/libfoobar.so'
"""
assert not self.is_mac_bundle
path = os.path.join("$(obj)." + self.toolset, self.path)
if self.type == "executable" or self._InstallImmediately():
path = "$(builddir)"
path = spec.get("product_dir", path)
return os.path.join(path, self.ComputeOutputBasename(spec))
def ComputeMacBundleOutput(self, spec):
"""Return the 'output' (full output path) to a bundle output directory."""
assert self.is_mac_bundle
path = generator_default_variables["PRODUCT_DIR"]
return os.path.join(path, self.xcode_settings.GetWrapperName())
def ComputeMacBundleBinaryOutput(self, spec):
"""Return the 'output' (full output path) to the binary in a bundle."""
path = generator_default_variables["PRODUCT_DIR"]
return os.path.join(path, self.xcode_settings.GetExecutablePath())
def ComputeDeps(self, spec):
"""Compute the dependencies of a gyp spec.
Returns a tuple (deps, link_deps), where each is a list of
filenames that will need to be put in front of make for either
building (deps) or linking (link_deps).
"""
deps = []
link_deps = []
if "dependencies" in spec:
deps.extend(
[
target_outputs[dep]
for dep in spec["dependencies"]
if target_outputs[dep]
]
)
for dep in spec["dependencies"]:
if dep in target_link_deps:
link_deps.append(target_link_deps[dep])
deps.extend(link_deps)
# TODO: It seems we need to transitively link in libraries (e.g. -lfoo)?
# This hack makes it work:
# link_deps.extend(spec.get('libraries', []))
return (gyp.common.uniquer(deps), gyp.common.uniquer(link_deps))
def GetSharedObjectFromSidedeck(self, sidedeck):
"""Return the shared object files based on sidedeck"""
return re.sub(r"\.x$", ".so", sidedeck)
def GetUnversionedSidedeckFromSidedeck(self, sidedeck):
"""Return the shared object files based on sidedeck"""
return re.sub(r"\.\d+\.x$", ".x", sidedeck)
def WriteDependencyOnExtraOutputs(self, target, extra_outputs):
self.WriteMakeRule(
[self.output_binary],
extra_outputs,
comment="Build our special outputs first.",
order_only=True,
)
def WriteTarget(
self, spec, configs, deps, link_deps, bundle_deps, extra_outputs, part_of_all
):
"""Write Makefile code to produce the final target of the gyp spec.
spec, configs: input from gyp.
deps, link_deps: dependency lists; see ComputeDeps()
extra_outputs: any extra outputs that our target should depend on
part_of_all: flag indicating this target is part of 'all'
"""
self.WriteLn("### Rules for final target.")
if extra_outputs:
self.WriteDependencyOnExtraOutputs(self.output_binary, extra_outputs)
self.WriteMakeRule(
extra_outputs,
deps,
comment=("Preserve order dependency of " "special output on deps."),
order_only=True,
)
target_postbuilds = {}
if self.type != "none":
for configname in sorted(configs.keys()):
config = configs[configname]
if self.flavor == "mac":
ldflags = self.xcode_settings.GetLdflags(
configname,
generator_default_variables["PRODUCT_DIR"],
lambda p: Sourceify(self.Absolutify(p)),
arch=config.get("xcode_configuration_platform"),
)
# TARGET_POSTBUILDS_$(BUILDTYPE) is added to postbuilds later on.
gyp_to_build = gyp.common.InvertRelativePath(self.path)
target_postbuild = self.xcode_settings.AddImplicitPostbuilds(
configname,
QuoteSpaces(
os.path.normpath(os.path.join(gyp_to_build, self.output))
),
QuoteSpaces(
os.path.normpath(
os.path.join(gyp_to_build, self.output_binary)
)
),
)
if target_postbuild:
target_postbuilds[configname] = target_postbuild
else:
ldflags = config.get("ldflags", [])
# Compute an rpath for this output if needed.
if any(dep.endswith(".so") or ".so." in dep for dep in deps):
# We want to get the literal string "$ORIGIN"
# into the link command, so we need lots of escaping.
ldflags.append(r"-Wl,-rpath=\$$ORIGIN/")
ldflags.append(r"-Wl,-rpath-link=\$(builddir)/")
library_dirs = config.get("library_dirs", [])
ldflags += [("-L%s" % library_dir) for library_dir in library_dirs]
self.WriteList(ldflags, "LDFLAGS_%s" % configname)
if self.flavor == "mac":
self.WriteList(
self.xcode_settings.GetLibtoolflags(configname),
"LIBTOOLFLAGS_%s" % configname,
)
libraries = spec.get("libraries")
if libraries:
# Remove duplicate entries
libraries = gyp.common.uniquer(libraries)
if self.flavor == "mac":
libraries = self.xcode_settings.AdjustLibraries(libraries)
self.WriteList(libraries, "LIBS")
self.WriteLn(
"%s: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))"
% QuoteSpaces(self.output_binary)
)
self.WriteLn("%s: LIBS := $(LIBS)" % QuoteSpaces(self.output_binary))
if self.flavor == "mac":
self.WriteLn(
"%s: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE))"
% QuoteSpaces(self.output_binary)
)
# Postbuild actions. Like actions, but implicitly depend on the target's
# output.
postbuilds = []
if self.flavor == "mac":
if target_postbuilds:
postbuilds.append("$(TARGET_POSTBUILDS_$(BUILDTYPE))")
postbuilds.extend(gyp.xcode_emulation.GetSpecPostbuildCommands(spec))
if postbuilds:
# Envvars may be referenced by TARGET_POSTBUILDS_$(BUILDTYPE),
# so we must output its definition first, since we declare variables
# using ":=".
self.WriteSortedXcodeEnv(self.output, self.GetSortedXcodePostbuildEnv())
for configname in target_postbuilds:
self.WriteLn(
"%s: TARGET_POSTBUILDS_%s := %s"
% (
QuoteSpaces(self.output),
configname,
gyp.common.EncodePOSIXShellList(target_postbuilds[configname]),
)
)
# Postbuilds expect to be run in the gyp file's directory, so insert an
# implicit postbuild to cd to there.
postbuilds.insert(0, gyp.common.EncodePOSIXShellList(["cd", self.path]))
for i, postbuild in enumerate(postbuilds):
if not postbuild.startswith("$"):
postbuilds[i] = EscapeShellArgument(postbuild)
self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(self.output))
self.WriteLn(
"%s: POSTBUILDS := %s"
% (QuoteSpaces(self.output), " ".join(postbuilds))
)
# A bundle directory depends on its dependencies such as bundle resources
# and bundle binary. When all dependencies have been built, the bundle
# needs to be packaged.
if self.is_mac_bundle:
# If the framework doesn't contain a binary, then nothing depends
# on the actions -- make the framework depend on them directly too.
self.WriteDependencyOnExtraOutputs(self.output, extra_outputs)
# Bundle dependencies. Note that the code below adds actions to this
# target, so if you move these two lines, move the lines below as well.
self.WriteList([QuoteSpaces(dep) for dep in bundle_deps], "BUNDLE_DEPS")
self.WriteLn("%s: $(BUNDLE_DEPS)" % QuoteSpaces(self.output))
# After the framework is built, package it. Needs to happen before
# postbuilds, since postbuilds depend on this.
if self.type in ("shared_library", "loadable_module"):
self.WriteLn(
"\t@$(call do_cmd,mac_package_framework,,,%s)"
% self.xcode_settings.GetFrameworkVersion()
)
# Bundle postbuilds can depend on the whole bundle, so run them after
# the bundle is packaged, not already after the bundle binary is done.
if postbuilds:
self.WriteLn("\t@$(call do_postbuilds)")
postbuilds = [] # Don't write postbuilds for target's output.
# Needed by test/mac/gyptest-rebuild.py.
self.WriteLn("\t@true # No-op, used by tests")
# Since this target depends on binary and resources which are in
# nested subfolders, the framework directory will be older than
# its dependencies usually. To prevent this rule from executing
# on every build (expensive, especially with postbuilds), expliclity
# update the time on the framework directory.
self.WriteLn("\t@touch -c %s" % QuoteSpaces(self.output))
if postbuilds:
assert not self.is_mac_bundle, (
"Postbuilds for bundles should be done "
"on the bundle, not the binary (target '%s')" % self.target
)
assert "product_dir" not in spec, (
"Postbuilds do not work with " "custom product_dir"
)
if self.type == "executable":
self.WriteLn(
"%s: LD_INPUTS := %s"
% (
QuoteSpaces(self.output_binary),
" ".join(QuoteSpaces(dep) for dep in link_deps),
)
)
if self.toolset == "host" and self.flavor == "android":
self.WriteDoCmd(
[self.output_binary],
link_deps,
"link_host",
part_of_all,
postbuilds=postbuilds,
)
else:
self.WriteDoCmd(
[self.output_binary],
link_deps,
"link",
part_of_all,
postbuilds=postbuilds,
)
elif self.type == "static_library":
for link_dep in link_deps:
assert " " not in link_dep, (
"Spaces in alink input filenames not supported (%s)" % link_dep
)
if (
self.flavor not in ("mac", "openbsd", "netbsd", "win")
and not self.is_standalone_static_library
):
if self.flavor in ("linux", "android"):
self.WriteMakeRule(
[self.output_binary],
link_deps,
actions=["$(call create_thin_archive,$@,$^)"],
)
else:
self.WriteDoCmd(
[self.output_binary],
link_deps,
"alink_thin",
part_of_all,
postbuilds=postbuilds,
)
else:
if self.flavor in ("linux", "android"):
self.WriteMakeRule(
[self.output_binary],
link_deps,
actions=["$(call create_archive,$@,$^)"],
)
else:
self.WriteDoCmd(
[self.output_binary],
link_deps,
"alink",
part_of_all,
postbuilds=postbuilds,
)
elif self.type == "shared_library":
self.WriteLn(
"%s: LD_INPUTS := %s"
% (
QuoteSpaces(self.output_binary),
" ".join(QuoteSpaces(dep) for dep in link_deps),
)
)
self.WriteDoCmd(
[self.output_binary],
link_deps,
"solink",
part_of_all,
postbuilds=postbuilds,
)
# z/OS has a .so target as well as a sidedeck .x target
if self.flavor == "zos":
self.WriteLn(
"%s: %s"
% (
QuoteSpaces(
self.GetSharedObjectFromSidedeck(self.output_binary)
),
QuoteSpaces(self.output_binary),
)
)
elif self.type == "loadable_module":
for link_dep in link_deps:
assert " " not in link_dep, (
"Spaces in module input filenames not supported (%s)" % link_dep
)
if self.toolset == "host" and self.flavor == "android":
self.WriteDoCmd(
[self.output_binary],
link_deps,
"solink_module_host",
part_of_all,
postbuilds=postbuilds,
)
else:
self.WriteDoCmd(
[self.output_binary],
link_deps,
"solink_module",
part_of_all,
postbuilds=postbuilds,
)
elif self.type == "none":
# Write a stamp line.
self.WriteDoCmd(
[self.output_binary], deps, "touch", part_of_all, postbuilds=postbuilds
)
else:
print("WARNING: no output for", self.type, self.target)
# Add an alias for each target (if there are any outputs).
# Installable target aliases are created below.
if (self.output and self.output != self.target) and (
self.type not in self._INSTALLABLE_TARGETS
):
self.WriteMakeRule(
[self.target], [self.output], comment="Add target alias", phony=True
)
if part_of_all:
self.WriteMakeRule(
["all"],
[self.target],
comment='Add target alias to "all" target.',
phony=True,
)
# Add special-case rules for our installable targets.
# 1) They need to install to the build dir or "product" dir.
# 2) They get shortcuts for building (e.g. "make chrome").
# 3) They are part of "make all".
if self.type in self._INSTALLABLE_TARGETS or self.is_standalone_static_library:
if self.type == "shared_library":
file_desc = "shared library"
elif self.type == "static_library":
file_desc = "static library"
else:
file_desc = "executable"
install_path = self._InstallableTargetInstallPath()
installable_deps = []
if self.flavor != "zos":
installable_deps.append(self.output)
if (
self.flavor == "mac"
and "product_dir" not in spec
and self.toolset == "target"
):
# On mac, products are created in install_path immediately.
assert install_path == self.output, "{} != {}".format(
install_path,
self.output,
)
# Point the target alias to the final binary output.
self.WriteMakeRule(
[self.target], [install_path], comment="Add target alias", phony=True
)
if install_path != self.output:
assert not self.is_mac_bundle # See comment a few lines above.
self.WriteDoCmd(
[install_path],
[self.output],
"copy",
comment="Copy this to the %s output path." % file_desc,
part_of_all=part_of_all,
)
if self.flavor != "zos":
installable_deps.append(install_path)
if self.flavor == "zos" and self.type == "shared_library":
# lib.target/libnode.so has a dependency on $(obj).target/libnode.so
self.WriteDoCmd(
[self.GetSharedObjectFromSidedeck(install_path)],
[self.GetSharedObjectFromSidedeck(self.output)],
"copy",
comment="Copy this to the %s output path." % file_desc,
part_of_all=part_of_all,
)
# Create a symlink of libnode.x to libnode.version.x
self.WriteDoCmd(
[self.GetUnversionedSidedeckFromSidedeck(install_path)],
[install_path],
"symlink",
comment="Symlnk this to the %s output path." % file_desc,
part_of_all=part_of_all,
)
# Place libnode.version.so and libnode.x symlink in lib.target dir
installable_deps.append(self.GetSharedObjectFromSidedeck(install_path))
installable_deps.append(
self.GetUnversionedSidedeckFromSidedeck(install_path)
)
if self.output != self.alias and self.alias != self.target:
self.WriteMakeRule(
[self.alias],
installable_deps,
comment="Short alias for building this %s." % file_desc,
phony=True,
)
if self.flavor == "zos" and self.type == "shared_library":
# Make sure that .x symlink target is run
self.WriteMakeRule(
["all"],
[
self.GetUnversionedSidedeckFromSidedeck(install_path),
self.GetSharedObjectFromSidedeck(install_path),
],
comment='Add %s to "all" target.' % file_desc,
phony=True,
)
elif part_of_all:
self.WriteMakeRule(
["all"],
[install_path],
comment='Add %s to "all" target.' % file_desc,
phony=True,
)
def WriteList(self, value_list, variable=None, prefix="", quoter=QuoteIfNecessary):
"""Write a variable definition that is a list of values.
E.g. WriteList(['a','b'], 'foo', prefix='blah') writes out
foo = blaha blahb
but in a pretty-printed style.
"""
values = ""
if value_list:
value_list = [quoter(prefix + value) for value in value_list]
values = " \\\n\t" + " \\\n\t".join(value_list)
self.fp.write(f"{variable} :={values}\n\n")
def WriteDoCmd(
self, outputs, inputs, command, part_of_all, comment=None, postbuilds=False
):
"""Write a Makefile rule that uses do_cmd.
This makes the outputs dependent on the command line that was run,
as well as support the V= make command line flag.
"""
suffix = ""
if postbuilds:
assert "," not in command
suffix = ",,1" # Tell do_cmd to honor $POSTBUILDS
self.WriteMakeRule(
outputs,
inputs,
actions=[f"$(call do_cmd,{command}{suffix})"],
comment=comment,
command=command,
force=True,
)
# Add our outputs to the list of targets we read depfiles from.
# all_deps is only used for deps file reading, and for deps files we replace
# spaces with ? because escaping doesn't work with make's $(sort) and
# other functions.
outputs = [QuoteSpaces(o, SPACE_REPLACEMENT) for o in outputs]
self.WriteLn("all_deps += %s" % " ".join(outputs))
def WriteMakeRule(
self,
outputs,
inputs,
actions=None,
comment=None,
order_only=False,
force=False,
phony=False,
command=None,
):
"""Write a Makefile rule, with some extra tricks.
outputs: a list of outputs for the rule (note: this is not directly
supported by make; see comments below)
inputs: a list of inputs for the rule
actions: a list of shell commands to run for the rule
comment: a comment to put in the Makefile above the rule (also useful
for making this Python script's code self-documenting)
order_only: if true, makes the dependency order-only
force: if true, include FORCE_DO_CMD as an order-only dep
phony: if true, the rule does not actually generate the named output, the
output is just a name to run the rule
command: (optional) command name to generate unambiguous labels
"""
outputs = [QuoteSpaces(o) for o in outputs]
inputs = [QuoteSpaces(i) for i in inputs]
if comment:
self.WriteLn("# " + comment)
if phony:
self.WriteLn(".PHONY: " + " ".join(outputs))
if actions:
self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0])
force_append = " FORCE_DO_CMD" if force else ""
if order_only:
# Order only rule: Just write a simple rule.
# TODO(evanm): just make order_only a list of deps instead of this hack.
self.WriteLn(
"{}: | {}{}".format(" ".join(outputs), " ".join(inputs), force_append)
)
elif len(outputs) == 1:
# Regular rule, one output: Just write a simple rule.
self.WriteLn("{}: {}{}".format(outputs[0], " ".join(inputs), force_append))
else:
# Regular rule, more than one output: Multiple outputs are tricky in
# make. We will write three rules:
# - All outputs depend on an intermediate file.
# - Make .INTERMEDIATE depend on the intermediate.
# - The intermediate file depends on the inputs and executes the
# actual command.
# - The intermediate recipe will 'touch' the intermediate file.
# - The multi-output rule will have an do-nothing recipe.
# Hash the target name to avoid generating overlong filenames.
cmddigest = hashlib.sha1(
(command or self.target).encode("utf-8")
).hexdigest()
intermediate = "%s.intermediate" % cmddigest
self.WriteLn("{}: {}".format(" ".join(outputs), intermediate))
self.WriteLn("\t%s" % "@:")
self.WriteLn("{}: {}".format(".INTERMEDIATE", intermediate))
self.WriteLn(
"{}: {}{}".format(intermediate, " ".join(inputs), force_append)
)
actions.insert(0, "$(call do_cmd,touch)")
if actions:
for action in actions:
self.WriteLn("\t%s" % action)
self.WriteLn()
def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
"""Write a set of LOCAL_XXX definitions for Android NDK.
These variable definitions will be used by Android NDK but do nothing for
non-Android applications.
Arguments:
module_name: Android NDK module name, which must be unique among all
module names.
all_sources: A list of source files (will be filtered by Compilable).
link_deps: A list of link dependencies, which must be sorted in
the order from dependencies to dependents.
"""
if self.type not in ("executable", "shared_library", "static_library"):
return
self.WriteLn("# Variable definitions for Android applications")
self.WriteLn("include $(CLEAR_VARS)")
self.WriteLn("LOCAL_MODULE := " + module_name)
self.WriteLn(
"LOCAL_CFLAGS := $(CFLAGS_$(BUILDTYPE)) "
"$(DEFS_$(BUILDTYPE)) "
# LOCAL_CFLAGS is applied to both of C and C++. There is
# no way to specify $(CFLAGS_C_$(BUILDTYPE)) only for C
# sources.
"$(CFLAGS_C_$(BUILDTYPE)) "
# $(INCS_$(BUILDTYPE)) includes the prefix '-I' while
# LOCAL_C_INCLUDES does not expect it. So put it in
# LOCAL_CFLAGS.
"$(INCS_$(BUILDTYPE))"
)
# LOCAL_CXXFLAGS is obsolete and LOCAL_CPPFLAGS is preferred.
self.WriteLn("LOCAL_CPPFLAGS := $(CFLAGS_CC_$(BUILDTYPE))")
self.WriteLn("LOCAL_C_INCLUDES :=")
self.WriteLn("LOCAL_LDLIBS := $(LDFLAGS_$(BUILDTYPE)) $(LIBS)")
# Detect the C++ extension.
cpp_ext = {".cc": 0, ".cpp": 0, ".cxx": 0}
default_cpp_ext = ".cpp"
for filename in all_sources:
ext = os.path.splitext(filename)[1]
if ext in cpp_ext:
cpp_ext[ext] += 1
if cpp_ext[ext] > cpp_ext[default_cpp_ext]:
default_cpp_ext = ext
self.WriteLn("LOCAL_CPP_EXTENSION := " + default_cpp_ext)
self.WriteList(
list(map(self.Absolutify, filter(Compilable, all_sources))),
"LOCAL_SRC_FILES",
)
# Filter out those which do not match prefix and suffix and produce
# the resulting list without prefix and suffix.
def DepsToModules(deps, prefix, suffix):
modules = []
for filepath in deps:
filename = os.path.basename(filepath)
if filename.startswith(prefix) and filename.endswith(suffix):
modules.append(filename[len(prefix) : -len(suffix)])
return modules
# Retrieve the default value of 'SHARED_LIB_SUFFIX'
params = {"flavor": "linux"}
default_variables = {}
CalculateVariables(default_variables, params)
self.WriteList(
DepsToModules(
link_deps,
generator_default_variables["SHARED_LIB_PREFIX"],
default_variables["SHARED_LIB_SUFFIX"],
),
"LOCAL_SHARED_LIBRARIES",
)
self.WriteList(
DepsToModules(
link_deps,
generator_default_variables["STATIC_LIB_PREFIX"],
generator_default_variables["STATIC_LIB_SUFFIX"],
),
"LOCAL_STATIC_LIBRARIES",
)
if self.type == "executable":
self.WriteLn("include $(BUILD_EXECUTABLE)")
elif self.type == "shared_library":
self.WriteLn("include $(BUILD_SHARED_LIBRARY)")
elif self.type == "static_library":
self.WriteLn("include $(BUILD_STATIC_LIBRARY)")
self.WriteLn()
def WriteLn(self, text=""):
self.fp.write(text + "\n")
def GetSortedXcodeEnv(self, additional_settings=None):
return gyp.xcode_emulation.GetSortedXcodeEnv(
self.xcode_settings,
"$(abs_builddir)",
os.path.join("$(abs_srcdir)", self.path),
"$(BUILDTYPE)",
additional_settings,
)
def GetSortedXcodePostbuildEnv(self):
# CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
# TODO(thakis): It would be nice to have some general mechanism instead.
strip_save_file = self.xcode_settings.GetPerTargetSetting(
"CHROMIUM_STRIP_SAVE_FILE", ""
)
# Even if strip_save_file is empty, explicitly write it. Else a postbuild
# might pick up an export from an earlier target.
return self.GetSortedXcodeEnv(
additional_settings={"CHROMIUM_STRIP_SAVE_FILE": strip_save_file}
)
def WriteSortedXcodeEnv(self, target, env):
for k, v in env:
# For
# foo := a\ b
# the escaped space does the right thing. For
# export foo := a\ b
# it does not -- the backslash is written to the env as literal character.
# So don't escape spaces in |env[k]|.
self.WriteLn(f"{QuoteSpaces(target)}: export {k} := {v}")
def Objectify(self, path):
"""Convert a path to its output directory form."""
if "$(" in path:
path = path.replace("$(obj)/", "$(obj).%s/$(TARGET)/" % self.toolset)
if "$(obj)" not in path:
path = f"$(obj).{self.toolset}/$(TARGET)/{path}"
return path
def Pchify(self, path, lang):
"""Convert a prefix header path to its output directory form."""
path = self.Absolutify(path)
if "$(" in path:
path = path.replace(
"$(obj)/", f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}"
)
return path
return f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}/{path}"
def Absolutify(self, path):
"""Convert a subdirectory-relative path into a base-relative path.
Skips over paths that contain variables."""
if "$(" in path:
# Don't call normpath in this case, as it might collapse the
# path too aggressively if it features '..'. However it's still
# important to strip trailing slashes.
return path.rstrip("/")
return os.path.normpath(os.path.join(self.path, path))
def ExpandInputRoot(self, template, expansion, dirname):
if "%(INPUT_ROOT)s" not in template and "%(INPUT_DIRNAME)s" not in template:
return template
path = template % {
"INPUT_ROOT": expansion,
"INPUT_DIRNAME": dirname,
}
return path
def _InstallableTargetInstallPath(self):
"""Returns the location of the final output for an installable target."""
# Functionality removed for all platforms to match Xcode and hoist
# shared libraries into PRODUCT_DIR for users:
# Xcode puts shared_library results into PRODUCT_DIR, and some gyp files
# rely on this. Emulate this behavior for mac.
# if self.type == "shared_library" and (
# self.flavor != "mac" or self.toolset != "target"
# ):
# # Install all shared libs into a common directory (per toolset) for
# # convenient access with LD_LIBRARY_PATH.
# return "$(builddir)/lib.%s/%s" % (self.toolset, self.alias)
if self.flavor == "zos" and self.type == "shared_library":
return "$(builddir)/lib.%s/%s" % (self.toolset, self.alias)
return "$(builddir)/" + self.alias
def WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files):
"""Write the target to regenerate the Makefile."""
options = params["options"]
build_files_args = [
gyp.common.RelativePath(filename, options.toplevel_dir)
for filename in params["build_files_arg"]
]
gyp_binary = gyp.common.FixIfRelativePath(
params["gyp_binary"], options.toplevel_dir
)
if not gyp_binary.startswith(os.sep):
gyp_binary = os.path.join(".", gyp_binary)
root_makefile.write(
"quiet_cmd_regen_makefile = ACTION Regenerating $@\n"
"cmd_regen_makefile = cd $(srcdir); %(cmd)s\n"
"%(makefile_name)s: %(deps)s\n"
"\t$(call do_cmd,regen_makefile)\n\n"
% {
"makefile_name": makefile_name,
"deps": " ".join(SourceifyAndQuoteSpaces(bf) for bf in build_files),
"cmd": gyp.common.EncodePOSIXShellList(
[gyp_binary, "-fmake"] + gyp.RegenerateFlags(options) + build_files_args
),
}
)
def PerformBuild(data, configurations, params):
options = params["options"]
for config in configurations:
arguments = ["make"]
if options.toplevel_dir and options.toplevel_dir != ".":
arguments += "-C", options.toplevel_dir
arguments.append("BUILDTYPE=" + config)
print(f"Building [{config}]: {arguments}")
subprocess.check_call(arguments)
def GenerateOutput(target_list, target_dicts, data, params):
options = params["options"]
flavor = gyp.common.GetFlavor(params)
generator_flags = params.get("generator_flags", {})
builddir_name = generator_flags.get("output_dir", "out")
android_ndk_version = generator_flags.get("android_ndk_version", None)
default_target = generator_flags.get("default_target", "all")
def CalculateMakefilePath(build_file, base_name):
"""Determine where to write a Makefile for a given gyp file."""
# Paths in gyp files are relative to the .gyp file, but we want
# paths relative to the source root for the master makefile. Grab
# the path of the .gyp file as the base to relativize against.
# E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
base_path = gyp.common.RelativePath(os.path.dirname(build_file), options.depth)
# We write the file in the base_path directory.
output_file = os.path.join(options.depth, base_path, base_name)
if options.generator_output:
output_file = os.path.join(
options.depth, options.generator_output, base_path, base_name
)
base_path = gyp.common.RelativePath(
os.path.dirname(build_file), options.toplevel_dir
)
return base_path, output_file
# TODO: search for the first non-'Default' target. This can go
# away when we add verification that all targets have the
# necessary configurations.
default_configuration = None
toolsets = {target_dicts[target]["toolset"] for target in target_list}
for target in target_list:
spec = target_dicts[target]
if spec["default_configuration"] != "Default":
default_configuration = spec["default_configuration"]
break
if not default_configuration:
default_configuration = "Default"
srcdir = "."
makefile_name = "Makefile" + options.suffix
makefile_path = os.path.join(options.toplevel_dir, makefile_name)
if options.generator_output:
global srcdir_prefix
makefile_path = os.path.join(
options.toplevel_dir, options.generator_output, makefile_name
)
srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
srcdir_prefix = "$(srcdir)/"
flock_command = "flock"
copy_archive_arguments = "-af"
makedep_arguments = "-MMD"
header_params = {
"default_target": default_target,
"builddir": builddir_name,
"default_configuration": default_configuration,
"flock": flock_command,
"flock_index": 1,
"link_commands": LINK_COMMANDS_LINUX,
"extra_commands": "",
"srcdir": srcdir,
"copy_archive_args": copy_archive_arguments,
"makedep_args": makedep_arguments,
"CC.target": GetEnvironFallback(("CC_target", "CC"), "$(CC)"),
"AR.target": GetEnvironFallback(("AR_target", "AR"), "$(AR)"),
"CXX.target": GetEnvironFallback(("CXX_target", "CXX"), "$(CXX)"),
"LINK.target": GetEnvironFallback(("LINK_target", "LINK"), "$(LINK)"),
"PLI.target": GetEnvironFallback(("PLI_target", "PLI"), "pli"),
"CC.host": GetEnvironFallback(("CC_host", "CC"), "gcc"),
"AR.host": GetEnvironFallback(("AR_host", "AR"), "ar"),
"CXX.host": GetEnvironFallback(("CXX_host", "CXX"), "g++"),
"LINK.host": GetEnvironFallback(("LINK_host", "LINK"), "$(CXX.host)"),
"PLI.host": GetEnvironFallback(("PLI_host", "PLI"), "pli"),
}
if flavor == "mac":
flock_command = "./gyp-mac-tool flock"
header_params.update(
{
"flock": flock_command,
"flock_index": 2,
"link_commands": LINK_COMMANDS_MAC,
"extra_commands": SHARED_HEADER_MAC_COMMANDS,
}
)
elif flavor == "android":
header_params.update({"link_commands": LINK_COMMANDS_ANDROID})
elif flavor == "zos":
copy_archive_arguments = "-fPR"
CC_target = GetEnvironFallback(("CC_target", "CC"), "njsc")
makedep_arguments = "-MMD"
if CC_target == "clang":
CC_host = GetEnvironFallback(("CC_host", "CC"), "clang")
CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "clang++")
CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "clang++")
elif CC_target == "ibm-clang64":
CC_host = GetEnvironFallback(("CC_host", "CC"), "ibm-clang64")
CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "ibm-clang++64")
CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "ibm-clang++64")
elif CC_target == "ibm-clang":
CC_host = GetEnvironFallback(("CC_host", "CC"), "ibm-clang")
CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "ibm-clang++")
CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "ibm-clang++")
else:
# Node.js versions prior to v18:
makedep_arguments = "-qmakedep=gcc"
CC_host = GetEnvironFallback(("CC_host", "CC"), "njsc")
CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "njsc++")
CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "njsc++")
header_params.update(
{
"copy_archive_args": copy_archive_arguments,
"makedep_args": makedep_arguments,
"link_commands": LINK_COMMANDS_OS390,
"extra_commands": SHARED_HEADER_OS390_COMMANDS,
"CC.target": CC_target,
"CXX.target": CXX_target,
"CC.host": CC_host,
"CXX.host": CXX_host,
}
)
elif flavor == "solaris":
copy_archive_arguments = "-pPRf@"
header_params.update(
{
"copy_archive_args": copy_archive_arguments,
"flock": "./gyp-flock-tool flock",
"flock_index": 2,
}
)
elif flavor == "freebsd":
# Note: OpenBSD has sysutils/flock. lockf seems to be FreeBSD specific.
header_params.update({"flock": "lockf"})
elif flavor == "openbsd":
copy_archive_arguments = "-pPRf"
header_params.update({"copy_archive_args": copy_archive_arguments})
elif flavor == "aix":
copy_archive_arguments = "-pPRf"
header_params.update(
{
"copy_archive_args": copy_archive_arguments,
"link_commands": LINK_COMMANDS_AIX,
"flock": "./gyp-flock-tool flock",
"flock_index": 2,
}
)
elif flavor == "os400":
copy_archive_arguments = "-pPRf"
header_params.update(
{
"copy_archive_args": copy_archive_arguments,
"link_commands": LINK_COMMANDS_OS400,
"flock": "./gyp-flock-tool flock",
"flock_index": 2,
}
)
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
make_global_settings_array = data[build_file].get("make_global_settings", [])
wrappers = {}
for key, value in make_global_settings_array:
if key.endswith("_wrapper"):
wrappers[key[: -len("_wrapper")]] = "$(abspath %s)" % value
make_global_settings = ""
for key, value in make_global_settings_array:
if re.match(".*_wrapper", key):
continue
if value[0] != "$":
value = "$(abspath %s)" % value
wrapper = wrappers.get(key)
if wrapper:
value = f"{wrapper} {value}"
del wrappers[key]
if key in ("CC", "CC.host", "CXX", "CXX.host"):
make_global_settings += (
"ifneq (,$(filter $(origin %s), undefined default))\n" % key
)
# Let gyp-time envvars win over global settings.
env_key = key.replace(".", "_") # CC.host -> CC_host
if env_key in os.environ:
value = os.environ[env_key]
make_global_settings += f" {key} = {value}\n"
make_global_settings += "endif\n"
else:
make_global_settings += f"{key} ?= {value}\n"
# TODO(ukai): define cmd when only wrapper is specified in
# make_global_settings.
header_params["make_global_settings"] = make_global_settings
gyp.common.EnsureDirExists(makefile_path)
root_makefile = open(makefile_path, "w")
root_makefile.write(SHARED_HEADER % header_params)
# Currently any versions have the same effect, but in future the behavior
# could be different.
if android_ndk_version:
root_makefile.write(
"# Define LOCAL_PATH for build of Android applications.\n"
"LOCAL_PATH := $(call my-dir)\n"
"\n"
)
for toolset in toolsets:
root_makefile.write("TOOLSET := %s\n" % toolset)
WriteRootHeaderSuffixRules(root_makefile)
# Put build-time support tools next to the root Makefile.
dest_path = os.path.dirname(makefile_path)
gyp.common.CopyTool(flavor, dest_path)
# Find the list of targets that derive from the gyp file(s) being built.
needed_targets = set()
for build_file in params["build_files"]:
for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
needed_targets.add(target)
build_files = set()
include_list = set()
for qualified_target in target_list:
build_file, target, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
this_make_global_settings = data[build_file].get("make_global_settings", [])
assert make_global_settings_array == this_make_global_settings, (
"make_global_settings needs to be the same for all targets "
f"{this_make_global_settings} vs. {make_global_settings}"
)
build_files.add(gyp.common.RelativePath(build_file, options.toplevel_dir))
included_files = data[build_file]["included_files"]
for included_file in included_files:
# The included_files entries are relative to the dir of the build file
# that included them, so we have to undo that and then make them relative
# to the root dir.
relative_include_file = gyp.common.RelativePath(
gyp.common.UnrelativePath(included_file, build_file),
options.toplevel_dir,
)
abs_include_file = os.path.abspath(relative_include_file)
# If the include file is from the ~/.gyp dir, we should use absolute path
# so that relocating the src dir doesn't break the path.
if params["home_dot_gyp"] and abs_include_file.startswith(
params["home_dot_gyp"]
):
build_files.add(abs_include_file)
else:
build_files.add(relative_include_file)
base_path, output_file = CalculateMakefilePath(
build_file, target + "." + toolset + options.suffix + ".mk"
)
spec = target_dicts[qualified_target]
configs = spec["configurations"]
if flavor == "mac":
gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
writer = MakefileWriter(generator_flags, flavor)
writer.Write(
qualified_target,
base_path,
output_file,
spec,
configs,
part_of_all=qualified_target in needed_targets,
)
# Our root_makefile lives at the source root. Compute the relative path
# from there to the output_file for including.
mkfile_rel_path = gyp.common.RelativePath(
output_file, os.path.dirname(makefile_path)
)
include_list.add(mkfile_rel_path)
# Write out per-gyp (sub-project) Makefiles.
depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd())
for build_file in build_files:
# The paths in build_files were relativized above, so undo that before
# testing against the non-relativized items in target_list and before
# calculating the Makefile path.
build_file = os.path.join(depth_rel_path, build_file)
gyp_targets = [
target_dicts[qualified_target]["target_name"]
for qualified_target in target_list
if qualified_target.startswith(build_file)
and qualified_target in needed_targets
]
# Only generate Makefiles for gyp files with targets.
if not gyp_targets:
continue
base_path, output_file = CalculateMakefilePath(
build_file, os.path.splitext(os.path.basename(build_file))[0] + ".Makefile"
)
makefile_rel_path = gyp.common.RelativePath(
os.path.dirname(makefile_path), os.path.dirname(output_file)
)
writer.WriteSubMake(output_file, makefile_rel_path, gyp_targets, builddir_name)
# Write out the sorted list of includes.
root_makefile.write("\n")
for include_file in sorted(include_list):
# We wrap each .mk include in an if statement so users can tell make to
# not load a file by setting NO_LOAD. The below make code says, only
# load the .mk file if the .mk filename doesn't start with a token in
# NO_LOAD.
root_makefile.write(
"ifeq ($(strip $(foreach prefix,$(NO_LOAD),\\\n"
" $(findstring $(join ^,$(prefix)),\\\n"
" $(join ^," + include_file + ")))),)\n"
)
root_makefile.write(" include " + include_file + "\n")
root_makefile.write("endif\n")
root_makefile.write("\n")
if not generator_flags.get("standalone") and generator_flags.get(
"auto_regeneration", True
):
WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
root_makefile.write(SHARED_FOOTER)
root_makefile.close()
node-gyp-9.3.0/gyp/pylib/gyp/generator/msvs.py 0000664 0000000 0000000 00000446026 14321173220 0021321 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import ntpath
import os
import posixpath
import re
import subprocess
import sys
from collections import OrderedDict
import gyp.common
import gyp.easy_xml as easy_xml
import gyp.generator.ninja as ninja_generator
import gyp.MSVSNew as MSVSNew
import gyp.MSVSProject as MSVSProject
import gyp.MSVSSettings as MSVSSettings
import gyp.MSVSToolFile as MSVSToolFile
import gyp.MSVSUserFile as MSVSUserFile
import gyp.MSVSUtil as MSVSUtil
import gyp.MSVSVersion as MSVSVersion
from gyp.common import GypError
from gyp.common import OrderedSet
# Regular expression for validating Visual Studio GUIDs. If the GUID
# contains lowercase hex letters, MSVS will be fine. However,
# IncrediBuild BuildConsole will parse the solution file, but then
# silently skip building the target causing hard to track down errors.
# Note that this only happens with the BuildConsole, and does not occur
# if IncrediBuild is executed from inside Visual Studio. This regex
# validates that the string looks like a GUID with all uppercase hex
# letters.
VALID_MSVS_GUID_CHARS = re.compile(r"^[A-F0-9\-]+$")
generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
generator_default_variables = {
"DRIVER_PREFIX": "",
"DRIVER_SUFFIX": ".sys",
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": ".exe",
"STATIC_LIB_PREFIX": "",
"SHARED_LIB_PREFIX": "",
"STATIC_LIB_SUFFIX": ".lib",
"SHARED_LIB_SUFFIX": ".dll",
"INTERMEDIATE_DIR": "$(IntDir)",
"SHARED_INTERMEDIATE_DIR": "$(OutDir)/obj/global_intermediate",
"OS": "win",
"PRODUCT_DIR": "$(OutDir)",
"LIB_DIR": "$(OutDir)lib",
"RULE_INPUT_ROOT": "$(InputName)",
"RULE_INPUT_DIRNAME": "$(InputDir)",
"RULE_INPUT_EXT": "$(InputExt)",
"RULE_INPUT_NAME": "$(InputFileName)",
"RULE_INPUT_PATH": "$(InputPath)",
"CONFIGURATION_NAME": "$(ConfigurationName)",
}
# The msvs specific sections that hold paths
generator_additional_path_sections = [
"msvs_cygwin_dirs",
"msvs_props",
]
generator_additional_non_configuration_keys = [
"msvs_cygwin_dirs",
"msvs_cygwin_shell",
"msvs_large_pdb",
"msvs_shard",
"msvs_external_builder",
"msvs_external_builder_out_dir",
"msvs_external_builder_build_cmd",
"msvs_external_builder_clean_cmd",
"msvs_external_builder_clcompile_cmd",
"msvs_enable_winrt",
"msvs_requires_importlibrary",
"msvs_enable_winphone",
"msvs_application_type_revision",
"msvs_target_platform_version",
"msvs_target_platform_minversion",
]
generator_filelist_paths = None
# List of precompiled header related keys.
precomp_keys = [
"msvs_precompiled_header",
"msvs_precompiled_source",
]
cached_username = None
cached_domain = None
# TODO(gspencer): Switch the os.environ calls to be
# win32api.GetDomainName() and win32api.GetUserName() once the
# python version in depot_tools has been updated to work on Vista
# 64-bit.
def _GetDomainAndUserName():
if sys.platform not in ("win32", "cygwin"):
return ("DOMAIN", "USERNAME")
global cached_username
global cached_domain
if not cached_domain or not cached_username:
domain = os.environ.get("USERDOMAIN")
username = os.environ.get("USERNAME")
if not domain or not username:
call = subprocess.Popen(
["net", "config", "Workstation"], stdout=subprocess.PIPE
)
config = call.communicate()[0].decode("utf-8")
username_re = re.compile(r"^User name\s+(\S+)", re.MULTILINE)
username_match = username_re.search(config)
if username_match:
username = username_match.group(1)
domain_re = re.compile(r"^Logon domain\s+(\S+)", re.MULTILINE)
domain_match = domain_re.search(config)
if domain_match:
domain = domain_match.group(1)
cached_domain = domain
cached_username = username
return (cached_domain, cached_username)
fixpath_prefix = None
def _NormalizedSource(source):
"""Normalize the path.
But not if that gets rid of a variable, as this may expand to something
larger than one directory.
Arguments:
source: The path to be normalize.d
Returns:
The normalized path.
"""
normalized = os.path.normpath(source)
if source.count("$") == normalized.count("$"):
source = normalized
return source
def _FixPath(path, separator="\\"):
"""Convert paths to a form that will make sense in a vcproj file.
Arguments:
path: The path to convert, may contain / etc.
Returns:
The path with all slashes made into backslashes.
"""
if (
fixpath_prefix
and path
and not os.path.isabs(path)
and not path[0] == "$"
and not _IsWindowsAbsPath(path)
):
path = os.path.join(fixpath_prefix, path)
if separator == "\\":
path = path.replace("/", "\\")
path = _NormalizedSource(path)
if separator == "/":
path = path.replace("\\", "/")
if path and path[-1] == separator:
path = path[:-1]
return path
def _IsWindowsAbsPath(path):
"""
On Cygwin systems Python needs a little help determining if a path
is an absolute Windows path or not, so that
it does not treat those as relative, which results in bad paths like:
'..\\C:\\\\some_source_code_file.cc'
"""
return path.startswith("c:") or path.startswith("C:")
def _FixPaths(paths, separator="\\"):
"""Fix each of the paths of the list."""
return [_FixPath(i, separator) for i in paths]
def _ConvertSourcesToFilterHierarchy(
sources, prefix=None, excluded=None, list_excluded=True, msvs_version=None
):
"""Converts a list split source file paths into a vcproj folder hierarchy.
Arguments:
sources: A list of source file paths split.
prefix: A list of source file path layers meant to apply to each of sources.
excluded: A set of excluded files.
msvs_version: A MSVSVersion object.
Returns:
A hierarchy of filenames and MSVSProject.Filter objects that matches the
layout of the source tree.
For example:
_ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']],
prefix=['joe'])
-->
[MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']),
MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])]
"""
if not prefix:
prefix = []
result = []
excluded_result = []
folders = OrderedDict()
# Gather files into the final result, excluded, or folders.
for s in sources:
if len(s) == 1:
filename = _NormalizedSource("\\".join(prefix + s))
if filename in excluded:
excluded_result.append(filename)
else:
result.append(filename)
elif msvs_version and not msvs_version.UsesVcxproj():
# For MSVS 2008 and earlier, we need to process all files before walking
# the sub folders.
if not folders.get(s[0]):
folders[s[0]] = []
folders[s[0]].append(s[1:])
else:
contents = _ConvertSourcesToFilterHierarchy(
[s[1:]],
prefix + [s[0]],
excluded=excluded,
list_excluded=list_excluded,
msvs_version=msvs_version,
)
contents = MSVSProject.Filter(s[0], contents=contents)
result.append(contents)
# Add a folder for excluded files.
if excluded_result and list_excluded:
excluded_folder = MSVSProject.Filter(
"_excluded_files", contents=excluded_result
)
result.append(excluded_folder)
if msvs_version and msvs_version.UsesVcxproj():
return result
# Populate all the folders.
for f in folders:
contents = _ConvertSourcesToFilterHierarchy(
folders[f],
prefix=prefix + [f],
excluded=excluded,
list_excluded=list_excluded,
msvs_version=msvs_version,
)
contents = MSVSProject.Filter(f, contents=contents)
result.append(contents)
return result
def _ToolAppend(tools, tool_name, setting, value, only_if_unset=False):
if not value:
return
_ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset)
def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
# TODO(bradnelson): ugly hack, fix this more generally!!!
if "Directories" in setting or "Dependencies" in setting:
if type(value) == str:
value = value.replace("/", "\\")
else:
value = [i.replace("/", "\\") for i in value]
if not tools.get(tool_name):
tools[tool_name] = dict()
tool = tools[tool_name]
if "CompileAsWinRT" == setting:
return
if tool.get(setting):
if only_if_unset:
return
if type(tool[setting]) == list and type(value) == list:
tool[setting] += value
else:
raise TypeError(
'Appending "%s" to a non-list setting "%s" for tool "%s" is '
"not allowed, previous value: %s"
% (value, setting, tool_name, str(tool[setting]))
)
else:
tool[setting] = value
def _ConfigTargetVersion(config_data):
return config_data.get("msvs_target_version", "Windows7")
def _ConfigPlatform(config_data):
return config_data.get("msvs_configuration_platform", "Win32")
def _ConfigBaseName(config_name, platform_name):
if config_name.endswith("_" + platform_name):
return config_name[0 : -len(platform_name) - 1]
else:
return config_name
def _ConfigFullName(config_name, config_data):
platform_name = _ConfigPlatform(config_data)
return f"{_ConfigBaseName(config_name, platform_name)}|{platform_name}"
def _ConfigWindowsTargetPlatformVersion(config_data, version):
target_ver = config_data.get("msvs_windows_target_platform_version")
if target_ver and re.match(r"^\d+", target_ver):
return target_ver
config_ver = config_data.get("msvs_windows_sdk_version")
vers = [config_ver] if config_ver else version.compatible_sdks
for ver in vers:
for key in [
r"HKLM\Software\Microsoft\Microsoft SDKs\Windows\%s",
r"HKLM\Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows\%s",
]:
sdk_dir = MSVSVersion._RegistryGetValue(key % ver, "InstallationFolder")
if not sdk_dir:
continue
version = MSVSVersion._RegistryGetValue(key % ver, "ProductVersion") or ""
# Find a matching entry in sdk_dir\include.
expected_sdk_dir = r"%s\include" % sdk_dir
names = sorted(
(
x
for x in (
os.listdir(expected_sdk_dir)
if os.path.isdir(expected_sdk_dir)
else []
)
if x.startswith(version)
),
reverse=True,
)
if names:
return names[0]
else:
print(
"Warning: No include files found for detected "
"Windows SDK version %s" % (version),
file=sys.stdout,
)
def _BuildCommandLineForRuleRaw(
spec, cmd, cygwin_shell, has_input_path, quote_cmd, do_setup_env
):
if [x for x in cmd if "$(InputDir)" in x]:
input_dir_preamble = (
"set INPUTDIR=$(InputDir)\n"
"if NOT DEFINED INPUTDIR set INPUTDIR=.\\\n"
"set INPUTDIR=%INPUTDIR:~0,-1%\n"
)
else:
input_dir_preamble = ""
if cygwin_shell:
# Find path to cygwin.
cygwin_dir = _FixPath(spec.get("msvs_cygwin_dirs", ["."])[0])
# Prepare command.
direct_cmd = cmd
direct_cmd = [
i.replace("$(IntDir)", '`cygpath -m "${INTDIR}"`') for i in direct_cmd
]
direct_cmd = [
i.replace("$(OutDir)", '`cygpath -m "${OUTDIR}"`') for i in direct_cmd
]
direct_cmd = [
i.replace("$(InputDir)", '`cygpath -m "${INPUTDIR}"`') for i in direct_cmd
]
if has_input_path:
direct_cmd = [
i.replace("$(InputPath)", '`cygpath -m "${INPUTPATH}"`')
for i in direct_cmd
]
direct_cmd = ['\\"%s\\"' % i.replace('"', '\\\\\\"') for i in direct_cmd]
# direct_cmd = gyp.common.EncodePOSIXShellList(direct_cmd)
direct_cmd = " ".join(direct_cmd)
# TODO(quote): regularize quoting path names throughout the module
cmd = ""
if do_setup_env:
cmd += 'call "$(ProjectDir)%(cygwin_dir)s\\setup_env.bat" && '
cmd += "set CYGWIN=nontsec&& "
if direct_cmd.find("NUMBER_OF_PROCESSORS") >= 0:
cmd += "set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& "
if direct_cmd.find("INTDIR") >= 0:
cmd += "set INTDIR=$(IntDir)&& "
if direct_cmd.find("OUTDIR") >= 0:
cmd += "set OUTDIR=$(OutDir)&& "
if has_input_path and direct_cmd.find("INPUTPATH") >= 0:
cmd += "set INPUTPATH=$(InputPath) && "
cmd += 'bash -c "%(cmd)s"'
cmd = cmd % {"cygwin_dir": cygwin_dir, "cmd": direct_cmd}
return input_dir_preamble + cmd
else:
# Convert cat --> type to mimic unix.
if cmd[0] == "cat":
command = ["type"]
else:
command = [cmd[0].replace("/", "\\")]
# Add call before command to ensure that commands can be tied together one
# after the other without aborting in Incredibuild, since IB makes a bat
# file out of the raw command string, and some commands (like python) are
# actually batch files themselves.
command.insert(0, "call")
# Fix the paths
# TODO(quote): This is a really ugly heuristic, and will miss path fixing
# for arguments like "--arg=path", arg=path, or "/opt:path".
# If the argument starts with a slash or dash, or contains an equal sign,
# it's probably a command line switch.
# Return the path with forward slashes because the command using it might
# not support backslashes.
arguments = [
i if (i[:1] in "/-" or "=" in i) else _FixPath(i, "/")
for i in cmd[1:]
]
arguments = [i.replace("$(InputDir)", "%INPUTDIR%") for i in arguments]
arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments]
if quote_cmd:
# Support a mode for using cmd directly.
# Convert any paths to native form (first element is used directly).
# TODO(quote): regularize quoting path names throughout the module
arguments = ['"%s"' % i for i in arguments]
# Collapse into a single command.
return input_dir_preamble + " ".join(command + arguments)
def _BuildCommandLineForRule(spec, rule, has_input_path, do_setup_env):
# Currently this weird argument munging is used to duplicate the way a
# python script would need to be run as part of the chrome tree.
# Eventually we should add some sort of rule_default option to set this
# per project. For now the behavior chrome needs is the default.
mcs = rule.get("msvs_cygwin_shell")
if mcs is None:
mcs = int(spec.get("msvs_cygwin_shell", 1))
elif isinstance(mcs, str):
mcs = int(mcs)
quote_cmd = int(rule.get("msvs_quote_cmd", 1))
return _BuildCommandLineForRuleRaw(
spec, rule["action"], mcs, has_input_path, quote_cmd, do_setup_env=do_setup_env
)
def _AddActionStep(actions_dict, inputs, outputs, description, command):
"""Merge action into an existing list of actions.
Care must be taken so that actions which have overlapping inputs either don't
get assigned to the same input, or get collapsed into one.
Arguments:
actions_dict: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
inputs: list of inputs
outputs: list of outputs
description: description of the action
command: command line to execute
"""
# Require there to be at least one input (call sites will ensure this).
assert inputs
action = {
"inputs": inputs,
"outputs": outputs,
"description": description,
"command": command,
}
# Pick where to stick this action.
# While less than optimal in terms of build time, attach them to the first
# input for now.
chosen_input = inputs[0]
# Add it there.
if chosen_input not in actions_dict:
actions_dict[chosen_input] = []
actions_dict[chosen_input].append(action)
def _AddCustomBuildToolForMSVS(
p, spec, primary_input, inputs, outputs, description, cmd
):
"""Add a custom build tool to execute something.
Arguments:
p: the target project
spec: the target project dict
primary_input: input file to attach the build tool to
inputs: list of inputs
outputs: list of outputs
description: description of the action
cmd: command line to execute
"""
inputs = _FixPaths(inputs)
outputs = _FixPaths(outputs)
tool = MSVSProject.Tool(
"VCCustomBuildTool",
{
"Description": description,
"AdditionalDependencies": ";".join(inputs),
"Outputs": ";".join(outputs),
"CommandLine": cmd,
},
)
# Add to the properties of primary input for each config.
for config_name, c_data in spec["configurations"].items():
p.AddFileConfig(
_FixPath(primary_input), _ConfigFullName(config_name, c_data), tools=[tool]
)
def _AddAccumulatedActionsToMSVS(p, spec, actions_dict):
"""Add actions accumulated into an actions_dict, merging as needed.
Arguments:
p: the target project
spec: the target project dict
actions_dict: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
"""
for primary_input in actions_dict:
inputs = OrderedSet()
outputs = OrderedSet()
descriptions = []
commands = []
for action in actions_dict[primary_input]:
inputs.update(OrderedSet(action["inputs"]))
outputs.update(OrderedSet(action["outputs"]))
descriptions.append(action["description"])
commands.append(action["command"])
# Add the custom build step for one input file.
description = ", and also ".join(descriptions)
command = "\r\n".join(commands)
_AddCustomBuildToolForMSVS(
p,
spec,
primary_input=primary_input,
inputs=inputs,
outputs=outputs,
description=description,
cmd=command,
)
def _RuleExpandPath(path, input_file):
"""Given the input file to which a rule applied, string substitute a path.
Arguments:
path: a path to string expand
input_file: the file to which the rule applied.
Returns:
The string substituted path.
"""
path = path.replace(
"$(InputName)", os.path.splitext(os.path.split(input_file)[1])[0]
)
path = path.replace("$(InputDir)", os.path.dirname(input_file))
path = path.replace(
"$(InputExt)", os.path.splitext(os.path.split(input_file)[1])[1]
)
path = path.replace("$(InputFileName)", os.path.split(input_file)[1])
path = path.replace("$(InputPath)", input_file)
return path
def _FindRuleTriggerFiles(rule, sources):
"""Find the list of files which a particular rule applies to.
Arguments:
rule: the rule in question
sources: the set of all known source files for this project
Returns:
The list of sources that trigger a particular rule.
"""
return rule.get("rule_sources", [])
def _RuleInputsAndOutputs(rule, trigger_file):
"""Find the inputs and outputs generated by a rule.
Arguments:
rule: the rule in question.
trigger_file: the main trigger for this rule.
Returns:
The pair of (inputs, outputs) involved in this rule.
"""
raw_inputs = _FixPaths(rule.get("inputs", []))
raw_outputs = _FixPaths(rule.get("outputs", []))
inputs = OrderedSet()
outputs = OrderedSet()
inputs.add(trigger_file)
for i in raw_inputs:
inputs.add(_RuleExpandPath(i, trigger_file))
for o in raw_outputs:
outputs.add(_RuleExpandPath(o, trigger_file))
return (inputs, outputs)
def _GenerateNativeRulesForMSVS(p, rules, output_dir, spec, options):
"""Generate a native rules file.
Arguments:
p: the target project
rules: the set of rules to include
output_dir: the directory in which the project/gyp resides
spec: the project dict
options: global generator options
"""
rules_filename = "{}{}.rules".format(spec["target_name"], options.suffix)
rules_file = MSVSToolFile.Writer(
os.path.join(output_dir, rules_filename), spec["target_name"]
)
# Add each rule.
for r in rules:
rule_name = r["rule_name"]
rule_ext = r["extension"]
inputs = _FixPaths(r.get("inputs", []))
outputs = _FixPaths(r.get("outputs", []))
# Skip a rule with no action and no inputs.
if "action" not in r and not r.get("rule_sources", []):
continue
cmd = _BuildCommandLineForRule(spec, r, has_input_path=True, do_setup_env=True)
rules_file.AddCustomBuildRule(
name=rule_name,
description=r.get("message", rule_name),
extensions=[rule_ext],
additional_dependencies=inputs,
outputs=outputs,
cmd=cmd,
)
# Write out rules file.
rules_file.WriteIfChanged()
# Add rules file to project.
p.AddToolFile(rules_filename)
def _Cygwinify(path):
path = path.replace("$(OutDir)", "$(OutDirCygwin)")
path = path.replace("$(IntDir)", "$(IntDirCygwin)")
return path
def _GenerateExternalRules(rules, output_dir, spec, sources, options, actions_to_add):
"""Generate an external makefile to do a set of rules.
Arguments:
rules: the list of rules to include
output_dir: path containing project and gyp files
spec: project specification data
sources: set of sources known
options: global generator options
actions_to_add: The list of actions we will add to.
"""
filename = "{}_rules{}.mk".format(spec["target_name"], options.suffix)
mk_file = gyp.common.WriteOnDiff(os.path.join(output_dir, filename))
# Find cygwin style versions of some paths.
mk_file.write('OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n')
mk_file.write('IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n')
# Gather stuff needed to emit all: target.
all_inputs = OrderedSet()
all_outputs = OrderedSet()
all_output_dirs = OrderedSet()
first_outputs = []
for rule in rules:
trigger_files = _FindRuleTriggerFiles(rule, sources)
for tf in trigger_files:
inputs, outputs = _RuleInputsAndOutputs(rule, tf)
all_inputs.update(OrderedSet(inputs))
all_outputs.update(OrderedSet(outputs))
# Only use one target from each rule as the dependency for
# 'all' so we don't try to build each rule multiple times.
first_outputs.append(list(outputs)[0])
# Get the unique output directories for this rule.
output_dirs = [os.path.split(i)[0] for i in outputs]
for od in output_dirs:
all_output_dirs.add(od)
first_outputs_cyg = [_Cygwinify(i) for i in first_outputs]
# Write out all: target, including mkdir for each output directory.
mk_file.write("all: %s\n" % " ".join(first_outputs_cyg))
for od in all_output_dirs:
if od:
mk_file.write('\tmkdir -p `cygpath -u "%s"`\n' % od)
mk_file.write("\n")
# Define how each output is generated.
for rule in rules:
trigger_files = _FindRuleTriggerFiles(rule, sources)
for tf in trigger_files:
# Get all the inputs and outputs for this rule for this trigger file.
inputs, outputs = _RuleInputsAndOutputs(rule, tf)
inputs = [_Cygwinify(i) for i in inputs]
outputs = [_Cygwinify(i) for i in outputs]
# Prepare the command line for this rule.
cmd = [_RuleExpandPath(c, tf) for c in rule["action"]]
cmd = ['"%s"' % i for i in cmd]
cmd = " ".join(cmd)
# Add it to the makefile.
mk_file.write("{}: {}\n".format(" ".join(outputs), " ".join(inputs)))
mk_file.write("\t%s\n\n" % cmd)
# Close up the file.
mk_file.close()
# Add makefile to list of sources.
sources.add(filename)
# Add a build action to call makefile.
cmd = [
"make",
"OutDir=$(OutDir)",
"IntDir=$(IntDir)",
"-j",
"${NUMBER_OF_PROCESSORS_PLUS_1}",
"-f",
filename,
]
cmd = _BuildCommandLineForRuleRaw(spec, cmd, True, False, True, True)
# Insert makefile as 0'th input, so it gets the action attached there,
# as this is easier to understand from in the IDE.
all_inputs = list(all_inputs)
all_inputs.insert(0, filename)
_AddActionStep(
actions_to_add,
inputs=_FixPaths(all_inputs),
outputs=_FixPaths(all_outputs),
description="Running external rules for %s" % spec["target_name"],
command=cmd,
)
def _EscapeEnvironmentVariableExpansion(s):
"""Escapes % characters.
Escapes any % characters so that Windows-style environment variable
expansions will leave them alone.
See http://connect.microsoft.com/VisualStudio/feedback/details/106127/cl-d-name-text-containing-percentage-characters-doesnt-compile
to understand why we have to do this.
Args:
s: The string to be escaped.
Returns:
The escaped string.
""" # noqa: E731,E123,E501
s = s.replace("%", "%%")
return s
quote_replacer_regex = re.compile(r'(\\*)"')
def _EscapeCommandLineArgumentForMSVS(s):
"""Escapes a Windows command-line argument.
So that the Win32 CommandLineToArgv function will turn the escaped result back
into the original string.
See http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
("Parsing C++ Command-Line Arguments") to understand why we have to do
this.
Args:
s: the string to be escaped.
Returns:
the escaped string.
"""
def _Replace(match):
# For a literal quote, CommandLineToArgv requires an odd number of
# backslashes preceding it, and it produces half as many literal backslashes
# (rounded down). So we need to produce 2n+1 backslashes.
return 2 * match.group(1) + '\\"'
# Escape all quotes so that they are interpreted literally.
s = quote_replacer_regex.sub(_Replace, s)
# Now add unescaped quotes so that any whitespace is interpreted literally.
s = '"' + s + '"'
return s
delimiters_replacer_regex = re.compile(r"(\\*)([,;]+)")
def _EscapeVCProjCommandLineArgListItem(s):
"""Escapes command line arguments for MSVS.
The VCProj format stores string lists in a single string using commas and
semi-colons as separators, which must be quoted if they are to be
interpreted literally. However, command-line arguments may already have
quotes, and the VCProj parser is ignorant of the backslash escaping
convention used by CommandLineToArgv, so the command-line quotes and the
VCProj quotes may not be the same quotes. So to store a general
command-line argument in a VCProj list, we need to parse the existing
quoting according to VCProj's convention and quote any delimiters that are
not already quoted by that convention. The quotes that we add will also be
seen by CommandLineToArgv, so if backslashes precede them then we also have
to escape those backslashes according to the CommandLineToArgv
convention.
Args:
s: the string to be escaped.
Returns:
the escaped string.
"""
def _Replace(match):
# For a non-literal quote, CommandLineToArgv requires an even number of
# backslashes preceding it, and it produces half as many literal
# backslashes. So we need to produce 2n backslashes.
return 2 * match.group(1) + '"' + match.group(2) + '"'
segments = s.split('"')
# The unquoted segments are at the even-numbered indices.
for i in range(0, len(segments), 2):
segments[i] = delimiters_replacer_regex.sub(_Replace, segments[i])
# Concatenate back into a single string
s = '"'.join(segments)
if len(segments) % 2 == 0:
# String ends while still quoted according to VCProj's convention. This
# means the delimiter and the next list item that follow this one in the
# .vcproj file will be misinterpreted as part of this item. There is nothing
# we can do about this. Adding an extra quote would correct the problem in
# the VCProj but cause the same problem on the final command-line. Moving
# the item to the end of the list does works, but that's only possible if
# there's only one such item. Let's just warn the user.
print(
"Warning: MSVS may misinterpret the odd number of " + "quotes in " + s,
file=sys.stderr,
)
return s
def _EscapeCppDefineForMSVS(s):
"""Escapes a CPP define so that it will reach the compiler unaltered."""
s = _EscapeEnvironmentVariableExpansion(s)
s = _EscapeCommandLineArgumentForMSVS(s)
s = _EscapeVCProjCommandLineArgListItem(s)
# cl.exe replaces literal # characters with = in preprocessor definitions for
# some reason. Octal-encode to work around that.
s = s.replace("#", "\\%03o" % ord("#"))
return s
quote_replacer_regex2 = re.compile(r'(\\+)"')
def _EscapeCommandLineArgumentForMSBuild(s):
"""Escapes a Windows command-line argument for use by MSBuild."""
def _Replace(match):
return (len(match.group(1)) / 2 * 4) * "\\" + '\\"'
# Escape all quotes so that they are interpreted literally.
s = quote_replacer_regex2.sub(_Replace, s)
return s
def _EscapeMSBuildSpecialCharacters(s):
escape_dictionary = {
"%": "%25",
"$": "%24",
"@": "%40",
"'": "%27",
";": "%3B",
"?": "%3F",
"*": "%2A",
}
result = "".join([escape_dictionary.get(c, c) for c in s])
return result
def _EscapeCppDefineForMSBuild(s):
"""Escapes a CPP define so that it will reach the compiler unaltered."""
s = _EscapeEnvironmentVariableExpansion(s)
s = _EscapeCommandLineArgumentForMSBuild(s)
s = _EscapeMSBuildSpecialCharacters(s)
# cl.exe replaces literal # characters with = in preprocessor definitions for
# some reason. Octal-encode to work around that.
s = s.replace("#", "\\%03o" % ord("#"))
return s
def _GenerateRulesForMSVS(
p, output_dir, options, spec, sources, excluded_sources, actions_to_add
):
"""Generate all the rules for a particular project.
Arguments:
p: the project
output_dir: directory to emit rules to
options: global options passed to the generator
spec: the specification for this project
sources: the set of all known source files in this project
excluded_sources: the set of sources excluded from normal processing
actions_to_add: deferred list of actions to add in
"""
rules = spec.get("rules", [])
rules_native = [r for r in rules if not int(r.get("msvs_external_rule", 0))]
rules_external = [r for r in rules if int(r.get("msvs_external_rule", 0))]
# Handle rules that use a native rules file.
if rules_native:
_GenerateNativeRulesForMSVS(p, rules_native, output_dir, spec, options)
# Handle external rules (non-native rules).
if rules_external:
_GenerateExternalRules(
rules_external, output_dir, spec, sources, options, actions_to_add
)
_AdjustSourcesForRules(rules, sources, excluded_sources, False)
def _AdjustSourcesForRules(rules, sources, excluded_sources, is_msbuild):
# Add outputs generated by each rule (if applicable).
for rule in rules:
# Add in the outputs from this rule.
trigger_files = _FindRuleTriggerFiles(rule, sources)
for trigger_file in trigger_files:
# Remove trigger_file from excluded_sources to let the rule be triggered
# (e.g. rule trigger ax_enums.idl is added to excluded_sources
# because it's also in an action's inputs in the same project)
excluded_sources.discard(_FixPath(trigger_file))
# Done if not processing outputs as sources.
if int(rule.get("process_outputs_as_sources", False)):
inputs, outputs = _RuleInputsAndOutputs(rule, trigger_file)
inputs = OrderedSet(_FixPaths(inputs))
outputs = OrderedSet(_FixPaths(outputs))
inputs.remove(_FixPath(trigger_file))
sources.update(inputs)
if not is_msbuild:
excluded_sources.update(inputs)
sources.update(outputs)
def _FilterActionsFromExcluded(excluded_sources, actions_to_add):
"""Take inputs with actions attached out of the list of exclusions.
Arguments:
excluded_sources: list of source files not to be built.
actions_to_add: dict of actions keyed on source file they're attached to.
Returns:
excluded_sources with files that have actions attached removed.
"""
must_keep = OrderedSet(_FixPaths(actions_to_add.keys()))
return [s for s in excluded_sources if s not in must_keep]
def _GetDefaultConfiguration(spec):
return spec["configurations"][spec["default_configuration"]]
def _GetGuidOfProject(proj_path, spec):
"""Get the guid for the project.
Arguments:
proj_path: Path of the vcproj or vcxproj file to generate.
spec: The target dictionary containing the properties of the target.
Returns:
the guid.
Raises:
ValueError: if the specified GUID is invalid.
"""
# Pluck out the default configuration.
default_config = _GetDefaultConfiguration(spec)
# Decide the guid of the project.
guid = default_config.get("msvs_guid")
if guid:
if VALID_MSVS_GUID_CHARS.match(guid) is None:
raise ValueError(
'Invalid MSVS guid: "%s". Must match regex: "%s".'
% (guid, VALID_MSVS_GUID_CHARS.pattern)
)
guid = "{%s}" % guid
guid = guid or MSVSNew.MakeGuid(proj_path)
return guid
def _GetMsbuildToolsetOfProject(proj_path, spec, version):
"""Get the platform toolset for the project.
Arguments:
proj_path: Path of the vcproj or vcxproj file to generate.
spec: The target dictionary containing the properties of the target.
version: The MSVSVersion object.
Returns:
the platform toolset string or None.
"""
# Pluck out the default configuration.
default_config = _GetDefaultConfiguration(spec)
toolset = default_config.get("msbuild_toolset")
if not toolset and version.DefaultToolset():
toolset = version.DefaultToolset()
if spec["type"] == "windows_driver":
toolset = "WindowsKernelModeDriver10.0"
return toolset
def _GenerateProject(project, options, version, generator_flags, spec):
"""Generates a vcproj file.
Arguments:
project: the MSVSProject object.
options: global generator options.
version: the MSVSVersion object.
generator_flags: dict of generator-specific flags.
Returns:
A list of source files that cannot be found on disk.
"""
default_config = _GetDefaultConfiguration(project.spec)
# Skip emitting anything if told to with msvs_existing_vcproj option.
if default_config.get("msvs_existing_vcproj"):
return []
if version.UsesVcxproj():
return _GenerateMSBuildProject(project, options, version, generator_flags, spec)
else:
return _GenerateMSVSProject(project, options, version, generator_flags)
def _GenerateMSVSProject(project, options, version, generator_flags):
"""Generates a .vcproj file. It may create .rules and .user files too.
Arguments:
project: The project object we will generate the file for.
options: Global options passed to the generator.
version: The VisualStudioVersion object.
generator_flags: dict of generator-specific flags.
"""
spec = project.spec
gyp.common.EnsureDirExists(project.path)
platforms = _GetUniquePlatforms(spec)
p = MSVSProject.Writer(
project.path, version, spec["target_name"], project.guid, platforms
)
# Get directory project file is in.
project_dir = os.path.split(project.path)[0]
gyp_path = _NormalizedSource(project.build_file)
relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
config_type = _GetMSVSConfigurationType(spec, project.build_file)
for config_name, config in spec["configurations"].items():
_AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)
# Prepare list of sources and excluded sources.
gyp_file = os.path.split(project.build_file)[1]
sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, gyp_file)
# Add rules.
actions_to_add = {}
_GenerateRulesForMSVS(
p, project_dir, options, spec, sources, excluded_sources, actions_to_add
)
list_excluded = generator_flags.get("msvs_list_excluded_files", True)
sources, excluded_sources, excluded_idl = _AdjustSourcesAndConvertToFilterHierarchy(
spec, options, project_dir, sources, excluded_sources, list_excluded, version
)
# Add in files.
missing_sources = _VerifySourcesExist(sources, project_dir)
p.AddFiles(sources)
_AddToolFilesToMSVS(p, spec)
_HandlePreCompiledHeaders(p, sources, spec)
_AddActions(actions_to_add, spec, relative_path_of_gyp_file)
_AddCopies(actions_to_add, spec)
_WriteMSVSUserFile(project.path, version, spec)
# NOTE: this stanza must appear after all actions have been decided.
# Don't excluded sources with actions attached, or they won't run.
excluded_sources = _FilterActionsFromExcluded(excluded_sources, actions_to_add)
_ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, list_excluded)
_AddAccumulatedActionsToMSVS(p, spec, actions_to_add)
# Write it out.
p.WriteIfChanged()
return missing_sources
def _GetUniquePlatforms(spec):
"""Returns the list of unique platforms for this spec, e.g ['win32', ...].
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
The MSVSUserFile object created.
"""
# Gather list of unique platforms.
platforms = OrderedSet()
for configuration in spec["configurations"]:
platforms.add(_ConfigPlatform(spec["configurations"][configuration]))
platforms = list(platforms)
return platforms
def _CreateMSVSUserFile(proj_path, version, spec):
"""Generates a .user file for the user running this Gyp program.
Arguments:
proj_path: The path of the project file being created. The .user file
shares the same path (with an appropriate suffix).
version: The VisualStudioVersion object.
spec: The target dictionary containing the properties of the target.
Returns:
The MSVSUserFile object created.
"""
(domain, username) = _GetDomainAndUserName()
vcuser_filename = ".".join([proj_path, domain, username, "user"])
user_file = MSVSUserFile.Writer(vcuser_filename, version, spec["target_name"])
return user_file
def _GetMSVSConfigurationType(spec, build_file):
"""Returns the configuration type for this project.
It's a number defined by Microsoft. May raise an exception.
Args:
spec: The target dictionary containing the properties of the target.
build_file: The path of the gyp file.
Returns:
An integer, the configuration type.
"""
try:
config_type = {
"executable": "1", # .exe
"shared_library": "2", # .dll
"loadable_module": "2", # .dll
"static_library": "4", # .lib
"windows_driver": "5", # .sys
"none": "10", # Utility type
}[spec["type"]]
except KeyError:
if spec.get("type"):
raise GypError(
"Target type %s is not a valid target type for "
"target %s in %s." % (spec["type"], spec["target_name"], build_file)
)
else:
raise GypError(
"Missing type field for target %s in %s."
% (spec["target_name"], build_file)
)
return config_type
def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):
"""Adds a configuration to the MSVS project.
Many settings in a vcproj file are specific to a configuration. This
function the main part of the vcproj file that's configuration specific.
Arguments:
p: The target project being generated.
spec: The target dictionary containing the properties of the target.
config_type: The configuration type, a number as defined by Microsoft.
config_name: The name of the configuration.
config: The dictionary that defines the special processing to be done
for this configuration.
"""
# Get the information for this configuration
include_dirs, midl_include_dirs, resource_include_dirs = _GetIncludeDirs(config)
libraries = _GetLibraries(spec)
library_dirs = _GetLibraryDirs(config)
out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False)
defines = _GetDefines(config)
defines = [_EscapeCppDefineForMSVS(d) for d in defines]
disabled_warnings = _GetDisabledWarnings(config)
prebuild = config.get("msvs_prebuild")
postbuild = config.get("msvs_postbuild")
def_file = _GetModuleDefinition(spec)
precompiled_header = config.get("msvs_precompiled_header")
# Prepare the list of tools as a dictionary.
tools = dict()
# Add in user specified msvs_settings.
msvs_settings = config.get("msvs_settings", {})
MSVSSettings.ValidateMSVSSettings(msvs_settings)
# Prevent default library inheritance from the environment.
_ToolAppend(tools, "VCLinkerTool", "AdditionalDependencies", ["$(NOINHERIT)"])
for tool in msvs_settings:
settings = config["msvs_settings"][tool]
for setting in settings:
_ToolAppend(tools, tool, setting, settings[setting])
# Add the information to the appropriate tool
_ToolAppend(tools, "VCCLCompilerTool", "AdditionalIncludeDirectories", include_dirs)
_ToolAppend(tools, "VCMIDLTool", "AdditionalIncludeDirectories", midl_include_dirs)
_ToolAppend(
tools,
"VCResourceCompilerTool",
"AdditionalIncludeDirectories",
resource_include_dirs,
)
# Add in libraries.
_ToolAppend(tools, "VCLinkerTool", "AdditionalDependencies", libraries)
_ToolAppend(tools, "VCLinkerTool", "AdditionalLibraryDirectories", library_dirs)
if out_file:
_ToolAppend(tools, vc_tool, "OutputFile", out_file, only_if_unset=True)
# Add defines.
_ToolAppend(tools, "VCCLCompilerTool", "PreprocessorDefinitions", defines)
_ToolAppend(tools, "VCResourceCompilerTool", "PreprocessorDefinitions", defines)
# Change program database directory to prevent collisions.
_ToolAppend(
tools,
"VCCLCompilerTool",
"ProgramDataBaseFileName",
"$(IntDir)$(ProjectName)\\vc80.pdb",
only_if_unset=True,
)
# Add disabled warnings.
_ToolAppend(tools, "VCCLCompilerTool", "DisableSpecificWarnings", disabled_warnings)
# Add Pre-build.
_ToolAppend(tools, "VCPreBuildEventTool", "CommandLine", prebuild)
# Add Post-build.
_ToolAppend(tools, "VCPostBuildEventTool", "CommandLine", postbuild)
# Turn on precompiled headers if appropriate.
if precompiled_header:
precompiled_header = os.path.split(precompiled_header)[1]
_ToolAppend(tools, "VCCLCompilerTool", "UsePrecompiledHeader", "2")
_ToolAppend(
tools, "VCCLCompilerTool", "PrecompiledHeaderThrough", precompiled_header
)
_ToolAppend(tools, "VCCLCompilerTool", "ForcedIncludeFiles", precompiled_header)
# Loadable modules don't generate import libraries;
# tell dependent projects to not expect one.
if spec["type"] == "loadable_module":
_ToolAppend(tools, "VCLinkerTool", "IgnoreImportLibrary", "true")
# Set the module definition file if any.
if def_file:
_ToolAppend(tools, "VCLinkerTool", "ModuleDefinitionFile", def_file)
_AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name)
def _GetIncludeDirs(config):
"""Returns the list of directories to be used for #include directives.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of directory paths.
"""
# TODO(bradnelson): include_dirs should really be flexible enough not to
# require this sort of thing.
include_dirs = config.get("include_dirs", []) + config.get(
"msvs_system_include_dirs", []
)
midl_include_dirs = config.get("midl_include_dirs", []) + config.get(
"msvs_system_include_dirs", []
)
resource_include_dirs = config.get("resource_include_dirs", include_dirs)
include_dirs = _FixPaths(include_dirs)
midl_include_dirs = _FixPaths(midl_include_dirs)
resource_include_dirs = _FixPaths(resource_include_dirs)
return include_dirs, midl_include_dirs, resource_include_dirs
def _GetLibraryDirs(config):
"""Returns the list of directories to be used for library search paths.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of directory paths.
"""
library_dirs = config.get("library_dirs", [])
library_dirs = _FixPaths(library_dirs)
return library_dirs
def _GetLibraries(spec):
"""Returns the list of libraries for this configuration.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
The list of directory paths.
"""
libraries = spec.get("libraries", [])
# Strip out -l, as it is not used on windows (but is needed so we can pass
# in libraries that are assumed to be in the default library path).
# Also remove duplicate entries, leaving only the last duplicate, while
# preserving order.
found = OrderedSet()
unique_libraries_list = []
for entry in reversed(libraries):
library = re.sub(r"^\-l", "", entry)
if not os.path.splitext(library)[1]:
library += ".lib"
if library not in found:
found.add(library)
unique_libraries_list.append(library)
unique_libraries_list.reverse()
return unique_libraries_list
def _GetOutputFilePathAndTool(spec, msbuild):
"""Returns the path and tool to use for this target.
Figures out the path of the file this spec will create and the name of
the VC tool that will create it.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
A triple of (file path, name of the vc tool, name of the msbuild tool)
"""
# Select a name for the output file.
out_file = ""
vc_tool = ""
msbuild_tool = ""
output_file_map = {
"executable": ("VCLinkerTool", "Link", "$(OutDir)", ".exe"),
"shared_library": ("VCLinkerTool", "Link", "$(OutDir)", ".dll"),
"loadable_module": ("VCLinkerTool", "Link", "$(OutDir)", ".dll"),
"windows_driver": ("VCLinkerTool", "Link", "$(OutDir)", ".sys"),
"static_library": ("VCLibrarianTool", "Lib", "$(OutDir)lib\\", ".lib"),
}
output_file_props = output_file_map.get(spec["type"])
if output_file_props and int(spec.get("msvs_auto_output_file", 1)):
vc_tool, msbuild_tool, out_dir, suffix = output_file_props
if spec.get("standalone_static_library", 0):
out_dir = "$(OutDir)"
out_dir = spec.get("product_dir", out_dir)
product_extension = spec.get("product_extension")
if product_extension:
suffix = "." + product_extension
elif msbuild:
suffix = "$(TargetExt)"
prefix = spec.get("product_prefix", "")
product_name = spec.get("product_name", "$(ProjectName)")
out_file = ntpath.join(out_dir, prefix + product_name + suffix)
return out_file, vc_tool, msbuild_tool
def _GetOutputTargetExt(spec):
"""Returns the extension for this target, including the dot
If product_extension is specified, set target_extension to this to avoid
MSB8012, returns None otherwise. Ignores any target_extension settings in
the input files.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
A string with the extension, or None
"""
target_extension = spec.get("product_extension")
if target_extension:
return "." + target_extension
return None
def _GetDefines(config):
"""Returns the list of preprocessor definitions for this configuration.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of preprocessor definitions.
"""
defines = []
for d in config.get("defines", []):
if type(d) == list:
fd = "=".join([str(dpart) for dpart in d])
else:
fd = str(d)
defines.append(fd)
return defines
def _GetDisabledWarnings(config):
return [str(i) for i in config.get("msvs_disabled_warnings", [])]
def _GetModuleDefinition(spec):
def_file = ""
if spec["type"] in [
"shared_library",
"loadable_module",
"executable",
"windows_driver",
]:
def_files = [s for s in spec.get("sources", []) if s.endswith(".def")]
if len(def_files) == 1:
def_file = _FixPath(def_files[0])
elif def_files:
raise ValueError(
"Multiple module definition files in one target, target %s lists "
"multiple .def files: %s" % (spec["target_name"], " ".join(def_files))
)
return def_file
def _ConvertToolsToExpectedForm(tools):
"""Convert tools to a form expected by Visual Studio.
Arguments:
tools: A dictionary of settings; the tool name is the key.
Returns:
A list of Tool objects.
"""
tool_list = []
for tool, settings in tools.items():
# Collapse settings with lists.
settings_fixed = {}
for setting, value in settings.items():
if type(value) == list:
if (
tool == "VCLinkerTool" and setting == "AdditionalDependencies"
) or setting == "AdditionalOptions":
settings_fixed[setting] = " ".join(value)
else:
settings_fixed[setting] = ";".join(value)
else:
settings_fixed[setting] = value
# Add in this tool.
tool_list.append(MSVSProject.Tool(tool, settings_fixed))
return tool_list
def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name):
"""Add to the project file the configuration specified by config.
Arguments:
p: The target project being generated.
spec: the target project dict.
tools: A dictionary of settings; the tool name is the key.
config: The dictionary that defines the special processing to be done
for this configuration.
config_type: The configuration type, a number as defined by Microsoft.
config_name: The name of the configuration.
"""
attributes = _GetMSVSAttributes(spec, config, config_type)
# Add in this configuration.
tool_list = _ConvertToolsToExpectedForm(tools)
p.AddConfig(_ConfigFullName(config_name, config), attrs=attributes, tools=tool_list)
def _GetMSVSAttributes(spec, config, config_type):
# Prepare configuration attributes.
prepared_attrs = {}
source_attrs = config.get("msvs_configuration_attributes", {})
for a in source_attrs:
prepared_attrs[a] = source_attrs[a]
# Add props files.
vsprops_dirs = config.get("msvs_props", [])
vsprops_dirs = _FixPaths(vsprops_dirs)
if vsprops_dirs:
prepared_attrs["InheritedPropertySheets"] = ";".join(vsprops_dirs)
# Set configuration type.
prepared_attrs["ConfigurationType"] = config_type
output_dir = prepared_attrs.get(
"OutputDirectory", "$(SolutionDir)$(ConfigurationName)"
)
prepared_attrs["OutputDirectory"] = _FixPath(output_dir) + "\\"
if "IntermediateDirectory" not in prepared_attrs:
intermediate = "$(ConfigurationName)\\obj\\$(ProjectName)"
prepared_attrs["IntermediateDirectory"] = _FixPath(intermediate) + "\\"
else:
intermediate = _FixPath(prepared_attrs["IntermediateDirectory"]) + "\\"
intermediate = MSVSSettings.FixVCMacroSlashes(intermediate)
prepared_attrs["IntermediateDirectory"] = intermediate
return prepared_attrs
def _AddNormalizedSources(sources_set, sources_array):
sources_set.update(_NormalizedSource(s) for s in sources_array)
def _PrepareListOfSources(spec, generator_flags, gyp_file):
"""Prepare list of sources and excluded sources.
Besides the sources specified directly in the spec, adds the gyp file so
that a change to it will cause a re-compile. Also adds appropriate sources
for actions and copies. Assumes later stage will un-exclude files which
have custom build steps attached.
Arguments:
spec: The target dictionary containing the properties of the target.
gyp_file: The name of the gyp file.
Returns:
A pair of (list of sources, list of excluded sources).
The sources will be relative to the gyp file.
"""
sources = OrderedSet()
_AddNormalizedSources(sources, spec.get("sources", []))
excluded_sources = OrderedSet()
# Add in the gyp file.
if not generator_flags.get("standalone"):
sources.add(gyp_file)
# Add in 'action' inputs and outputs.
for a in spec.get("actions", []):
inputs = a["inputs"]
inputs = [_NormalizedSource(i) for i in inputs]
# Add all inputs to sources and excluded sources.
inputs = OrderedSet(inputs)
sources.update(inputs)
if not spec.get("msvs_external_builder"):
excluded_sources.update(inputs)
if int(a.get("process_outputs_as_sources", False)):
_AddNormalizedSources(sources, a.get("outputs", []))
# Add in 'copies' inputs and outputs.
for cpy in spec.get("copies", []):
_AddNormalizedSources(sources, cpy.get("files", []))
return (sources, excluded_sources)
def _AdjustSourcesAndConvertToFilterHierarchy(
spec, options, gyp_dir, sources, excluded_sources, list_excluded, version
):
"""Adjusts the list of sources and excluded sources.
Also converts the sets to lists.
Arguments:
spec: The target dictionary containing the properties of the target.
options: Global generator options.
gyp_dir: The path to the gyp file being processed.
sources: A set of sources to be included for this project.
excluded_sources: A set of sources to be excluded for this project.
version: A MSVSVersion object.
Returns:
A trio of (list of sources, list of excluded sources,
path of excluded IDL file)
"""
# Exclude excluded sources coming into the generator.
excluded_sources.update(OrderedSet(spec.get("sources_excluded", [])))
# Add excluded sources into sources for good measure.
sources.update(excluded_sources)
# Convert to proper windows form.
# NOTE: sources goes from being a set to a list here.
# NOTE: excluded_sources goes from being a set to a list here.
sources = _FixPaths(sources)
# Convert to proper windows form.
excluded_sources = _FixPaths(excluded_sources)
excluded_idl = _IdlFilesHandledNonNatively(spec, sources)
precompiled_related = _GetPrecompileRelatedFiles(spec)
# Find the excluded ones, minus the precompiled header related ones.
fully_excluded = [i for i in excluded_sources if i not in precompiled_related]
# Convert to folders and the right slashes.
sources = [i.split("\\") for i in sources]
sources = _ConvertSourcesToFilterHierarchy(
sources,
excluded=fully_excluded,
list_excluded=list_excluded,
msvs_version=version,
)
# Prune filters with a single child to flatten ugly directory structures
# such as ../../src/modules/module1 etc.
if version.UsesVcxproj():
while (
all([isinstance(s, MSVSProject.Filter) for s in sources])
and len({s.name for s in sources}) == 1
):
assert all([len(s.contents) == 1 for s in sources])
sources = [s.contents[0] for s in sources]
else:
while len(sources) == 1 and isinstance(sources[0], MSVSProject.Filter):
sources = sources[0].contents
return sources, excluded_sources, excluded_idl
def _IdlFilesHandledNonNatively(spec, sources):
# If any non-native rules use 'idl' as an extension exclude idl files.
# Gather a list here to use later.
using_idl = False
for rule in spec.get("rules", []):
if rule["extension"] == "idl" and int(rule.get("msvs_external_rule", 0)):
using_idl = True
break
if using_idl:
excluded_idl = [i for i in sources if i.endswith(".idl")]
else:
excluded_idl = []
return excluded_idl
def _GetPrecompileRelatedFiles(spec):
# Gather a list of precompiled header related sources.
precompiled_related = []
for _, config in spec["configurations"].items():
for k in precomp_keys:
f = config.get(k)
if f:
precompiled_related.append(_FixPath(f))
return precompiled_related
def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, list_excluded):
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
for file_name, excluded_configs in exclusions.items():
if not list_excluded and len(excluded_configs) == len(spec["configurations"]):
# If we're not listing excluded files, then they won't appear in the
# project, so don't try to configure them to be excluded.
pass
else:
for config_name, config in excluded_configs:
p.AddFileConfig(
file_name,
_ConfigFullName(config_name, config),
{"ExcludedFromBuild": "true"},
)
def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
exclusions = {}
# Exclude excluded sources from being built.
for f in excluded_sources:
excluded_configs = []
for config_name, config in spec["configurations"].items():
precomped = [_FixPath(config.get(i, "")) for i in precomp_keys]
# Don't do this for ones that are precompiled header related.
if f not in precomped:
excluded_configs.append((config_name, config))
exclusions[f] = excluded_configs
# If any non-native rules use 'idl' as an extension exclude idl files.
# Exclude them now.
for f in excluded_idl:
excluded_configs = []
for config_name, config in spec["configurations"].items():
excluded_configs.append((config_name, config))
exclusions[f] = excluded_configs
return exclusions
def _AddToolFilesToMSVS(p, spec):
# Add in tool files (rules).
tool_files = OrderedSet()
for _, config in spec["configurations"].items():
for f in config.get("msvs_tool_files", []):
tool_files.add(f)
for f in tool_files:
p.AddToolFile(f)
def _HandlePreCompiledHeaders(p, sources, spec):
# Pre-compiled header source stubs need a different compiler flag
# (generate precompiled header) and any source file not of the same
# kind (i.e. C vs. C++) as the precompiled header source stub needs
# to have use of precompiled headers disabled.
extensions_excluded_from_precompile = []
for config_name, config in spec["configurations"].items():
source = config.get("msvs_precompiled_source")
if source:
source = _FixPath(source)
# UsePrecompiledHeader=1 for if using precompiled headers.
tool = MSVSProject.Tool("VCCLCompilerTool", {"UsePrecompiledHeader": "1"})
p.AddFileConfig(
source, _ConfigFullName(config_name, config), {}, tools=[tool]
)
basename, extension = os.path.splitext(source)
if extension == ".c":
extensions_excluded_from_precompile = [".cc", ".cpp", ".cxx"]
else:
extensions_excluded_from_precompile = [".c"]
def DisableForSourceTree(source_tree):
for source in source_tree:
if isinstance(source, MSVSProject.Filter):
DisableForSourceTree(source.contents)
else:
basename, extension = os.path.splitext(source)
if extension in extensions_excluded_from_precompile:
for config_name, config in spec["configurations"].items():
tool = MSVSProject.Tool(
"VCCLCompilerTool",
{
"UsePrecompiledHeader": "0",
"ForcedIncludeFiles": "$(NOINHERIT)",
},
)
p.AddFileConfig(
_FixPath(source),
_ConfigFullName(config_name, config),
{},
tools=[tool],
)
# Do nothing if there was no precompiled source.
if extensions_excluded_from_precompile:
DisableForSourceTree(sources)
def _AddActions(actions_to_add, spec, relative_path_of_gyp_file):
# Add actions.
actions = spec.get("actions", [])
# Don't setup_env every time. When all the actions are run together in one
# batch file in VS, the PATH will grow too long.
# Membership in this set means that the cygwin environment has been set up,
# and does not need to be set up again.
have_setup_env = set()
for a in actions:
# Attach actions to the gyp file if nothing else is there.
inputs = a.get("inputs") or [relative_path_of_gyp_file]
attached_to = inputs[0]
need_setup_env = attached_to not in have_setup_env
cmd = _BuildCommandLineForRule(
spec, a, has_input_path=False, do_setup_env=need_setup_env
)
have_setup_env.add(attached_to)
# Add the action.
_AddActionStep(
actions_to_add,
inputs=inputs,
outputs=a.get("outputs", []),
description=a.get("message", a["action_name"]),
command=cmd,
)
def _WriteMSVSUserFile(project_path, version, spec):
# Add run_as and test targets.
if "run_as" in spec:
run_as = spec["run_as"]
action = run_as.get("action", [])
environment = run_as.get("environment", [])
working_directory = run_as.get("working_directory", ".")
elif int(spec.get("test", 0)):
action = ["$(TargetPath)", "--gtest_print_time"]
environment = []
working_directory = "."
else:
return # Nothing to add
# Write out the user file.
user_file = _CreateMSVSUserFile(project_path, version, spec)
for config_name, c_data in spec["configurations"].items():
user_file.AddDebugSettings(
_ConfigFullName(config_name, c_data), action, environment, working_directory
)
user_file.WriteIfChanged()
def _AddCopies(actions_to_add, spec):
copies = _GetCopies(spec)
for inputs, outputs, cmd, description in copies:
_AddActionStep(
actions_to_add,
inputs=inputs,
outputs=outputs,
description=description,
command=cmd,
)
def _GetCopies(spec):
copies = []
# Add copies.
for cpy in spec.get("copies", []):
for src in cpy.get("files", []):
dst = os.path.join(cpy["destination"], os.path.basename(src))
# _AddCustomBuildToolForMSVS() will call _FixPath() on the inputs and
# outputs, so do the same for our generated command line.
if src.endswith("/"):
src_bare = src[:-1]
base_dir = posixpath.split(src_bare)[0]
outer_dir = posixpath.split(src_bare)[1]
fixed_dst = _FixPath(dst)
full_dst = f'"{fixed_dst}\\{outer_dir}\\"'
cmd = 'mkdir {} 2>nul & cd "{}" && xcopy /e /f /y "{}" {}'.format(
full_dst,
_FixPath(base_dir),
outer_dir,
full_dst,
)
copies.append(
(
[src],
["dummy_copies", dst],
cmd,
f"Copying {src} to {fixed_dst}",
)
)
else:
fix_dst = _FixPath(cpy["destination"])
cmd = 'mkdir "{}" 2>nul & set ERRORLEVEL=0 & copy /Y "{}" "{}"'.format(
fix_dst,
_FixPath(src),
_FixPath(dst),
)
copies.append(([src], [dst], cmd, f"Copying {src} to {fix_dst}"))
return copies
def _GetPathDict(root, path):
# |path| will eventually be empty (in the recursive calls) if it was initially
# relative; otherwise it will eventually end up as '\', 'D:\', etc.
if not path or path.endswith(os.sep):
return root
parent, folder = os.path.split(path)
parent_dict = _GetPathDict(root, parent)
if folder not in parent_dict:
parent_dict[folder] = dict()
return parent_dict[folder]
def _DictsToFolders(base_path, bucket, flat):
# Convert to folders recursively.
children = []
for folder, contents in bucket.items():
if type(contents) == dict:
folder_children = _DictsToFolders(
os.path.join(base_path, folder), contents, flat
)
if flat:
children += folder_children
else:
folder_children = MSVSNew.MSVSFolder(
os.path.join(base_path, folder),
name="(" + folder + ")",
entries=folder_children,
)
children.append(folder_children)
else:
children.append(contents)
return children
def _CollapseSingles(parent, node):
# Recursively explorer the tree of dicts looking for projects which are
# the sole item in a folder which has the same name as the project. Bring
# such projects up one level.
if type(node) == dict and len(node) == 1 and next(iter(node)) == parent + ".vcproj":
return node[next(iter(node))]
if type(node) != dict:
return node
for child in node:
node[child] = _CollapseSingles(child, node[child])
return node
def _GatherSolutionFolders(sln_projects, project_objects, flat):
root = {}
# Convert into a tree of dicts on path.
for p in sln_projects:
gyp_file, target = gyp.common.ParseQualifiedTarget(p)[0:2]
if p.endswith("#host"):
target += "_host"
gyp_dir = os.path.dirname(gyp_file)
path_dict = _GetPathDict(root, gyp_dir)
path_dict[target + ".vcproj"] = project_objects[p]
# Walk down from the top until we hit a folder that has more than one entry.
# In practice, this strips the top-level "src/" dir from the hierarchy in
# the solution.
while len(root) == 1 and type(root[next(iter(root))]) == dict:
root = root[next(iter(root))]
# Collapse singles.
root = _CollapseSingles("", root)
# Merge buckets until everything is a root entry.
return _DictsToFolders("", root, flat)
def _GetPathOfProject(qualified_target, spec, options, msvs_version):
default_config = _GetDefaultConfiguration(spec)
proj_filename = default_config.get("msvs_existing_vcproj")
if not proj_filename:
proj_filename = spec["target_name"]
if spec["toolset"] == "host":
proj_filename += "_host"
proj_filename = proj_filename + options.suffix + msvs_version.ProjectExtension()
build_file = gyp.common.BuildFile(qualified_target)
proj_path = os.path.join(os.path.dirname(build_file), proj_filename)
fix_prefix = None
if options.generator_output:
project_dir_path = os.path.dirname(os.path.abspath(proj_path))
proj_path = os.path.join(options.generator_output, proj_path)
fix_prefix = gyp.common.RelativePath(
project_dir_path, os.path.dirname(proj_path)
)
return proj_path, fix_prefix
def _GetPlatformOverridesOfProject(spec):
# Prepare a dict indicating which project configurations are used for which
# solution configurations for this target.
config_platform_overrides = {}
for config_name, c in spec["configurations"].items():
config_fullname = _ConfigFullName(config_name, c)
platform = c.get("msvs_target_platform", _ConfigPlatform(c))
fixed_config_fullname = "{}|{}".format(
_ConfigBaseName(config_name, _ConfigPlatform(c)),
platform,
)
if spec["toolset"] == "host" and generator_supports_multiple_toolsets:
fixed_config_fullname = f"{config_name}|x64"
config_platform_overrides[config_fullname] = fixed_config_fullname
return config_platform_overrides
def _CreateProjectObjects(target_list, target_dicts, options, msvs_version):
"""Create a MSVSProject object for the targets found in target list.
Arguments:
target_list: the list of targets to generate project objects for.
target_dicts: the dictionary of specifications.
options: global generator options.
msvs_version: the MSVSVersion object.
Returns:
A set of created projects, keyed by target.
"""
global fixpath_prefix
# Generate each project.
projects = {}
for qualified_target in target_list:
spec = target_dicts[qualified_target]
proj_path, fixpath_prefix = _GetPathOfProject(
qualified_target, spec, options, msvs_version
)
guid = _GetGuidOfProject(proj_path, spec)
overrides = _GetPlatformOverridesOfProject(spec)
build_file = gyp.common.BuildFile(qualified_target)
# Create object for this project.
target_name = spec["target_name"]
if spec["toolset"] == "host":
target_name += "_host"
obj = MSVSNew.MSVSProject(
proj_path,
name=target_name,
guid=guid,
spec=spec,
build_file=build_file,
config_platform_overrides=overrides,
fixpath_prefix=fixpath_prefix,
)
# Set project toolset if any (MS build only)
if msvs_version.UsesVcxproj():
obj.set_msbuild_toolset(
_GetMsbuildToolsetOfProject(proj_path, spec, msvs_version)
)
projects[qualified_target] = obj
# Set all the dependencies, but not if we are using an external builder like
# ninja
for project in projects.values():
if not project.spec.get("msvs_external_builder"):
deps = project.spec.get("dependencies", [])
deps = [projects[d] for d in deps]
project.set_dependencies(deps)
return projects
def _InitNinjaFlavor(params, target_list, target_dicts):
"""Initialize targets for the ninja flavor.
This sets up the necessary variables in the targets to generate msvs projects
that use ninja as an external builder. The variables in the spec are only set
if they have not been set. This allows individual specs to override the
default values initialized here.
Arguments:
params: Params provided to the generator.
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
"""
for qualified_target in target_list:
spec = target_dicts[qualified_target]
if spec.get("msvs_external_builder"):
# The spec explicitly defined an external builder, so don't change it.
continue
path_to_ninja = spec.get("msvs_path_to_ninja", "ninja.exe")
spec["msvs_external_builder"] = "ninja"
if not spec.get("msvs_external_builder_out_dir"):
gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
gyp_dir = os.path.dirname(gyp_file)
configuration = "$(Configuration)"
if params.get("target_arch") == "x64":
configuration += "_x64"
if params.get("target_arch") == "arm64":
configuration += "_arm64"
spec["msvs_external_builder_out_dir"] = os.path.join(
gyp.common.RelativePath(params["options"].toplevel_dir, gyp_dir),
ninja_generator.ComputeOutputDir(params),
configuration,
)
if not spec.get("msvs_external_builder_build_cmd"):
spec["msvs_external_builder_build_cmd"] = [
path_to_ninja,
"-C",
"$(OutDir)",
"$(ProjectName)",
]
if not spec.get("msvs_external_builder_clean_cmd"):
spec["msvs_external_builder_clean_cmd"] = [
path_to_ninja,
"-C",
"$(OutDir)",
"-tclean",
"$(ProjectName)",
]
def CalculateVariables(default_variables, params):
"""Generated variables that require params to be known."""
generator_flags = params.get("generator_flags", {})
# Select project file format version (if unset, default to auto detecting).
msvs_version = MSVSVersion.SelectVisualStudioVersion(
generator_flags.get("msvs_version", "auto")
)
# Stash msvs_version for later (so we don't have to probe the system twice).
params["msvs_version"] = msvs_version
# Set a variable so conditions can be based on msvs_version.
default_variables["MSVS_VERSION"] = msvs_version.ShortName()
# To determine processor word size on Windows, in addition to checking
# PROCESSOR_ARCHITECTURE (which reflects the word size of the current
# process), it is also necessary to check PROCESSOR_ARCITEW6432 (which
# contains the actual word size of the system when running thru WOW64).
if (
os.environ.get("PROCESSOR_ARCHITECTURE", "").find("64") >= 0
or os.environ.get("PROCESSOR_ARCHITEW6432", "").find("64") >= 0
):
default_variables["MSVS_OS_BITS"] = 64
else:
default_variables["MSVS_OS_BITS"] = 32
if gyp.common.GetFlavor(params) == "ninja":
default_variables["SHARED_INTERMEDIATE_DIR"] = "$(OutDir)gen"
def PerformBuild(data, configurations, params):
options = params["options"]
msvs_version = params["msvs_version"]
devenv = os.path.join(msvs_version.path, "Common7", "IDE", "devenv.com")
for build_file, build_file_dict in data.items():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != ".gyp":
continue
sln_path = build_file_root + options.suffix + ".sln"
if options.generator_output:
sln_path = os.path.join(options.generator_output, sln_path)
for config in configurations:
arguments = [devenv, sln_path, "/Build", config]
print(f"Building [{config}]: {arguments}")
subprocess.check_call(arguments)
def CalculateGeneratorInputInfo(params):
if params.get("flavor") == "ninja":
toplevel = params["options"].toplevel_dir
qualified_out_dir = os.path.normpath(
os.path.join(
toplevel,
ninja_generator.ComputeOutputDir(params),
"gypfiles-msvs-ninja",
)
)
global generator_filelist_paths
generator_filelist_paths = {
"toplevel": toplevel,
"qualified_out_dir": qualified_out_dir,
}
def GenerateOutput(target_list, target_dicts, data, params):
"""Generate .sln and .vcproj files.
This is the entry point for this generator.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
data: Dictionary containing per .gyp data.
"""
global fixpath_prefix
options = params["options"]
# Get the project file format version back out of where we stashed it in
# GeneratorCalculatedVariables.
msvs_version = params["msvs_version"]
generator_flags = params.get("generator_flags", {})
# Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
(target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts)
# Optionally use the large PDB workaround for targets marked with
# 'msvs_large_pdb': 1.
(target_list, target_dicts) = MSVSUtil.InsertLargePdbShims(
target_list, target_dicts, generator_default_variables
)
# Optionally configure each spec to use ninja as the external builder.
if params.get("flavor") == "ninja":
_InitNinjaFlavor(params, target_list, target_dicts)
# Prepare the set of configurations.
configs = set()
for qualified_target in target_list:
spec = target_dicts[qualified_target]
for config_name, config in spec["configurations"].items():
config_name = _ConfigFullName(config_name, config)
configs.add(config_name)
if config_name == "Release|arm64":
configs.add("Release|x64")
configs = list(configs)
# Figure out all the projects that will be generated and their guids
project_objects = _CreateProjectObjects(
target_list, target_dicts, options, msvs_version
)
# Generate each project.
missing_sources = []
for project in project_objects.values():
fixpath_prefix = project.fixpath_prefix
missing_sources.extend(
_GenerateProject(project, options, msvs_version, generator_flags, spec)
)
fixpath_prefix = None
for build_file in data:
# Validate build_file extension
target_only_configs = configs
if generator_supports_multiple_toolsets:
target_only_configs = [i for i in configs if i.endswith("arm64")]
if not build_file.endswith(".gyp"):
continue
sln_path = os.path.splitext(build_file)[0] + options.suffix + ".sln"
if options.generator_output:
sln_path = os.path.join(options.generator_output, sln_path)
# Get projects in the solution, and their dependents.
sln_projects = gyp.common.BuildFileTargets(target_list, build_file)
sln_projects += gyp.common.DeepDependencyTargets(target_dicts, sln_projects)
# Create folder hierarchy.
root_entries = _GatherSolutionFolders(
sln_projects, project_objects, flat=msvs_version.FlatSolution()
)
# Create solution.
sln = MSVSNew.MSVSSolution(
sln_path,
entries=root_entries,
variants=target_only_configs,
websiteProperties=False,
version=msvs_version,
)
sln.Write()
if missing_sources:
error_message = "Missing input files:\n" + "\n".join(set(missing_sources))
if generator_flags.get("msvs_error_on_missing_sources", False):
raise GypError(error_message)
else:
print("Warning: " + error_message, file=sys.stdout)
def _GenerateMSBuildFiltersFile(
filters_path,
source_files,
rule_dependencies,
extension_to_rule_name,
platforms,
toolset,
):
"""Generate the filters file.
This file is used by Visual Studio to organize the presentation of source
files into folders.
Arguments:
filters_path: The path of the file to be created.
source_files: The hierarchical structure of all the sources.
extension_to_rule_name: A dictionary mapping file extensions to rules.
"""
filter_group = []
source_group = []
_AppendFiltersForMSBuild(
"",
source_files,
rule_dependencies,
extension_to_rule_name,
platforms,
toolset,
filter_group,
source_group,
)
if filter_group:
content = [
"Project",
{
"ToolsVersion": "4.0",
"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003",
},
["ItemGroup"] + filter_group,
["ItemGroup"] + source_group,
]
easy_xml.WriteXmlIfChanged(content, filters_path, pretty=True, win32=True)
elif os.path.exists(filters_path):
# We don't need this filter anymore. Delete the old filter file.
os.unlink(filters_path)
def _AppendFiltersForMSBuild(
parent_filter_name,
sources,
rule_dependencies,
extension_to_rule_name,
platforms,
toolset,
filter_group,
source_group,
):
"""Creates the list of filters and sources to be added in the filter file.
Args:
parent_filter_name: The name of the filter under which the sources are
found.
sources: The hierarchy of filters and sources to process.
extension_to_rule_name: A dictionary mapping file extensions to rules.
filter_group: The list to which filter entries will be appended.
source_group: The list to which source entries will be appended.
"""
for source in sources:
if isinstance(source, MSVSProject.Filter):
# We have a sub-filter. Create the name of that sub-filter.
if not parent_filter_name:
filter_name = source.name
else:
filter_name = f"{parent_filter_name}\\{source.name}"
# Add the filter to the group.
filter_group.append(
[
"Filter",
{"Include": filter_name},
["UniqueIdentifier", MSVSNew.MakeGuid(source.name)],
]
)
# Recurse and add its dependents.
_AppendFiltersForMSBuild(
filter_name,
source.contents,
rule_dependencies,
extension_to_rule_name,
platforms,
toolset,
filter_group,
source_group,
)
else:
# It's a source. Create a source entry.
_, element = _MapFileToMsBuildSourceType(
source, rule_dependencies, extension_to_rule_name, platforms, toolset
)
source_entry = [element, {"Include": source}]
# Specify the filter it is part of, if any.
if parent_filter_name:
source_entry.append(["Filter", parent_filter_name])
source_group.append(source_entry)
def _MapFileToMsBuildSourceType(
source, rule_dependencies, extension_to_rule_name, platforms, toolset
):
"""Returns the group and element type of the source file.
Arguments:
source: The source file name.
extension_to_rule_name: A dictionary mapping file extensions to rules.
Returns:
A pair of (group this file should be part of, the label of element)
"""
_, ext = os.path.splitext(source)
ext = ext.lower()
if ext in extension_to_rule_name:
group = "rule"
element = extension_to_rule_name[ext]
elif ext in [".cc", ".cpp", ".c", ".cxx", ".mm"]:
group = "compile"
element = "ClCompile"
elif ext in [".h", ".hxx"]:
group = "include"
element = "ClInclude"
elif ext == ".rc":
group = "resource"
element = "ResourceCompile"
elif ext in [".s", ".asm"]:
group = "masm"
element = "MASM"
if "arm64" in platforms and toolset == "target":
element = "MARMASM"
elif ext == ".idl":
group = "midl"
element = "Midl"
elif source in rule_dependencies:
group = "rule_dependency"
element = "CustomBuild"
else:
group = "none"
element = "None"
return (group, element)
def _GenerateRulesForMSBuild(
output_dir,
options,
spec,
sources,
excluded_sources,
props_files_of_rules,
targets_files_of_rules,
actions_to_add,
rule_dependencies,
extension_to_rule_name,
):
# MSBuild rules are implemented using three files: an XML file, a .targets
# file and a .props file.
# For more details see:
# https://devblogs.microsoft.com/cppblog/quick-help-on-vs2010-custom-build-rule/
rules = spec.get("rules", [])
rules_native = [r for r in rules if not int(r.get("msvs_external_rule", 0))]
rules_external = [r for r in rules if int(r.get("msvs_external_rule", 0))]
msbuild_rules = []
for rule in rules_native:
# Skip a rule with no action and no inputs.
if "action" not in rule and not rule.get("rule_sources", []):
continue
msbuild_rule = MSBuildRule(rule, spec)
msbuild_rules.append(msbuild_rule)
rule_dependencies.update(msbuild_rule.additional_dependencies.split(";"))
extension_to_rule_name[msbuild_rule.extension] = msbuild_rule.rule_name
if msbuild_rules:
base = spec["target_name"] + options.suffix
props_name = base + ".props"
targets_name = base + ".targets"
xml_name = base + ".xml"
props_files_of_rules.add(props_name)
targets_files_of_rules.add(targets_name)
props_path = os.path.join(output_dir, props_name)
targets_path = os.path.join(output_dir, targets_name)
xml_path = os.path.join(output_dir, xml_name)
_GenerateMSBuildRulePropsFile(props_path, msbuild_rules)
_GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules)
_GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules)
if rules_external:
_GenerateExternalRules(
rules_external, output_dir, spec, sources, options, actions_to_add
)
_AdjustSourcesForRules(rules, sources, excluded_sources, True)
class MSBuildRule:
"""Used to store information used to generate an MSBuild rule.
Attributes:
rule_name: The rule name, sanitized to use in XML.
target_name: The name of the target.
after_targets: The name of the AfterTargets element.
before_targets: The name of the BeforeTargets element.
depends_on: The name of the DependsOn element.
compute_output: The name of the ComputeOutput element.
dirs_to_make: The name of the DirsToMake element.
inputs: The name of the _inputs element.
tlog: The name of the _tlog element.
extension: The extension this rule applies to.
description: The message displayed when this rule is invoked.
additional_dependencies: A string listing additional dependencies.
outputs: The outputs of this rule.
command: The command used to run the rule.
"""
def __init__(self, rule, spec):
self.display_name = rule["rule_name"]
# Assure that the rule name is only characters and numbers
self.rule_name = re.sub(r"\W", "_", self.display_name)
# Create the various element names, following the example set by the
# Visual Studio 2008 to 2010 conversion. I don't know if VS2010
# is sensitive to the exact names.
self.target_name = "_" + self.rule_name
self.after_targets = self.rule_name + "AfterTargets"
self.before_targets = self.rule_name + "BeforeTargets"
self.depends_on = self.rule_name + "DependsOn"
self.compute_output = "Compute%sOutput" % self.rule_name
self.dirs_to_make = self.rule_name + "DirsToMake"
self.inputs = self.rule_name + "_inputs"
self.tlog = self.rule_name + "_tlog"
self.extension = rule["extension"]
if not self.extension.startswith("."):
self.extension = "." + self.extension
self.description = MSVSSettings.ConvertVCMacrosToMSBuild(
rule.get("message", self.rule_name)
)
old_additional_dependencies = _FixPaths(rule.get("inputs", []))
self.additional_dependencies = ";".join(
[
MSVSSettings.ConvertVCMacrosToMSBuild(i)
for i in old_additional_dependencies
]
)
old_outputs = _FixPaths(rule.get("outputs", []))
self.outputs = ";".join(
[MSVSSettings.ConvertVCMacrosToMSBuild(i) for i in old_outputs]
)
old_command = _BuildCommandLineForRule(
spec, rule, has_input_path=True, do_setup_env=True
)
self.command = MSVSSettings.ConvertVCMacrosToMSBuild(old_command)
def _GenerateMSBuildRulePropsFile(props_path, msbuild_rules):
"""Generate the .props file."""
content = [
"Project",
{"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003"},
]
for rule in msbuild_rules:
content.extend(
[
[
"PropertyGroup",
{
"Condition": "'$(%s)' == '' and '$(%s)' == '' and "
"'$(ConfigurationType)' != 'Makefile'"
% (rule.before_targets, rule.after_targets)
},
[rule.before_targets, "Midl"],
[rule.after_targets, "CustomBuild"],
],
[
"PropertyGroup",
[
rule.depends_on,
{"Condition": "'$(ConfigurationType)' != 'Makefile'"},
"_SelectedFiles;$(%s)" % rule.depends_on,
],
],
[
"ItemDefinitionGroup",
[
rule.rule_name,
["CommandLineTemplate", rule.command],
["Outputs", rule.outputs],
["ExecutionDescription", rule.description],
["AdditionalDependencies", rule.additional_dependencies],
],
],
]
)
easy_xml.WriteXmlIfChanged(content, props_path, pretty=True, win32=True)
def _GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules):
"""Generate the .targets file."""
content = [
"Project",
{"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003"},
]
item_group = [
"ItemGroup",
[
"PropertyPageSchema",
{"Include": "$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml"},
],
]
for rule in msbuild_rules:
item_group.append(
[
"AvailableItemName",
{"Include": rule.rule_name},
["Targets", rule.target_name],
]
)
content.append(item_group)
for rule in msbuild_rules:
content.append(
[
"UsingTask",
{
"TaskName": rule.rule_name,
"TaskFactory": "XamlTaskFactory",
"AssemblyName": "Microsoft.Build.Tasks.v4.0",
},
["Task", "$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml"],
]
)
for rule in msbuild_rules:
rule_name = rule.rule_name
target_outputs = "%%(%s.Outputs)" % rule_name
target_inputs = (
"%%(%s.Identity);%%(%s.AdditionalDependencies);" "$(MSBuildProjectFile)"
) % (rule_name, rule_name)
rule_inputs = "%%(%s.Identity)" % rule_name
extension_condition = (
"'%(Extension)'=='.obj' or "
"'%(Extension)'=='.res' or "
"'%(Extension)'=='.rsc' or "
"'%(Extension)'=='.lib'"
)
remove_section = [
"ItemGroup",
{"Condition": "'@(SelectedFiles)' != ''"},
[
rule_name,
{
"Remove": "@(%s)" % rule_name,
"Condition": "'%(Identity)' != '@(SelectedFiles)'",
},
],
]
inputs_section = [
"ItemGroup",
[rule.inputs, {"Include": "%%(%s.AdditionalDependencies)" % rule_name}],
]
logging_section = [
"ItemGroup",
[
rule.tlog,
{
"Include": "%%(%s.Outputs)" % rule_name,
"Condition": (
"'%%(%s.Outputs)' != '' and "
"'%%(%s.ExcludedFromBuild)' != 'true'" % (rule_name, rule_name)
),
},
["Source", "@(%s, '|')" % rule_name],
["Inputs", "@(%s -> '%%(Fullpath)', ';')" % rule.inputs],
],
]
message_section = [
"Message",
{"Importance": "High", "Text": "%%(%s.ExecutionDescription)" % rule_name},
]
write_tlog_section = [
"WriteLinesToFile",
{
"Condition": "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule.tlog, rule.tlog),
"File": "$(IntDir)$(ProjectName).write.1.tlog",
"Lines": "^%%(%s.Source);@(%s->'%%(Fullpath)')"
% (rule.tlog, rule.tlog),
},
]
read_tlog_section = [
"WriteLinesToFile",
{
"Condition": "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule.tlog, rule.tlog),
"File": "$(IntDir)$(ProjectName).read.1.tlog",
"Lines": f"^%({rule.tlog}.Source);%({rule.tlog}.Inputs)",
},
]
command_and_input_section = [
rule_name,
{
"Condition": "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule_name, rule_name),
"EchoOff": "true",
"StandardOutputImportance": "High",
"StandardErrorImportance": "High",
"CommandLineTemplate": "%%(%s.CommandLineTemplate)" % rule_name,
"AdditionalOptions": "%%(%s.AdditionalOptions)" % rule_name,
"Inputs": rule_inputs,
},
]
content.extend(
[
[
"Target",
{
"Name": rule.target_name,
"BeforeTargets": "$(%s)" % rule.before_targets,
"AfterTargets": "$(%s)" % rule.after_targets,
"Condition": "'@(%s)' != ''" % rule_name,
"DependsOnTargets": "$(%s);%s"
% (rule.depends_on, rule.compute_output),
"Outputs": target_outputs,
"Inputs": target_inputs,
},
remove_section,
inputs_section,
logging_section,
message_section,
write_tlog_section,
read_tlog_section,
command_and_input_section,
],
[
"PropertyGroup",
[
"ComputeLinkInputsTargets",
"$(ComputeLinkInputsTargets);",
"%s;" % rule.compute_output,
],
[
"ComputeLibInputsTargets",
"$(ComputeLibInputsTargets);",
"%s;" % rule.compute_output,
],
],
[
"Target",
{
"Name": rule.compute_output,
"Condition": "'@(%s)' != ''" % rule_name,
},
[
"ItemGroup",
[
rule.dirs_to_make,
{
"Condition": "'@(%s)' != '' and "
"'%%(%s.ExcludedFromBuild)' != 'true'"
% (rule_name, rule_name),
"Include": "%%(%s.Outputs)" % rule_name,
},
],
[
"Link",
{
"Include": "%%(%s.Identity)" % rule.dirs_to_make,
"Condition": extension_condition,
},
],
[
"Lib",
{
"Include": "%%(%s.Identity)" % rule.dirs_to_make,
"Condition": extension_condition,
},
],
[
"ImpLib",
{
"Include": "%%(%s.Identity)" % rule.dirs_to_make,
"Condition": extension_condition,
},
],
],
[
"MakeDir",
{
"Directories": (
"@(%s->'%%(RootDir)%%(Directory)')" % rule.dirs_to_make
)
},
],
],
]
)
easy_xml.WriteXmlIfChanged(content, targets_path, pretty=True, win32=True)
def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):
# Generate the .xml file
content = [
"ProjectSchemaDefinitions",
{
"xmlns": (
"clr-namespace:Microsoft.Build.Framework.XamlTypes;"
"assembly=Microsoft.Build.Framework"
),
"xmlns:x": "http://schemas.microsoft.com/winfx/2006/xaml",
"xmlns:sys": "clr-namespace:System;assembly=mscorlib",
"xmlns:transformCallback": "Microsoft.Cpp.Dev10.ConvertPropertyCallback",
},
]
for rule in msbuild_rules:
content.extend(
[
[
"Rule",
{
"Name": rule.rule_name,
"PageTemplate": "tool",
"DisplayName": rule.display_name,
"Order": "200",
},
[
"Rule.DataSource",
[
"DataSource",
{"Persistence": "ProjectFile", "ItemType": rule.rule_name},
],
],
[
"Rule.Categories",
[
"Category",
{"Name": "General"},
["Category.DisplayName", ["sys:String", "General"]],
],
[
"Category",
{"Name": "Command Line", "Subtype": "CommandLine"},
["Category.DisplayName", ["sys:String", "Command Line"]],
],
],
[
"StringListProperty",
{
"Name": "Inputs",
"Category": "Command Line",
"IsRequired": "true",
"Switch": " ",
},
[
"StringListProperty.DataSource",
[
"DataSource",
{
"Persistence": "ProjectFile",
"ItemType": rule.rule_name,
"SourceType": "Item",
},
],
],
],
[
"StringProperty",
{
"Name": "CommandLineTemplate",
"DisplayName": "Command Line",
"Visible": "False",
"IncludeInCommandLine": "False",
},
],
[
"DynamicEnumProperty",
{
"Name": rule.before_targets,
"Category": "General",
"EnumProvider": "Targets",
"IncludeInCommandLine": "False",
},
[
"DynamicEnumProperty.DisplayName",
["sys:String", "Execute Before"],
],
[
"DynamicEnumProperty.Description",
[
"sys:String",
"Specifies the targets for the build customization"
" to run before.",
],
],
[
"DynamicEnumProperty.ProviderSettings",
[
"NameValuePair",
{
"Name": "Exclude",
"Value": "^%s|^Compute" % rule.before_targets,
},
],
],
[
"DynamicEnumProperty.DataSource",
[
"DataSource",
{
"Persistence": "ProjectFile",
"HasConfigurationCondition": "true",
},
],
],
],
[
"DynamicEnumProperty",
{
"Name": rule.after_targets,
"Category": "General",
"EnumProvider": "Targets",
"IncludeInCommandLine": "False",
},
[
"DynamicEnumProperty.DisplayName",
["sys:String", "Execute After"],
],
[
"DynamicEnumProperty.Description",
[
"sys:String",
(
"Specifies the targets for the build customization"
" to run after."
),
],
],
[
"DynamicEnumProperty.ProviderSettings",
[
"NameValuePair",
{
"Name": "Exclude",
"Value": "^%s|^Compute" % rule.after_targets,
},
],
],
[
"DynamicEnumProperty.DataSource",
[
"DataSource",
{
"Persistence": "ProjectFile",
"ItemType": "",
"HasConfigurationCondition": "true",
},
],
],
],
[
"StringListProperty",
{
"Name": "Outputs",
"DisplayName": "Outputs",
"Visible": "False",
"IncludeInCommandLine": "False",
},
],
[
"StringProperty",
{
"Name": "ExecutionDescription",
"DisplayName": "Execution Description",
"Visible": "False",
"IncludeInCommandLine": "False",
},
],
[
"StringListProperty",
{
"Name": "AdditionalDependencies",
"DisplayName": "Additional Dependencies",
"IncludeInCommandLine": "False",
"Visible": "false",
},
],
[
"StringProperty",
{
"Subtype": "AdditionalOptions",
"Name": "AdditionalOptions",
"Category": "Command Line",
},
[
"StringProperty.DisplayName",
["sys:String", "Additional Options"],
],
[
"StringProperty.Description",
["sys:String", "Additional Options"],
],
],
],
[
"ItemType",
{"Name": rule.rule_name, "DisplayName": rule.display_name},
],
[
"FileExtension",
{"Name": "*" + rule.extension, "ContentType": rule.rule_name},
],
[
"ContentType",
{
"Name": rule.rule_name,
"DisplayName": "",
"ItemType": rule.rule_name,
},
],
]
)
easy_xml.WriteXmlIfChanged(content, xml_path, pretty=True, win32=True)
def _GetConfigurationAndPlatform(name, settings, spec):
configuration = name.rsplit("_", 1)[0]
platform = settings.get("msvs_configuration_platform", "Win32")
if spec["toolset"] == "host" and platform == "arm64":
platform = "x64" # Host-only tools are always built for x64
return (configuration, platform)
def _GetConfigurationCondition(name, settings, spec):
return r"'$(Configuration)|$(Platform)'=='%s|%s'" % _GetConfigurationAndPlatform(
name, settings, spec
)
def _GetMSBuildProjectConfigurations(configurations, spec):
group = ["ItemGroup", {"Label": "ProjectConfigurations"}]
for (name, settings) in sorted(configurations.items()):
configuration, platform = _GetConfigurationAndPlatform(name, settings, spec)
designation = f"{configuration}|{platform}"
group.append(
[
"ProjectConfiguration",
{"Include": designation},
["Configuration", configuration],
["Platform", platform],
]
)
return [group]
def _GetMSBuildGlobalProperties(spec, version, guid, gyp_file_name):
namespace = os.path.splitext(gyp_file_name)[0]
properties = [
[
"PropertyGroup",
{"Label": "Globals"},
["ProjectGuid", guid],
["Keyword", "Win32Proj"],
["RootNamespace", namespace],
["IgnoreWarnCompileDuplicatedFilename", "true"],
]
]
if (
os.environ.get("PROCESSOR_ARCHITECTURE") == "AMD64"
or os.environ.get("PROCESSOR_ARCHITEW6432") == "AMD64"
):
properties[0].append(["PreferredToolArchitecture", "x64"])
if spec.get("msvs_target_platform_version"):
target_platform_version = spec.get("msvs_target_platform_version")
properties[0].append(["WindowsTargetPlatformVersion", target_platform_version])
if spec.get("msvs_target_platform_minversion"):
target_platform_minversion = spec.get("msvs_target_platform_minversion")
properties[0].append(
["WindowsTargetPlatformMinVersion", target_platform_minversion]
)
else:
properties[0].append(
["WindowsTargetPlatformMinVersion", target_platform_version]
)
if spec.get("msvs_enable_winrt"):
properties[0].append(["DefaultLanguage", "en-US"])
properties[0].append(["AppContainerApplication", "true"])
if spec.get("msvs_application_type_revision"):
app_type_revision = spec.get("msvs_application_type_revision")
properties[0].append(["ApplicationTypeRevision", app_type_revision])
else:
properties[0].append(["ApplicationTypeRevision", "8.1"])
if spec.get("msvs_enable_winphone"):
properties[0].append(["ApplicationType", "Windows Phone"])
else:
properties[0].append(["ApplicationType", "Windows Store"])
platform_name = None
msvs_windows_sdk_version = None
for configuration in spec["configurations"].values():
platform_name = platform_name or _ConfigPlatform(configuration)
msvs_windows_sdk_version = (
msvs_windows_sdk_version
or _ConfigWindowsTargetPlatformVersion(configuration, version)
)
if platform_name and msvs_windows_sdk_version:
break
if msvs_windows_sdk_version:
properties[0].append(
["WindowsTargetPlatformVersion", str(msvs_windows_sdk_version)]
)
elif version.compatible_sdks:
raise GypError(
"%s requires any SDK of %s version, but none were found"
% (version.description, version.compatible_sdks)
)
if platform_name == "ARM":
properties[0].append(["WindowsSDKDesktopARMSupport", "true"])
return properties
def _GetMSBuildConfigurationDetails(spec, build_file):
properties = {}
for name, settings in spec["configurations"].items():
msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file)
condition = _GetConfigurationCondition(name, settings, spec)
character_set = msbuild_attributes.get("CharacterSet")
config_type = msbuild_attributes.get("ConfigurationType")
_AddConditionalProperty(properties, condition, "ConfigurationType", config_type)
if config_type == "Driver":
_AddConditionalProperty(properties, condition, "DriverType", "WDM")
_AddConditionalProperty(
properties, condition, "TargetVersion", _ConfigTargetVersion(settings)
)
if character_set:
if "msvs_enable_winrt" not in spec:
_AddConditionalProperty(
properties, condition, "CharacterSet", character_set
)
return _GetMSBuildPropertyGroup(spec, "Configuration", properties)
def _GetMSBuildLocalProperties(msbuild_toolset):
# Currently the only local property we support is PlatformToolset
properties = {}
if msbuild_toolset:
properties = [
[
"PropertyGroup",
{"Label": "Locals"},
["PlatformToolset", msbuild_toolset],
]
]
return properties
def _GetMSBuildPropertySheets(configurations, spec):
user_props = r"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
additional_props = {}
props_specified = False
for name, settings in sorted(configurations.items()):
configuration = _GetConfigurationCondition(name, settings, spec)
if "msbuild_props" in settings:
additional_props[configuration] = _FixPaths(settings["msbuild_props"])
props_specified = True
else:
additional_props[configuration] = ""
if not props_specified:
return [
[
"ImportGroup",
{"Label": "PropertySheets"},
[
"Import",
{
"Project": user_props,
"Condition": "exists('%s')" % user_props,
"Label": "LocalAppDataPlatform",
},
],
]
]
else:
sheets = []
for condition, props in additional_props.items():
import_group = [
"ImportGroup",
{"Label": "PropertySheets", "Condition": condition},
[
"Import",
{
"Project": user_props,
"Condition": "exists('%s')" % user_props,
"Label": "LocalAppDataPlatform",
},
],
]
for props_file in props:
import_group.append(["Import", {"Project": props_file}])
sheets.append(import_group)
return sheets
def _ConvertMSVSBuildAttributes(spec, config, build_file):
config_type = _GetMSVSConfigurationType(spec, build_file)
msvs_attributes = _GetMSVSAttributes(spec, config, config_type)
msbuild_attributes = {}
for a in msvs_attributes:
if a in ["IntermediateDirectory", "OutputDirectory"]:
directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a])
if not directory.endswith("\\"):
directory += "\\"
msbuild_attributes[a] = directory
elif a == "CharacterSet":
msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a])
elif a == "ConfigurationType":
msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a])
else:
print("Warning: Do not know how to convert MSVS attribute " + a)
return msbuild_attributes
def _ConvertMSVSCharacterSet(char_set):
if char_set.isdigit():
char_set = {"0": "MultiByte", "1": "Unicode", "2": "MultiByte"}[char_set]
return char_set
def _ConvertMSVSConfigurationType(config_type):
if config_type.isdigit():
config_type = {
"1": "Application",
"2": "DynamicLibrary",
"4": "StaticLibrary",
"5": "Driver",
"10": "Utility",
}[config_type]
return config_type
def _GetMSBuildAttributes(spec, config, build_file):
if "msbuild_configuration_attributes" not in config:
msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file)
else:
config_type = _GetMSVSConfigurationType(spec, build_file)
config_type = _ConvertMSVSConfigurationType(config_type)
msbuild_attributes = config.get("msbuild_configuration_attributes", {})
msbuild_attributes.setdefault("ConfigurationType", config_type)
output_dir = msbuild_attributes.get(
"OutputDirectory", "$(SolutionDir)$(Configuration)"
)
msbuild_attributes["OutputDirectory"] = _FixPath(output_dir) + "\\"
if "IntermediateDirectory" not in msbuild_attributes:
intermediate = _FixPath("$(Configuration)") + "\\"
msbuild_attributes["IntermediateDirectory"] = intermediate
if "CharacterSet" in msbuild_attributes:
msbuild_attributes["CharacterSet"] = _ConvertMSVSCharacterSet(
msbuild_attributes["CharacterSet"]
)
if "TargetName" not in msbuild_attributes:
prefix = spec.get("product_prefix", "")
product_name = spec.get("product_name", "$(ProjectName)")
target_name = prefix + product_name
msbuild_attributes["TargetName"] = target_name
if "TargetExt" not in msbuild_attributes and "product_extension" in spec:
ext = spec.get("product_extension")
msbuild_attributes["TargetExt"] = "." + ext
if spec.get("msvs_external_builder"):
external_out_dir = spec.get("msvs_external_builder_out_dir", ".")
msbuild_attributes["OutputDirectory"] = _FixPath(external_out_dir) + "\\"
# Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
# (depending on the tool used) to avoid MSB8012 warning.
msbuild_tool_map = {
"executable": "Link",
"shared_library": "Link",
"loadable_module": "Link",
"windows_driver": "Link",
"static_library": "Lib",
}
msbuild_tool = msbuild_tool_map.get(spec["type"])
if msbuild_tool:
msbuild_settings = config["finalized_msbuild_settings"]
out_file = msbuild_settings[msbuild_tool].get("OutputFile")
if out_file:
msbuild_attributes["TargetPath"] = _FixPath(out_file)
target_ext = msbuild_settings[msbuild_tool].get("TargetExt")
if target_ext:
msbuild_attributes["TargetExt"] = target_ext
return msbuild_attributes
def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
# TODO(jeanluc) We could optimize out the following and do it only if
# there are actions.
# TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
new_paths = []
cygwin_dirs = spec.get("msvs_cygwin_dirs", ["."])[0]
if cygwin_dirs:
cyg_path = "$(MSBuildProjectDirectory)\\%s\\bin\\" % _FixPath(cygwin_dirs)
new_paths.append(cyg_path)
# TODO(jeanluc) Change the convention to have both a cygwin_dir and a
# python_dir.
python_path = cyg_path.replace("cygwin\\bin", "python_26")
new_paths.append(python_path)
if new_paths:
new_paths = "$(ExecutablePath);" + ";".join(new_paths)
properties = {}
for (name, configuration) in sorted(configurations.items()):
condition = _GetConfigurationCondition(name, configuration, spec)
attributes = _GetMSBuildAttributes(spec, configuration, build_file)
msbuild_settings = configuration["finalized_msbuild_settings"]
_AddConditionalProperty(
properties, condition, "IntDir", attributes["IntermediateDirectory"]
)
_AddConditionalProperty(
properties, condition, "OutDir", attributes["OutputDirectory"]
)
_AddConditionalProperty(
properties, condition, "TargetName", attributes["TargetName"]
)
if "TargetExt" in attributes:
_AddConditionalProperty(
properties, condition, "TargetExt", attributes["TargetExt"]
)
if attributes.get("TargetPath"):
_AddConditionalProperty(
properties, condition, "TargetPath", attributes["TargetPath"]
)
if attributes.get("TargetExt"):
_AddConditionalProperty(
properties, condition, "TargetExt", attributes["TargetExt"]
)
if new_paths:
_AddConditionalProperty(properties, condition, "ExecutablePath", new_paths)
tool_settings = msbuild_settings.get("", {})
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild("", name, value)
_AddConditionalProperty(properties, condition, name, formatted_value)
return _GetMSBuildPropertyGroup(spec, None, properties)
def _AddConditionalProperty(properties, condition, name, value):
"""Adds a property / conditional value pair to a dictionary.
Arguments:
properties: The dictionary to be modified. The key is the name of the
property. The value is itself a dictionary; its key is the value and
the value a list of condition for which this value is true.
condition: The condition under which the named property has the value.
name: The name of the property.
value: The value of the property.
"""
if name not in properties:
properties[name] = {}
values = properties[name]
if value not in values:
values[value] = []
conditions = values[value]
conditions.append(condition)
# Regex for msvs variable references ( i.e. $(FOO) ).
MSVS_VARIABLE_REFERENCE = re.compile(r"\$\(([a-zA-Z_][a-zA-Z0-9_]*)\)")
def _GetMSBuildPropertyGroup(spec, label, properties):
"""Returns a PropertyGroup definition for the specified properties.
Arguments:
spec: The target project dict.
label: An optional label for the PropertyGroup.
properties: The dictionary to be converted. The key is the name of the
property. The value is itself a dictionary; its key is the value and
the value a list of condition for which this value is true.
"""
group = ["PropertyGroup"]
if label:
group.append({"Label": label})
num_configurations = len(spec["configurations"])
def GetEdges(node):
# Use a definition of edges such that user_of_variable -> used_varible.
# This happens to be easier in this case, since a variable's
# definition contains all variables it references in a single string.
edges = set()
for value in sorted(properties[node].keys()):
# Add to edges all $(...) references to variables.
#
# Variable references that refer to names not in properties are excluded
# These can exist for instance to refer built in definitions like
# $(SolutionDir).
#
# Self references are ignored. Self reference is used in a few places to
# append to the default value. I.e. PATH=$(PATH);other_path
edges.update(
{
v
for v in MSVS_VARIABLE_REFERENCE.findall(value)
if v in properties and v != node
}
)
return edges
properties_ordered = gyp.common.TopologicallySorted(properties.keys(), GetEdges)
# Walk properties in the reverse of a topological sort on
# user_of_variable -> used_variable as this ensures variables are
# defined before they are used.
# NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
for name in reversed(properties_ordered):
values = properties[name]
for value, conditions in sorted(values.items()):
if len(conditions) == num_configurations:
# If the value is the same all configurations,
# just add one unconditional entry.
group.append([name, value])
else:
for condition in conditions:
group.append([name, {"Condition": condition}, value])
return [group]
def _GetMSBuildToolSettingsSections(spec, configurations):
groups = []
for (name, configuration) in sorted(configurations.items()):
msbuild_settings = configuration["finalized_msbuild_settings"]
group = [
"ItemDefinitionGroup",
{"Condition": _GetConfigurationCondition(name, configuration, spec)},
]
for tool_name, tool_settings in sorted(msbuild_settings.items()):
# Skip the tool named '' which is a holder of global settings handled
# by _GetMSBuildConfigurationGlobalProperties.
if tool_name:
if tool_settings:
tool = [tool_name]
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild(
tool_name, name, value
)
tool.append([name, formatted_value])
group.append(tool)
groups.append(group)
return groups
def _FinalizeMSBuildSettings(spec, configuration):
if "msbuild_settings" in configuration:
converted = False
msbuild_settings = configuration["msbuild_settings"]
MSVSSettings.ValidateMSBuildSettings(msbuild_settings)
else:
converted = True
msvs_settings = configuration.get("msvs_settings", {})
msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings)
include_dirs, midl_include_dirs, resource_include_dirs = _GetIncludeDirs(
configuration
)
libraries = _GetLibraries(spec)
library_dirs = _GetLibraryDirs(configuration)
out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True)
target_ext = _GetOutputTargetExt(spec)
defines = _GetDefines(configuration)
if converted:
# Visual Studio 2010 has TR1
defines = [d for d in defines if d != "_HAS_TR1=0"]
# Warn of ignored settings
ignored_settings = ["msvs_tool_files"]
for ignored_setting in ignored_settings:
value = configuration.get(ignored_setting)
if value:
print(
"Warning: The automatic conversion to MSBuild does not handle "
"%s. Ignoring setting of %s" % (ignored_setting, str(value))
)
defines = [_EscapeCppDefineForMSBuild(d) for d in defines]
disabled_warnings = _GetDisabledWarnings(configuration)
prebuild = configuration.get("msvs_prebuild")
postbuild = configuration.get("msvs_postbuild")
def_file = _GetModuleDefinition(spec)
precompiled_header = configuration.get("msvs_precompiled_header")
# Add the information to the appropriate tool
# TODO(jeanluc) We could optimize and generate these settings only if
# the corresponding files are found, e.g. don't generate ResourceCompile
# if you don't have any resources.
_ToolAppend(
msbuild_settings, "ClCompile", "AdditionalIncludeDirectories", include_dirs
)
_ToolAppend(
msbuild_settings, "Midl", "AdditionalIncludeDirectories", midl_include_dirs
)
_ToolAppend(
msbuild_settings,
"ResourceCompile",
"AdditionalIncludeDirectories",
resource_include_dirs,
)
# Add in libraries, note that even for empty libraries, we want this
# set, to prevent inheriting default libraries from the environment.
_ToolSetOrAppend(msbuild_settings, "Link", "AdditionalDependencies", libraries)
_ToolAppend(msbuild_settings, "Link", "AdditionalLibraryDirectories", library_dirs)
if out_file:
_ToolAppend(
msbuild_settings, msbuild_tool, "OutputFile", out_file, only_if_unset=True
)
if target_ext:
_ToolAppend(
msbuild_settings, msbuild_tool, "TargetExt", target_ext, only_if_unset=True
)
# Add defines.
_ToolAppend(msbuild_settings, "ClCompile", "PreprocessorDefinitions", defines)
_ToolAppend(msbuild_settings, "ResourceCompile", "PreprocessorDefinitions", defines)
# Add disabled warnings.
_ToolAppend(
msbuild_settings, "ClCompile", "DisableSpecificWarnings", disabled_warnings
)
# Turn on precompiled headers if appropriate.
if precompiled_header:
precompiled_header = os.path.split(precompiled_header)[1]
_ToolAppend(msbuild_settings, "ClCompile", "PrecompiledHeader", "Use")
_ToolAppend(
msbuild_settings, "ClCompile", "PrecompiledHeaderFile", precompiled_header
)
_ToolAppend(
msbuild_settings, "ClCompile", "ForcedIncludeFiles", [precompiled_header]
)
else:
_ToolAppend(msbuild_settings, "ClCompile", "PrecompiledHeader", "NotUsing")
# Turn off WinRT compilation
_ToolAppend(msbuild_settings, "ClCompile", "CompileAsWinRT", "false")
# Turn on import libraries if appropriate
if spec.get("msvs_requires_importlibrary"):
_ToolAppend(msbuild_settings, "", "IgnoreImportLibrary", "false")
# Loadable modules don't generate import libraries;
# tell dependent projects to not expect one.
if spec["type"] == "loadable_module":
_ToolAppend(msbuild_settings, "", "IgnoreImportLibrary", "true")
# Set the module definition file if any.
if def_file:
_ToolAppend(msbuild_settings, "Link", "ModuleDefinitionFile", def_file)
configuration["finalized_msbuild_settings"] = msbuild_settings
if prebuild:
_ToolAppend(msbuild_settings, "PreBuildEvent", "Command", prebuild)
if postbuild:
_ToolAppend(msbuild_settings, "PostBuildEvent", "Command", postbuild)
def _GetValueFormattedForMSBuild(tool_name, name, value):
if type(value) == list:
# For some settings, VS2010 does not automatically extends the settings
# TODO(jeanluc) Is this what we want?
if name in [
"AdditionalIncludeDirectories",
"AdditionalLibraryDirectories",
"AdditionalOptions",
"DelayLoadDLLs",
"DisableSpecificWarnings",
"PreprocessorDefinitions",
]:
value.append("%%(%s)" % name)
# For most tools, entries in a list should be separated with ';' but some
# settings use a space. Check for those first.
exceptions = {
"ClCompile": ["AdditionalOptions"],
"Link": ["AdditionalOptions"],
"Lib": ["AdditionalOptions"],
}
if tool_name in exceptions and name in exceptions[tool_name]:
char = " "
else:
char = ";"
formatted_value = char.join(
[MSVSSettings.ConvertVCMacrosToMSBuild(i) for i in value]
)
else:
formatted_value = MSVSSettings.ConvertVCMacrosToMSBuild(value)
return formatted_value
def _VerifySourcesExist(sources, root_dir):
"""Verifies that all source files exist on disk.
Checks that all regular source files, i.e. not created at run time,
exist on disk. Missing files cause needless recompilation but no otherwise
visible errors.
Arguments:
sources: A recursive list of Filter/file names.
root_dir: The root directory for the relative path names.
Returns:
A list of source files that cannot be found on disk.
"""
missing_sources = []
for source in sources:
if isinstance(source, MSVSProject.Filter):
missing_sources.extend(_VerifySourcesExist(source.contents, root_dir))
else:
if "$" not in source:
full_path = os.path.join(root_dir, source)
if not os.path.exists(full_path):
missing_sources.append(full_path)
return missing_sources
def _GetMSBuildSources(
spec,
sources,
exclusions,
rule_dependencies,
extension_to_rule_name,
actions_spec,
sources_handled_by_action,
list_excluded,
):
groups = [
"none",
"masm",
"midl",
"include",
"compile",
"resource",
"rule",
"rule_dependency",
]
grouped_sources = {}
for g in groups:
grouped_sources[g] = []
_AddSources2(
spec,
sources,
exclusions,
grouped_sources,
rule_dependencies,
extension_to_rule_name,
sources_handled_by_action,
list_excluded,
)
sources = []
for g in groups:
if grouped_sources[g]:
sources.append(["ItemGroup"] + grouped_sources[g])
if actions_spec:
sources.append(["ItemGroup"] + actions_spec)
return sources
def _AddSources2(
spec,
sources,
exclusions,
grouped_sources,
rule_dependencies,
extension_to_rule_name,
sources_handled_by_action,
list_excluded,
):
extensions_excluded_from_precompile = []
for source in sources:
if isinstance(source, MSVSProject.Filter):
_AddSources2(
spec,
source.contents,
exclusions,
grouped_sources,
rule_dependencies,
extension_to_rule_name,
sources_handled_by_action,
list_excluded,
)
else:
if source not in sources_handled_by_action:
detail = []
excluded_configurations = exclusions.get(source, [])
if len(excluded_configurations) == len(spec["configurations"]):
detail.append(["ExcludedFromBuild", "true"])
else:
for config_name, configuration in sorted(excluded_configurations):
condition = _GetConfigurationCondition(
config_name, configuration
)
detail.append(
["ExcludedFromBuild", {"Condition": condition}, "true"]
)
# Add precompile if needed
for config_name, configuration in spec["configurations"].items():
precompiled_source = configuration.get(
"msvs_precompiled_source", ""
)
if precompiled_source != "":
precompiled_source = _FixPath(precompiled_source)
if not extensions_excluded_from_precompile:
# If the precompiled header is generated by a C source,
# we must not try to use it for C++ sources,
# and vice versa.
basename, extension = os.path.splitext(precompiled_source)
if extension == ".c":
extensions_excluded_from_precompile = [
".cc",
".cpp",
".cxx",
]
else:
extensions_excluded_from_precompile = [".c"]
if precompiled_source == source:
condition = _GetConfigurationCondition(
config_name, configuration, spec
)
detail.append(
["PrecompiledHeader", {"Condition": condition}, "Create"]
)
else:
# Turn off precompiled header usage for source files of a
# different type than the file that generated the
# precompiled header.
for extension in extensions_excluded_from_precompile:
if source.endswith(extension):
detail.append(["PrecompiledHeader", ""])
detail.append(["ForcedIncludeFiles", ""])
group, element = _MapFileToMsBuildSourceType(
source,
rule_dependencies,
extension_to_rule_name,
_GetUniquePlatforms(spec),
spec["toolset"],
)
if group == "compile" and not os.path.isabs(source):
# Add an value to support duplicate source
# file basenames, except for absolute paths to avoid paths
# with more than 260 characters.
file_name = os.path.splitext(source)[0] + ".obj"
if file_name.startswith("..\\"):
file_name = re.sub(r"^(\.\.\\)+", "", file_name)
elif file_name.startswith("$("):
file_name = re.sub(r"^\$\([^)]+\)\\", "", file_name)
detail.append(["ObjectFileName", "$(IntDir)\\" + file_name])
grouped_sources[group].append([element, {"Include": source}] + detail)
def _GetMSBuildProjectReferences(project):
references = []
if project.dependencies:
group = ["ItemGroup"]
added_dependency_set = set()
for dependency in project.dependencies:
dependency_spec = dependency.spec
should_skip_dep = False
if project.spec["toolset"] == "target":
if dependency_spec["toolset"] == "host":
if dependency_spec["type"] == "static_library":
should_skip_dep = True
if dependency.name.startswith("run_"):
should_skip_dep = False
if should_skip_dep:
continue
canonical_name = dependency.name.replace("_host", "")
added_dependency_set.add(canonical_name)
guid = dependency.guid
project_dir = os.path.split(project.path)[0]
relative_path = gyp.common.RelativePath(dependency.path, project_dir)
project_ref = [
"ProjectReference",
{"Include": relative_path},
["Project", guid],
["ReferenceOutputAssembly", "false"],
]
for config in dependency.spec.get("configurations", {}).values():
if config.get("msvs_use_library_dependency_inputs", 0):
project_ref.append(["UseLibraryDependencyInputs", "true"])
break
# If it's disabled in any config, turn it off in the reference.
if config.get("msvs_2010_disable_uldi_when_referenced", 0):
project_ref.append(["UseLibraryDependencyInputs", "false"])
break
group.append(project_ref)
references.append(group)
return references
def _GenerateMSBuildProject(project, options, version, generator_flags, spec):
spec = project.spec
configurations = spec["configurations"]
toolset = spec["toolset"]
project_dir, project_file_name = os.path.split(project.path)
gyp.common.EnsureDirExists(project.path)
# Prepare list of sources and excluded sources.
gyp_file = os.path.split(project.build_file)[1]
sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, gyp_file)
# Add rules.
actions_to_add = {}
props_files_of_rules = set()
targets_files_of_rules = set()
rule_dependencies = set()
extension_to_rule_name = {}
list_excluded = generator_flags.get("msvs_list_excluded_files", True)
platforms = _GetUniquePlatforms(spec)
# Don't generate rules if we are using an external builder like ninja.
if not spec.get("msvs_external_builder"):
_GenerateRulesForMSBuild(
project_dir,
options,
spec,
sources,
excluded_sources,
props_files_of_rules,
targets_files_of_rules,
actions_to_add,
rule_dependencies,
extension_to_rule_name,
)
else:
rules = spec.get("rules", [])
_AdjustSourcesForRules(rules, sources, excluded_sources, True)
sources, excluded_sources, excluded_idl = _AdjustSourcesAndConvertToFilterHierarchy(
spec, options, project_dir, sources, excluded_sources, list_excluded, version
)
# Don't add actions if we are using an external builder like ninja.
if not spec.get("msvs_external_builder"):
_AddActions(actions_to_add, spec, project.build_file)
_AddCopies(actions_to_add, spec)
# NOTE: this stanza must appear after all actions have been decided.
# Don't excluded sources with actions attached, or they won't run.
excluded_sources = _FilterActionsFromExcluded(excluded_sources, actions_to_add)
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild(
spec, actions_to_add
)
_GenerateMSBuildFiltersFile(
project.path + ".filters",
sources,
rule_dependencies,
extension_to_rule_name,
platforms,
toolset,
)
missing_sources = _VerifySourcesExist(sources, project_dir)
for configuration in configurations.values():
_FinalizeMSBuildSettings(spec, configuration)
# Add attributes to root element
import_default_section = [
["Import", {"Project": r"$(VCTargetsPath)\Microsoft.Cpp.Default.props"}]
]
import_cpp_props_section = [
["Import", {"Project": r"$(VCTargetsPath)\Microsoft.Cpp.props"}]
]
import_cpp_targets_section = [
["Import", {"Project": r"$(VCTargetsPath)\Microsoft.Cpp.targets"}]
]
import_masm_props_section = [
["Import", {"Project": r"$(VCTargetsPath)\BuildCustomizations\masm.props"}]
]
import_masm_targets_section = [
["Import", {"Project": r"$(VCTargetsPath)\BuildCustomizations\masm.targets"}]
]
import_marmasm_props_section = [
["Import", {"Project": r"$(VCTargetsPath)\BuildCustomizations\marmasm.props"}]
]
import_marmasm_targets_section = [
["Import", {"Project": r"$(VCTargetsPath)\BuildCustomizations\marmasm.targets"}]
]
macro_section = [["PropertyGroup", {"Label": "UserMacros"}]]
content = [
"Project",
{
"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003",
"ToolsVersion": version.ProjectVersion(),
"DefaultTargets": "Build",
},
]
content += _GetMSBuildProjectConfigurations(configurations, spec)
content += _GetMSBuildGlobalProperties(
spec, version, project.guid, project_file_name
)
content += import_default_section
content += _GetMSBuildConfigurationDetails(spec, project.build_file)
if spec.get("msvs_enable_winphone"):
content += _GetMSBuildLocalProperties("v120_wp81")
else:
content += _GetMSBuildLocalProperties(project.msbuild_toolset)
content += import_cpp_props_section
content += import_masm_props_section
if "arm64" in platforms and toolset == "target":
content += import_marmasm_props_section
content += _GetMSBuildExtensions(props_files_of_rules)
content += _GetMSBuildPropertySheets(configurations, spec)
content += macro_section
content += _GetMSBuildConfigurationGlobalProperties(
spec, configurations, project.build_file
)
content += _GetMSBuildToolSettingsSections(spec, configurations)
content += _GetMSBuildSources(
spec,
sources,
exclusions,
rule_dependencies,
extension_to_rule_name,
actions_spec,
sources_handled_by_action,
list_excluded,
)
content += _GetMSBuildProjectReferences(project)
content += import_cpp_targets_section
content += import_masm_targets_section
if "arm64" in platforms and toolset == "target":
content += import_marmasm_targets_section
content += _GetMSBuildExtensionTargets(targets_files_of_rules)
if spec.get("msvs_external_builder"):
content += _GetMSBuildExternalBuilderTargets(spec)
# TODO(jeanluc) File a bug to get rid of runas. We had in MSVS:
# has_run_as = _WriteMSVSUserFile(project.path, version, spec)
easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
return missing_sources
def _GetMSBuildExternalBuilderTargets(spec):
"""Return a list of MSBuild targets for external builders.
The "Build" and "Clean" targets are always generated. If the spec contains
'msvs_external_builder_clcompile_cmd', then the "ClCompile" target will also
be generated, to support building selected C/C++ files.
Arguments:
spec: The gyp target spec.
Returns:
List of MSBuild 'Target' specs.
"""
build_cmd = _BuildCommandLineForRuleRaw(
spec, spec["msvs_external_builder_build_cmd"], False, False, False, False
)
build_target = ["Target", {"Name": "Build"}]
build_target.append(["Exec", {"Command": build_cmd}])
clean_cmd = _BuildCommandLineForRuleRaw(
spec, spec["msvs_external_builder_clean_cmd"], False, False, False, False
)
clean_target = ["Target", {"Name": "Clean"}]
clean_target.append(["Exec", {"Command": clean_cmd}])
targets = [build_target, clean_target]
if spec.get("msvs_external_builder_clcompile_cmd"):
clcompile_cmd = _BuildCommandLineForRuleRaw(
spec,
spec["msvs_external_builder_clcompile_cmd"],
False,
False,
False,
False,
)
clcompile_target = ["Target", {"Name": "ClCompile"}]
clcompile_target.append(["Exec", {"Command": clcompile_cmd}])
targets.append(clcompile_target)
return targets
def _GetMSBuildExtensions(props_files_of_rules):
extensions = ["ImportGroup", {"Label": "ExtensionSettings"}]
for props_file in props_files_of_rules:
extensions.append(["Import", {"Project": props_file}])
return [extensions]
def _GetMSBuildExtensionTargets(targets_files_of_rules):
targets_node = ["ImportGroup", {"Label": "ExtensionTargets"}]
for targets_file in sorted(targets_files_of_rules):
targets_node.append(["Import", {"Project": targets_file}])
return [targets_node]
def _GenerateActionsForMSBuild(spec, actions_to_add):
"""Add actions accumulated into an actions_to_add, merging as needed.
Arguments:
spec: the target project dict
actions_to_add: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
Returns:
A pair of (action specification, the sources handled by this action).
"""
sources_handled_by_action = OrderedSet()
actions_spec = []
for primary_input, actions in actions_to_add.items():
if generator_supports_multiple_toolsets:
primary_input = primary_input.replace(".exe", "_host.exe")
inputs = OrderedSet()
outputs = OrderedSet()
descriptions = []
commands = []
for action in actions:
def fixup_host_exe(i):
if "$(OutDir)" in i:
i = i.replace(".exe", "_host.exe")
return i
if generator_supports_multiple_toolsets:
action["inputs"] = [fixup_host_exe(i) for i in action["inputs"]]
inputs.update(OrderedSet(action["inputs"]))
outputs.update(OrderedSet(action["outputs"]))
descriptions.append(action["description"])
cmd = action["command"]
if generator_supports_multiple_toolsets:
cmd = cmd.replace(".exe", "_host.exe")
# For most actions, add 'call' so that actions that invoke batch files
# return and continue executing. msbuild_use_call provides a way to
# disable this but I have not seen any adverse effect from doing that
# for everything.
if action.get("msbuild_use_call", True):
cmd = "call " + cmd
commands.append(cmd)
# Add the custom build action for one input file.
description = ", and also ".join(descriptions)
# We can't join the commands simply with && because the command line will
# get too long. See also _AddActions: cygwin's setup_env mustn't be called
# for every invocation or the command that sets the PATH will grow too
# long.
command = "\r\n".join(
[c + "\r\nif %errorlevel% neq 0 exit /b %errorlevel%" for c in commands]
)
_AddMSBuildAction(
spec,
primary_input,
inputs,
outputs,
command,
description,
sources_handled_by_action,
actions_spec,
)
return actions_spec, sources_handled_by_action
def _AddMSBuildAction(
spec,
primary_input,
inputs,
outputs,
cmd,
description,
sources_handled_by_action,
actions_spec,
):
command = MSVSSettings.ConvertVCMacrosToMSBuild(cmd)
primary_input = _FixPath(primary_input)
inputs_array = _FixPaths(inputs)
outputs_array = _FixPaths(outputs)
additional_inputs = ";".join([i for i in inputs_array if i != primary_input])
outputs = ";".join(outputs_array)
sources_handled_by_action.add(primary_input)
action_spec = ["CustomBuild", {"Include": primary_input}]
action_spec.extend(
# TODO(jeanluc) 'Document' for all or just if as_sources?
[
["FileType", "Document"],
["Command", command],
["Message", description],
["Outputs", outputs],
]
)
if additional_inputs:
action_spec.append(["AdditionalInputs", additional_inputs])
actions_spec.append(action_spec)
node-gyp-9.3.0/gyp/pylib/gyp/generator/msvs_test.py 0000775 0000000 0000000 00000002362 14321173220 0022352 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the msvs.py file. """
import gyp.generator.msvs as msvs
import unittest
from io import StringIO
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.stderr = StringIO()
def test_GetLibraries(self):
self.assertEqual(msvs._GetLibraries({}), [])
self.assertEqual(msvs._GetLibraries({"libraries": []}), [])
self.assertEqual(
msvs._GetLibraries({"other": "foo", "libraries": ["a.lib"]}), ["a.lib"]
)
self.assertEqual(msvs._GetLibraries({"libraries": ["-la"]}), ["a.lib"])
self.assertEqual(
msvs._GetLibraries(
{
"libraries": [
"a.lib",
"b.lib",
"c.lib",
"-lb.lib",
"-lb.lib",
"d.lib",
"a.lib",
]
}
),
["c.lib", "b.lib", "d.lib", "a.lib"],
)
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/generator/ninja.py 0000664 0000000 0000000 00000347207 14321173220 0021431 0 ustar 00root root 0000000 0000000 # Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import collections
import copy
import hashlib
import json
import multiprocessing
import os.path
import re
import signal
import subprocess
import sys
import gyp
import gyp.common
import gyp.msvs_emulation
import gyp.MSVSUtil as MSVSUtil
import gyp.xcode_emulation
from io import StringIO
from gyp.common import GetEnvironFallback
import gyp.ninja_syntax as ninja_syntax
generator_default_variables = {
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"STATIC_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
"SHARED_LIB_PREFIX": "lib",
# Gyp expects the following variables to be expandable by the build
# system to the appropriate locations. Ninja prefers paths to be
# known at gyp time. To resolve this, introduce special
# variables starting with $! and $| (which begin with a $ so gyp knows it
# should be treated specially, but is otherwise an invalid
# ninja/shell variable) that are passed to gyp here but expanded
# before writing out into the target .ninja files; see
# ExpandSpecial.
# $! is used for variables that represent a path and that can only appear at
# the start of a string, while $| is used for variables that can appear
# anywhere in a string.
"INTERMEDIATE_DIR": "$!INTERMEDIATE_DIR",
"SHARED_INTERMEDIATE_DIR": "$!PRODUCT_DIR/gen",
"PRODUCT_DIR": "$!PRODUCT_DIR",
"CONFIGURATION_NAME": "$|CONFIGURATION_NAME",
# Special variables that may be used by gyp 'rule' targets.
# We generate definitions for these variables on the fly when processing a
# rule.
"RULE_INPUT_ROOT": "${root}",
"RULE_INPUT_DIRNAME": "${dirname}",
"RULE_INPUT_PATH": "${source}",
"RULE_INPUT_EXT": "${ext}",
"RULE_INPUT_NAME": "${name}",
}
# Placates pylint.
generator_additional_non_configuration_keys = []
generator_additional_path_sections = []
generator_extra_sources_for_rules = []
generator_filelist_paths = None
generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
def StripPrefix(arg, prefix):
if arg.startswith(prefix):
return arg[len(prefix) :]
return arg
def QuoteShellArgument(arg, flavor):
"""Quote a string such that it will be interpreted as a single argument
by the shell."""
# Rather than attempting to enumerate the bad shell characters, just
# allow common OK ones and quote anything else.
if re.match(r"^[a-zA-Z0-9_=.\\/-]+$", arg):
return arg # No quoting necessary.
if flavor == "win":
return gyp.msvs_emulation.QuoteForRspFile(arg)
return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'"
def Define(d, flavor):
"""Takes a preprocessor define and returns a -D parameter that's ninja- and
shell-escaped."""
if flavor == "win":
# cl.exe replaces literal # characters with = in preprocessor definitions for
# some reason. Octal-encode to work around that.
d = d.replace("#", "\\%03o" % ord("#"))
return QuoteShellArgument(ninja_syntax.escape("-D" + d), flavor)
def AddArch(output, arch):
"""Adds an arch string to an output path."""
output, extension = os.path.splitext(output)
return f"{output}.{arch}{extension}"
class Target:
"""Target represents the paths used within a single gyp target.
Conceptually, building a single target A is a series of steps:
1) actions/rules/copies generates source/resources/etc.
2) compiles generates .o files
3) link generates a binary (library/executable)
4) bundle merges the above in a mac bundle
(Any of these steps can be optional.)
From a build ordering perspective, a dependent target B could just
depend on the last output of this series of steps.
But some dependent commands sometimes need to reach inside the box.
For example, when linking B it needs to get the path to the static
library generated by A.
This object stores those paths. To keep things simple, member
variables only store concrete paths to single files, while methods
compute derived values like "the last output of the target".
"""
def __init__(self, type):
# Gyp type ("static_library", etc.) of this target.
self.type = type
# File representing whether any input dependencies necessary for
# dependent actions have completed.
self.preaction_stamp = None
# File representing whether any input dependencies necessary for
# dependent compiles have completed.
self.precompile_stamp = None
# File representing the completion of actions/rules/copies, if any.
self.actions_stamp = None
# Path to the output of the link step, if any.
self.binary = None
# Path to the file representing the completion of building the bundle,
# if any.
self.bundle = None
# On Windows, incremental linking requires linking against all the .objs
# that compose a .lib (rather than the .lib itself). That list is stored
# here. In this case, we also need to save the compile_deps for the target,
# so that the target that directly depends on the .objs can also depend
# on those.
self.component_objs = None
self.compile_deps = None
# Windows only. The import .lib is the output of a build step, but
# because dependents only link against the lib (not both the lib and the
# dll) we keep track of the import library here.
self.import_lib = None
# Track if this target contains any C++ files, to decide if gcc or g++
# should be used for linking.
self.uses_cpp = False
def Linkable(self):
"""Return true if this is a target that can be linked against."""
return self.type in ("static_library", "shared_library")
def UsesToc(self, flavor):
"""Return true if the target should produce a restat rule based on a TOC
file."""
# For bundles, the .TOC should be produced for the binary, not for
# FinalOutput(). But the naive approach would put the TOC file into the
# bundle, so don't do this for bundles for now.
if flavor == "win" or self.bundle:
return False
return self.type in ("shared_library", "loadable_module")
def PreActionInput(self, flavor):
"""Return the path, if any, that should be used as a dependency of
any dependent action step."""
if self.UsesToc(flavor):
return self.FinalOutput() + ".TOC"
return self.FinalOutput() or self.preaction_stamp
def PreCompileInput(self):
"""Return the path, if any, that should be used as a dependency of
any dependent compile step."""
return self.actions_stamp or self.precompile_stamp
def FinalOutput(self):
"""Return the last output of the target, which depends on all prior
steps."""
return self.bundle or self.binary or self.actions_stamp
# A small discourse on paths as used within the Ninja build:
# All files we produce (both at gyp and at build time) appear in the
# build directory (e.g. out/Debug).
#
# Paths within a given .gyp file are always relative to the directory
# containing the .gyp file. Call these "gyp paths". This includes
# sources as well as the starting directory a given gyp rule/action
# expects to be run from. We call the path from the source root to
# the gyp file the "base directory" within the per-.gyp-file
# NinjaWriter code.
#
# All paths as written into the .ninja files are relative to the build
# directory. Call these paths "ninja paths".
#
# We translate between these two notions of paths with two helper
# functions:
#
# - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file)
# into the equivalent ninja path.
#
# - GypPathToUniqueOutput translates a gyp path into a ninja path to write
# an output file; the result can be namespaced such that it is unique
# to the input file name as well as the output target name.
class NinjaWriter:
def __init__(
self,
hash_for_rules,
target_outputs,
base_dir,
build_dir,
output_file,
toplevel_build,
output_file_name,
flavor,
toplevel_dir=None,
):
"""
base_dir: path from source root to directory containing this gyp file,
by gyp semantics, all input paths are relative to this
build_dir: path from source root to build output
toplevel_dir: path to the toplevel directory
"""
self.hash_for_rules = hash_for_rules
self.target_outputs = target_outputs
self.base_dir = base_dir
self.build_dir = build_dir
self.ninja = ninja_syntax.Writer(output_file)
self.toplevel_build = toplevel_build
self.output_file_name = output_file_name
self.flavor = flavor
self.abs_build_dir = None
if toplevel_dir is not None:
self.abs_build_dir = os.path.abspath(os.path.join(toplevel_dir, build_dir))
self.obj_ext = ".obj" if flavor == "win" else ".o"
if flavor == "win":
# See docstring of msvs_emulation.GenerateEnvironmentFiles().
self.win_env = {}
for arch in ("x86", "x64"):
self.win_env[arch] = "environment." + arch
# Relative path from build output dir to base dir.
build_to_top = gyp.common.InvertRelativePath(build_dir, toplevel_dir)
self.build_to_base = os.path.join(build_to_top, base_dir)
# Relative path from base dir to build dir.
base_to_top = gyp.common.InvertRelativePath(base_dir, toplevel_dir)
self.base_to_build = os.path.join(base_to_top, build_dir)
def ExpandSpecial(self, path, product_dir=None):
"""Expand specials like $!PRODUCT_DIR in |path|.
If |product_dir| is None, assumes the cwd is already the product
dir. Otherwise, |product_dir| is the relative path to the product
dir.
"""
PRODUCT_DIR = "$!PRODUCT_DIR"
if PRODUCT_DIR in path:
if product_dir:
path = path.replace(PRODUCT_DIR, product_dir)
else:
path = path.replace(PRODUCT_DIR + "/", "")
path = path.replace(PRODUCT_DIR + "\\", "")
path = path.replace(PRODUCT_DIR, ".")
INTERMEDIATE_DIR = "$!INTERMEDIATE_DIR"
if INTERMEDIATE_DIR in path:
int_dir = self.GypPathToUniqueOutput("gen")
# GypPathToUniqueOutput generates a path relative to the product dir,
# so insert product_dir in front if it is provided.
path = path.replace(
INTERMEDIATE_DIR, os.path.join(product_dir or "", int_dir)
)
CONFIGURATION_NAME = "$|CONFIGURATION_NAME"
path = path.replace(CONFIGURATION_NAME, self.config_name)
return path
def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
if self.flavor == "win":
path = self.msvs_settings.ConvertVSMacros(path, config=self.config_name)
path = path.replace(generator_default_variables["RULE_INPUT_ROOT"], root)
path = path.replace(generator_default_variables["RULE_INPUT_DIRNAME"], dirname)
path = path.replace(generator_default_variables["RULE_INPUT_PATH"], source)
path = path.replace(generator_default_variables["RULE_INPUT_EXT"], ext)
path = path.replace(generator_default_variables["RULE_INPUT_NAME"], name)
return path
def GypPathToNinja(self, path, env=None):
"""Translate a gyp path to a ninja path, optionally expanding environment
variable references in |path| with |env|.
See the above discourse on path conversions."""
if env:
if self.flavor == "mac":
path = gyp.xcode_emulation.ExpandEnvVars(path, env)
elif self.flavor == "win":
path = gyp.msvs_emulation.ExpandMacros(path, env)
if path.startswith("$!"):
expanded = self.ExpandSpecial(path)
if self.flavor == "win":
expanded = os.path.normpath(expanded)
return expanded
if "$|" in path:
path = self.ExpandSpecial(path)
assert "$" not in path, path
return os.path.normpath(os.path.join(self.build_to_base, path))
def GypPathToUniqueOutput(self, path, qualified=True):
"""Translate a gyp path to a ninja path for writing output.
If qualified is True, qualify the resulting filename with the name
of the target. This is necessary when e.g. compiling the same
path twice for two separate output targets.
See the above discourse on path conversions."""
path = self.ExpandSpecial(path)
assert not path.startswith("$"), path
# Translate the path following this scheme:
# Input: foo/bar.gyp, target targ, references baz/out.o
# Output: obj/foo/baz/targ.out.o (if qualified)
# obj/foo/baz/out.o (otherwise)
# (and obj.host instead of obj for cross-compiles)
#
# Why this scheme and not some other one?
# 1) for a given input, you can compute all derived outputs by matching
# its path, even if the input is brought via a gyp file with '..'.
# 2) simple files like libraries and stamps have a simple filename.
obj = "obj"
if self.toolset != "target":
obj += "." + self.toolset
path_dir, path_basename = os.path.split(path)
assert not os.path.isabs(path_dir), (
"'%s' can not be absolute path (see crbug.com/462153)." % path_dir
)
if qualified:
path_basename = self.name + "." + path_basename
return os.path.normpath(
os.path.join(obj, self.base_dir, path_dir, path_basename)
)
def WriteCollapsedDependencies(self, name, targets, order_only=None):
"""Given a list of targets, return a path for a single file
representing the result of building all the targets or None.
Uses a stamp file if necessary."""
assert targets == [item for item in targets if item], targets
if len(targets) == 0:
assert not order_only
return None
if len(targets) > 1 or order_only:
stamp = self.GypPathToUniqueOutput(name + ".stamp")
targets = self.ninja.build(stamp, "stamp", targets, order_only=order_only)
self.ninja.newline()
return targets[0]
def _SubninjaNameForArch(self, arch):
output_file_base = os.path.splitext(self.output_file_name)[0]
return f"{output_file_base}.{arch}.ninja"
def WriteSpec(self, spec, config_name, generator_flags):
"""The main entry point for NinjaWriter: write the build rules for a spec.
Returns a Target object, which represents the output paths for this spec.
Returns None if there are no outputs (e.g. a settings-only 'none' type
target)."""
self.config_name = config_name
self.name = spec["target_name"]
self.toolset = spec["toolset"]
config = spec["configurations"][config_name]
self.target = Target(spec["type"])
self.is_standalone_static_library = bool(
spec.get("standalone_static_library", 0)
)
self.target_rpath = generator_flags.get("target_rpath", r"\$$ORIGIN/lib/")
self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
self.xcode_settings = self.msvs_settings = None
if self.flavor == "mac":
self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
if mac_toolchain_dir:
self.xcode_settings.mac_toolchain_dir = mac_toolchain_dir
if self.flavor == "win":
self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, generator_flags)
arch = self.msvs_settings.GetArch(config_name)
self.ninja.variable("arch", self.win_env[arch])
self.ninja.variable("cc", "$cl_" + arch)
self.ninja.variable("cxx", "$cl_" + arch)
self.ninja.variable("cc_host", "$cl_" + arch)
self.ninja.variable("cxx_host", "$cl_" + arch)
self.ninja.variable("asm", "$ml_" + arch)
if self.flavor == "mac":
self.archs = self.xcode_settings.GetActiveArchs(config_name)
if len(self.archs) > 1:
self.arch_subninjas = {
arch: ninja_syntax.Writer(
OpenOutput(
os.path.join(
self.toplevel_build, self._SubninjaNameForArch(arch)
),
"w",
)
)
for arch in self.archs
}
# Compute predepends for all rules.
# actions_depends is the dependencies this target depends on before running
# any of its action/rule/copy steps.
# compile_depends is the dependencies this target depends on before running
# any of its compile steps.
actions_depends = []
compile_depends = []
# TODO(evan): it is rather confusing which things are lists and which
# are strings. Fix these.
if "dependencies" in spec:
for dep in spec["dependencies"]:
if dep in self.target_outputs:
target = self.target_outputs[dep]
actions_depends.append(target.PreActionInput(self.flavor))
compile_depends.append(target.PreCompileInput())
if target.uses_cpp:
self.target.uses_cpp = True
actions_depends = [item for item in actions_depends if item]
compile_depends = [item for item in compile_depends if item]
actions_depends = self.WriteCollapsedDependencies(
"actions_depends", actions_depends
)
compile_depends = self.WriteCollapsedDependencies(
"compile_depends", compile_depends
)
self.target.preaction_stamp = actions_depends
self.target.precompile_stamp = compile_depends
# Write out actions, rules, and copies. These must happen before we
# compile any sources, so compute a list of predependencies for sources
# while we do it.
extra_sources = []
mac_bundle_depends = []
self.target.actions_stamp = self.WriteActionsRulesCopies(
spec, extra_sources, actions_depends, mac_bundle_depends
)
# If we have actions/rules/copies, we depend directly on those, but
# otherwise we depend on dependent target's actions/rules/copies etc.
# We never need to explicitly depend on previous target's link steps,
# because no compile ever depends on them.
compile_depends_stamp = self.target.actions_stamp or compile_depends
# Write out the compilation steps, if any.
link_deps = []
try:
sources = extra_sources + spec.get("sources", [])
except TypeError:
print("extra_sources: ", str(extra_sources))
print('spec.get("sources"): ', str(spec.get("sources")))
raise
if sources:
if self.flavor == "mac" and len(self.archs) > 1:
# Write subninja file containing compile and link commands scoped to
# a single arch if a fat binary is being built.
for arch in self.archs:
self.ninja.subninja(self._SubninjaNameForArch(arch))
pch = None
if self.flavor == "win":
gyp.msvs_emulation.VerifyMissingSources(
sources, self.abs_build_dir, generator_flags, self.GypPathToNinja
)
pch = gyp.msvs_emulation.PrecompiledHeader(
self.msvs_settings,
config_name,
self.GypPathToNinja,
self.GypPathToUniqueOutput,
self.obj_ext,
)
else:
pch = gyp.xcode_emulation.MacPrefixHeader(
self.xcode_settings,
self.GypPathToNinja,
lambda path, lang: self.GypPathToUniqueOutput(path + "-" + lang),
)
link_deps = self.WriteSources(
self.ninja,
config_name,
config,
sources,
compile_depends_stamp,
pch,
spec,
)
# Some actions/rules output 'sources' that are already object files.
obj_outputs = [f for f in sources if f.endswith(self.obj_ext)]
if obj_outputs:
if self.flavor != "mac" or len(self.archs) == 1:
link_deps += [self.GypPathToNinja(o) for o in obj_outputs]
else:
print(
"Warning: Actions/rules writing object files don't work with "
"multiarch targets, dropping. (target %s)" % spec["target_name"]
)
elif self.flavor == "mac" and len(self.archs) > 1:
link_deps = collections.defaultdict(list)
compile_deps = self.target.actions_stamp or actions_depends
if self.flavor == "win" and self.target.type == "static_library":
self.target.component_objs = link_deps
self.target.compile_deps = compile_deps
# Write out a link step, if needed.
output = None
is_empty_bundle = not link_deps and not mac_bundle_depends
if link_deps or self.target.actions_stamp or actions_depends:
output = self.WriteTarget(
spec, config_name, config, link_deps, compile_deps
)
if self.is_mac_bundle:
mac_bundle_depends.append(output)
# Bundle all of the above together, if needed.
if self.is_mac_bundle:
output = self.WriteMacBundle(spec, mac_bundle_depends, is_empty_bundle)
if not output:
return None
assert self.target.FinalOutput(), output
return self.target
def _WinIdlRule(self, source, prebuild, outputs):
"""Handle the implicit VS .idl rule for one source file. Fills |outputs|
with files that are generated."""
outdir, output, vars, flags = self.msvs_settings.GetIdlBuildData(
source, self.config_name
)
outdir = self.GypPathToNinja(outdir)
def fix_path(path, rel=None):
path = os.path.join(outdir, path)
dirname, basename = os.path.split(source)
root, ext = os.path.splitext(basename)
path = self.ExpandRuleVariables(path, root, dirname, source, ext, basename)
if rel:
path = os.path.relpath(path, rel)
return path
vars = [(name, fix_path(value, outdir)) for name, value in vars]
output = [fix_path(p) for p in output]
vars.append(("outdir", outdir))
vars.append(("idlflags", flags))
input = self.GypPathToNinja(source)
self.ninja.build(output, "idl", input, variables=vars, order_only=prebuild)
outputs.extend(output)
def WriteWinIdlFiles(self, spec, prebuild):
"""Writes rules to match MSVS's implicit idl handling."""
assert self.flavor == "win"
if self.msvs_settings.HasExplicitIdlRulesOrActions(spec):
return []
outputs = []
for source in filter(lambda x: x.endswith(".idl"), spec["sources"]):
self._WinIdlRule(source, prebuild, outputs)
return outputs
def WriteActionsRulesCopies(
self, spec, extra_sources, prebuild, mac_bundle_depends
):
"""Write out the Actions, Rules, and Copies steps. Return a path
representing the outputs of these steps."""
outputs = []
if self.is_mac_bundle:
mac_bundle_resources = spec.get("mac_bundle_resources", [])[:]
else:
mac_bundle_resources = []
extra_mac_bundle_resources = []
if "actions" in spec:
outputs += self.WriteActions(
spec["actions"], extra_sources, prebuild, extra_mac_bundle_resources
)
if "rules" in spec:
outputs += self.WriteRules(
spec["rules"],
extra_sources,
prebuild,
mac_bundle_resources,
extra_mac_bundle_resources,
)
if "copies" in spec:
outputs += self.WriteCopies(spec["copies"], prebuild, mac_bundle_depends)
if "sources" in spec and self.flavor == "win":
outputs += self.WriteWinIdlFiles(spec, prebuild)
if self.xcode_settings and self.xcode_settings.IsIosFramework():
self.WriteiOSFrameworkHeaders(spec, outputs, prebuild)
stamp = self.WriteCollapsedDependencies("actions_rules_copies", outputs)
if self.is_mac_bundle:
xcassets = self.WriteMacBundleResources(
extra_mac_bundle_resources + mac_bundle_resources, mac_bundle_depends
)
partial_info_plist = self.WriteMacXCassets(xcassets, mac_bundle_depends)
self.WriteMacInfoPlist(partial_info_plist, mac_bundle_depends)
return stamp
def GenerateDescription(self, verb, message, fallback):
"""Generate and return a description of a build step.
|verb| is the short summary, e.g. ACTION or RULE.
|message| is a hand-written description, or None if not available.
|fallback| is the gyp-level name of the step, usable as a fallback.
"""
if self.toolset != "target":
verb += "(%s)" % self.toolset
if message:
return f"{verb} {self.ExpandSpecial(message)}"
else:
return f"{verb} {self.name}: {fallback}"
def WriteActions(
self, actions, extra_sources, prebuild, extra_mac_bundle_resources
):
# Actions cd into the base directory.
env = self.GetToolchainEnv()
all_outputs = []
for action in actions:
# First write out a rule for the action.
name = "{}_{}".format(action["action_name"], self.hash_for_rules)
description = self.GenerateDescription(
"ACTION", action.get("message", None), name
)
win_shell_flags = (
self.msvs_settings.GetRuleShellFlags(action)
if self.flavor == "win"
else None
)
args = action["action"]
depfile = action.get("depfile", None)
if depfile:
depfile = self.ExpandSpecial(depfile, self.base_to_build)
pool = "console" if int(action.get("ninja_use_console", 0)) else None
rule_name, _ = self.WriteNewNinjaRule(
name, args, description, win_shell_flags, env, pool, depfile=depfile
)
inputs = [self.GypPathToNinja(i, env) for i in action["inputs"]]
if int(action.get("process_outputs_as_sources", False)):
extra_sources += action["outputs"]
if int(action.get("process_outputs_as_mac_bundle_resources", False)):
extra_mac_bundle_resources += action["outputs"]
outputs = [self.GypPathToNinja(o, env) for o in action["outputs"]]
# Then write out an edge using the rule.
self.ninja.build(outputs, rule_name, inputs, order_only=prebuild)
all_outputs += outputs
self.ninja.newline()
return all_outputs
def WriteRules(
self,
rules,
extra_sources,
prebuild,
mac_bundle_resources,
extra_mac_bundle_resources,
):
env = self.GetToolchainEnv()
all_outputs = []
for rule in rules:
# Skip a rule with no action and no inputs.
if "action" not in rule and not rule.get("rule_sources", []):
continue
# First write out a rule for the rule action.
name = "{}_{}".format(rule["rule_name"], self.hash_for_rules)
args = rule["action"]
description = self.GenerateDescription(
"RULE",
rule.get("message", None),
("%s " + generator_default_variables["RULE_INPUT_PATH"]) % name,
)
win_shell_flags = (
self.msvs_settings.GetRuleShellFlags(rule)
if self.flavor == "win"
else None
)
pool = "console" if int(rule.get("ninja_use_console", 0)) else None
rule_name, args = self.WriteNewNinjaRule(
name, args, description, win_shell_flags, env, pool
)
# TODO: if the command references the outputs directly, we should
# simplify it to just use $out.
# Rules can potentially make use of some special variables which
# must vary per source file.
# Compute the list of variables we'll need to provide.
special_locals = ("source", "root", "dirname", "ext", "name")
needed_variables = {"source"}
for argument in args:
for var in special_locals:
if "${%s}" % var in argument:
needed_variables.add(var)
needed_variables = sorted(needed_variables)
def cygwin_munge(path):
# pylint: disable=cell-var-from-loop
if win_shell_flags and win_shell_flags.cygwin:
return path.replace("\\", "/")
return path
inputs = [self.GypPathToNinja(i, env) for i in rule.get("inputs", [])]
# If there are n source files matching the rule, and m additional rule
# inputs, then adding 'inputs' to each build edge written below will
# write m * n inputs. Collapsing reduces this to m + n.
sources = rule.get("rule_sources", [])
num_inputs = len(inputs)
if prebuild:
num_inputs += 1
if num_inputs > 2 and len(sources) > 2:
inputs = [
self.WriteCollapsedDependencies(
rule["rule_name"], inputs, order_only=prebuild
)
]
prebuild = []
# For each source file, write an edge that generates all the outputs.
for source in sources:
source = os.path.normpath(source)
dirname, basename = os.path.split(source)
root, ext = os.path.splitext(basename)
# Gather the list of inputs and outputs, expanding $vars if possible.
outputs = [
self.ExpandRuleVariables(o, root, dirname, source, ext, basename)
for o in rule["outputs"]
]
if int(rule.get("process_outputs_as_sources", False)):
extra_sources += outputs
was_mac_bundle_resource = source in mac_bundle_resources
if was_mac_bundle_resource or int(
rule.get("process_outputs_as_mac_bundle_resources", False)
):
extra_mac_bundle_resources += outputs
# Note: This is n_resources * n_outputs_in_rule.
# Put to-be-removed items in a set and
# remove them all in a single pass
# if this becomes a performance issue.
if was_mac_bundle_resource:
mac_bundle_resources.remove(source)
extra_bindings = []
for var in needed_variables:
if var == "root":
extra_bindings.append(("root", cygwin_munge(root)))
elif var == "dirname":
# '$dirname' is a parameter to the rule action, which means
# it shouldn't be converted to a Ninja path. But we don't
# want $!PRODUCT_DIR in there either.
dirname_expanded = self.ExpandSpecial(
dirname, self.base_to_build
)
extra_bindings.append(
("dirname", cygwin_munge(dirname_expanded))
)
elif var == "source":
# '$source' is a parameter to the rule action, which means
# it shouldn't be converted to a Ninja path. But we don't
# want $!PRODUCT_DIR in there either.
source_expanded = self.ExpandSpecial(source, self.base_to_build)
extra_bindings.append(("source", cygwin_munge(source_expanded)))
elif var == "ext":
extra_bindings.append(("ext", ext))
elif var == "name":
extra_bindings.append(("name", cygwin_munge(basename)))
else:
assert var is None, repr(var)
outputs = [self.GypPathToNinja(o, env) for o in outputs]
if self.flavor == "win":
# WriteNewNinjaRule uses unique_name to create a rsp file on win.
extra_bindings.append(
("unique_name", hashlib.md5(outputs[0]).hexdigest())
)
self.ninja.build(
outputs,
rule_name,
self.GypPathToNinja(source),
implicit=inputs,
order_only=prebuild,
variables=extra_bindings,
)
all_outputs.extend(outputs)
return all_outputs
def WriteCopies(self, copies, prebuild, mac_bundle_depends):
outputs = []
if self.xcode_settings:
extra_env = self.xcode_settings.GetPerTargetSettings()
env = self.GetToolchainEnv(additional_settings=extra_env)
else:
env = self.GetToolchainEnv()
for to_copy in copies:
for path in to_copy["files"]:
# Normalize the path so trailing slashes don't confuse us.
path = os.path.normpath(path)
basename = os.path.split(path)[1]
src = self.GypPathToNinja(path, env)
dst = self.GypPathToNinja(
os.path.join(to_copy["destination"], basename), env
)
outputs += self.ninja.build(dst, "copy", src, order_only=prebuild)
if self.is_mac_bundle:
# gyp has mac_bundle_resources to copy things into a bundle's
# Resources folder, but there's no built-in way to copy files
# to other places in the bundle.
# Hence, some targets use copies for this.
# Check if this file is copied into the current bundle,
# and if so add it to the bundle depends so
# that dependent targets get rebuilt if the copy input changes.
if dst.startswith(
self.xcode_settings.GetBundleContentsFolderPath()
):
mac_bundle_depends.append(dst)
return outputs
def WriteiOSFrameworkHeaders(self, spec, outputs, prebuild):
"""Prebuild steps to generate hmap files and copy headers to destination."""
framework = self.ComputeMacBundleOutput()
all_sources = spec["sources"]
copy_headers = spec["mac_framework_headers"]
output = self.GypPathToUniqueOutput("headers.hmap")
self.xcode_settings.header_map_path = output
all_headers = map(
self.GypPathToNinja, filter(lambda x: x.endswith(".h"), all_sources)
)
variables = [
("framework", framework),
("copy_headers", map(self.GypPathToNinja, copy_headers)),
]
outputs.extend(
self.ninja.build(
output,
"compile_ios_framework_headers",
all_headers,
variables=variables,
order_only=prebuild,
)
)
def WriteMacBundleResources(self, resources, bundle_depends):
"""Writes ninja edges for 'mac_bundle_resources'."""
xcassets = []
extra_env = self.xcode_settings.GetPerTargetSettings()
env = self.GetSortedXcodeEnv(additional_settings=extra_env)
env = self.ComputeExportEnvString(env)
isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
for output, res in gyp.xcode_emulation.GetMacBundleResources(
generator_default_variables["PRODUCT_DIR"],
self.xcode_settings,
map(self.GypPathToNinja, resources),
):
output = self.ExpandSpecial(output)
if os.path.splitext(output)[-1] != ".xcassets":
self.ninja.build(
output,
"mac_tool",
res,
variables=[
("mactool_cmd", "copy-bundle-resource"),
("env", env),
("binary", isBinary),
],
)
bundle_depends.append(output)
else:
xcassets.append(res)
return xcassets
def WriteMacXCassets(self, xcassets, bundle_depends):
"""Writes ninja edges for 'mac_bundle_resources' .xcassets files.
This add an invocation of 'actool' via the 'mac_tool.py' helper script.
It assumes that the assets catalogs define at least one imageset and
thus an Assets.car file will be generated in the application resources
directory. If this is not the case, then the build will probably be done
at each invocation of ninja."""
if not xcassets:
return
extra_arguments = {}
settings_to_arg = {
"XCASSETS_APP_ICON": "app-icon",
"XCASSETS_LAUNCH_IMAGE": "launch-image",
}
settings = self.xcode_settings.xcode_settings[self.config_name]
for settings_key, arg_name in settings_to_arg.items():
value = settings.get(settings_key)
if value:
extra_arguments[arg_name] = value
partial_info_plist = None
if extra_arguments:
partial_info_plist = self.GypPathToUniqueOutput(
"assetcatalog_generated_info.plist"
)
extra_arguments["output-partial-info-plist"] = partial_info_plist
outputs = []
outputs.append(
os.path.join(self.xcode_settings.GetBundleResourceFolder(), "Assets.car")
)
if partial_info_plist:
outputs.append(partial_info_plist)
keys = QuoteShellArgument(json.dumps(extra_arguments), self.flavor)
extra_env = self.xcode_settings.GetPerTargetSettings()
env = self.GetSortedXcodeEnv(additional_settings=extra_env)
env = self.ComputeExportEnvString(env)
bundle_depends.extend(
self.ninja.build(
outputs,
"compile_xcassets",
xcassets,
variables=[("env", env), ("keys", keys)],
)
)
return partial_info_plist
def WriteMacInfoPlist(self, partial_info_plist, bundle_depends):
"""Write build rules for bundle Info.plist files."""
info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
generator_default_variables["PRODUCT_DIR"],
self.xcode_settings,
self.GypPathToNinja,
)
if not info_plist:
return
out = self.ExpandSpecial(out)
if defines:
# Create an intermediate file to store preprocessed results.
intermediate_plist = self.GypPathToUniqueOutput(
os.path.basename(info_plist)
)
defines = " ".join([Define(d, self.flavor) for d in defines])
info_plist = self.ninja.build(
intermediate_plist,
"preprocess_infoplist",
info_plist,
variables=[("defines", defines)],
)
env = self.GetSortedXcodeEnv(additional_settings=extra_env)
env = self.ComputeExportEnvString(env)
if partial_info_plist:
intermediate_plist = self.GypPathToUniqueOutput("merged_info.plist")
info_plist = self.ninja.build(
intermediate_plist, "merge_infoplist", [partial_info_plist, info_plist]
)
keys = self.xcode_settings.GetExtraPlistItems(self.config_name)
keys = QuoteShellArgument(json.dumps(keys), self.flavor)
isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
self.ninja.build(
out,
"copy_infoplist",
info_plist,
variables=[("env", env), ("keys", keys), ("binary", isBinary)],
)
bundle_depends.append(out)
def WriteSources(
self,
ninja_file,
config_name,
config,
sources,
predepends,
precompiled_header,
spec,
):
"""Write build rules to compile all of |sources|."""
if self.toolset == "host":
self.ninja.variable("ar", "$ar_host")
self.ninja.variable("cc", "$cc_host")
self.ninja.variable("cxx", "$cxx_host")
self.ninja.variable("ld", "$ld_host")
self.ninja.variable("ldxx", "$ldxx_host")
self.ninja.variable("nm", "$nm_host")
self.ninja.variable("readelf", "$readelf_host")
if self.flavor != "mac" or len(self.archs) == 1:
return self.WriteSourcesForArch(
self.ninja,
config_name,
config,
sources,
predepends,
precompiled_header,
spec,
)
else:
return {
arch: self.WriteSourcesForArch(
self.arch_subninjas[arch],
config_name,
config,
sources,
predepends,
precompiled_header,
spec,
arch=arch,
)
for arch in self.archs
}
def WriteSourcesForArch(
self,
ninja_file,
config_name,
config,
sources,
predepends,
precompiled_header,
spec,
arch=None,
):
"""Write build rules to compile all of |sources|."""
extra_defines = []
if self.flavor == "mac":
cflags = self.xcode_settings.GetCflags(config_name, arch=arch)
cflags_c = self.xcode_settings.GetCflagsC(config_name)
cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
cflags_objc = ["$cflags_c"] + self.xcode_settings.GetCflagsObjC(config_name)
cflags_objcc = ["$cflags_cc"] + self.xcode_settings.GetCflagsObjCC(
config_name
)
elif self.flavor == "win":
asmflags = self.msvs_settings.GetAsmflags(config_name)
cflags = self.msvs_settings.GetCflags(config_name)
cflags_c = self.msvs_settings.GetCflagsC(config_name)
cflags_cc = self.msvs_settings.GetCflagsCC(config_name)
extra_defines = self.msvs_settings.GetComputedDefines(config_name)
# See comment at cc_command for why there's two .pdb files.
pdbpath_c = pdbpath_cc = self.msvs_settings.GetCompilerPdbName(
config_name, self.ExpandSpecial
)
if not pdbpath_c:
obj = "obj"
if self.toolset != "target":
obj += "." + self.toolset
pdbpath = os.path.normpath(os.path.join(obj, self.base_dir, self.name))
pdbpath_c = pdbpath + ".c.pdb"
pdbpath_cc = pdbpath + ".cc.pdb"
self.WriteVariableList(ninja_file, "pdbname_c", [pdbpath_c])
self.WriteVariableList(ninja_file, "pdbname_cc", [pdbpath_cc])
self.WriteVariableList(ninja_file, "pchprefix", [self.name])
else:
cflags = config.get("cflags", [])
cflags_c = config.get("cflags_c", [])
cflags_cc = config.get("cflags_cc", [])
# Respect environment variables related to build, but target-specific
# flags can still override them.
if self.toolset == "target":
cflags_c = (
os.environ.get("CPPFLAGS", "").split()
+ os.environ.get("CFLAGS", "").split()
+ cflags_c
)
cflags_cc = (
os.environ.get("CPPFLAGS", "").split()
+ os.environ.get("CXXFLAGS", "").split()
+ cflags_cc
)
elif self.toolset == "host":
cflags_c = (
os.environ.get("CPPFLAGS_host", "").split()
+ os.environ.get("CFLAGS_host", "").split()
+ cflags_c
)
cflags_cc = (
os.environ.get("CPPFLAGS_host", "").split()
+ os.environ.get("CXXFLAGS_host", "").split()
+ cflags_cc
)
defines = config.get("defines", []) + extra_defines
self.WriteVariableList(
ninja_file, "defines", [Define(d, self.flavor) for d in defines]
)
if self.flavor == "win":
self.WriteVariableList(
ninja_file, "asmflags", map(self.ExpandSpecial, asmflags)
)
self.WriteVariableList(
ninja_file,
"rcflags",
[
QuoteShellArgument(self.ExpandSpecial(f), self.flavor)
for f in self.msvs_settings.GetRcflags(
config_name, self.GypPathToNinja
)
],
)
include_dirs = config.get("include_dirs", [])
env = self.GetToolchainEnv()
if self.flavor == "win":
include_dirs = self.msvs_settings.AdjustIncludeDirs(
include_dirs, config_name
)
self.WriteVariableList(
ninja_file,
"includes",
[
QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
for i in include_dirs
],
)
if self.flavor == "win":
midl_include_dirs = config.get("midl_include_dirs", [])
midl_include_dirs = self.msvs_settings.AdjustMidlIncludeDirs(
midl_include_dirs, config_name
)
self.WriteVariableList(
ninja_file,
"midl_includes",
[
QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
for i in midl_include_dirs
],
)
pch_commands = precompiled_header.GetPchBuildCommands(arch)
if self.flavor == "mac":
# Most targets use no precompiled headers, so only write these if needed.
for ext, var in [
("c", "cflags_pch_c"),
("cc", "cflags_pch_cc"),
("m", "cflags_pch_objc"),
("mm", "cflags_pch_objcc"),
]:
include = precompiled_header.GetInclude(ext, arch)
if include:
ninja_file.variable(var, include)
arflags = config.get("arflags", [])
self.WriteVariableList(ninja_file, "cflags", map(self.ExpandSpecial, cflags))
self.WriteVariableList(
ninja_file, "cflags_c", map(self.ExpandSpecial, cflags_c)
)
self.WriteVariableList(
ninja_file, "cflags_cc", map(self.ExpandSpecial, cflags_cc)
)
if self.flavor == "mac":
self.WriteVariableList(
ninja_file, "cflags_objc", map(self.ExpandSpecial, cflags_objc)
)
self.WriteVariableList(
ninja_file, "cflags_objcc", map(self.ExpandSpecial, cflags_objcc)
)
self.WriteVariableList(ninja_file, "arflags", map(self.ExpandSpecial, arflags))
ninja_file.newline()
outputs = []
has_rc_source = False
for source in sources:
filename, ext = os.path.splitext(source)
ext = ext[1:]
obj_ext = self.obj_ext
if ext in ("cc", "cpp", "cxx"):
command = "cxx"
self.target.uses_cpp = True
elif ext == "c" or (ext == "S" and self.flavor != "win"):
command = "cc"
elif ext == "s" and self.flavor != "win": # Doesn't generate .o.d files.
command = "cc_s"
elif (
self.flavor == "win"
and ext in ("asm", "S")
and not self.msvs_settings.HasExplicitAsmRules(spec)
):
command = "asm"
# Add the _asm suffix as msvs is capable of handling .cc and
# .asm files of the same name without collision.
obj_ext = "_asm.obj"
elif self.flavor == "mac" and ext == "m":
command = "objc"
elif self.flavor == "mac" and ext == "mm":
command = "objcxx"
self.target.uses_cpp = True
elif self.flavor == "win" and ext == "rc":
command = "rc"
obj_ext = ".res"
has_rc_source = True
else:
# Ignore unhandled extensions.
continue
input = self.GypPathToNinja(source)
output = self.GypPathToUniqueOutput(filename + obj_ext)
if arch is not None:
output = AddArch(output, arch)
implicit = precompiled_header.GetObjDependencies([input], [output], arch)
variables = []
if self.flavor == "win":
variables, output, implicit = precompiled_header.GetFlagsModifications(
input,
output,
implicit,
command,
cflags_c,
cflags_cc,
self.ExpandSpecial,
)
ninja_file.build(
output,
command,
input,
implicit=[gch for _, _, gch in implicit],
order_only=predepends,
variables=variables,
)
outputs.append(output)
if has_rc_source:
resource_include_dirs = config.get("resource_include_dirs", include_dirs)
self.WriteVariableList(
ninja_file,
"resource_includes",
[
QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
for i in resource_include_dirs
],
)
self.WritePchTargets(ninja_file, pch_commands)
ninja_file.newline()
return outputs
def WritePchTargets(self, ninja_file, pch_commands):
"""Writes ninja rules to compile prefix headers."""
if not pch_commands:
return
for gch, lang_flag, lang, input in pch_commands:
var_name = {
"c": "cflags_pch_c",
"cc": "cflags_pch_cc",
"m": "cflags_pch_objc",
"mm": "cflags_pch_objcc",
}[lang]
map = {
"c": "cc",
"cc": "cxx",
"m": "objc",
"mm": "objcxx",
}
cmd = map.get(lang)
ninja_file.build(gch, cmd, input, variables=[(var_name, lang_flag)])
def WriteLink(self, spec, config_name, config, link_deps, compile_deps):
"""Write out a link step. Fills out target.binary. """
if self.flavor != "mac" or len(self.archs) == 1:
return self.WriteLinkForArch(
self.ninja, spec, config_name, config, link_deps, compile_deps
)
else:
output = self.ComputeOutput(spec)
inputs = [
self.WriteLinkForArch(
self.arch_subninjas[arch],
spec,
config_name,
config,
link_deps[arch],
compile_deps,
arch=arch,
)
for arch in self.archs
]
extra_bindings = []
build_output = output
if not self.is_mac_bundle:
self.AppendPostbuildVariable(extra_bindings, spec, output, output)
# TODO(yyanagisawa): more work needed to fix:
# https://code.google.com/p/gyp/issues/detail?id=411
if (
spec["type"] in ("shared_library", "loadable_module")
and not self.is_mac_bundle
):
extra_bindings.append(("lib", output))
self.ninja.build(
[output, output + ".TOC"],
"solipo",
inputs,
variables=extra_bindings,
)
else:
self.ninja.build(build_output, "lipo", inputs, variables=extra_bindings)
return output
def WriteLinkForArch(
self, ninja_file, spec, config_name, config, link_deps, compile_deps, arch=None
):
"""Write out a link step. Fills out target.binary. """
command = {
"executable": "link",
"loadable_module": "solink_module",
"shared_library": "solink",
}[spec["type"]]
command_suffix = ""
implicit_deps = set()
solibs = set()
order_deps = set()
if compile_deps:
# Normally, the compiles of the target already depend on compile_deps,
# but a shared_library target might have no sources and only link together
# a few static_library deps, so the link step also needs to depend
# on compile_deps to make sure actions in the shared_library target
# get run before the link.
order_deps.add(compile_deps)
if "dependencies" in spec:
# Two kinds of dependencies:
# - Linkable dependencies (like a .a or a .so): add them to the link line.
# - Non-linkable dependencies (like a rule that generates a file
# and writes a stamp file): add them to implicit_deps
extra_link_deps = set()
for dep in spec["dependencies"]:
target = self.target_outputs.get(dep)
if not target:
continue
linkable = target.Linkable()
if linkable:
new_deps = []
if (
self.flavor == "win"
and target.component_objs
and self.msvs_settings.IsUseLibraryDependencyInputs(config_name)
):
new_deps = target.component_objs
if target.compile_deps:
order_deps.add(target.compile_deps)
elif self.flavor == "win" and target.import_lib:
new_deps = [target.import_lib]
elif target.UsesToc(self.flavor):
solibs.add(target.binary)
implicit_deps.add(target.binary + ".TOC")
else:
new_deps = [target.binary]
for new_dep in new_deps:
if new_dep not in extra_link_deps:
extra_link_deps.add(new_dep)
link_deps.append(new_dep)
final_output = target.FinalOutput()
if not linkable or final_output != target.binary:
implicit_deps.add(final_output)
extra_bindings = []
if self.target.uses_cpp and self.flavor != "win":
extra_bindings.append(("ld", "$ldxx"))
output = self.ComputeOutput(spec, arch)
if arch is None and not self.is_mac_bundle:
self.AppendPostbuildVariable(extra_bindings, spec, output, output)
is_executable = spec["type"] == "executable"
# The ldflags config key is not used on mac or win. On those platforms
# linker flags are set via xcode_settings and msvs_settings, respectively.
if self.toolset == "target":
env_ldflags = os.environ.get("LDFLAGS", "").split()
elif self.toolset == "host":
env_ldflags = os.environ.get("LDFLAGS_host", "").split()
if self.flavor == "mac":
ldflags = self.xcode_settings.GetLdflags(
config_name,
self.ExpandSpecial(generator_default_variables["PRODUCT_DIR"]),
self.GypPathToNinja,
arch,
)
ldflags = env_ldflags + ldflags
elif self.flavor == "win":
manifest_base_name = self.GypPathToUniqueOutput(
self.ComputeOutputFileName(spec)
)
(
ldflags,
intermediate_manifest,
manifest_files,
) = self.msvs_settings.GetLdflags(
config_name,
self.GypPathToNinja,
self.ExpandSpecial,
manifest_base_name,
output,
is_executable,
self.toplevel_build,
)
ldflags = env_ldflags + ldflags
self.WriteVariableList(ninja_file, "manifests", manifest_files)
implicit_deps = implicit_deps.union(manifest_files)
if intermediate_manifest:
self.WriteVariableList(
ninja_file, "intermediatemanifest", [intermediate_manifest]
)
command_suffix = _GetWinLinkRuleNameSuffix(
self.msvs_settings.IsEmbedManifest(config_name)
)
def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja)
if def_file:
implicit_deps.add(def_file)
else:
# Respect environment variables related to build, but target-specific
# flags can still override them.
ldflags = env_ldflags + config.get("ldflags", [])
if is_executable and len(solibs):
rpath = "lib/"
if self.toolset != "target":
rpath += self.toolset
ldflags.append(r"-Wl,-rpath=\$$ORIGIN/%s" % rpath)
else:
ldflags.append("-Wl,-rpath=%s" % self.target_rpath)
ldflags.append("-Wl,-rpath-link=%s" % rpath)
self.WriteVariableList(ninja_file, "ldflags", map(self.ExpandSpecial, ldflags))
library_dirs = config.get("library_dirs", [])
if self.flavor == "win":
library_dirs = [
self.msvs_settings.ConvertVSMacros(library_dir, config_name)
for library_dir in library_dirs
]
library_dirs = [
"/LIBPATH:"
+ QuoteShellArgument(self.GypPathToNinja(library_dir), self.flavor)
for library_dir in library_dirs
]
else:
library_dirs = [
QuoteShellArgument("-L" + self.GypPathToNinja(library_dir), self.flavor)
for library_dir in library_dirs
]
libraries = gyp.common.uniquer(
map(self.ExpandSpecial, spec.get("libraries", []))
)
if self.flavor == "mac":
libraries = self.xcode_settings.AdjustLibraries(libraries, config_name)
elif self.flavor == "win":
libraries = self.msvs_settings.AdjustLibraries(libraries)
self.WriteVariableList(ninja_file, "libs", library_dirs + libraries)
linked_binary = output
if command in ("solink", "solink_module"):
extra_bindings.append(("soname", os.path.split(output)[1]))
extra_bindings.append(("lib", gyp.common.EncodePOSIXShellArgument(output)))
if self.flavor != "win":
link_file_list = output
if self.is_mac_bundle:
# 'Dependency Framework.framework/Versions/A/Dependency Framework'
# -> 'Dependency Framework.framework.rsp'
link_file_list = self.xcode_settings.GetWrapperName()
if arch:
link_file_list += "." + arch
link_file_list += ".rsp"
# If an rspfile contains spaces, ninja surrounds the filename with
# quotes around it and then passes it to open(), creating a file with
# quotes in its name (and when looking for the rsp file, the name
# makes it through bash which strips the quotes) :-/
link_file_list = link_file_list.replace(" ", "_")
extra_bindings.append(
(
"link_file_list",
gyp.common.EncodePOSIXShellArgument(link_file_list),
)
)
if self.flavor == "win":
extra_bindings.append(("binary", output))
if (
"/NOENTRY" not in ldflags
and not self.msvs_settings.GetNoImportLibrary(config_name)
):
self.target.import_lib = output + ".lib"
extra_bindings.append(
("implibflag", "/IMPLIB:%s" % self.target.import_lib)
)
pdbname = self.msvs_settings.GetPDBName(
config_name, self.ExpandSpecial, output + ".pdb"
)
output = [output, self.target.import_lib]
if pdbname:
output.append(pdbname)
elif not self.is_mac_bundle:
output = [output, output + ".TOC"]
else:
command = command + "_notoc"
elif self.flavor == "win":
extra_bindings.append(("binary", output))
pdbname = self.msvs_settings.GetPDBName(
config_name, self.ExpandSpecial, output + ".pdb"
)
if pdbname:
output = [output, pdbname]
if len(solibs):
extra_bindings.append(
("solibs", gyp.common.EncodePOSIXShellList(sorted(solibs)))
)
ninja_file.build(
output,
command + command_suffix,
link_deps,
implicit=sorted(implicit_deps),
order_only=list(order_deps),
variables=extra_bindings,
)
return linked_binary
def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
extra_link_deps = any(
self.target_outputs.get(dep).Linkable()
for dep in spec.get("dependencies", [])
if dep in self.target_outputs
)
if spec["type"] == "none" or (not link_deps and not extra_link_deps):
# TODO(evan): don't call this function for 'none' target types, as
# it doesn't do anything, and we fake out a 'binary' with a stamp file.
self.target.binary = compile_deps
self.target.type = "none"
elif spec["type"] == "static_library":
self.target.binary = self.ComputeOutput(spec)
if (
self.flavor not in ("ios", "mac", "netbsd", "openbsd", "win")
and not self.is_standalone_static_library
):
self.ninja.build(
self.target.binary, "alink_thin", link_deps, order_only=compile_deps
)
else:
variables = []
if self.xcode_settings:
libtool_flags = self.xcode_settings.GetLibtoolflags(config_name)
if libtool_flags:
variables.append(("libtool_flags", libtool_flags))
if self.msvs_settings:
libflags = self.msvs_settings.GetLibFlags(
config_name, self.GypPathToNinja
)
variables.append(("libflags", libflags))
if self.flavor != "mac" or len(self.archs) == 1:
self.AppendPostbuildVariable(
variables, spec, self.target.binary, self.target.binary
)
self.ninja.build(
self.target.binary,
"alink",
link_deps,
order_only=compile_deps,
variables=variables,
)
else:
inputs = []
for arch in self.archs:
output = self.ComputeOutput(spec, arch)
self.arch_subninjas[arch].build(
output,
"alink",
link_deps[arch],
order_only=compile_deps,
variables=variables,
)
inputs.append(output)
# TODO: It's not clear if
# libtool_flags should be passed to the alink
# call that combines single-arch .a files into a fat .a file.
self.AppendPostbuildVariable(
variables, spec, self.target.binary, self.target.binary
)
self.ninja.build(
self.target.binary,
"alink",
inputs,
# FIXME: test proving order_only=compile_deps isn't
# needed.
variables=variables,
)
else:
self.target.binary = self.WriteLink(
spec, config_name, config, link_deps, compile_deps
)
return self.target.binary
def WriteMacBundle(self, spec, mac_bundle_depends, is_empty):
assert self.is_mac_bundle
package_framework = spec["type"] in ("shared_library", "loadable_module")
output = self.ComputeMacBundleOutput()
if is_empty:
output += ".stamp"
variables = []
self.AppendPostbuildVariable(
variables,
spec,
output,
self.target.binary,
is_command_start=not package_framework,
)
if package_framework and not is_empty:
if spec["type"] == "shared_library" and self.xcode_settings.isIOS:
self.ninja.build(
output,
"package_ios_framework",
mac_bundle_depends,
variables=variables,
)
else:
variables.append(("version", self.xcode_settings.GetFrameworkVersion()))
self.ninja.build(
output, "package_framework", mac_bundle_depends, variables=variables
)
else:
self.ninja.build(output, "stamp", mac_bundle_depends, variables=variables)
self.target.bundle = output
return output
def GetToolchainEnv(self, additional_settings=None):
"""Returns the variables toolchain would set for build steps."""
env = self.GetSortedXcodeEnv(additional_settings=additional_settings)
if self.flavor == "win":
env = self.GetMsvsToolchainEnv(additional_settings=additional_settings)
return env
def GetMsvsToolchainEnv(self, additional_settings=None):
"""Returns the variables Visual Studio would set for build steps."""
return self.msvs_settings.GetVSMacroEnv(
"$!PRODUCT_DIR", config=self.config_name
)
def GetSortedXcodeEnv(self, additional_settings=None):
"""Returns the variables Xcode would set for build steps."""
assert self.abs_build_dir
abs_build_dir = self.abs_build_dir
return gyp.xcode_emulation.GetSortedXcodeEnv(
self.xcode_settings,
abs_build_dir,
os.path.join(abs_build_dir, self.build_to_base),
self.config_name,
additional_settings,
)
def GetSortedXcodePostbuildEnv(self):
"""Returns the variables Xcode would set for postbuild steps."""
postbuild_settings = {}
# CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
# TODO(thakis): It would be nice to have some general mechanism instead.
strip_save_file = self.xcode_settings.GetPerTargetSetting(
"CHROMIUM_STRIP_SAVE_FILE"
)
if strip_save_file:
postbuild_settings["CHROMIUM_STRIP_SAVE_FILE"] = strip_save_file
return self.GetSortedXcodeEnv(additional_settings=postbuild_settings)
def AppendPostbuildVariable(
self, variables, spec, output, binary, is_command_start=False
):
"""Adds a 'postbuild' variable if there is a postbuild for |output|."""
postbuild = self.GetPostbuildCommand(spec, output, binary, is_command_start)
if postbuild:
variables.append(("postbuilds", postbuild))
def GetPostbuildCommand(self, spec, output, output_binary, is_command_start):
"""Returns a shell command that runs all the postbuilds, and removes
|output| if any of them fails. If |is_command_start| is False, then the
returned string will start with ' && '."""
if not self.xcode_settings or spec["type"] == "none" or not output:
return ""
output = QuoteShellArgument(output, self.flavor)
postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands(spec, quiet=True)
if output_binary is not None:
postbuilds = self.xcode_settings.AddImplicitPostbuilds(
self.config_name,
os.path.normpath(os.path.join(self.base_to_build, output)),
QuoteShellArgument(
os.path.normpath(os.path.join(self.base_to_build, output_binary)),
self.flavor,
),
postbuilds,
quiet=True,
)
if not postbuilds:
return ""
# Postbuilds expect to be run in the gyp file's directory, so insert an
# implicit postbuild to cd to there.
postbuilds.insert(
0, gyp.common.EncodePOSIXShellList(["cd", self.build_to_base])
)
env = self.ComputeExportEnvString(self.GetSortedXcodePostbuildEnv())
# G will be non-null if any postbuild fails. Run all postbuilds in a
# subshell.
commands = (
env
+ " ("
+ " && ".join([ninja_syntax.escape(command) for command in postbuilds])
)
command_string = (
commands
+ "); G=$$?; "
# Remove the final output if any postbuild failed.
"((exit $$G) || rm -rf %s) " % output
+ "&& exit $$G)"
)
if is_command_start:
return "(" + command_string + " && "
else:
return "$ && (" + command_string
def ComputeExportEnvString(self, env):
"""Given an environment, returns a string looking like
'export FOO=foo; export BAR="${FOO} bar;'
that exports |env| to the shell."""
export_str = []
for k, v in env:
export_str.append(
"export %s=%s;"
% (k, ninja_syntax.escape(gyp.common.EncodePOSIXShellArgument(v)))
)
return " ".join(export_str)
def ComputeMacBundleOutput(self):
"""Return the 'output' (full output path) to a bundle output directory."""
assert self.is_mac_bundle
path = generator_default_variables["PRODUCT_DIR"]
return self.ExpandSpecial(
os.path.join(path, self.xcode_settings.GetWrapperName())
)
def ComputeOutputFileName(self, spec, type=None):
"""Compute the filename of the final output for the current target."""
if not type:
type = spec["type"]
default_variables = copy.copy(generator_default_variables)
CalculateVariables(default_variables, {"flavor": self.flavor})
# Compute filename prefix: the product prefix, or a default for
# the product type.
DEFAULT_PREFIX = {
"loadable_module": default_variables["SHARED_LIB_PREFIX"],
"shared_library": default_variables["SHARED_LIB_PREFIX"],
"static_library": default_variables["STATIC_LIB_PREFIX"],
"executable": default_variables["EXECUTABLE_PREFIX"],
}
prefix = spec.get("product_prefix", DEFAULT_PREFIX.get(type, ""))
# Compute filename extension: the product extension, or a default
# for the product type.
DEFAULT_EXTENSION = {
"loadable_module": default_variables["SHARED_LIB_SUFFIX"],
"shared_library": default_variables["SHARED_LIB_SUFFIX"],
"static_library": default_variables["STATIC_LIB_SUFFIX"],
"executable": default_variables["EXECUTABLE_SUFFIX"],
}
extension = spec.get("product_extension")
if extension:
extension = "." + extension
else:
extension = DEFAULT_EXTENSION.get(type, "")
if "product_name" in spec:
# If we were given an explicit name, use that.
target = spec["product_name"]
else:
# Otherwise, derive a name from the target name.
target = spec["target_name"]
if prefix == "lib":
# Snip out an extra 'lib' from libs if appropriate.
target = StripPrefix(target, "lib")
if type in (
"static_library",
"loadable_module",
"shared_library",
"executable",
):
return f"{prefix}{target}{extension}"
elif type == "none":
return "%s.stamp" % target
else:
raise Exception("Unhandled output type %s" % type)
def ComputeOutput(self, spec, arch=None):
"""Compute the path for the final output of the spec."""
type = spec["type"]
if self.flavor == "win":
override = self.msvs_settings.GetOutputName(
self.config_name, self.ExpandSpecial
)
if override:
return override
if (
arch is None
and self.flavor == "mac"
and type
in ("static_library", "executable", "shared_library", "loadable_module")
):
filename = self.xcode_settings.GetExecutablePath()
else:
filename = self.ComputeOutputFileName(spec, type)
if arch is None and "product_dir" in spec:
path = os.path.join(spec["product_dir"], filename)
return self.ExpandSpecial(path)
# Some products go into the output root, libraries go into shared library
# dir, and everything else goes into the normal place.
type_in_output_root = ["executable", "loadable_module"]
if self.flavor == "mac" and self.toolset == "target":
type_in_output_root += ["shared_library", "static_library"]
elif self.flavor == "win" and self.toolset == "target":
type_in_output_root += ["shared_library"]
if arch is not None:
# Make sure partial executables don't end up in a bundle or the regular
# output directory.
archdir = "arch"
if self.toolset != "target":
archdir = os.path.join("arch", "%s" % self.toolset)
return os.path.join(archdir, AddArch(filename, arch))
elif type in type_in_output_root or self.is_standalone_static_library:
return filename
elif type == "shared_library":
libdir = "lib"
if self.toolset != "target":
libdir = os.path.join("lib", "%s" % self.toolset)
return os.path.join(libdir, filename)
else:
return self.GypPathToUniqueOutput(filename, qualified=False)
def WriteVariableList(self, ninja_file, var, values):
assert not isinstance(values, str)
if values is None:
values = []
ninja_file.variable(var, " ".join(values))
def WriteNewNinjaRule(
self, name, args, description, win_shell_flags, env, pool, depfile=None
):
"""Write out a new ninja "rule" statement for a given command.
Returns the name of the new rule, and a copy of |args| with variables
expanded."""
if self.flavor == "win":
args = [
self.msvs_settings.ConvertVSMacros(
arg, self.base_to_build, config=self.config_name
)
for arg in args
]
description = self.msvs_settings.ConvertVSMacros(
description, config=self.config_name
)
elif self.flavor == "mac":
# |env| is an empty list on non-mac.
args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args]
description = gyp.xcode_emulation.ExpandEnvVars(description, env)
# TODO: we shouldn't need to qualify names; we do it because
# currently the ninja rule namespace is global, but it really
# should be scoped to the subninja.
rule_name = self.name
if self.toolset == "target":
rule_name += "." + self.toolset
rule_name += "." + name
rule_name = re.sub("[^a-zA-Z0-9_]", "_", rule_name)
# Remove variable references, but not if they refer to the magic rule
# variables. This is not quite right, as it also protects these for
# actions, not just for rules where they are valid. Good enough.
protect = ["${root}", "${dirname}", "${source}", "${ext}", "${name}"]
protect = "(?!" + "|".join(map(re.escape, protect)) + ")"
description = re.sub(protect + r"\$", "_", description)
# gyp dictates that commands are run from the base directory.
# cd into the directory before running, and adjust paths in
# the arguments to point to the proper locations.
rspfile = None
rspfile_content = None
args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args]
if self.flavor == "win":
rspfile = rule_name + ".$unique_name.rsp"
# The cygwin case handles this inside the bash sub-shell.
run_in = "" if win_shell_flags.cygwin else " " + self.build_to_base
if win_shell_flags.cygwin:
rspfile_content = self.msvs_settings.BuildCygwinBashCommandLine(
args, self.build_to_base
)
else:
rspfile_content = gyp.msvs_emulation.EncodeRspFileList(
args, win_shell_flags.quote)
command = (
"%s gyp-win-tool action-wrapper $arch " % sys.executable
+ rspfile
+ run_in
)
else:
env = self.ComputeExportEnvString(env)
command = gyp.common.EncodePOSIXShellList(args)
command = "cd %s; " % self.build_to_base + env + command
# GYP rules/actions express being no-ops by not touching their outputs.
# Avoid executing downstream dependencies in this case by specifying
# restat=1 to ninja.
self.ninja.rule(
rule_name,
command,
description,
depfile=depfile,
restat=True,
pool=pool,
rspfile=rspfile,
rspfile_content=rspfile_content,
)
self.ninja.newline()
return rule_name, args
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
global generator_additional_non_configuration_keys
global generator_additional_path_sections
flavor = gyp.common.GetFlavor(params)
if flavor == "mac":
default_variables.setdefault("OS", "mac")
default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
default_variables.setdefault(
"SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
)
default_variables.setdefault(
"LIB_DIR", generator_default_variables["PRODUCT_DIR"]
)
# Copy additional generator configuration data from Xcode, which is shared
# by the Mac Ninja generator.
import gyp.generator.xcode as xcode_generator
generator_additional_non_configuration_keys = getattr(
xcode_generator, "generator_additional_non_configuration_keys", []
)
generator_additional_path_sections = getattr(
xcode_generator, "generator_additional_path_sections", []
)
global generator_extra_sources_for_rules
generator_extra_sources_for_rules = getattr(
xcode_generator, "generator_extra_sources_for_rules", []
)
elif flavor == "win":
exts = gyp.MSVSUtil.TARGET_TYPE_EXT
default_variables.setdefault("OS", "win")
default_variables["EXECUTABLE_SUFFIX"] = "." + exts["executable"]
default_variables["STATIC_LIB_PREFIX"] = ""
default_variables["STATIC_LIB_SUFFIX"] = "." + exts["static_library"]
default_variables["SHARED_LIB_PREFIX"] = ""
default_variables["SHARED_LIB_SUFFIX"] = "." + exts["shared_library"]
# Copy additional generator configuration data from VS, which is shared
# by the Windows Ninja generator.
import gyp.generator.msvs as msvs_generator
generator_additional_non_configuration_keys = getattr(
msvs_generator, "generator_additional_non_configuration_keys", []
)
generator_additional_path_sections = getattr(
msvs_generator, "generator_additional_path_sections", []
)
gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
else:
operating_system = flavor
if flavor == "android":
operating_system = "linux" # Keep this legacy behavior for now.
default_variables.setdefault("OS", operating_system)
default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
default_variables.setdefault(
"SHARED_LIB_DIR", os.path.join("$!PRODUCT_DIR", "lib")
)
default_variables.setdefault("LIB_DIR", os.path.join("$!PRODUCT_DIR", "obj"))
def ComputeOutputDir(params):
"""Returns the path from the toplevel_dir to the build output directory."""
# generator_dir: relative path from pwd to where make puts build files.
# Makes migrating from make to ninja easier, ninja doesn't put anything here.
generator_dir = os.path.relpath(params["options"].generator_output or ".")
# output_dir: relative path from generator_dir to the build directory.
output_dir = params.get("generator_flags", {}).get("output_dir", "out")
# Relative path from source root to our output files. e.g. "out"
return os.path.normpath(os.path.join(generator_dir, output_dir))
def CalculateGeneratorInputInfo(params):
"""Called by __init__ to initialize generator values based on params."""
# E.g. "out/gypfiles"
toplevel = params["options"].toplevel_dir
qualified_out_dir = os.path.normpath(
os.path.join(toplevel, ComputeOutputDir(params), "gypfiles")
)
global generator_filelist_paths
generator_filelist_paths = {
"toplevel": toplevel,
"qualified_out_dir": qualified_out_dir,
}
def OpenOutput(path, mode="w"):
"""Open |path| for writing, creating directories if necessary."""
gyp.common.EnsureDirExists(path)
return open(path, mode)
def CommandWithWrapper(cmd, wrappers, prog):
wrapper = wrappers.get(cmd, "")
if wrapper:
return wrapper + " " + prog
return prog
def GetDefaultConcurrentLinks():
"""Returns a best-guess for a number of concurrent links."""
pool_size = int(os.environ.get("GYP_LINK_CONCURRENCY", 0))
if pool_size:
return pool_size
if sys.platform in ("win32", "cygwin"):
import ctypes
class MEMORYSTATUSEX(ctypes.Structure):
_fields_ = [
("dwLength", ctypes.c_ulong),
("dwMemoryLoad", ctypes.c_ulong),
("ullTotalPhys", ctypes.c_ulonglong),
("ullAvailPhys", ctypes.c_ulonglong),
("ullTotalPageFile", ctypes.c_ulonglong),
("ullAvailPageFile", ctypes.c_ulonglong),
("ullTotalVirtual", ctypes.c_ulonglong),
("ullAvailVirtual", ctypes.c_ulonglong),
("sullAvailExtendedVirtual", ctypes.c_ulonglong),
]
stat = MEMORYSTATUSEX()
stat.dwLength = ctypes.sizeof(stat)
ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
# VS 2015 uses 20% more working set than VS 2013 and can consume all RAM
# on a 64 GiB machine.
mem_limit = max(1, stat.ullTotalPhys // (5 * (2 ** 30))) # total / 5GiB
hard_cap = max(1, int(os.environ.get("GYP_LINK_CONCURRENCY_MAX", 2 ** 32)))
return min(mem_limit, hard_cap)
elif sys.platform.startswith("linux"):
if os.path.exists("/proc/meminfo"):
with open("/proc/meminfo") as meminfo:
memtotal_re = re.compile(r"^MemTotal:\s*(\d*)\s*kB")
for line in meminfo:
match = memtotal_re.match(line)
if not match:
continue
# Allow 8Gb per link on Linux because Gold is quite memory hungry
return max(1, int(match.group(1)) // (8 * (2 ** 20)))
return 1
elif sys.platform == "darwin":
try:
avail_bytes = int(subprocess.check_output(["sysctl", "-n", "hw.memsize"]))
# A static library debug build of Chromium's unit_tests takes ~2.7GB, so
# 4GB per ld process allows for some more bloat.
return max(1, avail_bytes // (4 * (2 ** 30))) # total / 4GB
except subprocess.CalledProcessError:
return 1
else:
# TODO(scottmg): Implement this for other platforms.
return 1
def _GetWinLinkRuleNameSuffix(embed_manifest):
"""Returns the suffix used to select an appropriate linking rule depending on
whether the manifest embedding is enabled."""
return "_embed" if embed_manifest else ""
def _AddWinLinkRules(master_ninja, embed_manifest):
"""Adds link rules for Windows platform to |master_ninja|."""
def FullLinkCommand(ldcmd, out, binary_type):
resource_name = {"exe": "1", "dll": "2"}[binary_type]
return (
"%(python)s gyp-win-tool link-with-manifests $arch %(embed)s "
'%(out)s "%(ldcmd)s" %(resname)s $mt $rc "$intermediatemanifest" '
"$manifests"
% {
"python": sys.executable,
"out": out,
"ldcmd": ldcmd,
"resname": resource_name,
"embed": embed_manifest,
}
)
rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest)
use_separate_mspdbsrv = int(os.environ.get("GYP_USE_SEPARATE_MSPDBSRV", "0")) != 0
dlldesc = "LINK%s(DLL) $binary" % rule_name_suffix.upper()
dllcmd = (
"%s gyp-win-tool link-wrapper $arch %s "
"$ld /nologo $implibflag /DLL /OUT:$binary "
"@$binary.rsp" % (sys.executable, use_separate_mspdbsrv)
)
dllcmd = FullLinkCommand(dllcmd, "$binary", "dll")
master_ninja.rule(
"solink" + rule_name_suffix,
description=dlldesc,
command=dllcmd,
rspfile="$binary.rsp",
rspfile_content="$libs $in_newline $ldflags",
restat=True,
pool="link_pool",
)
master_ninja.rule(
"solink_module" + rule_name_suffix,
description=dlldesc,
command=dllcmd,
rspfile="$binary.rsp",
rspfile_content="$libs $in_newline $ldflags",
restat=True,
pool="link_pool",
)
# Note that ldflags goes at the end so that it has the option of
# overriding default settings earlier in the command line.
exe_cmd = (
"%s gyp-win-tool link-wrapper $arch %s "
"$ld /nologo /OUT:$binary @$binary.rsp"
% (sys.executable, use_separate_mspdbsrv)
)
exe_cmd = FullLinkCommand(exe_cmd, "$binary", "exe")
master_ninja.rule(
"link" + rule_name_suffix,
description="LINK%s $binary" % rule_name_suffix.upper(),
command=exe_cmd,
rspfile="$binary.rsp",
rspfile_content="$in_newline $libs $ldflags",
pool="link_pool",
)
def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name):
options = params["options"]
flavor = gyp.common.GetFlavor(params)
generator_flags = params.get("generator_flags", {})
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.normpath(os.path.join(ComputeOutputDir(params), config_name))
toplevel_build = os.path.join(options.toplevel_dir, build_dir)
master_ninja_file = OpenOutput(os.path.join(toplevel_build, "build.ninja"))
master_ninja = ninja_syntax.Writer(master_ninja_file, width=120)
# Put build-time support tools in out/{config_name}.
gyp.common.CopyTool(flavor, toplevel_build, generator_flags)
# Grab make settings for CC/CXX.
# The rules are
# - The priority from low to high is gcc/g++, the 'make_global_settings' in
# gyp, the environment variable.
# - If there is no 'make_global_settings' for CC.host/CXX.host or
# 'CC_host'/'CXX_host' environment variable, cc_host/cxx_host should be set
# to cc/cxx.
if flavor == "win":
ar = "lib.exe"
# cc and cxx must be set to the correct architecture by overriding with one
# of cl_x86 or cl_x64 below.
cc = "UNSET"
cxx = "UNSET"
ld = "link.exe"
ld_host = "$ld"
else:
ar = "ar"
cc = "cc"
cxx = "c++"
ld = "$cc"
ldxx = "$cxx"
ld_host = "$cc_host"
ldxx_host = "$cxx_host"
ar_host = ar
cc_host = None
cxx_host = None
cc_host_global_setting = None
cxx_host_global_setting = None
clang_cl = None
nm = "nm"
nm_host = "nm"
readelf = "readelf"
readelf_host = "readelf"
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
make_global_settings = data[build_file].get("make_global_settings", [])
build_to_root = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
wrappers = {}
for key, value in make_global_settings:
if key == "AR":
ar = os.path.join(build_to_root, value)
if key == "AR.host":
ar_host = os.path.join(build_to_root, value)
if key == "CC":
cc = os.path.join(build_to_root, value)
if cc.endswith("clang-cl"):
clang_cl = cc
if key == "CXX":
cxx = os.path.join(build_to_root, value)
if key == "CC.host":
cc_host = os.path.join(build_to_root, value)
cc_host_global_setting = value
if key == "CXX.host":
cxx_host = os.path.join(build_to_root, value)
cxx_host_global_setting = value
if key == "LD":
ld = os.path.join(build_to_root, value)
if key == "LD.host":
ld_host = os.path.join(build_to_root, value)
if key == "LDXX":
ldxx = os.path.join(build_to_root, value)
if key == "LDXX.host":
ldxx_host = os.path.join(build_to_root, value)
if key == "NM":
nm = os.path.join(build_to_root, value)
if key == "NM.host":
nm_host = os.path.join(build_to_root, value)
if key == "READELF":
readelf = os.path.join(build_to_root, value)
if key == "READELF.host":
readelf_host = os.path.join(build_to_root, value)
if key.endswith("_wrapper"):
wrappers[key[: -len("_wrapper")]] = os.path.join(build_to_root, value)
# Support wrappers from environment variables too.
for key, value in os.environ.items():
if key.lower().endswith("_wrapper"):
key_prefix = key[: -len("_wrapper")]
key_prefix = re.sub(r"\.HOST$", ".host", key_prefix)
wrappers[key_prefix] = os.path.join(build_to_root, value)
mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
if mac_toolchain_dir:
wrappers["LINK"] = "export DEVELOPER_DIR='%s' &&" % mac_toolchain_dir
if flavor == "win":
configs = [
target_dicts[qualified_target]["configurations"][config_name]
for qualified_target in target_list
]
shared_system_includes = None
if not generator_flags.get("ninja_use_custom_environment_files", 0):
shared_system_includes = gyp.msvs_emulation.ExtractSharedMSVSSystemIncludes(
configs, generator_flags
)
cl_paths = gyp.msvs_emulation.GenerateEnvironmentFiles(
toplevel_build, generator_flags, shared_system_includes, OpenOutput
)
for arch, path in sorted(cl_paths.items()):
if clang_cl:
# If we have selected clang-cl, use that instead.
path = clang_cl
command = CommandWithWrapper(
"CC", wrappers, QuoteShellArgument(path, "win")
)
if clang_cl:
# Use clang-cl to cross-compile for x86 or x86_64.
command += " -m32" if arch == "x86" else " -m64"
master_ninja.variable("cl_" + arch, command)
cc = GetEnvironFallback(["CC_target", "CC"], cc)
master_ninja.variable("cc", CommandWithWrapper("CC", wrappers, cc))
cxx = GetEnvironFallback(["CXX_target", "CXX"], cxx)
master_ninja.variable("cxx", CommandWithWrapper("CXX", wrappers, cxx))
if flavor == "win":
master_ninja.variable("ld", ld)
master_ninja.variable("idl", "midl.exe")
master_ninja.variable("ar", ar)
master_ninja.variable("rc", "rc.exe")
master_ninja.variable("ml_x86", "ml.exe")
master_ninja.variable("ml_x64", "ml64.exe")
master_ninja.variable("mt", "mt.exe")
else:
master_ninja.variable("ld", CommandWithWrapper("LINK", wrappers, ld))
master_ninja.variable("ldxx", CommandWithWrapper("LINK", wrappers, ldxx))
master_ninja.variable("ar", GetEnvironFallback(["AR_target", "AR"], ar))
if flavor != "mac":
# Mac does not use readelf/nm for .TOC generation, so avoiding polluting
# the master ninja with extra unused variables.
master_ninja.variable("nm", GetEnvironFallback(["NM_target", "NM"], nm))
master_ninja.variable(
"readelf", GetEnvironFallback(["READELF_target", "READELF"], readelf)
)
if generator_supports_multiple_toolsets:
if not cc_host:
cc_host = cc
if not cxx_host:
cxx_host = cxx
master_ninja.variable("ar_host", GetEnvironFallback(["AR_host"], ar_host))
master_ninja.variable("nm_host", GetEnvironFallback(["NM_host"], nm_host))
master_ninja.variable(
"readelf_host", GetEnvironFallback(["READELF_host"], readelf_host)
)
cc_host = GetEnvironFallback(["CC_host"], cc_host)
cxx_host = GetEnvironFallback(["CXX_host"], cxx_host)
# The environment variable could be used in 'make_global_settings', like
# ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
if "$(CC)" in cc_host and cc_host_global_setting:
cc_host = cc_host_global_setting.replace("$(CC)", cc)
if "$(CXX)" in cxx_host and cxx_host_global_setting:
cxx_host = cxx_host_global_setting.replace("$(CXX)", cxx)
master_ninja.variable(
"cc_host", CommandWithWrapper("CC.host", wrappers, cc_host)
)
master_ninja.variable(
"cxx_host", CommandWithWrapper("CXX.host", wrappers, cxx_host)
)
if flavor == "win":
master_ninja.variable("ld_host", ld_host)
else:
master_ninja.variable(
"ld_host", CommandWithWrapper("LINK", wrappers, ld_host)
)
master_ninja.variable(
"ldxx_host", CommandWithWrapper("LINK", wrappers, ldxx_host)
)
master_ninja.newline()
master_ninja.pool("link_pool", depth=GetDefaultConcurrentLinks())
master_ninja.newline()
deps = "msvc" if flavor == "win" else "gcc"
if flavor != "win":
master_ninja.rule(
"cc",
description="CC $out",
command=(
"$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c "
"$cflags_pch_c -c $in -o $out"
),
depfile="$out.d",
deps=deps,
)
master_ninja.rule(
"cc_s",
description="CC $out",
command=(
"$cc $defines $includes $cflags $cflags_c "
"$cflags_pch_c -c $in -o $out"
),
)
master_ninja.rule(
"cxx",
description="CXX $out",
command=(
"$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc "
"$cflags_pch_cc -c $in -o $out"
),
depfile="$out.d",
deps=deps,
)
else:
# TODO(scottmg) Separate pdb names is a test to see if it works around
# http://crbug.com/142362. It seems there's a race between the creation of
# the .pdb by the precompiled header step for .cc and the compilation of
# .c files. This should be handled by mspdbsrv, but rarely errors out with
# c1xx : fatal error C1033: cannot open program database
# By making the rules target separate pdb files this might be avoided.
cc_command = (
"ninja -t msvc -e $arch " + "-- "
"$cc /nologo /showIncludes /FC "
"@$out.rsp /c $in /Fo$out /Fd$pdbname_c "
)
cxx_command = (
"ninja -t msvc -e $arch " + "-- "
"$cxx /nologo /showIncludes /FC "
"@$out.rsp /c $in /Fo$out /Fd$pdbname_cc "
)
master_ninja.rule(
"cc",
description="CC $out",
command=cc_command,
rspfile="$out.rsp",
rspfile_content="$defines $includes $cflags $cflags_c",
deps=deps,
)
master_ninja.rule(
"cxx",
description="CXX $out",
command=cxx_command,
rspfile="$out.rsp",
rspfile_content="$defines $includes $cflags $cflags_cc",
deps=deps,
)
master_ninja.rule(
"idl",
description="IDL $in",
command=(
"%s gyp-win-tool midl-wrapper $arch $outdir "
"$tlb $h $dlldata $iid $proxy $in "
"$midl_includes $idlflags" % sys.executable
),
)
master_ninja.rule(
"rc",
description="RC $in",
# Note: $in must be last otherwise rc.exe complains.
command=(
"%s gyp-win-tool rc-wrapper "
"$arch $rc $defines $resource_includes $rcflags /fo$out $in"
% sys.executable
),
)
master_ninja.rule(
"asm",
description="ASM $out",
command=(
"%s gyp-win-tool asm-wrapper "
"$arch $asm $defines $includes $asmflags /c /Fo $out $in"
% sys.executable
),
)
if flavor not in ("ios", "mac", "win"):
master_ninja.rule(
"alink",
description="AR $out",
command="rm -f $out && $ar rcs $arflags $out $in",
)
master_ninja.rule(
"alink_thin",
description="AR $out",
command="rm -f $out && $ar rcsT $arflags $out $in",
)
# This allows targets that only need to depend on $lib's API to declare an
# order-only dependency on $lib.TOC and avoid relinking such downstream
# dependencies when $lib changes only in non-public ways.
# The resulting string leaves an uninterpolated %{suffix} which
# is used in the final substitution below.
mtime_preserving_solink_base = (
"if [ ! -e $lib -o ! -e $lib.TOC ]; then "
"%(solink)s && %(extract_toc)s > $lib.TOC; else "
"%(solink)s && %(extract_toc)s > $lib.tmp && "
"if ! cmp -s $lib.tmp $lib.TOC; then mv $lib.tmp $lib.TOC ; "
"fi; fi"
% {
"solink": "$ld -shared $ldflags -o $lib -Wl,-soname=$soname %(suffix)s",
"extract_toc": (
"{ $readelf -d $lib | grep SONAME ; "
"$nm -gD -f p $lib | cut -f1-2 -d' '; }"
),
}
)
master_ninja.rule(
"solink",
description="SOLINK $lib",
restat=True,
command=mtime_preserving_solink_base
% {"suffix": "@$link_file_list"}, # noqa: E501
rspfile="$link_file_list",
rspfile_content=(
"-Wl,--whole-archive $in $solibs -Wl," "--no-whole-archive $libs"
),
pool="link_pool",
)
master_ninja.rule(
"solink_module",
description="SOLINK(module) $lib",
restat=True,
command=mtime_preserving_solink_base % {"suffix": "@$link_file_list"},
rspfile="$link_file_list",
rspfile_content="-Wl,--start-group $in $solibs $libs -Wl,--end-group",
pool="link_pool",
)
master_ninja.rule(
"link",
description="LINK $out",
command=(
"$ld $ldflags -o $out "
"-Wl,--start-group $in $solibs $libs -Wl,--end-group"
),
pool="link_pool",
)
elif flavor == "win":
master_ninja.rule(
"alink",
description="LIB $out",
command=(
"%s gyp-win-tool link-wrapper $arch False "
"$ar /nologo /ignore:4221 /OUT:$out @$out.rsp" % sys.executable
),
rspfile="$out.rsp",
rspfile_content="$in_newline $libflags",
)
_AddWinLinkRules(master_ninja, embed_manifest=True)
_AddWinLinkRules(master_ninja, embed_manifest=False)
else:
master_ninja.rule(
"objc",
description="OBJC $out",
command=(
"$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc "
"$cflags_pch_objc -c $in -o $out"
),
depfile="$out.d",
deps=deps,
)
master_ninja.rule(
"objcxx",
description="OBJCXX $out",
command=(
"$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_objcc "
"$cflags_pch_objcc -c $in -o $out"
),
depfile="$out.d",
deps=deps,
)
master_ninja.rule(
"alink",
description="LIBTOOL-STATIC $out, POSTBUILDS",
command="rm -f $out && "
"./gyp-mac-tool filter-libtool libtool $libtool_flags "
"-static -o $out $in"
"$postbuilds",
)
master_ninja.rule(
"lipo",
description="LIPO $out, POSTBUILDS",
command="rm -f $out && lipo -create $in -output $out$postbuilds",
)
master_ninja.rule(
"solipo",
description="SOLIPO $out, POSTBUILDS",
command=(
"rm -f $lib $lib.TOC && lipo -create $in -output $lib$postbuilds &&"
"%(extract_toc)s > $lib.TOC"
% {
"extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
"nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }"
}
),
)
# Record the public interface of $lib in $lib.TOC. See the corresponding
# comment in the posix section above for details.
solink_base = "$ld %(type)s $ldflags -o $lib %(suffix)s"
mtime_preserving_solink_base = (
"if [ ! -e $lib -o ! -e $lib.TOC ] || "
# Always force dependent targets to relink if this library
# reexports something. Handling this correctly would require
# recursive TOC dumping but this is rare in practice, so punt.
"otool -l $lib | grep -q LC_REEXPORT_DYLIB ; then "
"%(solink)s && %(extract_toc)s > $lib.TOC; "
"else "
"%(solink)s && %(extract_toc)s > $lib.tmp && "
"if ! cmp -s $lib.tmp $lib.TOC; then "
"mv $lib.tmp $lib.TOC ; "
"fi; "
"fi"
% {
"solink": solink_base,
"extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
"nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }",
}
)
solink_suffix = "@$link_file_list$postbuilds"
master_ninja.rule(
"solink",
description="SOLINK $lib, POSTBUILDS",
restat=True,
command=mtime_preserving_solink_base
% {"suffix": solink_suffix, "type": "-shared"},
rspfile="$link_file_list",
rspfile_content="$in $solibs $libs",
pool="link_pool",
)
master_ninja.rule(
"solink_notoc",
description="SOLINK $lib, POSTBUILDS",
restat=True,
command=solink_base % {"suffix": solink_suffix, "type": "-shared"},
rspfile="$link_file_list",
rspfile_content="$in $solibs $libs",
pool="link_pool",
)
master_ninja.rule(
"solink_module",
description="SOLINK(module) $lib, POSTBUILDS",
restat=True,
command=mtime_preserving_solink_base
% {"suffix": solink_suffix, "type": "-bundle"},
rspfile="$link_file_list",
rspfile_content="$in $solibs $libs",
pool="link_pool",
)
master_ninja.rule(
"solink_module_notoc",
description="SOLINK(module) $lib, POSTBUILDS",
restat=True,
command=solink_base % {"suffix": solink_suffix, "type": "-bundle"},
rspfile="$link_file_list",
rspfile_content="$in $solibs $libs",
pool="link_pool",
)
master_ninja.rule(
"link",
description="LINK $out, POSTBUILDS",
command=("$ld $ldflags -o $out " "$in $solibs $libs$postbuilds"),
pool="link_pool",
)
master_ninja.rule(
"preprocess_infoplist",
description="PREPROCESS INFOPLIST $out",
command=(
"$cc -E -P -Wno-trigraphs -x c $defines $in -o $out && "
"plutil -convert xml1 $out $out"
),
)
master_ninja.rule(
"copy_infoplist",
description="COPY INFOPLIST $in",
command="$env ./gyp-mac-tool copy-info-plist $in $out $binary $keys",
)
master_ninja.rule(
"merge_infoplist",
description="MERGE INFOPLISTS $in",
command="$env ./gyp-mac-tool merge-info-plist $out $in",
)
master_ninja.rule(
"compile_xcassets",
description="COMPILE XCASSETS $in",
command="$env ./gyp-mac-tool compile-xcassets $keys $in",
)
master_ninja.rule(
"compile_ios_framework_headers",
description="COMPILE HEADER MAPS AND COPY FRAMEWORK HEADERS $in",
command="$env ./gyp-mac-tool compile-ios-framework-header-map $out "
"$framework $in && $env ./gyp-mac-tool "
"copy-ios-framework-headers $framework $copy_headers",
)
master_ninja.rule(
"mac_tool",
description="MACTOOL $mactool_cmd $in",
command="$env ./gyp-mac-tool $mactool_cmd $in $out $binary",
)
master_ninja.rule(
"package_framework",
description="PACKAGE FRAMEWORK $out, POSTBUILDS",
command="./gyp-mac-tool package-framework $out $version$postbuilds "
"&& touch $out",
)
master_ninja.rule(
"package_ios_framework",
description="PACKAGE IOS FRAMEWORK $out, POSTBUILDS",
command="./gyp-mac-tool package-ios-framework $out $postbuilds "
"&& touch $out",
)
if flavor == "win":
master_ninja.rule(
"stamp",
description="STAMP $out",
command="%s gyp-win-tool stamp $out" % sys.executable,
)
else:
master_ninja.rule(
"stamp", description="STAMP $out", command="${postbuilds}touch $out"
)
if flavor == "win":
master_ninja.rule(
"copy",
description="COPY $in $out",
command="%s gyp-win-tool recursive-mirror $in $out" % sys.executable,
)
elif flavor == "zos":
master_ninja.rule(
"copy",
description="COPY $in $out",
command="rm -rf $out && cp -fRP $in $out",
)
else:
master_ninja.rule(
"copy",
description="COPY $in $out",
command="ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)",
)
master_ninja.newline()
all_targets = set()
for build_file in params["build_files"]:
for target in gyp.common.AllTargets(
target_list, target_dicts, os.path.normpath(build_file)
):
all_targets.add(target)
all_outputs = set()
# target_outputs is a map from qualified target name to a Target object.
target_outputs = {}
# target_short_names is a map from target short name to a list of Target
# objects.
target_short_names = {}
# short name of targets that were skipped because they didn't contain anything
# interesting.
# NOTE: there may be overlap between this an non_empty_target_names.
empty_target_names = set()
# Set of non-empty short target names.
# NOTE: there may be overlap between this an empty_target_names.
non_empty_target_names = set()
for qualified_target in target_list:
# qualified_target is like: third_party/icu/icu.gyp:icui18n#target
build_file, name, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
this_make_global_settings = data[build_file].get("make_global_settings", [])
assert make_global_settings == this_make_global_settings, (
"make_global_settings needs to be the same for all targets. "
f"{this_make_global_settings} vs. {make_global_settings}"
)
spec = target_dicts[qualified_target]
if flavor == "mac":
gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
# If build_file is a symlink, we must not follow it because there's a chance
# it could point to a path above toplevel_dir, and we cannot correctly deal
# with that case at the moment.
build_file = gyp.common.RelativePath(build_file, options.toplevel_dir, False)
qualified_target_for_hash = gyp.common.QualifiedTarget(
build_file, name, toolset
)
qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
base_path = os.path.dirname(build_file)
obj = "obj"
if toolset != "target":
obj += "." + toolset
output_file = os.path.join(obj, base_path, name + ".ninja")
ninja_output = StringIO()
writer = NinjaWriter(
hash_for_rules,
target_outputs,
base_path,
build_dir,
ninja_output,
toplevel_build,
output_file,
flavor,
toplevel_dir=options.toplevel_dir,
)
target = writer.WriteSpec(spec, config_name, generator_flags)
if ninja_output.tell() > 0:
# Only create files for ninja files that actually have contents.
with OpenOutput(os.path.join(toplevel_build, output_file)) as ninja_file:
ninja_file.write(ninja_output.getvalue())
ninja_output.close()
master_ninja.subninja(output_file)
if target:
if name != target.FinalOutput() and spec["toolset"] == "target":
target_short_names.setdefault(name, []).append(target)
target_outputs[qualified_target] = target
if qualified_target in all_targets:
all_outputs.add(target.FinalOutput())
non_empty_target_names.add(name)
else:
empty_target_names.add(name)
if target_short_names:
# Write a short name to build this target. This benefits both the
# "build chrome" case as well as the gyp tests, which expect to be
# able to run actions and build libraries by their short name.
master_ninja.newline()
master_ninja.comment("Short names for targets.")
for short_name in sorted(target_short_names):
master_ninja.build(
short_name,
"phony",
[x.FinalOutput() for x in target_short_names[short_name]],
)
# Write phony targets for any empty targets that weren't written yet. As
# short names are not necessarily unique only do this for short names that
# haven't already been output for another target.
empty_target_names = empty_target_names - non_empty_target_names
if empty_target_names:
master_ninja.newline()
master_ninja.comment("Empty targets (output for completeness).")
for name in sorted(empty_target_names):
master_ninja.build(name, "phony")
if all_outputs:
master_ninja.newline()
master_ninja.build("all", "phony", sorted(all_outputs))
master_ninja.default(generator_flags.get("default_target", "all"))
master_ninja_file.close()
def PerformBuild(data, configurations, params):
options = params["options"]
for config in configurations:
builddir = os.path.join(options.toplevel_dir, "out", config)
arguments = ["ninja", "-C", builddir]
print(f"Building [{config}]: {arguments}")
subprocess.check_call(arguments)
def CallGenerateOutputForConfig(arglist):
# Ignore the interrupt signal so that the parent process catches it and
# kills all multiprocessing children.
signal.signal(signal.SIGINT, signal.SIG_IGN)
(target_list, target_dicts, data, params, config_name) = arglist
GenerateOutputForConfig(target_list, target_dicts, data, params, config_name)
def GenerateOutput(target_list, target_dicts, data, params):
# Update target_dicts for iOS device builds.
target_dicts = gyp.xcode_emulation.CloneConfigurationForDeviceAndEmulator(
target_dicts
)
user_config = params.get("generator_flags", {}).get("config", None)
if gyp.common.GetFlavor(params) == "win":
target_list, target_dicts = MSVSUtil.ShardTargets(target_list, target_dicts)
target_list, target_dicts = MSVSUtil.InsertLargePdbShims(
target_list, target_dicts, generator_default_variables
)
if user_config:
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
if params["parallel"]:
try:
pool = multiprocessing.Pool(len(config_names))
arglists = []
for config_name in config_names:
arglists.append(
(target_list, target_dicts, data, params, config_name)
)
pool.map(CallGenerateOutputForConfig, arglists)
except KeyboardInterrupt as e:
pool.terminate()
raise e
else:
for config_name in config_names:
GenerateOutputForConfig(
target_list, target_dicts, data, params, config_name
)
node-gyp-9.3.0/gyp/pylib/gyp/generator/ninja_test.py 0000664 0000000 0000000 00000003566 14321173220 0022465 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the ninja.py file. """
import sys
import unittest
import gyp.generator.ninja as ninja
class TestPrefixesAndSuffixes(unittest.TestCase):
def test_BinaryNamesWindows(self):
# These cannot run on non-Windows as they require a VS installation to
# correctly handle variable expansion.
if sys.platform.startswith("win"):
writer = ninja.NinjaWriter(
"foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win"
)
spec = {"target_name": "wee"}
self.assertTrue(
writer.ComputeOutputFileName(spec, "executable").endswith(".exe")
)
self.assertTrue(
writer.ComputeOutputFileName(spec, "shared_library").endswith(".dll")
)
self.assertTrue(
writer.ComputeOutputFileName(spec, "static_library").endswith(".lib")
)
def test_BinaryNamesLinux(self):
writer = ninja.NinjaWriter(
"foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "linux"
)
spec = {"target_name": "wee"}
self.assertTrue("." not in writer.ComputeOutputFileName(spec, "executable"))
self.assertTrue(
writer.ComputeOutputFileName(spec, "shared_library").startswith("lib")
)
self.assertTrue(
writer.ComputeOutputFileName(spec, "static_library").startswith("lib")
)
self.assertTrue(
writer.ComputeOutputFileName(spec, "shared_library").endswith(".so")
)
self.assertTrue(
writer.ComputeOutputFileName(spec, "static_library").endswith(".a")
)
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/generator/xcode.py 0000664 0000000 0000000 00000201103 14321173220 0021414 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import filecmp
import gyp.common
import gyp.xcodeproj_file
import gyp.xcode_ninja
import errno
import os
import sys
import posixpath
import re
import shutil
import subprocess
import tempfile
# Project files generated by this module will use _intermediate_var as a
# custom Xcode setting whose value is a DerivedSources-like directory that's
# project-specific and configuration-specific. The normal choice,
# DERIVED_FILE_DIR, is target-specific, which is thought to be too restrictive
# as it is likely that multiple targets within a single project file will want
# to access the same set of generated files. The other option,
# PROJECT_DERIVED_FILE_DIR, is unsuitable because while it is project-specific,
# it is not configuration-specific. INTERMEDIATE_DIR is defined as
# $(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION).
_intermediate_var = "INTERMEDIATE_DIR"
# SHARED_INTERMEDIATE_DIR is the same, except that it is shared among all
# targets that share the same BUILT_PRODUCTS_DIR.
_shared_intermediate_var = "SHARED_INTERMEDIATE_DIR"
_library_search_paths_var = "LIBRARY_SEARCH_PATHS"
generator_default_variables = {
"EXECUTABLE_PREFIX": "",
"EXECUTABLE_SUFFIX": "",
"STATIC_LIB_PREFIX": "lib",
"SHARED_LIB_PREFIX": "lib",
"STATIC_LIB_SUFFIX": ".a",
"SHARED_LIB_SUFFIX": ".dylib",
# INTERMEDIATE_DIR is a place for targets to build up intermediate products.
# It is specific to each build environment. It is only guaranteed to exist
# and be constant within the context of a project, corresponding to a single
# input file. Some build environments may allow their intermediate directory
# to be shared on a wider scale, but this is not guaranteed.
"INTERMEDIATE_DIR": "$(%s)" % _intermediate_var,
"OS": "mac",
"PRODUCT_DIR": "$(BUILT_PRODUCTS_DIR)",
"LIB_DIR": "$(BUILT_PRODUCTS_DIR)",
"RULE_INPUT_ROOT": "$(INPUT_FILE_BASE)",
"RULE_INPUT_EXT": "$(INPUT_FILE_SUFFIX)",
"RULE_INPUT_NAME": "$(INPUT_FILE_NAME)",
"RULE_INPUT_PATH": "$(INPUT_FILE_PATH)",
"RULE_INPUT_DIRNAME": "$(INPUT_FILE_DIRNAME)",
"SHARED_INTERMEDIATE_DIR": "$(%s)" % _shared_intermediate_var,
"CONFIGURATION_NAME": "$(CONFIGURATION)",
}
# The Xcode-specific sections that hold paths.
generator_additional_path_sections = [
"mac_bundle_resources",
"mac_framework_headers",
"mac_framework_private_headers",
# 'mac_framework_dirs', input already handles _dirs endings.
]
# The Xcode-specific keys that exist on targets and aren't moved down to
# configurations.
generator_additional_non_configuration_keys = [
"ios_app_extension",
"ios_watch_app",
"ios_watchkit_extension",
"mac_bundle",
"mac_bundle_resources",
"mac_framework_headers",
"mac_framework_private_headers",
"mac_xctest_bundle",
"mac_xcuitest_bundle",
"xcode_create_dependents_test_runner",
]
# We want to let any rules apply to files that are resources also.
generator_extra_sources_for_rules = [
"mac_bundle_resources",
"mac_framework_headers",
"mac_framework_private_headers",
]
generator_filelist_paths = None
# Xcode's standard set of library directories, which don't need to be duplicated
# in LIBRARY_SEARCH_PATHS. This list is not exhaustive, but that's okay.
xcode_standard_library_dirs = frozenset(
["$(SDKROOT)/usr/lib", "$(SDKROOT)/usr/local/lib"]
)
def CreateXCConfigurationList(configuration_names):
xccl = gyp.xcodeproj_file.XCConfigurationList({"buildConfigurations": []})
if len(configuration_names) == 0:
configuration_names = ["Default"]
for configuration_name in configuration_names:
xcbc = gyp.xcodeproj_file.XCBuildConfiguration({"name": configuration_name})
xccl.AppendProperty("buildConfigurations", xcbc)
xccl.SetProperty("defaultConfigurationName", configuration_names[0])
return xccl
class XcodeProject:
def __init__(self, gyp_path, path, build_file_dict):
self.gyp_path = gyp_path
self.path = path
self.project = gyp.xcodeproj_file.PBXProject(path=path)
projectDirPath = gyp.common.RelativePath(
os.path.dirname(os.path.abspath(self.gyp_path)),
os.path.dirname(path) or ".",
)
self.project.SetProperty("projectDirPath", projectDirPath)
self.project_file = gyp.xcodeproj_file.XCProjectFile(
{"rootObject": self.project}
)
self.build_file_dict = build_file_dict
# TODO(mark): add destructor that cleans up self.path if created_dir is
# True and things didn't complete successfully. Or do something even
# better with "try"?
self.created_dir = False
try:
os.makedirs(self.path)
self.created_dir = True
except OSError as e:
if e.errno != errno.EEXIST:
raise
def Finalize1(self, xcode_targets, serialize_all_tests):
# Collect a list of all of the build configuration names used by the
# various targets in the file. It is very heavily advised to keep each
# target in an entire project (even across multiple project files) using
# the same set of configuration names.
configurations = []
for xct in self.project.GetProperty("targets"):
xccl = xct.GetProperty("buildConfigurationList")
xcbcs = xccl.GetProperty("buildConfigurations")
for xcbc in xcbcs:
name = xcbc.GetProperty("name")
if name not in configurations:
configurations.append(name)
# Replace the XCConfigurationList attached to the PBXProject object with
# a new one specifying all of the configuration names used by the various
# targets.
try:
xccl = CreateXCConfigurationList(configurations)
self.project.SetProperty("buildConfigurationList", xccl)
except Exception:
sys.stderr.write("Problem with gyp file %s\n" % self.gyp_path)
raise
# The need for this setting is explained above where _intermediate_var is
# defined. The comments below about wanting to avoid project-wide build
# settings apply here too, but this needs to be set on a project-wide basis
# so that files relative to the _intermediate_var setting can be displayed
# properly in the Xcode UI.
#
# Note that for configuration-relative files such as anything relative to
# _intermediate_var, for the purposes of UI tree view display, Xcode will
# only resolve the configuration name once, when the project file is
# opened. If the active build configuration is changed, the project file
# must be closed and reopened if it is desired for the tree view to update.
# This is filed as Apple radar 6588391.
xccl.SetBuildSetting(
_intermediate_var, "$(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION)"
)
xccl.SetBuildSetting(
_shared_intermediate_var, "$(SYMROOT)/DerivedSources/$(CONFIGURATION)"
)
# Set user-specified project-wide build settings and config files. This
# is intended to be used very sparingly. Really, almost everything should
# go into target-specific build settings sections. The project-wide
# settings are only intended to be used in cases where Xcode attempts to
# resolve variable references in a project context as opposed to a target
# context, such as when resolving sourceTree references while building up
# the tree tree view for UI display.
# Any values set globally are applied to all configurations, then any
# per-configuration values are applied.
for xck, xcv in self.build_file_dict.get("xcode_settings", {}).items():
xccl.SetBuildSetting(xck, xcv)
if "xcode_config_file" in self.build_file_dict:
config_ref = self.project.AddOrGetFileInRootGroup(
self.build_file_dict["xcode_config_file"]
)
xccl.SetBaseConfiguration(config_ref)
build_file_configurations = self.build_file_dict.get("configurations", {})
if build_file_configurations:
for config_name in configurations:
build_file_configuration_named = build_file_configurations.get(
config_name, {}
)
if build_file_configuration_named:
xcc = xccl.ConfigurationNamed(config_name)
for xck, xcv in build_file_configuration_named.get(
"xcode_settings", {}
).items():
xcc.SetBuildSetting(xck, xcv)
if "xcode_config_file" in build_file_configuration_named:
config_ref = self.project.AddOrGetFileInRootGroup(
build_file_configurations[config_name]["xcode_config_file"]
)
xcc.SetBaseConfiguration(config_ref)
# Sort the targets based on how they appeared in the input.
# TODO(mark): Like a lot of other things here, this assumes internal
# knowledge of PBXProject - in this case, of its "targets" property.
# ordinary_targets are ordinary targets that are already in the project
# file. run_test_targets are the targets that run unittests and should be
# used for the Run All Tests target. support_targets are the action/rule
# targets used by GYP file targets, just kept for the assert check.
ordinary_targets = []
run_test_targets = []
support_targets = []
# targets is full list of targets in the project.
targets = []
# does the it define it's own "all"?
has_custom_all = False
# targets_for_all is the list of ordinary_targets that should be listed
# in this project's "All" target. It includes each non_runtest_target
# that does not have suppress_wildcard set.
targets_for_all = []
for target in self.build_file_dict["targets"]:
target_name = target["target_name"]
toolset = target["toolset"]
qualified_target = gyp.common.QualifiedTarget(
self.gyp_path, target_name, toolset
)
xcode_target = xcode_targets[qualified_target]
# Make sure that the target being added to the sorted list is already in
# the unsorted list.
assert xcode_target in self.project._properties["targets"]
targets.append(xcode_target)
ordinary_targets.append(xcode_target)
if xcode_target.support_target:
support_targets.append(xcode_target.support_target)
targets.append(xcode_target.support_target)
if not int(target.get("suppress_wildcard", False)):
targets_for_all.append(xcode_target)
if target_name.lower() == "all":
has_custom_all = True
# If this target has a 'run_as' attribute, add its target to the
# targets, and add it to the test targets.
if target.get("run_as"):
# Make a target to run something. It should have one
# dependency, the parent xcode target.
xccl = CreateXCConfigurationList(configurations)
run_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
"name": "Run " + target_name,
"productName": xcode_target.GetProperty("productName"),
"buildConfigurationList": xccl,
},
parent=self.project,
)
run_target.AddDependency(xcode_target)
command = target["run_as"]
script = ""
if command.get("working_directory"):
script = (
script
+ 'cd "%s"\n'
% gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
command.get("working_directory")
)
)
if command.get("environment"):
script = (
script
+ "\n".join(
[
'export %s="%s"'
% (
key,
gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
val
),
)
for (key, val) in command.get("environment").items()
]
)
+ "\n"
)
# Some test end up using sockets, files on disk, etc. and can get
# confused if more then one test runs at a time. The generator
# flag 'xcode_serialize_all_test_runs' controls the forcing of all
# tests serially. It defaults to True. To get serial runs this
# little bit of python does the same as the linux flock utility to
# make sure only one runs at a time.
command_prefix = ""
if serialize_all_tests:
command_prefix = """python -c "import fcntl, subprocess, sys
file = open('$TMPDIR/GYP_serialize_test_runs', 'a')
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
sys.exit(subprocess.call(sys.argv[1:]))" """
# If we were unable to exec for some reason, we want to exit
# with an error, and fixup variable references to be shell
# syntax instead of xcode syntax.
script = (
script
+ "exec "
+ command_prefix
+ "%s\nexit 1\n"
% gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
gyp.common.EncodePOSIXShellList(command.get("action"))
)
)
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
{"shellScript": script, "showEnvVarsInLog": 0}
)
run_target.AppendProperty("buildPhases", ssbp)
# Add the run target to the project file.
targets.append(run_target)
run_test_targets.append(run_target)
xcode_target.test_runner = run_target
# Make sure that the list of targets being replaced is the same length as
# the one replacing it, but allow for the added test runner targets.
assert len(self.project._properties["targets"]) == len(ordinary_targets) + len(
support_targets
)
self.project._properties["targets"] = targets
# Get rid of unnecessary levels of depth in groups like the Source group.
self.project.RootGroupsTakeOverOnlyChildren(True)
# Sort the groups nicely. Do this after sorting the targets, because the
# Products group is sorted based on the order of the targets.
self.project.SortGroups()
# Create an "All" target if there's more than one target in this project
# file and the project didn't define its own "All" target. Put a generated
# "All" target first so that people opening up the project for the first
# time will build everything by default.
if len(targets_for_all) > 1 and not has_custom_all:
xccl = CreateXCConfigurationList(configurations)
all_target = gyp.xcodeproj_file.PBXAggregateTarget(
{"buildConfigurationList": xccl, "name": "All"}, parent=self.project
)
for target in targets_for_all:
all_target.AddDependency(target)
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._properties. It's important to get the "All" target first,
# though.
self.project._properties["targets"].insert(0, all_target)
# The same, but for run_test_targets.
if len(run_test_targets) > 1:
xccl = CreateXCConfigurationList(configurations)
run_all_tests_target = gyp.xcodeproj_file.PBXAggregateTarget(
{"buildConfigurationList": xccl, "name": "Run All Tests"},
parent=self.project,
)
for run_test_target in run_test_targets:
run_all_tests_target.AddDependency(run_test_target)
# Insert after the "All" target, which must exist if there is more than
# one run_test_target.
self.project._properties["targets"].insert(1, run_all_tests_target)
def Finalize2(self, xcode_targets, xcode_target_to_target_dict):
# Finalize2 needs to happen in a separate step because the process of
# updating references to other projects depends on the ordering of targets
# within remote project files. Finalize1 is responsible for sorting duty,
# and once all project files are sorted, Finalize2 can come in and update
# these references.
# To support making a "test runner" target that will run all the tests
# that are direct dependents of any given target, we look for
# xcode_create_dependents_test_runner being set on an Aggregate target,
# and generate a second target that will run the tests runners found under
# the marked target.
for bf_tgt in self.build_file_dict["targets"]:
if int(bf_tgt.get("xcode_create_dependents_test_runner", 0)):
tgt_name = bf_tgt["target_name"]
toolset = bf_tgt["toolset"]
qualified_target = gyp.common.QualifiedTarget(
self.gyp_path, tgt_name, toolset
)
xcode_target = xcode_targets[qualified_target]
if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget):
# Collect all the run test targets.
all_run_tests = []
pbxtds = xcode_target.GetProperty("dependencies")
for pbxtd in pbxtds:
pbxcip = pbxtd.GetProperty("targetProxy")
dependency_xct = pbxcip.GetProperty("remoteGlobalIDString")
if hasattr(dependency_xct, "test_runner"):
all_run_tests.append(dependency_xct.test_runner)
# Directly depend on all the runners as they depend on the target
# that builds them.
if len(all_run_tests) > 0:
run_all_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
"name": "Run %s Tests" % tgt_name,
"productName": tgt_name,
},
parent=self.project,
)
for run_test_target in all_run_tests:
run_all_target.AddDependency(run_test_target)
# Insert the test runner after the related target.
idx = self.project._properties["targets"].index(xcode_target)
self.project._properties["targets"].insert(
idx + 1, run_all_target
)
# Update all references to other projects, to make sure that the lists of
# remote products are complete. Otherwise, Xcode will fill them in when
# it opens the project file, which will result in unnecessary diffs.
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._other_pbxprojects.
for other_pbxproject in self.project._other_pbxprojects.keys():
self.project.AddOrGetProjectReference(other_pbxproject)
self.project.SortRemoteProductReferences()
# Give everything an ID.
self.project_file.ComputeIDs()
# Make sure that no two objects in the project file have the same ID. If
# multiple objects wind up with the same ID, upon loading the file, Xcode
# will only recognize one object (the last one in the file?) and the
# results are unpredictable.
self.project_file.EnsureNoIDCollisions()
def Write(self):
# Write the project file to a temporary location first. Xcode watches for
# changes to the project file and presents a UI sheet offering to reload
# the project when it does change. However, in some cases, especially when
# multiple projects are open or when Xcode is busy, things don't work so
# seamlessly. Sometimes, Xcode is able to detect that a project file has
# changed but can't unload it because something else is referencing it.
# To mitigate this problem, and to avoid even having Xcode present the UI
# sheet when an open project is rewritten for inconsequential changes, the
# project file is written to a temporary file in the xcodeproj directory
# first. The new temporary file is then compared to the existing project
# file, if any. If they differ, the new file replaces the old; otherwise,
# the new project file is simply deleted. Xcode properly detects a file
# being renamed over an open project file as a change and so it remains
# able to present the "project file changed" sheet under this system.
# Writing to a temporary file first also avoids the possible problem of
# Xcode rereading an incomplete project file.
(output_fd, new_pbxproj_path) = tempfile.mkstemp(
suffix=".tmp", prefix="project.pbxproj.gyp.", dir=self.path
)
try:
output_file = os.fdopen(output_fd, "w")
self.project_file.Print(output_file)
output_file.close()
pbxproj_path = os.path.join(self.path, "project.pbxproj")
same = False
try:
same = filecmp.cmp(pbxproj_path, new_pbxproj_path, False)
except OSError as e:
if e.errno != errno.ENOENT:
raise
if same:
# The new file is identical to the old one, just get rid of the new
# one.
os.unlink(new_pbxproj_path)
else:
# The new file is different from the old one, or there is no old one.
# Rename the new file to the permanent name.
#
# tempfile.mkstemp uses an overly restrictive mode, resulting in a
# file that can only be read by the owner, regardless of the umask.
# There's no reason to not respect the umask here, which means that
# an extra hoop is required to fetch it and reset the new file's mode.
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(0o77)
os.umask(umask)
os.chmod(new_pbxproj_path, 0o666 & ~umask)
os.rename(new_pbxproj_path, pbxproj_path)
except Exception:
# Don't leave turds behind. In fact, if this code was responsible for
# creating the xcodeproj directory, get rid of that too.
os.unlink(new_pbxproj_path)
if self.created_dir:
shutil.rmtree(self.path, True)
raise
def AddSourceToTarget(source, type, pbxp, xct):
# TODO(mark): Perhaps source_extensions and library_extensions can be made a
# little bit fancier.
source_extensions = ["c", "cc", "cpp", "cxx", "m", "mm", "s", "swift"]
# .o is conceptually more of a "source" than a "library," but Xcode thinks
# of "sources" as things to compile and "libraries" (or "frameworks") as
# things to link with. Adding an object file to an Xcode target's frameworks
# phase works properly.
library_extensions = ["a", "dylib", "framework", "o"]
basename = posixpath.basename(source)
(root, ext) = posixpath.splitext(basename)
if ext:
ext = ext[1:].lower()
if ext in source_extensions and type != "none":
xct.SourcesPhase().AddFile(source)
elif ext in library_extensions and type != "none":
xct.FrameworksPhase().AddFile(source)
else:
# Files that aren't added to a sources or frameworks build phase can still
# go into the project file, just not as part of a build phase.
pbxp.AddOrGetFileInRootGroup(source)
def AddResourceToTarget(resource, pbxp, xct):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
xct.ResourcesPhase().AddFile(resource)
def AddHeaderToTarget(header, pbxp, xct, is_public):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
settings = "{ATTRIBUTES = (%s, ); }" % ("Private", "Public")[is_public]
xct.HeadersPhase().AddFile(header, settings)
_xcode_variable_re = re.compile(r"(\$\((.*?)\))")
def ExpandXcodeVariables(string, expansions):
"""Expands Xcode-style $(VARIABLES) in string per the expansions dict.
In some rare cases, it is appropriate to expand Xcode variables when a
project file is generated. For any substring $(VAR) in string, if VAR is a
key in the expansions dict, $(VAR) will be replaced with expansions[VAR].
Any $(VAR) substring in string for which VAR is not a key in the expansions
dict will remain in the returned string.
"""
matches = _xcode_variable_re.findall(string)
if matches is None:
return string
matches.reverse()
for match in matches:
(to_replace, variable) = match
if variable not in expansions:
continue
replacement = expansions[variable]
string = re.sub(re.escape(to_replace), replacement, string)
return string
_xcode_define_re = re.compile(r"([\\\"\' ])")
def EscapeXcodeDefine(s):
"""We must escape the defines that we give to XCode so that it knows not to
split on spaces and to respect backslash and quote literals. However, we
must not quote the define, or Xcode will incorrectly interpret variables
especially $(inherited)."""
return re.sub(_xcode_define_re, r"\\\1", s)
def PerformBuild(data, configurations, params):
options = params["options"]
for build_file, build_file_dict in data.items():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != ".gyp":
continue
xcodeproj_path = build_file_root + options.suffix + ".xcodeproj"
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
for config in configurations:
arguments = ["xcodebuild", "-project", xcodeproj_path]
arguments += ["-configuration", config]
print(f"Building [{config}]: {arguments}")
subprocess.check_call(arguments)
def CalculateGeneratorInputInfo(params):
toplevel = params["options"].toplevel_dir
if params.get("flavor") == "ninja":
generator_dir = os.path.relpath(params["options"].generator_output or ".")
output_dir = params.get("generator_flags", {}).get("output_dir", "out")
output_dir = os.path.normpath(os.path.join(generator_dir, output_dir))
qualified_out_dir = os.path.normpath(
os.path.join(toplevel, output_dir, "gypfiles-xcode-ninja")
)
else:
output_dir = os.path.normpath(os.path.join(toplevel, "xcodebuild"))
qualified_out_dir = os.path.normpath(
os.path.join(toplevel, output_dir, "gypfiles")
)
global generator_filelist_paths
generator_filelist_paths = {
"toplevel": toplevel,
"qualified_out_dir": qualified_out_dir,
}
def GenerateOutput(target_list, target_dicts, data, params):
# Optionally configure each spec to use ninja as the external builder.
ninja_wrapper = params.get("flavor") == "ninja"
if ninja_wrapper:
(target_list, target_dicts, data) = gyp.xcode_ninja.CreateWrapper(
target_list, target_dicts, data, params
)
options = params["options"]
generator_flags = params.get("generator_flags", {})
parallel_builds = generator_flags.get("xcode_parallel_builds", True)
serialize_all_tests = generator_flags.get("xcode_serialize_all_test_runs", True)
upgrade_check_project_version = generator_flags.get(
"xcode_upgrade_check_project_version", None
)
# Format upgrade_check_project_version with leading zeros as needed.
if upgrade_check_project_version:
upgrade_check_project_version = str(upgrade_check_project_version)
while len(upgrade_check_project_version) < 4:
upgrade_check_project_version = "0" + upgrade_check_project_version
skip_excluded_files = not generator_flags.get("xcode_list_excluded_files", True)
xcode_projects = {}
for build_file, build_file_dict in data.items():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != ".gyp":
continue
xcodeproj_path = build_file_root + options.suffix + ".xcodeproj"
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
xcp = XcodeProject(build_file, xcodeproj_path, build_file_dict)
xcode_projects[build_file] = xcp
pbxp = xcp.project
# Set project-level attributes from multiple options
project_attributes = {}
if parallel_builds:
project_attributes["BuildIndependentTargetsInParallel"] = "YES"
if upgrade_check_project_version:
project_attributes["LastUpgradeCheck"] = upgrade_check_project_version
project_attributes[
"LastTestingUpgradeCheck"
] = upgrade_check_project_version
project_attributes["LastSwiftUpdateCheck"] = upgrade_check_project_version
pbxp.SetProperty("attributes", project_attributes)
# Add gyp/gypi files to project
if not generator_flags.get("standalone"):
main_group = pbxp.GetProperty("mainGroup")
build_group = gyp.xcodeproj_file.PBXGroup({"name": "Build"})
main_group.AppendChild(build_group)
for included_file in build_file_dict["included_files"]:
build_group.AddOrGetFileByPath(included_file, False)
xcode_targets = {}
xcode_target_to_target_dict = {}
for qualified_target in target_list:
[build_file, target_name, toolset] = gyp.common.ParseQualifiedTarget(
qualified_target
)
spec = target_dicts[qualified_target]
if spec["toolset"] != "target":
raise Exception(
"Multiple toolsets not supported in xcode build (target %s)"
% qualified_target
)
configuration_names = [spec["default_configuration"]]
for configuration_name in sorted(spec["configurations"].keys()):
if configuration_name not in configuration_names:
configuration_names.append(configuration_name)
xcp = xcode_projects[build_file]
pbxp = xcp.project
# Set up the configurations for the target according to the list of names
# supplied.
xccl = CreateXCConfigurationList(configuration_names)
# Create an XCTarget subclass object for the target. The type with
# "+bundle" appended will be used if the target has "mac_bundle" set.
# loadable_modules not in a mac_bundle are mapped to
# com.googlecode.gyp.xcode.bundle, a pseudo-type that xcode.py interprets
# to create a single-file mh_bundle.
_types = {
"executable": "com.apple.product-type.tool",
"loadable_module": "com.googlecode.gyp.xcode.bundle",
"shared_library": "com.apple.product-type.library.dynamic",
"static_library": "com.apple.product-type.library.static",
"mac_kernel_extension": "com.apple.product-type.kernel-extension",
"executable+bundle": "com.apple.product-type.application",
"loadable_module+bundle": "com.apple.product-type.bundle",
"loadable_module+xctest": "com.apple.product-type.bundle.unit-test",
"loadable_module+xcuitest": "com.apple.product-type.bundle.ui-testing",
"shared_library+bundle": "com.apple.product-type.framework",
"executable+extension+bundle": "com.apple.product-type.app-extension",
"executable+watch+extension+bundle":
"com.apple.product-type.watchkit-extension",
"executable+watch+bundle": "com.apple.product-type.application.watchapp",
"mac_kernel_extension+bundle": "com.apple.product-type.kernel-extension",
}
target_properties = {
"buildConfigurationList": xccl,
"name": target_name,
}
type = spec["type"]
is_xctest = int(spec.get("mac_xctest_bundle", 0))
is_xcuitest = int(spec.get("mac_xcuitest_bundle", 0))
is_bundle = int(spec.get("mac_bundle", 0)) or is_xctest
is_app_extension = int(spec.get("ios_app_extension", 0))
is_watchkit_extension = int(spec.get("ios_watchkit_extension", 0))
is_watch_app = int(spec.get("ios_watch_app", 0))
if type != "none":
type_bundle_key = type
if is_xcuitest:
type_bundle_key += "+xcuitest"
assert type == "loadable_module", (
"mac_xcuitest_bundle targets must have type loadable_module "
"(target %s)" % target_name
)
elif is_xctest:
type_bundle_key += "+xctest"
assert type == "loadable_module", (
"mac_xctest_bundle targets must have type loadable_module "
"(target %s)" % target_name
)
elif is_app_extension:
assert is_bundle, (
"ios_app_extension flag requires mac_bundle "
"(target %s)" % target_name
)
type_bundle_key += "+extension+bundle"
elif is_watchkit_extension:
assert is_bundle, (
"ios_watchkit_extension flag requires mac_bundle "
"(target %s)" % target_name
)
type_bundle_key += "+watch+extension+bundle"
elif is_watch_app:
assert is_bundle, (
"ios_watch_app flag requires mac_bundle "
"(target %s)" % target_name
)
type_bundle_key += "+watch+bundle"
elif is_bundle:
type_bundle_key += "+bundle"
xctarget_type = gyp.xcodeproj_file.PBXNativeTarget
try:
target_properties["productType"] = _types[type_bundle_key]
except KeyError as e:
gyp.common.ExceptionAppend(
e,
"-- unknown product type while " "writing target %s" % target_name,
)
raise
else:
xctarget_type = gyp.xcodeproj_file.PBXAggregateTarget
assert not is_bundle, (
'mac_bundle targets cannot have type none (target "%s")' % target_name
)
assert not is_xcuitest, (
'mac_xcuitest_bundle targets cannot have type none (target "%s")'
% target_name
)
assert not is_xctest, (
'mac_xctest_bundle targets cannot have type none (target "%s")'
% target_name
)
target_product_name = spec.get("product_name")
if target_product_name is not None:
target_properties["productName"] = target_product_name
xct = xctarget_type(
target_properties,
parent=pbxp,
force_outdir=spec.get("product_dir"),
force_prefix=spec.get("product_prefix"),
force_extension=spec.get("product_extension"),
)
pbxp.AppendProperty("targets", xct)
xcode_targets[qualified_target] = xct
xcode_target_to_target_dict[xct] = spec
spec_actions = spec.get("actions", [])
spec_rules = spec.get("rules", [])
# Xcode has some "issues" with checking dependencies for the "Compile
# sources" step with any source files/headers generated by actions/rules.
# To work around this, if a target is building anything directly (not
# type "none"), then a second target is used to run the GYP actions/rules
# and is made a dependency of this target. This way the work is done
# before the dependency checks for what should be recompiled.
support_xct = None
# The Xcode "issues" don't affect xcode-ninja builds, since the dependency
# logic all happens in ninja. Don't bother creating the extra targets in
# that case.
if type != "none" and (spec_actions or spec_rules) and not ninja_wrapper:
support_xccl = CreateXCConfigurationList(configuration_names)
support_target_suffix = generator_flags.get(
"support_target_suffix", " Support"
)
support_target_properties = {
"buildConfigurationList": support_xccl,
"name": target_name + support_target_suffix,
}
if target_product_name:
support_target_properties["productName"] = (
target_product_name + " Support"
)
support_xct = gyp.xcodeproj_file.PBXAggregateTarget(
support_target_properties, parent=pbxp
)
pbxp.AppendProperty("targets", support_xct)
xct.AddDependency(support_xct)
# Hang the support target off the main target so it can be tested/found
# by the generator during Finalize.
xct.support_target = support_xct
prebuild_index = 0
# Add custom shell script phases for "actions" sections.
for action in spec_actions:
# There's no need to write anything into the script to ensure that the
# output directories already exist, because Xcode will look at the
# declared outputs and automatically ensure that they exist for us.
# Do we have a message to print when this action runs?
message = action.get("message")
if message:
message = "echo note: " + gyp.common.EncodePOSIXShellArgument(message)
else:
message = ""
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(action["action"])
# Convert Xcode-type variable references to sh-compatible environment
# variable references.
message_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(message)
action_string_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
action_string
)
script = ""
# Include the optional message
if message_sh:
script += message_sh + "\n"
# Be sure the script runs in exec, and that if exec fails, the script
# exits signalling an error.
script += "exec " + action_string_sh + "\nexit 1\n"
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
{
"inputPaths": action["inputs"],
"name": 'Action "' + action["action_name"] + '"',
"outputPaths": action["outputs"],
"shellScript": script,
"showEnvVarsInLog": 0,
}
)
if support_xct:
support_xct.AppendProperty("buildPhases", ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move into xcodeproj_file
# itself.
xct._properties["buildPhases"].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# TODO(mark): Should verify that at most one of these is specified.
if int(action.get("process_outputs_as_sources", False)):
for output in action["outputs"]:
AddSourceToTarget(output, type, pbxp, xct)
if int(action.get("process_outputs_as_mac_bundle_resources", False)):
for output in action["outputs"]:
AddResourceToTarget(output, pbxp, xct)
# tgt_mac_bundle_resources holds the list of bundle resources so
# the rule processing can check against it.
if is_bundle:
tgt_mac_bundle_resources = spec.get("mac_bundle_resources", [])
else:
tgt_mac_bundle_resources = []
# Add custom shell script phases driving "make" for "rules" sections.
#
# Xcode's built-in rule support is almost powerful enough to use directly,
# but there are a few significant deficiencies that render them unusable.
# There are workarounds for some of its inadequacies, but in aggregate,
# the workarounds added complexity to the generator, and some workarounds
# actually require input files to be crafted more carefully than I'd like.
# Consequently, until Xcode rules are made more capable, "rules" input
# sections will be handled in Xcode output by shell script build phases
# performed prior to the compilation phase.
#
# The following problems with Xcode rules were found. The numbers are
# Apple radar IDs. I hope that these shortcomings are addressed, I really
# liked having the rules handled directly in Xcode during the period that
# I was prototyping this.
#
# 6588600 Xcode compiles custom script rule outputs too soon, compilation
# fails. This occurs when rule outputs from distinct inputs are
# interdependent. The only workaround is to put rules and their
# inputs in a separate target from the one that compiles the rule
# outputs. This requires input file cooperation and it means that
# process_outputs_as_sources is unusable.
# 6584932 Need to declare that custom rule outputs should be excluded from
# compilation. A possible workaround is to lie to Xcode about a
# rule's output, giving it a dummy file it doesn't know how to
# compile. The rule action script would need to touch the dummy.
# 6584839 I need a way to declare additional inputs to a custom rule.
# A possible workaround is a shell script phase prior to
# compilation that touches a rule's primary input files if any
# would-be additional inputs are newer than the output. Modifying
# the source tree - even just modification times - feels dirty.
# 6564240 Xcode "custom script" build rules always dump all environment
# variables. This is a low-prioroty problem and is not a
# show-stopper.
rules_by_ext = {}
for rule in spec_rules:
rules_by_ext[rule["extension"]] = rule
# First, some definitions:
#
# A "rule source" is a file that was listed in a target's "sources"
# list and will have a rule applied to it on the basis of matching the
# rule's "extensions" attribute. Rule sources are direct inputs to
# rules.
#
# Rule definitions may specify additional inputs in their "inputs"
# attribute. These additional inputs are used for dependency tracking
# purposes.
#
# A "concrete output" is a rule output with input-dependent variables
# resolved. For example, given a rule with:
# 'extension': 'ext', 'outputs': ['$(INPUT_FILE_BASE).cc'],
# if the target's "sources" list contained "one.ext" and "two.ext",
# the "concrete output" for rule input "two.ext" would be "two.cc". If
# a rule specifies multiple outputs, each input file that the rule is
# applied to will have the same number of concrete outputs.
#
# If any concrete outputs are outdated or missing relative to their
# corresponding rule_source or to any specified additional input, the
# rule action must be performed to generate the concrete outputs.
# concrete_outputs_by_rule_source will have an item at the same index
# as the rule['rule_sources'] that it corresponds to. Each item is a
# list of all of the concrete outputs for the rule_source.
concrete_outputs_by_rule_source = []
# concrete_outputs_all is a flat list of all concrete outputs that this
# rule is able to produce, given the known set of input files
# (rule_sources) that apply to it.
concrete_outputs_all = []
# messages & actions are keyed by the same indices as rule['rule_sources']
# and concrete_outputs_by_rule_source. They contain the message and
# action to perform after resolving input-dependent variables. The
# message is optional, in which case None is stored for each rule source.
messages = []
actions = []
for rule_source in rule.get("rule_sources", []):
rule_source_dirname, rule_source_basename = posixpath.split(rule_source)
(rule_source_root, rule_source_ext) = posixpath.splitext(
rule_source_basename
)
# These are the same variable names that Xcode uses for its own native
# rule support. Because Xcode's rule engine is not being used, they
# need to be expanded as they are written to the makefile.
rule_input_dict = {
"INPUT_FILE_BASE": rule_source_root,
"INPUT_FILE_SUFFIX": rule_source_ext,
"INPUT_FILE_NAME": rule_source_basename,
"INPUT_FILE_PATH": rule_source,
"INPUT_FILE_DIRNAME": rule_source_dirname,
}
concrete_outputs_for_this_rule_source = []
for output in rule.get("outputs", []):
# Fortunately, Xcode and make both use $(VAR) format for their
# variables, so the expansion is the only transformation necessary.
# Any remaining $(VAR)-type variables in the string can be given
# directly to make, which will pick up the correct settings from
# what Xcode puts into the environment.
concrete_output = ExpandXcodeVariables(output, rule_input_dict)
concrete_outputs_for_this_rule_source.append(concrete_output)
# Add all concrete outputs to the project.
pbxp.AddOrGetFileInRootGroup(concrete_output)
concrete_outputs_by_rule_source.append(
concrete_outputs_for_this_rule_source
)
concrete_outputs_all.extend(concrete_outputs_for_this_rule_source)
# TODO(mark): Should verify that at most one of these is specified.
if int(rule.get("process_outputs_as_sources", False)):
for output in concrete_outputs_for_this_rule_source:
AddSourceToTarget(output, type, pbxp, xct)
# If the file came from the mac_bundle_resources list or if the rule
# is marked to process outputs as bundle resource, do so.
was_mac_bundle_resource = rule_source in tgt_mac_bundle_resources
if was_mac_bundle_resource or int(
rule.get("process_outputs_as_mac_bundle_resources", False)
):
for output in concrete_outputs_for_this_rule_source:
AddResourceToTarget(output, pbxp, xct)
# Do we have a message to print when this rule runs?
message = rule.get("message")
if message:
message = gyp.common.EncodePOSIXShellArgument(message)
message = ExpandXcodeVariables(message, rule_input_dict)
messages.append(message)
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(rule["action"])
action = ExpandXcodeVariables(action_string, rule_input_dict)
actions.append(action)
if len(concrete_outputs_all) > 0:
# TODO(mark): There's a possibility for collision here. Consider
# target "t" rule "A_r" and target "t_A" rule "r".
makefile_name = "%s.make" % re.sub(
"[^a-zA-Z0-9_]", "_", "{}_{}".format(target_name, rule["rule_name"])
)
makefile_path = os.path.join(
xcode_projects[build_file].path, makefile_name
)
# TODO(mark): try/close? Write to a temporary file and swap it only
# if it's got changes?
makefile = open(makefile_path, "w")
# make will build the first target in the makefile by default. By
# convention, it's called "all". List all (or at least one)
# concrete output for each rule source as a prerequisite of the "all"
# target.
makefile.write("all: \\\n")
for concrete_output_index, concrete_output_by_rule_source in enumerate(
concrete_outputs_by_rule_source
):
# Only list the first (index [0]) concrete output of each input
# in the "all" target. Otherwise, a parallel make (-j > 1) would
# attempt to process each input multiple times simultaneously.
# Otherwise, "all" could just contain the entire list of
# concrete_outputs_all.
concrete_output = concrete_output_by_rule_source[0]
if (
concrete_output_index
== len(concrete_outputs_by_rule_source) - 1
):
eol = ""
else:
eol = " \\"
makefile.write(f" {concrete_output}{eol}\n")
for (rule_source, concrete_outputs, message, action) in zip(
rule["rule_sources"],
concrete_outputs_by_rule_source,
messages,
actions,
):
makefile.write("\n")
# Add a rule that declares it can build each concrete output of a
# rule source. Collect the names of the directories that are
# required.
concrete_output_dirs = []
for concrete_output_index, concrete_output in enumerate(
concrete_outputs
):
if concrete_output_index == 0:
bol = ""
else:
bol = " "
makefile.write(f"{bol}{concrete_output} \\\n")
concrete_output_dir = posixpath.dirname(concrete_output)
if (
concrete_output_dir
and concrete_output_dir not in concrete_output_dirs
):
concrete_output_dirs.append(concrete_output_dir)
makefile.write(" : \\\n")
# The prerequisites for this rule are the rule source itself and
# the set of additional rule inputs, if any.
prerequisites = [rule_source]
prerequisites.extend(rule.get("inputs", []))
for prerequisite_index, prerequisite in enumerate(prerequisites):
if prerequisite_index == len(prerequisites) - 1:
eol = ""
else:
eol = " \\"
makefile.write(f" {prerequisite}{eol}\n")
# Make sure that output directories exist before executing the rule
# action.
if len(concrete_output_dirs) > 0:
makefile.write(
'\t@mkdir -p "%s"\n' % '" "'.join(concrete_output_dirs)
)
# The rule message and action have already had
# the necessary variable substitutions performed.
if message:
# Mark it with note: so Xcode picks it up in build output.
makefile.write("\t@echo note: %s\n" % message)
makefile.write("\t%s\n" % action)
makefile.close()
# It might be nice to ensure that needed output directories exist
# here rather than in each target in the Makefile, but that wouldn't
# work if there ever was a concrete output that had an input-dependent
# variable anywhere other than in the leaf position.
# Don't declare any inputPaths or outputPaths. If they're present,
# Xcode will provide a slight optimization by only running the script
# phase if any output is missing or outdated relative to any input.
# Unfortunately, it will also assume that all outputs are touched by
# the script, and if the outputs serve as files in a compilation
# phase, they will be unconditionally rebuilt. Since make might not
# rebuild everything that could be declared here as an output, this
# extra compilation activity is unnecessary. With inputPaths and
# outputPaths not supplied, make will always be called, but it knows
# enough to not do anything when everything is up-to-date.
# To help speed things up, pass -j COUNT to make so it does some work
# in parallel. Don't use ncpus because Xcode will build ncpus targets
# in parallel and if each target happens to have a rules step, there
# would be ncpus^2 things going. With a machine that has 2 quad-core
# Xeons, a build can quickly run out of processes based on
# scheduling/other tasks, and randomly failing builds are no good.
script = (
"""JOB_COUNT="$(/usr/sbin/sysctl -n hw.ncpu)"
if [ "${JOB_COUNT}" -gt 4 ]; then
JOB_COUNT=4
fi
exec xcrun make -f "${PROJECT_FILE_PATH}/%s" -j "${JOB_COUNT}"
exit 1
"""
% makefile_name
)
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
{
"name": 'Rule "' + rule["rule_name"] + '"',
"shellScript": script,
"showEnvVarsInLog": 0,
}
)
if support_xct:
support_xct.AppendProperty("buildPhases", ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move
# into xcodeproj_file itself.
xct._properties["buildPhases"].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# Extra rule inputs also go into the project file. Concrete outputs were
# already added when they were computed.
groups = ["inputs", "inputs_excluded"]
if skip_excluded_files:
groups = [x for x in groups if not x.endswith("_excluded")]
for group in groups:
for item in rule.get(group, []):
pbxp.AddOrGetFileInRootGroup(item)
# Add "sources".
for source in spec.get("sources", []):
(source_root, source_extension) = posixpath.splitext(source)
if source_extension[1:] not in rules_by_ext:
# AddSourceToTarget will add the file to a root group if it's not
# already there.
AddSourceToTarget(source, type, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(source)
# Add "mac_bundle_resources" and "mac_framework_private_headers" if
# it's a bundle of any type.
if is_bundle:
for resource in tgt_mac_bundle_resources:
(resource_root, resource_extension) = posixpath.splitext(resource)
if resource_extension[1:] not in rules_by_ext:
AddResourceToTarget(resource, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(resource)
for header in spec.get("mac_framework_private_headers", []):
AddHeaderToTarget(header, pbxp, xct, False)
# Add "mac_framework_headers". These can be valid for both frameworks
# and static libraries.
if is_bundle or type == "static_library":
for header in spec.get("mac_framework_headers", []):
AddHeaderToTarget(header, pbxp, xct, True)
# Add "copies".
pbxcp_dict = {}
for copy_group in spec.get("copies", []):
dest = copy_group["destination"]
if dest[0] not in ("/", "$"):
# Relative paths are relative to $(SRCROOT).
dest = "$(SRCROOT)/" + dest
code_sign = int(copy_group.get("xcode_code_sign", 0))
settings = (None, "{ATTRIBUTES = (CodeSignOnCopy, ); }")[code_sign]
# Coalesce multiple "copies" sections in the same target with the same
# "destination" property into the same PBXCopyFilesBuildPhase, otherwise
# they'll wind up with ID collisions.
pbxcp = pbxcp_dict.get(dest, None)
if pbxcp is None:
pbxcp = gyp.xcodeproj_file.PBXCopyFilesBuildPhase(
{"name": "Copy to " + copy_group["destination"]}, parent=xct
)
pbxcp.SetDestination(dest)
# TODO(mark): The usual comment about this knowing too much about
# gyp.xcodeproj_file internals applies.
xct._properties["buildPhases"].insert(prebuild_index, pbxcp)
pbxcp_dict[dest] = pbxcp
for file in copy_group["files"]:
pbxcp.AddFile(file, settings)
# Excluded files can also go into the project file.
if not skip_excluded_files:
for key in [
"sources",
"mac_bundle_resources",
"mac_framework_headers",
"mac_framework_private_headers",
]:
excluded_key = key + "_excluded"
for item in spec.get(excluded_key, []):
pbxp.AddOrGetFileInRootGroup(item)
# So can "inputs" and "outputs" sections of "actions" groups.
groups = ["inputs", "inputs_excluded", "outputs", "outputs_excluded"]
if skip_excluded_files:
groups = [x for x in groups if not x.endswith("_excluded")]
for action in spec.get("actions", []):
for group in groups:
for item in action.get(group, []):
# Exclude anything in BUILT_PRODUCTS_DIR. They're products, not
# sources.
if not item.startswith("$(BUILT_PRODUCTS_DIR)/"):
pbxp.AddOrGetFileInRootGroup(item)
for postbuild in spec.get("postbuilds", []):
action_string_sh = gyp.common.EncodePOSIXShellList(postbuild["action"])
script = "exec " + action_string_sh + "\nexit 1\n"
# Make the postbuild step depend on the output of ld or ar from this
# target. Apparently putting the script step after the link step isn't
# sufficient to ensure proper ordering in all cases. With an input
# declared but no outputs, the script step should run every time, as
# desired.
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
{
"inputPaths": ["$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)"],
"name": 'Postbuild "' + postbuild["postbuild_name"] + '"',
"shellScript": script,
"showEnvVarsInLog": 0,
}
)
xct.AppendProperty("buildPhases", ssbp)
# Add dependencies before libraries, because adding a dependency may imply
# adding a library. It's preferable to keep dependencies listed first
# during a link phase so that they can override symbols that would
# otherwise be provided by libraries, which will usually include system
# libraries. On some systems, ld is finicky and even requires the
# libraries to be ordered in such a way that unresolved symbols in
# earlier-listed libraries may only be resolved by later-listed libraries.
# The Mac linker doesn't work that way, but other platforms do, and so
# their linker invocations need to be constructed in this way. There's
# no compelling reason for Xcode's linker invocations to differ.
if "dependencies" in spec:
for dependency in spec["dependencies"]:
xct.AddDependency(xcode_targets[dependency])
# The support project also gets the dependencies (in case they are
# needed for the actions/rules to work).
if support_xct:
support_xct.AddDependency(xcode_targets[dependency])
if "libraries" in spec:
for library in spec["libraries"]:
xct.FrameworksPhase().AddFile(library)
# Add the library's directory to LIBRARY_SEARCH_PATHS if necessary.
# I wish Xcode handled this automatically.
library_dir = posixpath.dirname(library)
if library_dir not in xcode_standard_library_dirs and (
not xct.HasBuildSetting(_library_search_paths_var)
or library_dir not in xct.GetBuildSetting(_library_search_paths_var)
):
xct.AppendBuildSetting(_library_search_paths_var, library_dir)
for configuration_name in configuration_names:
configuration = spec["configurations"][configuration_name]
xcbc = xct.ConfigurationNamed(configuration_name)
for include_dir in configuration.get("mac_framework_dirs", []):
xcbc.AppendBuildSetting("FRAMEWORK_SEARCH_PATHS", include_dir)
for include_dir in configuration.get("include_dirs", []):
xcbc.AppendBuildSetting("HEADER_SEARCH_PATHS", include_dir)
for library_dir in configuration.get("library_dirs", []):
if library_dir not in xcode_standard_library_dirs and (
not xcbc.HasBuildSetting(_library_search_paths_var)
or library_dir
not in xcbc.GetBuildSetting(_library_search_paths_var)
):
xcbc.AppendBuildSetting(_library_search_paths_var, library_dir)
if "defines" in configuration:
for define in configuration["defines"]:
set_define = EscapeXcodeDefine(define)
xcbc.AppendBuildSetting("GCC_PREPROCESSOR_DEFINITIONS", set_define)
if "xcode_settings" in configuration:
for xck, xcv in configuration["xcode_settings"].items():
xcbc.SetBuildSetting(xck, xcv)
if "xcode_config_file" in configuration:
config_ref = pbxp.AddOrGetFileInRootGroup(
configuration["xcode_config_file"]
)
xcbc.SetBaseConfiguration(config_ref)
build_files = []
for build_file, build_file_dict in data.items():
if build_file.endswith(".gyp"):
build_files.append(build_file)
for build_file in build_files:
xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests)
for build_file in build_files:
xcode_projects[build_file].Finalize2(xcode_targets, xcode_target_to_target_dict)
for build_file in build_files:
xcode_projects[build_file].Write()
node-gyp-9.3.0/gyp/pylib/gyp/generator/xcode_test.py 0000664 0000000 0000000 00000001240 14321173220 0022453 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the xcode.py file. """
import gyp.generator.xcode as xcode
import unittest
import sys
class TestEscapeXcodeDefine(unittest.TestCase):
if sys.platform == "darwin":
def test_InheritedRemainsUnescaped(self):
self.assertEqual(xcode.EscapeXcodeDefine("$(inherited)"), "$(inherited)")
def test_Escaping(self):
self.assertEqual(xcode.EscapeXcodeDefine('a b"c\\'), 'a\\ b\\"c\\\\')
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/input.py 0000664 0000000 0000000 00000367377 14321173220 0017515 0 ustar 00root root 0000000 0000000 # Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import ast
import gyp.common
import gyp.simple_copy
import multiprocessing
import os.path
import re
import shlex
import signal
import subprocess
import sys
import threading
import traceback
from distutils.version import StrictVersion
from gyp.common import GypError
from gyp.common import OrderedSet
# A list of types that are treated as linkable.
linkable_types = [
"executable",
"shared_library",
"loadable_module",
"mac_kernel_extension",
"windows_driver",
]
# A list of sections that contain links to other targets.
dependency_sections = ["dependencies", "export_dependent_settings"]
# base_path_sections is a list of sections defined by GYP that contain
# pathnames. The generators can provide more keys, the two lists are merged
# into path_sections, but you should call IsPathSection instead of using either
# list directly.
base_path_sections = [
"destination",
"files",
"include_dirs",
"inputs",
"libraries",
"outputs",
"sources",
]
path_sections = set()
# These per-process dictionaries are used to cache build file data when loading
# in parallel mode.
per_process_data = {}
per_process_aux_data = {}
def IsPathSection(section):
# If section ends in one of the '=+?!' characters, it's applied to a section
# without the trailing characters. '/' is notably absent from this list,
# because there's no way for a regular expression to be treated as a path.
while section and section[-1:] in "=+?!":
section = section[:-1]
if section in path_sections:
return True
# Sections matching the regexp '_(dir|file|path)s?$' are also
# considered PathSections. Using manual string matching since that
# is much faster than the regexp and this can be called hundreds of
# thousands of times so micro performance matters.
if "_" in section:
tail = section[-6:]
if tail[-1] == "s":
tail = tail[:-1]
if tail[-5:] in ("_file", "_path"):
return True
return tail[-4:] == "_dir"
return False
# base_non_configuration_keys is a list of key names that belong in the target
# itself and should not be propagated into its configurations. It is merged
# with a list that can come from the generator to
# create non_configuration_keys.
base_non_configuration_keys = [
# Sections that must exist inside targets and not configurations.
"actions",
"configurations",
"copies",
"default_configuration",
"dependencies",
"dependencies_original",
"libraries",
"postbuilds",
"product_dir",
"product_extension",
"product_name",
"product_prefix",
"rules",
"run_as",
"sources",
"standalone_static_library",
"suppress_wildcard",
"target_name",
"toolset",
"toolsets",
"type",
# Sections that can be found inside targets or configurations, but that
# should not be propagated from targets into their configurations.
"variables",
]
non_configuration_keys = []
# Keys that do not belong inside a configuration dictionary.
invalid_configuration_keys = [
"actions",
"all_dependent_settings",
"configurations",
"dependencies",
"direct_dependent_settings",
"libraries",
"link_settings",
"sources",
"standalone_static_library",
"target_name",
"type",
]
# Controls whether or not the generator supports multiple toolsets.
multiple_toolsets = False
# Paths for converting filelist paths to output paths: {
# toplevel,
# qualified_output_dir,
# }
generator_filelist_paths = None
def GetIncludedBuildFiles(build_file_path, aux_data, included=None):
"""Return a list of all build files included into build_file_path.
The returned list will contain build_file_path as well as all other files
that it included, either directly or indirectly. Note that the list may
contain files that were included into a conditional section that evaluated
to false and was not merged into build_file_path's dict.
aux_data is a dict containing a key for each build file or included build
file. Those keys provide access to dicts whose "included" keys contain
lists of all other files included by the build file.
included should be left at its default None value by external callers. It
is used for recursion.
The returned list will not contain any duplicate entries. Each build file
in the list will be relative to the current directory.
"""
if included is None:
included = []
if build_file_path in included:
return included
included.append(build_file_path)
for included_build_file in aux_data[build_file_path].get("included", []):
GetIncludedBuildFiles(included_build_file, aux_data, included)
return included
def CheckedEval(file_contents):
"""Return the eval of a gyp file.
The gyp file is restricted to dictionaries and lists only, and
repeated keys are not allowed.
Note that this is slower than eval() is.
"""
syntax_tree = ast.parse(file_contents)
assert isinstance(syntax_tree, ast.Module)
c1 = syntax_tree.body
assert len(c1) == 1
c2 = c1[0]
assert isinstance(c2, ast.Expr)
return CheckNode(c2.value, [])
def CheckNode(node, keypath):
if isinstance(node, ast.Dict):
dict = {}
for key, value in zip(node.keys, node.values):
assert isinstance(key, ast.Str)
key = key.s
if key in dict:
raise GypError(
"Key '"
+ key
+ "' repeated at level "
+ repr(len(keypath) + 1)
+ " with key path '"
+ ".".join(keypath)
+ "'"
)
kp = list(keypath) # Make a copy of the list for descending this node.
kp.append(key)
dict[key] = CheckNode(value, kp)
return dict
elif isinstance(node, ast.List):
children = []
for index, child in enumerate(node.elts):
kp = list(keypath) # Copy list.
kp.append(repr(index))
children.append(CheckNode(child, kp))
return children
elif isinstance(node, ast.Str):
return node.s
else:
raise TypeError(
"Unknown AST node at key path '" + ".".join(keypath) + "': " + repr(node)
)
def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check):
if build_file_path in data:
return data[build_file_path]
if os.path.exists(build_file_path):
build_file_contents = open(build_file_path, encoding='utf-8').read()
else:
raise GypError(f"{build_file_path} not found (cwd: {os.getcwd()})")
build_file_data = None
try:
if check:
build_file_data = CheckedEval(build_file_contents)
else:
build_file_data = eval(build_file_contents, {"__builtins__": {}}, None)
except SyntaxError as e:
e.filename = build_file_path
raise
except Exception as e:
gyp.common.ExceptionAppend(e, "while reading " + build_file_path)
raise
if type(build_file_data) is not dict:
raise GypError("%s does not evaluate to a dictionary." % build_file_path)
data[build_file_path] = build_file_data
aux_data[build_file_path] = {}
# Scan for includes and merge them in.
if "skip_includes" not in build_file_data or not build_file_data["skip_includes"]:
try:
if is_target:
LoadBuildFileIncludesIntoDict(
build_file_data, build_file_path, data, aux_data, includes, check
)
else:
LoadBuildFileIncludesIntoDict(
build_file_data, build_file_path, data, aux_data, None, check
)
except Exception as e:
gyp.common.ExceptionAppend(
e, "while reading includes of " + build_file_path
)
raise
return build_file_data
def LoadBuildFileIncludesIntoDict(
subdict, subdict_path, data, aux_data, includes, check
):
includes_list = []
if includes is not None:
includes_list.extend(includes)
if "includes" in subdict:
for include in subdict["includes"]:
# "include" is specified relative to subdict_path, so compute the real
# path to include by appending the provided "include" to the directory
# in which subdict_path resides.
relative_include = os.path.normpath(
os.path.join(os.path.dirname(subdict_path), include)
)
includes_list.append(relative_include)
# Unhook the includes list, it's no longer needed.
del subdict["includes"]
# Merge in the included files.
for include in includes_list:
if "included" not in aux_data[subdict_path]:
aux_data[subdict_path]["included"] = []
aux_data[subdict_path]["included"].append(include)
gyp.DebugOutput(gyp.DEBUG_INCLUDES, "Loading Included File: '%s'", include)
MergeDicts(
subdict,
LoadOneBuildFile(include, data, aux_data, None, False, check),
subdict_path,
include,
)
# Recurse into subdictionaries.
for k, v in subdict.items():
if type(v) is dict:
LoadBuildFileIncludesIntoDict(v, subdict_path, data, aux_data, None, check)
elif type(v) is list:
LoadBuildFileIncludesIntoList(v, subdict_path, data, aux_data, check)
# This recurses into lists so that it can look for dicts.
def LoadBuildFileIncludesIntoList(sublist, sublist_path, data, aux_data, check):
for item in sublist:
if type(item) is dict:
LoadBuildFileIncludesIntoDict(
item, sublist_path, data, aux_data, None, check
)
elif type(item) is list:
LoadBuildFileIncludesIntoList(item, sublist_path, data, aux_data, check)
# Processes toolsets in all the targets. This recurses into condition entries
# since they can contain toolsets as well.
def ProcessToolsetsInDict(data):
if "targets" in data:
target_list = data["targets"]
new_target_list = []
for target in target_list:
# If this target already has an explicit 'toolset', and no 'toolsets'
# list, don't modify it further.
if "toolset" in target and "toolsets" not in target:
new_target_list.append(target)
continue
if multiple_toolsets:
toolsets = target.get("toolsets", ["target"])
else:
toolsets = ["target"]
# Make sure this 'toolsets' definition is only processed once.
if "toolsets" in target:
del target["toolsets"]
if len(toolsets) > 0:
# Optimization: only do copies if more than one toolset is specified.
for build in toolsets[1:]:
new_target = gyp.simple_copy.deepcopy(target)
new_target["toolset"] = build
new_target_list.append(new_target)
target["toolset"] = toolsets[0]
new_target_list.append(target)
data["targets"] = new_target_list
if "conditions" in data:
for condition in data["conditions"]:
if type(condition) is list:
for condition_dict in condition[1:]:
if type(condition_dict) is dict:
ProcessToolsetsInDict(condition_dict)
# TODO(mark): I don't love this name. It just means that it's going to load
# a build file that contains targets and is expected to provide a targets dict
# that contains the targets...
def LoadTargetBuildFile(
build_file_path,
data,
aux_data,
variables,
includes,
depth,
check,
load_dependencies,
):
# If depth is set, predefine the DEPTH variable to be a relative path from
# this build file's directory to the directory identified by depth.
if depth:
# TODO(dglazkov) The backslash/forward-slash replacement at the end is a
# temporary measure. This should really be addressed by keeping all paths
# in POSIX until actual project generation.
d = gyp.common.RelativePath(depth, os.path.dirname(build_file_path))
if d == "":
variables["DEPTH"] = "."
else:
variables["DEPTH"] = d.replace("\\", "/")
# The 'target_build_files' key is only set when loading target build files in
# the non-parallel code path, where LoadTargetBuildFile is called
# recursively. In the parallel code path, we don't need to check whether the
# |build_file_path| has already been loaded, because the 'scheduled' set in
# ParallelState guarantees that we never load the same |build_file_path|
# twice.
if "target_build_files" in data:
if build_file_path in data["target_build_files"]:
# Already loaded.
return False
data["target_build_files"].add(build_file_path)
gyp.DebugOutput(
gyp.DEBUG_INCLUDES, "Loading Target Build File '%s'", build_file_path
)
build_file_data = LoadOneBuildFile(
build_file_path, data, aux_data, includes, True, check
)
# Store DEPTH for later use in generators.
build_file_data["_DEPTH"] = depth
# Set up the included_files key indicating which .gyp files contributed to
# this target dict.
if "included_files" in build_file_data:
raise GypError(build_file_path + " must not contain included_files key")
included = GetIncludedBuildFiles(build_file_path, aux_data)
build_file_data["included_files"] = []
for included_file in included:
# included_file is relative to the current directory, but it needs to
# be made relative to build_file_path's directory.
included_relative = gyp.common.RelativePath(
included_file, os.path.dirname(build_file_path)
)
build_file_data["included_files"].append(included_relative)
# Do a first round of toolsets expansion so that conditions can be defined
# per toolset.
ProcessToolsetsInDict(build_file_data)
# Apply "pre"/"early" variable expansions and condition evaluations.
ProcessVariablesAndConditionsInDict(
build_file_data, PHASE_EARLY, variables, build_file_path
)
# Since some toolsets might have been defined conditionally, perform
# a second round of toolsets expansion now.
ProcessToolsetsInDict(build_file_data)
# Look at each project's target_defaults dict, and merge settings into
# targets.
if "target_defaults" in build_file_data:
if "targets" not in build_file_data:
raise GypError("Unable to find targets in build file %s" % build_file_path)
index = 0
while index < len(build_file_data["targets"]):
# This procedure needs to give the impression that target_defaults is
# used as defaults, and the individual targets inherit from that.
# The individual targets need to be merged into the defaults. Make
# a deep copy of the defaults for each target, merge the target dict
# as found in the input file into that copy, and then hook up the
# copy with the target-specific data merged into it as the replacement
# target dict.
old_target_dict = build_file_data["targets"][index]
new_target_dict = gyp.simple_copy.deepcopy(
build_file_data["target_defaults"]
)
MergeDicts(
new_target_dict, old_target_dict, build_file_path, build_file_path
)
build_file_data["targets"][index] = new_target_dict
index += 1
# No longer needed.
del build_file_data["target_defaults"]
# Look for dependencies. This means that dependency resolution occurs
# after "pre" conditionals and variable expansion, but before "post" -
# in other words, you can't put a "dependencies" section inside a "post"
# conditional within a target.
dependencies = []
if "targets" in build_file_data:
for target_dict in build_file_data["targets"]:
if "dependencies" not in target_dict:
continue
for dependency in target_dict["dependencies"]:
dependencies.append(
gyp.common.ResolveTarget(build_file_path, dependency, None)[0]
)
if load_dependencies:
for dependency in dependencies:
try:
LoadTargetBuildFile(
dependency,
data,
aux_data,
variables,
includes,
depth,
check,
load_dependencies,
)
except Exception as e:
gyp.common.ExceptionAppend(
e, "while loading dependencies of %s" % build_file_path
)
raise
else:
return (build_file_path, dependencies)
def CallLoadTargetBuildFile(
global_flags,
build_file_path,
variables,
includes,
depth,
check,
generator_input_info,
):
"""Wrapper around LoadTargetBuildFile for parallel processing.
This wrapper is used when LoadTargetBuildFile is executed in
a worker process.
"""
try:
signal.signal(signal.SIGINT, signal.SIG_IGN)
# Apply globals so that the worker process behaves the same.
for key, value in global_flags.items():
globals()[key] = value
SetGeneratorGlobals(generator_input_info)
result = LoadTargetBuildFile(
build_file_path,
per_process_data,
per_process_aux_data,
variables,
includes,
depth,
check,
False,
)
if not result:
return result
(build_file_path, dependencies) = result
# We can safely pop the build_file_data from per_process_data because it
# will never be referenced by this process again, so we don't need to keep
# it in the cache.
build_file_data = per_process_data.pop(build_file_path)
# This gets serialized and sent back to the main process via a pipe.
# It's handled in LoadTargetBuildFileCallback.
return (build_file_path, build_file_data, dependencies)
except GypError as e:
sys.stderr.write("gyp: %s\n" % e)
return None
except Exception as e:
print("Exception:", e, file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
return None
class ParallelProcessingError(Exception):
pass
class ParallelState:
"""Class to keep track of state when processing input files in parallel.
If build files are loaded in parallel, use this to keep track of
state during farming out and processing parallel jobs. It's stored
in a global so that the callback function can have access to it.
"""
def __init__(self):
# The multiprocessing pool.
self.pool = None
# The condition variable used to protect this object and notify
# the main loop when there might be more data to process.
self.condition = None
# The "data" dict that was passed to LoadTargetBuildFileParallel
self.data = None
# The number of parallel calls outstanding; decremented when a response
# was received.
self.pending = 0
# The set of all build files that have been scheduled, so we don't
# schedule the same one twice.
self.scheduled = set()
# A list of dependency build file paths that haven't been scheduled yet.
self.dependencies = []
# Flag to indicate if there was an error in a child process.
self.error = False
def LoadTargetBuildFileCallback(self, result):
"""Handle the results of running LoadTargetBuildFile in another process.
"""
self.condition.acquire()
if not result:
self.error = True
self.condition.notify()
self.condition.release()
return
(build_file_path0, build_file_data0, dependencies0) = result
self.data[build_file_path0] = build_file_data0
self.data["target_build_files"].add(build_file_path0)
for new_dependency in dependencies0:
if new_dependency not in self.scheduled:
self.scheduled.add(new_dependency)
self.dependencies.append(new_dependency)
self.pending -= 1
self.condition.notify()
self.condition.release()
def LoadTargetBuildFilesParallel(
build_files, data, variables, includes, depth, check, generator_input_info
):
parallel_state = ParallelState()
parallel_state.condition = threading.Condition()
# Make copies of the build_files argument that we can modify while working.
parallel_state.dependencies = list(build_files)
parallel_state.scheduled = set(build_files)
parallel_state.pending = 0
parallel_state.data = data
try:
parallel_state.condition.acquire()
while parallel_state.dependencies or parallel_state.pending:
if parallel_state.error:
break
if not parallel_state.dependencies:
parallel_state.condition.wait()
continue
dependency = parallel_state.dependencies.pop()
parallel_state.pending += 1
global_flags = {
"path_sections": globals()["path_sections"],
"non_configuration_keys": globals()["non_configuration_keys"],
"multiple_toolsets": globals()["multiple_toolsets"],
}
if not parallel_state.pool:
parallel_state.pool = multiprocessing.Pool(multiprocessing.cpu_count())
parallel_state.pool.apply_async(
CallLoadTargetBuildFile,
args=(
global_flags,
dependency,
variables,
includes,
depth,
check,
generator_input_info,
),
callback=parallel_state.LoadTargetBuildFileCallback,
)
except KeyboardInterrupt as e:
parallel_state.pool.terminate()
raise e
parallel_state.condition.release()
parallel_state.pool.close()
parallel_state.pool.join()
parallel_state.pool = None
if parallel_state.error:
sys.exit(1)
# Look for the bracket that matches the first bracket seen in a
# string, and return the start and end as a tuple. For example, if
# the input is something like "<(foo <(bar)) blah", then it would
# return (1, 13), indicating the entire string except for the leading
# "<" and trailing " blah".
LBRACKETS = set("{[(")
BRACKETS = {"}": "{", "]": "[", ")": "("}
def FindEnclosingBracketGroup(input_str):
stack = []
start = -1
for index, char in enumerate(input_str):
if char in LBRACKETS:
stack.append(char)
if start == -1:
start = index
elif char in BRACKETS:
if not stack:
return (-1, -1)
if stack.pop() != BRACKETS[char]:
return (-1, -1)
if not stack:
return (start, index + 1)
return (-1, -1)
def IsStrCanonicalInt(string):
"""Returns True if |string| is in its canonical integer form.
The canonical form is such that str(int(string)) == string.
"""
if type(string) is str:
# This function is called a lot so for maximum performance, avoid
# involving regexps which would otherwise make the code much
# shorter. Regexps would need twice the time of this function.
if string:
if string == "0":
return True
if string[0] == "-":
string = string[1:]
if not string:
return False
if "1" <= string[0] <= "9":
return string.isdigit()
return False
# This matches things like "<(asdf)", "(?P<(?:(?:!?@?)|\|)?)"
r"(?P[-a-zA-Z0-9_.]+)?"
r"\((?P\s*\[?)"
r"(?P.*?)(\]?)\))"
)
# This matches the same as early_variable_re, but with '>' instead of '<'.
late_variable_re = re.compile(
r"(?P(?P>(?:(?:!?@?)|\|)?)"
r"(?P[-a-zA-Z0-9_.]+)?"
r"\((?P\s*\[?)"
r"(?P.*?)(\]?)\))"
)
# This matches the same as early_variable_re, but with '^' instead of '<'.
latelate_variable_re = re.compile(
r"(?P(?P[\^](?:(?:!?@?)|\|)?)"
r"(?P[-a-zA-Z0-9_.]+)?"
r"\((?P\s*\[?)"
r"(?P.*?)(\]?)\))"
)
# Global cache of results from running commands so they don't have to be run
# more then once.
cached_command_results = {}
def FixupPlatformCommand(cmd):
if sys.platform == "win32":
if type(cmd) is list:
cmd = [re.sub("^cat ", "type ", cmd[0])] + cmd[1:]
else:
cmd = re.sub("^cat ", "type ", cmd)
return cmd
PHASE_EARLY = 0
PHASE_LATE = 1
PHASE_LATELATE = 2
def ExpandVariables(input, phase, variables, build_file):
# Look for the pattern that gets expanded into variables
if phase == PHASE_EARLY:
variable_re = early_variable_re
expansion_symbol = "<"
elif phase == PHASE_LATE:
variable_re = late_variable_re
expansion_symbol = ">"
elif phase == PHASE_LATELATE:
variable_re = latelate_variable_re
expansion_symbol = "^"
else:
assert False
input_str = str(input)
if IsStrCanonicalInt(input_str):
return int(input_str)
# Do a quick scan to determine if an expensive regex search is warranted.
if expansion_symbol not in input_str:
return input_str
# Get the entire list of matches as a list of MatchObject instances.
# (using findall here would return strings instead of MatchObjects).
matches = list(variable_re.finditer(input_str))
if not matches:
return input_str
output = input_str
# Reverse the list of matches so that replacements are done right-to-left.
# That ensures that earlier replacements won't mess up the string in a
# way that causes later calls to find the earlier substituted text instead
# of what's intended for replacement.
matches.reverse()
for match_group in matches:
match = match_group.groupdict()
gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Matches: %r", match)
# match['replace'] is the substring to look for, match['type']
# is the character code for the replacement type (< > ! <| >| <@
# >@ !@), match['is_array'] contains a '[' for command
# arrays, and match['content'] is the name of the variable (< >)
# or command to run (!). match['command_string'] is an optional
# command string. Currently, only 'pymod_do_main' is supported.
# run_command is true if a ! variant is used.
run_command = "!" in match["type"]
command_string = match["command_string"]
# file_list is true if a | variant is used.
file_list = "|" in match["type"]
# Capture these now so we can adjust them later.
replace_start = match_group.start("replace")
replace_end = match_group.end("replace")
# Find the ending paren, and re-evaluate the contained string.
(c_start, c_end) = FindEnclosingBracketGroup(input_str[replace_start:])
# Adjust the replacement range to match the entire command
# found by FindEnclosingBracketGroup (since the variable_re
# probably doesn't match the entire command if it contained
# nested variables).
replace_end = replace_start + c_end
# Find the "real" replacement, matching the appropriate closing
# paren, and adjust the replacement start and end.
replacement = input_str[replace_start:replace_end]
# Figure out what the contents of the variable parens are.
contents_start = replace_start + c_start + 1
contents_end = replace_end - 1
contents = input_str[contents_start:contents_end]
# Do filter substitution now for <|().
# Admittedly, this is different than the evaluation order in other
# contexts. However, since filtration has no chance to run on <|(),
# this seems like the only obvious way to give them access to filters.
if file_list:
processed_variables = gyp.simple_copy.deepcopy(variables)
ProcessListFiltersInDict(contents, processed_variables)
# Recurse to expand variables in the contents
contents = ExpandVariables(contents, phase, processed_variables, build_file)
else:
# Recurse to expand variables in the contents
contents = ExpandVariables(contents, phase, variables, build_file)
# Strip off leading/trailing whitespace so that variable matches are
# simpler below (and because they are rarely needed).
contents = contents.strip()
# expand_to_list is true if an @ variant is used. In that case,
# the expansion should result in a list. Note that the caller
# is to be expecting a list in return, and not all callers do
# because not all are working in list context. Also, for list
# expansions, there can be no other text besides the variable
# expansion in the input string.
expand_to_list = "@" in match["type"] and input_str == replacement
if run_command or file_list:
# Find the build file's directory, so commands can be run or file lists
# generated relative to it.
build_file_dir = os.path.dirname(build_file)
if build_file_dir == "" and not file_list:
# If build_file is just a leaf filename indicating a file in the
# current directory, build_file_dir might be an empty string. Set
# it to None to signal to subprocess.Popen that it should run the
# command in the current directory.
build_file_dir = None
# Support <|(listfile.txt ...) which generates a file
# containing items from a gyp list, generated at gyp time.
# This works around actions/rules which have more inputs than will
# fit on the command line.
if file_list:
if type(contents) is list:
contents_list = contents
else:
contents_list = contents.split(" ")
replacement = contents_list[0]
if os.path.isabs(replacement):
raise GypError('| cannot handle absolute paths, got "%s"' % replacement)
if not generator_filelist_paths:
path = os.path.join(build_file_dir, replacement)
else:
if os.path.isabs(build_file_dir):
toplevel = generator_filelist_paths["toplevel"]
rel_build_file_dir = gyp.common.RelativePath(
build_file_dir, toplevel
)
else:
rel_build_file_dir = build_file_dir
qualified_out_dir = generator_filelist_paths["qualified_out_dir"]
path = os.path.join(qualified_out_dir, rel_build_file_dir, replacement)
gyp.common.EnsureDirExists(path)
replacement = gyp.common.RelativePath(path, build_file_dir)
f = gyp.common.WriteOnDiff(path)
for i in contents_list[1:]:
f.write("%s\n" % i)
f.close()
elif run_command:
use_shell = True
if match["is_array"]:
contents = eval(contents)
use_shell = False
# Check for a cached value to avoid executing commands, or generating
# file lists more than once. The cache key contains the command to be
# run as well as the directory to run it from, to account for commands
# that depend on their current directory.
# TODO(http://code.google.com/p/gyp/issues/detail?id=111): In theory,
# someone could author a set of GYP files where each time the command
# is invoked it produces different output by design. When the need
# arises, the syntax should be extended to support no caching off a
# command's output so it is run every time.
cache_key = (str(contents), build_file_dir)
cached_value = cached_command_results.get(cache_key, None)
if cached_value is None:
gyp.DebugOutput(
gyp.DEBUG_VARIABLES,
"Executing command '%s' in directory '%s'",
contents,
build_file_dir,
)
replacement = ""
if command_string == "pymod_do_main":
# 0:
raise GypError(
"Call to '%s' returned exit status %d while in %s."
% (contents, result.returncode, build_file)
)
replacement = result.stdout.decode("utf-8").rstrip()
cached_command_results[cache_key] = replacement
else:
gyp.DebugOutput(
gyp.DEBUG_VARIABLES,
"Had cache value for command '%s' in directory '%s'",
contents,
build_file_dir,
)
replacement = cached_value
else:
if contents not in variables:
if contents[-1] in ["!", "/"]:
# In order to allow cross-compiles (nacl) to happen more naturally,
# we will allow references to >(sources/) etc. to resolve to
# and empty list if undefined. This allows actions to:
# 'action!': [
# '>@(_sources!)',
# ],
# 'action/': [
# '>@(_sources/)',
# ],
replacement = []
else:
raise GypError(
"Undefined variable " + contents + " in " + build_file
)
else:
replacement = variables[contents]
if isinstance(replacement, bytes) and not isinstance(replacement, str):
replacement = replacement.decode("utf-8") # done on Python 3 only
if type(replacement) is list:
for item in replacement:
if isinstance(item, bytes) and not isinstance(item, str):
item = item.decode("utf-8") # done on Python 3 only
if not contents[-1] == "/" and type(item) not in (str, int):
raise GypError(
"Variable "
+ contents
+ " must expand to a string or list of strings; "
+ "list contains a "
+ item.__class__.__name__
)
# Run through the list and handle variable expansions in it. Since
# the list is guaranteed not to contain dicts, this won't do anything
# with conditions sections.
ProcessVariablesAndConditionsInList(
replacement, phase, variables, build_file
)
elif type(replacement) not in (str, int):
raise GypError(
"Variable "
+ contents
+ " must expand to a string or list of strings; "
+ "found a "
+ replacement.__class__.__name__
)
if expand_to_list:
# Expanding in list context. It's guaranteed that there's only one
# replacement to do in |input_str| and that it's this replacement. See
# above.
if type(replacement) is list:
# If it's already a list, make a copy.
output = replacement[:]
else:
# Split it the same way sh would split arguments.
output = shlex.split(str(replacement))
else:
# Expanding in string context.
encoded_replacement = ""
if type(replacement) is list:
# When expanding a list into string context, turn the list items
# into a string in a way that will work with a subprocess call.
#
# TODO(mark): This isn't completely correct. This should
# call a generator-provided function that observes the
# proper list-to-argument quoting rules on a specific
# platform instead of just calling the POSIX encoding
# routine.
encoded_replacement = gyp.common.EncodePOSIXShellList(replacement)
else:
encoded_replacement = replacement
output = (
output[:replace_start] + str(encoded_replacement) + output[replace_end:]
)
# Prepare for the next match iteration.
input_str = output
if output == input:
gyp.DebugOutput(
gyp.DEBUG_VARIABLES,
"Found only identity matches on %r, avoiding infinite " "recursion.",
output,
)
else:
# Look for more matches now that we've replaced some, to deal with
# expanding local variables (variables defined in the same
# variables block as this one).
gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Found output %r, recursing.", output)
if type(output) is list:
if output and type(output[0]) is list:
# Leave output alone if it's a list of lists.
# We don't want such lists to be stringified.
pass
else:
new_output = []
for item in output:
new_output.append(
ExpandVariables(item, phase, variables, build_file)
)
output = new_output
else:
output = ExpandVariables(output, phase, variables, build_file)
# Convert all strings that are canonically-represented integers into integers.
if type(output) is list:
for index, outstr in enumerate(output):
if IsStrCanonicalInt(outstr):
output[index] = int(outstr)
elif IsStrCanonicalInt(output):
output = int(output)
return output
# The same condition is often evaluated over and over again so it
# makes sense to cache as much as possible between evaluations.
cached_conditions_asts = {}
def EvalCondition(condition, conditions_key, phase, variables, build_file):
"""Returns the dict that should be used or None if the result was
that nothing should be used."""
if type(condition) is not list:
raise GypError(conditions_key + " must be a list")
if len(condition) < 2:
# It's possible that condition[0] won't work in which case this
# attempt will raise its own IndexError. That's probably fine.
raise GypError(
conditions_key
+ " "
+ condition[0]
+ " must be at least length 2, not "
+ str(len(condition))
)
i = 0
result = None
while i < len(condition):
cond_expr = condition[i]
true_dict = condition[i + 1]
if type(true_dict) is not dict:
raise GypError(
"{} {} must be followed by a dictionary, not {}".format(
conditions_key, cond_expr, type(true_dict)
)
)
if len(condition) > i + 2 and type(condition[i + 2]) is dict:
false_dict = condition[i + 2]
i = i + 3
if i != len(condition):
raise GypError(
"{} {} has {} unexpected trailing items".format(
conditions_key, cond_expr, len(condition) - i
)
)
else:
false_dict = None
i = i + 2
if result is None:
result = EvalSingleCondition(
cond_expr, true_dict, false_dict, phase, variables, build_file
)
return result
def EvalSingleCondition(cond_expr, true_dict, false_dict, phase, variables, build_file):
"""Returns true_dict if cond_expr evaluates to true, and false_dict
otherwise."""
# Do expansions on the condition itself. Since the condition can naturally
# contain variable references without needing to resort to GYP expansion
# syntax, this is of dubious value for variables, but someone might want to
# use a command expansion directly inside a condition.
cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, build_file)
if type(cond_expr_expanded) not in (str, int):
raise ValueError(
"Variable expansion in this context permits str and int "
+ "only, found "
+ cond_expr_expanded.__class__.__name__
)
try:
if cond_expr_expanded in cached_conditions_asts:
ast_code = cached_conditions_asts[cond_expr_expanded]
else:
ast_code = compile(cond_expr_expanded, "", "eval")
cached_conditions_asts[cond_expr_expanded] = ast_code
env = {"__builtins__": {}, "v": StrictVersion}
if eval(ast_code, env, variables):
return true_dict
return false_dict
except SyntaxError as e:
syntax_error = SyntaxError(
"%s while evaluating condition '%s' in %s "
"at character %d." % (str(e.args[0]), e.text, build_file, e.offset),
e.filename,
e.lineno,
e.offset,
e.text,
)
raise syntax_error
except NameError as e:
gyp.common.ExceptionAppend(
e,
f"while evaluating condition '{cond_expr_expanded}' in {build_file}",
)
raise GypError(e)
def ProcessConditionsInDict(the_dict, phase, variables, build_file):
# Process a 'conditions' or 'target_conditions' section in the_dict,
# depending on phase.
# early -> conditions
# late -> target_conditions
# latelate -> no conditions
#
# Each item in a conditions list consists of cond_expr, a string expression
# evaluated as the condition, and true_dict, a dict that will be merged into
# the_dict if cond_expr evaluates to true. Optionally, a third item,
# false_dict, may be present. false_dict is merged into the_dict if
# cond_expr evaluates to false.
#
# Any dict merged into the_dict will be recursively processed for nested
# conditionals and other expansions, also according to phase, immediately
# prior to being merged.
if phase == PHASE_EARLY:
conditions_key = "conditions"
elif phase == PHASE_LATE:
conditions_key = "target_conditions"
elif phase == PHASE_LATELATE:
return
else:
assert False
if conditions_key not in the_dict:
return
conditions_list = the_dict[conditions_key]
# Unhook the conditions list, it's no longer needed.
del the_dict[conditions_key]
for condition in conditions_list:
merge_dict = EvalCondition(
condition, conditions_key, phase, variables, build_file
)
if merge_dict is not None:
# Expand variables and nested conditinals in the merge_dict before
# merging it.
ProcessVariablesAndConditionsInDict(
merge_dict, phase, variables, build_file
)
MergeDicts(the_dict, merge_dict, build_file, build_file)
def LoadAutomaticVariablesFromDict(variables, the_dict):
# Any keys with plain string values in the_dict become automatic variables.
# The variable name is the key name with a "_" character prepended.
for key, value in the_dict.items():
if type(value) in (str, int, list):
variables["_" + key] = value
def LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key):
# Any keys in the_dict's "variables" dict, if it has one, becomes a
# variable. The variable name is the key name in the "variables" dict.
# Variables that end with the % character are set only if they are unset in
# the variables dict. the_dict_key is the name of the key that accesses
# the_dict in the_dict's parent dict. If the_dict's parent is not a dict
# (it could be a list or it could be parentless because it is a root dict),
# the_dict_key will be None.
for key, value in the_dict.get("variables", {}).items():
if type(value) not in (str, int, list):
continue
if key.endswith("%"):
variable_name = key[:-1]
if variable_name in variables:
# If the variable is already set, don't set it.
continue
if the_dict_key == "variables" and variable_name in the_dict:
# If the variable is set without a % in the_dict, and the_dict is a
# variables dict (making |variables| a variables sub-dict of a
# variables dict), use the_dict's definition.
value = the_dict[variable_name]
else:
variable_name = key
variables[variable_name] = value
def ProcessVariablesAndConditionsInDict(
the_dict, phase, variables_in, build_file, the_dict_key=None
):
"""Handle all variable and command expansion and conditional evaluation.
This function is the public entry point for all variable expansions and
conditional evaluations. The variables_in dictionary will not be modified
by this function.
"""
# Make a copy of the variables_in dict that can be modified during the
# loading of automatics and the loading of the variables dict.
variables = variables_in.copy()
LoadAutomaticVariablesFromDict(variables, the_dict)
if "variables" in the_dict:
# Make sure all the local variables are added to the variables
# list before we process them so that you can reference one
# variable from another. They will be fully expanded by recursion
# in ExpandVariables.
for key, value in the_dict["variables"].items():
variables[key] = value
# Handle the associated variables dict first, so that any variable
# references within can be resolved prior to using them as variables.
# Pass a copy of the variables dict to avoid having it be tainted.
# Otherwise, it would have extra automatics added for everything that
# should just be an ordinary variable in this scope.
ProcessVariablesAndConditionsInDict(
the_dict["variables"], phase, variables, build_file, "variables"
)
LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key)
for key, value in the_dict.items():
# Skip "variables", which was already processed if present.
if key != "variables" and type(value) is str:
expanded = ExpandVariables(value, phase, variables, build_file)
if type(expanded) not in (str, int):
raise ValueError(
"Variable expansion in this context permits str and int "
+ "only, found "
+ expanded.__class__.__name__
+ " for "
+ key
)
the_dict[key] = expanded
# Variable expansion may have resulted in changes to automatics. Reload.
# TODO(mark): Optimization: only reload if no changes were made.
variables = variables_in.copy()
LoadAutomaticVariablesFromDict(variables, the_dict)
LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key)
# Process conditions in this dict. This is done after variable expansion
# so that conditions may take advantage of expanded variables. For example,
# if the_dict contains:
# {'type': '<(library_type)',
# 'conditions': [['_type=="static_library"', { ... }]]},
# _type, as used in the condition, will only be set to the value of
# library_type if variable expansion is performed before condition
# processing. However, condition processing should occur prior to recursion
# so that variables (both automatic and "variables" dict type) may be
# adjusted by conditions sections, merged into the_dict, and have the
# intended impact on contained dicts.
#
# This arrangement means that a "conditions" section containing a "variables"
# section will only have those variables effective in subdicts, not in
# the_dict. The workaround is to put a "conditions" section within a
# "variables" section. For example:
# {'conditions': [['os=="mac"', {'variables': {'define': 'IS_MAC'}}]],
# 'defines': ['<(define)'],
# 'my_subdict': {'defines': ['<(define)']}},
# will not result in "IS_MAC" being appended to the "defines" list in the
# current scope but would result in it being appended to the "defines" list
# within "my_subdict". By comparison:
# {'variables': {'conditions': [['os=="mac"', {'define': 'IS_MAC'}]]},
# 'defines': ['<(define)'],
# 'my_subdict': {'defines': ['<(define)']}},
# will append "IS_MAC" to both "defines" lists.
# Evaluate conditions sections, allowing variable expansions within them
# as well as nested conditionals. This will process a 'conditions' or
# 'target_conditions' section, perform appropriate merging and recursive
# conditional and variable processing, and then remove the conditions section
# from the_dict if it is present.
ProcessConditionsInDict(the_dict, phase, variables, build_file)
# Conditional processing may have resulted in changes to automatics or the
# variables dict. Reload.
variables = variables_in.copy()
LoadAutomaticVariablesFromDict(variables, the_dict)
LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key)
# Recurse into child dicts, or process child lists which may result in
# further recursion into descendant dicts.
for key, value in the_dict.items():
# Skip "variables" and string values, which were already processed if
# present.
if key == "variables" or type(value) is str:
continue
if type(value) is dict:
# Pass a copy of the variables dict so that subdicts can't influence
# parents.
ProcessVariablesAndConditionsInDict(
value, phase, variables, build_file, key
)
elif type(value) is list:
# The list itself can't influence the variables dict, and
# ProcessVariablesAndConditionsInList will make copies of the variables
# dict if it needs to pass it to something that can influence it. No
# copy is necessary here.
ProcessVariablesAndConditionsInList(value, phase, variables, build_file)
elif type(value) is not int:
raise TypeError("Unknown type " + value.__class__.__name__ + " for " + key)
def ProcessVariablesAndConditionsInList(the_list, phase, variables, build_file):
# Iterate using an index so that new values can be assigned into the_list.
index = 0
while index < len(the_list):
item = the_list[index]
if type(item) is dict:
# Make a copy of the variables dict so that it won't influence anything
# outside of its own scope.
ProcessVariablesAndConditionsInDict(item, phase, variables, build_file)
elif type(item) is list:
ProcessVariablesAndConditionsInList(item, phase, variables, build_file)
elif type(item) is str:
expanded = ExpandVariables(item, phase, variables, build_file)
if type(expanded) in (str, int):
the_list[index] = expanded
elif type(expanded) is list:
the_list[index : index + 1] = expanded
index += len(expanded)
# index now identifies the next item to examine. Continue right now
# without falling into the index increment below.
continue
else:
raise ValueError(
"Variable expansion in this context permits strings and "
+ "lists only, found "
+ expanded.__class__.__name__
+ " at "
+ index
)
elif type(item) is not int:
raise TypeError(
"Unknown type " + item.__class__.__name__ + " at index " + index
)
index = index + 1
def BuildTargetsDict(data):
"""Builds a dict mapping fully-qualified target names to their target dicts.
|data| is a dict mapping loaded build files by pathname relative to the
current directory. Values in |data| are build file contents. For each
|data| value with a "targets" key, the value of the "targets" key is taken
as a list containing target dicts. Each target's fully-qualified name is
constructed from the pathname of the build file (|data| key) and its
"target_name" property. These fully-qualified names are used as the keys
in the returned dict. These keys provide access to the target dicts,
the dicts in the "targets" lists.
"""
targets = {}
for build_file in data["target_build_files"]:
for target in data[build_file].get("targets", []):
target_name = gyp.common.QualifiedTarget(
build_file, target["target_name"], target["toolset"]
)
if target_name in targets:
raise GypError("Duplicate target definitions for " + target_name)
targets[target_name] = target
return targets
def QualifyDependencies(targets):
"""Make dependency links fully-qualified relative to the current directory.
|targets| is a dict mapping fully-qualified target names to their target
dicts. For each target in this dict, keys known to contain dependency
links are examined, and any dependencies referenced will be rewritten
so that they are fully-qualified and relative to the current directory.
All rewritten dependencies are suitable for use as keys to |targets| or a
similar dict.
"""
all_dependency_sections = [
dep + op for dep in dependency_sections for op in ("", "!", "/")
]
for target, target_dict in targets.items():
target_build_file = gyp.common.BuildFile(target)
toolset = target_dict["toolset"]
for dependency_key in all_dependency_sections:
dependencies = target_dict.get(dependency_key, [])
for index, dep in enumerate(dependencies):
dep_file, dep_target, dep_toolset = gyp.common.ResolveTarget(
target_build_file, dep, toolset
)
if not multiple_toolsets:
# Ignore toolset specification in the dependency if it is specified.
dep_toolset = toolset
dependency = gyp.common.QualifiedTarget(
dep_file, dep_target, dep_toolset
)
dependencies[index] = dependency
# Make sure anything appearing in a list other than "dependencies" also
# appears in the "dependencies" list.
if (
dependency_key != "dependencies"
and dependency not in target_dict["dependencies"]
):
raise GypError(
"Found "
+ dependency
+ " in "
+ dependency_key
+ " of "
+ target
+ ", but not in dependencies"
)
def ExpandWildcardDependencies(targets, data):
"""Expands dependencies specified as build_file:*.
For each target in |targets|, examines sections containing links to other
targets. If any such section contains a link of the form build_file:*, it
is taken as a wildcard link, and is expanded to list each target in
build_file. The |data| dict provides access to build file dicts.
Any target that does not wish to be included by wildcard can provide an
optional "suppress_wildcard" key in its target dict. When present and
true, a wildcard dependency link will not include such targets.
All dependency names, including the keys to |targets| and the values in each
dependency list, must be qualified when this function is called.
"""
for target, target_dict in targets.items():
target_build_file = gyp.common.BuildFile(target)
for dependency_key in dependency_sections:
dependencies = target_dict.get(dependency_key, [])
# Loop this way instead of "for dependency in" or "for index in range"
# because the dependencies list will be modified within the loop body.
index = 0
while index < len(dependencies):
(
dependency_build_file,
dependency_target,
dependency_toolset,
) = gyp.common.ParseQualifiedTarget(dependencies[index])
if dependency_target != "*" and dependency_toolset != "*":
# Not a wildcard. Keep it moving.
index = index + 1
continue
if dependency_build_file == target_build_file:
# It's an error for a target to depend on all other targets in
# the same file, because a target cannot depend on itself.
raise GypError(
"Found wildcard in "
+ dependency_key
+ " of "
+ target
+ " referring to same build file"
)
# Take the wildcard out and adjust the index so that the next
# dependency in the list will be processed the next time through the
# loop.
del dependencies[index]
index = index - 1
# Loop through the targets in the other build file, adding them to
# this target's list of dependencies in place of the removed
# wildcard.
dependency_target_dicts = data[dependency_build_file]["targets"]
for dependency_target_dict in dependency_target_dicts:
if int(dependency_target_dict.get("suppress_wildcard", False)):
continue
dependency_target_name = dependency_target_dict["target_name"]
if (
dependency_target != "*"
and dependency_target != dependency_target_name
):
continue
dependency_target_toolset = dependency_target_dict["toolset"]
if (
dependency_toolset != "*"
and dependency_toolset != dependency_target_toolset
):
continue
dependency = gyp.common.QualifiedTarget(
dependency_build_file,
dependency_target_name,
dependency_target_toolset,
)
index = index + 1
dependencies.insert(index, dependency)
index = index + 1
def Unify(items):
"""Removes duplicate elements from items, keeping the first element."""
seen = {}
return [seen.setdefault(e, e) for e in items if e not in seen]
def RemoveDuplicateDependencies(targets):
"""Makes sure every dependency appears only once in all targets's dependency
lists."""
for target_name, target_dict in targets.items():
for dependency_key in dependency_sections:
dependencies = target_dict.get(dependency_key, [])
if dependencies:
target_dict[dependency_key] = Unify(dependencies)
def Filter(items, item):
"""Removes item from items."""
res = {}
return [res.setdefault(e, e) for e in items if e != item]
def RemoveSelfDependencies(targets):
"""Remove self dependencies from targets that have the prune_self_dependency
variable set."""
for target_name, target_dict in targets.items():
for dependency_key in dependency_sections:
dependencies = target_dict.get(dependency_key, [])
if dependencies:
for t in dependencies:
if t == target_name:
if (
targets[t]
.get("variables", {})
.get("prune_self_dependency", 0)
):
target_dict[dependency_key] = Filter(
dependencies, target_name
)
def RemoveLinkDependenciesFromNoneTargets(targets):
"""Remove dependencies having the 'link_dependency' attribute from the 'none'
targets."""
for target_name, target_dict in targets.items():
for dependency_key in dependency_sections:
dependencies = target_dict.get(dependency_key, [])
if dependencies:
for t in dependencies:
if target_dict.get("type", None) == "none":
if targets[t].get("variables", {}).get("link_dependency", 0):
target_dict[dependency_key] = Filter(
target_dict[dependency_key], t
)
class DependencyGraphNode:
"""
Attributes:
ref: A reference to an object that this DependencyGraphNode represents.
dependencies: List of DependencyGraphNodes on which this one depends.
dependents: List of DependencyGraphNodes that depend on this one.
"""
class CircularException(GypError):
pass
def __init__(self, ref):
self.ref = ref
self.dependencies = []
self.dependents = []
def __repr__(self):
return "" % self.ref
def FlattenToList(self):
# flat_list is the sorted list of dependencies - actually, the list items
# are the "ref" attributes of DependencyGraphNodes. Every target will
# appear in flat_list after all of its dependencies, and before all of its
# dependents.
flat_list = OrderedSet()
def ExtractNodeRef(node):
"""Extracts the object that the node represents from the given node."""
return node.ref
# in_degree_zeros is the list of DependencyGraphNodes that have no
# dependencies not in flat_list. Initially, it is a copy of the children
# of this node, because when the graph was built, nodes with no
# dependencies were made implicit dependents of the root node.
in_degree_zeros = sorted(self.dependents[:], key=ExtractNodeRef)
while in_degree_zeros:
# Nodes in in_degree_zeros have no dependencies not in flat_list, so they
# can be appended to flat_list. Take these nodes out of in_degree_zeros
# as work progresses, so that the next node to process from the list can
# always be accessed at a consistent position.
node = in_degree_zeros.pop()
flat_list.add(node.ref)
# Look at dependents of the node just added to flat_list. Some of them
# may now belong in in_degree_zeros.
for node_dependent in sorted(node.dependents, key=ExtractNodeRef):
is_in_degree_zero = True
# TODO: We want to check through the
# node_dependent.dependencies list but if it's long and we
# always start at the beginning, then we get O(n^2) behaviour.
for node_dependent_dependency in sorted(
node_dependent.dependencies, key=ExtractNodeRef
):
if node_dependent_dependency.ref not in flat_list:
# The dependent one or more dependencies not in flat_list.
# There will be more chances to add it to flat_list
# when examining it again as a dependent of those other
# dependencies, provided that there are no cycles.
is_in_degree_zero = False
break
if is_in_degree_zero:
# All of the dependent's dependencies are already in flat_list. Add
# it to in_degree_zeros where it will be processed in a future
# iteration of the outer loop.
in_degree_zeros += [node_dependent]
return list(flat_list)
def FindCycles(self):
"""
Returns a list of cycles in the graph, where each cycle is its own list.
"""
results = []
visited = set()
def Visit(node, path):
for child in node.dependents:
if child in path:
results.append([child] + path[: path.index(child) + 1])
elif child not in visited:
visited.add(child)
Visit(child, [child] + path)
visited.add(self)
Visit(self, [self])
return results
def DirectDependencies(self, dependencies=None):
"""Returns a list of just direct dependencies."""
if dependencies is None:
dependencies = []
for dependency in self.dependencies:
# Check for None, corresponding to the root node.
if dependency.ref and dependency.ref not in dependencies:
dependencies.append(dependency.ref)
return dependencies
def _AddImportedDependencies(self, targets, dependencies=None):
"""Given a list of direct dependencies, adds indirect dependencies that
other dependencies have declared to export their settings.
This method does not operate on self. Rather, it operates on the list
of dependencies in the |dependencies| argument. For each dependency in
that list, if any declares that it exports the settings of one of its
own dependencies, those dependencies whose settings are "passed through"
are added to the list. As new items are added to the list, they too will
be processed, so it is possible to import settings through multiple levels
of dependencies.
This method is not terribly useful on its own, it depends on being
"primed" with a list of direct dependencies such as one provided by
DirectDependencies. DirectAndImportedDependencies is intended to be the
public entry point.
"""
if dependencies is None:
dependencies = []
index = 0
while index < len(dependencies):
dependency = dependencies[index]
dependency_dict = targets[dependency]
# Add any dependencies whose settings should be imported to the list
# if not already present. Newly-added items will be checked for
# their own imports when the list iteration reaches them.
# Rather than simply appending new items, insert them after the
# dependency that exported them. This is done to more closely match
# the depth-first method used by DeepDependencies.
add_index = 1
for imported_dependency in dependency_dict.get(
"export_dependent_settings", []
):
if imported_dependency not in dependencies:
dependencies.insert(index + add_index, imported_dependency)
add_index = add_index + 1
index = index + 1
return dependencies
def DirectAndImportedDependencies(self, targets, dependencies=None):
"""Returns a list of a target's direct dependencies and all indirect
dependencies that a dependency has advertised settings should be exported
through the dependency for.
"""
dependencies = self.DirectDependencies(dependencies)
return self._AddImportedDependencies(targets, dependencies)
def DeepDependencies(self, dependencies=None):
"""Returns an OrderedSet of all of a target's dependencies, recursively."""
if dependencies is None:
# Using a list to get ordered output and a set to do fast "is it
# already added" checks.
dependencies = OrderedSet()
for dependency in self.dependencies:
# Check for None, corresponding to the root node.
if dependency.ref is None:
continue
if dependency.ref not in dependencies:
dependency.DeepDependencies(dependencies)
dependencies.add(dependency.ref)
return dependencies
def _LinkDependenciesInternal(
self, targets, include_shared_libraries, dependencies=None, initial=True
):
"""Returns an OrderedSet of dependency targets that are linked
into this target.
This function has a split personality, depending on the setting of
|initial|. Outside callers should always leave |initial| at its default
setting.
When adding a target to the list of dependencies, this function will
recurse into itself with |initial| set to False, to collect dependencies
that are linked into the linkable target for which the list is being built.
If |include_shared_libraries| is False, the resulting dependencies will not
include shared_library targets that are linked into this target.
"""
if dependencies is None:
# Using a list to get ordered output and a set to do fast "is it
# already added" checks.
dependencies = OrderedSet()
# Check for None, corresponding to the root node.
if self.ref is None:
return dependencies
# It's kind of sucky that |targets| has to be passed into this function,
# but that's presently the easiest way to access the target dicts so that
# this function can find target types.
if "target_name" not in targets[self.ref]:
raise GypError("Missing 'target_name' field in target.")
if "type" not in targets[self.ref]:
raise GypError(
"Missing 'type' field in target %s" % targets[self.ref]["target_name"]
)
target_type = targets[self.ref]["type"]
is_linkable = target_type in linkable_types
if initial and not is_linkable:
# If this is the first target being examined and it's not linkable,
# return an empty list of link dependencies, because the link
# dependencies are intended to apply to the target itself (initial is
# True) and this target won't be linked.
return dependencies
# Don't traverse 'none' targets if explicitly excluded.
if target_type == "none" and not targets[self.ref].get(
"dependencies_traverse", True
):
dependencies.add(self.ref)
return dependencies
# Executables, mac kernel extensions, windows drivers and loadable modules
# are already fully and finally linked. Nothing else can be a link
# dependency of them, there can only be dependencies in the sense that a
# dependent target might run an executable or load the loadable_module.
if not initial and target_type in (
"executable",
"loadable_module",
"mac_kernel_extension",
"windows_driver",
):
return dependencies
# Shared libraries are already fully linked. They should only be included
# in |dependencies| when adjusting static library dependencies (in order to
# link against the shared_library's import lib), but should not be included
# in |dependencies| when propagating link_settings.
# The |include_shared_libraries| flag controls which of these two cases we
# are handling.
if (
not initial
and target_type == "shared_library"
and not include_shared_libraries
):
return dependencies
# The target is linkable, add it to the list of link dependencies.
if self.ref not in dependencies:
dependencies.add(self.ref)
if initial or not is_linkable:
# If this is a subsequent target and it's linkable, don't look any
# further for linkable dependencies, as they'll already be linked into
# this target linkable. Always look at dependencies of the initial
# target, and always look at dependencies of non-linkables.
for dependency in self.dependencies:
dependency._LinkDependenciesInternal(
targets, include_shared_libraries, dependencies, False
)
return dependencies
def DependenciesForLinkSettings(self, targets):
"""
Returns a list of dependency targets whose link_settings should be merged
into this target.
"""
# TODO(sbaig) Currently, chrome depends on the bug that shared libraries'
# link_settings are propagated. So for now, we will allow it, unless the
# 'allow_sharedlib_linksettings_propagation' flag is explicitly set to
# False. Once chrome is fixed, we can remove this flag.
include_shared_libraries = targets[self.ref].get(
"allow_sharedlib_linksettings_propagation", True
)
return self._LinkDependenciesInternal(targets, include_shared_libraries)
def DependenciesToLinkAgainst(self, targets):
"""
Returns a list of dependency targets that are linked into this target.
"""
return self._LinkDependenciesInternal(targets, True)
def BuildDependencyList(targets):
# Create a DependencyGraphNode for each target. Put it into a dict for easy
# access.
dependency_nodes = {}
for target, spec in targets.items():
if target not in dependency_nodes:
dependency_nodes[target] = DependencyGraphNode(target)
# Set up the dependency links. Targets that have no dependencies are treated
# as dependent on root_node.
root_node = DependencyGraphNode(None)
for target, spec in targets.items():
target_node = dependency_nodes[target]
dependencies = spec.get("dependencies")
if not dependencies:
target_node.dependencies = [root_node]
root_node.dependents.append(target_node)
else:
for dependency in dependencies:
dependency_node = dependency_nodes.get(dependency)
if not dependency_node:
raise GypError(
"Dependency '%s' not found while "
"trying to load target %s" % (dependency, target)
)
target_node.dependencies.append(dependency_node)
dependency_node.dependents.append(target_node)
flat_list = root_node.FlattenToList()
# If there's anything left unvisited, there must be a circular dependency
# (cycle).
if len(flat_list) != len(targets):
if not root_node.dependents:
# If all targets have dependencies, add the first target as a dependent
# of root_node so that the cycle can be discovered from root_node.
target = next(iter(targets))
target_node = dependency_nodes[target]
target_node.dependencies.append(root_node)
root_node.dependents.append(target_node)
cycles = []
for cycle in root_node.FindCycles():
paths = [node.ref for node in cycle]
cycles.append("Cycle: %s" % " -> ".join(paths))
raise DependencyGraphNode.CircularException(
"Cycles in dependency graph detected:\n" + "\n".join(cycles)
)
return [dependency_nodes, flat_list]
def VerifyNoGYPFileCircularDependencies(targets):
# Create a DependencyGraphNode for each gyp file containing a target. Put
# it into a dict for easy access.
dependency_nodes = {}
for target in targets:
build_file = gyp.common.BuildFile(target)
if build_file not in dependency_nodes:
dependency_nodes[build_file] = DependencyGraphNode(build_file)
# Set up the dependency links.
for target, spec in targets.items():
build_file = gyp.common.BuildFile(target)
build_file_node = dependency_nodes[build_file]
target_dependencies = spec.get("dependencies", [])
for dependency in target_dependencies:
try:
dependency_build_file = gyp.common.BuildFile(dependency)
except GypError as e:
gyp.common.ExceptionAppend(
e, "while computing dependencies of .gyp file %s" % build_file
)
raise
if dependency_build_file == build_file:
# A .gyp file is allowed to refer back to itself.
continue
dependency_node = dependency_nodes.get(dependency_build_file)
if not dependency_node:
raise GypError("Dependency '%s' not found" % dependency_build_file)
if dependency_node not in build_file_node.dependencies:
build_file_node.dependencies.append(dependency_node)
dependency_node.dependents.append(build_file_node)
# Files that have no dependencies are treated as dependent on root_node.
root_node = DependencyGraphNode(None)
for build_file_node in dependency_nodes.values():
if len(build_file_node.dependencies) == 0:
build_file_node.dependencies.append(root_node)
root_node.dependents.append(build_file_node)
flat_list = root_node.FlattenToList()
# If there's anything left unvisited, there must be a circular dependency
# (cycle).
if len(flat_list) != len(dependency_nodes):
if not root_node.dependents:
# If all files have dependencies, add the first file as a dependent
# of root_node so that the cycle can be discovered from root_node.
file_node = next(iter(dependency_nodes.values()))
file_node.dependencies.append(root_node)
root_node.dependents.append(file_node)
cycles = []
for cycle in root_node.FindCycles():
paths = [node.ref for node in cycle]
cycles.append("Cycle: %s" % " -> ".join(paths))
raise DependencyGraphNode.CircularException(
"Cycles in .gyp file dependency graph detected:\n" + "\n".join(cycles)
)
def DoDependentSettings(key, flat_list, targets, dependency_nodes):
# key should be one of all_dependent_settings, direct_dependent_settings,
# or link_settings.
for target in flat_list:
target_dict = targets[target]
build_file = gyp.common.BuildFile(target)
if key == "all_dependent_settings":
dependencies = dependency_nodes[target].DeepDependencies()
elif key == "direct_dependent_settings":
dependencies = dependency_nodes[target].DirectAndImportedDependencies(
targets
)
elif key == "link_settings":
dependencies = dependency_nodes[target].DependenciesForLinkSettings(targets)
else:
raise GypError(
"DoDependentSettings doesn't know how to determine "
"dependencies for " + key
)
for dependency in dependencies:
dependency_dict = targets[dependency]
if key not in dependency_dict:
continue
dependency_build_file = gyp.common.BuildFile(dependency)
MergeDicts(
target_dict, dependency_dict[key], build_file, dependency_build_file
)
def AdjustStaticLibraryDependencies(
flat_list, targets, dependency_nodes, sort_dependencies
):
# Recompute target "dependencies" properties. For each static library
# target, remove "dependencies" entries referring to other static libraries,
# unless the dependency has the "hard_dependency" attribute set. For each
# linkable target, add a "dependencies" entry referring to all of the
# target's computed list of link dependencies (including static libraries
# if no such entry is already present.
for target in flat_list:
target_dict = targets[target]
target_type = target_dict["type"]
if target_type == "static_library":
if "dependencies" not in target_dict:
continue
target_dict["dependencies_original"] = target_dict.get("dependencies", [])[
:
]
# A static library should not depend on another static library unless
# the dependency relationship is "hard," which should only be done when
# a dependent relies on some side effect other than just the build
# product, like a rule or action output. Further, if a target has a
# non-hard dependency, but that dependency exports a hard dependency,
# the non-hard dependency can safely be removed, but the exported hard
# dependency must be added to the target to keep the same dependency
# ordering.
dependencies = dependency_nodes[target].DirectAndImportedDependencies(
targets
)
index = 0
while index < len(dependencies):
dependency = dependencies[index]
dependency_dict = targets[dependency]
# Remove every non-hard static library dependency and remove every
# non-static library dependency that isn't a direct dependency.
if (
dependency_dict["type"] == "static_library"
and not dependency_dict.get("hard_dependency", False)
) or (
dependency_dict["type"] != "static_library"
and dependency not in target_dict["dependencies"]
):
# Take the dependency out of the list, and don't increment index
# because the next dependency to analyze will shift into the index
# formerly occupied by the one being removed.
del dependencies[index]
else:
index = index + 1
# Update the dependencies. If the dependencies list is empty, it's not
# needed, so unhook it.
if len(dependencies) > 0:
target_dict["dependencies"] = dependencies
else:
del target_dict["dependencies"]
elif target_type in linkable_types:
# Get a list of dependency targets that should be linked into this
# target. Add them to the dependencies list if they're not already
# present.
link_dependencies = dependency_nodes[target].DependenciesToLinkAgainst(
targets
)
for dependency in link_dependencies:
if dependency == target:
continue
if "dependencies" not in target_dict:
target_dict["dependencies"] = []
if dependency not in target_dict["dependencies"]:
target_dict["dependencies"].append(dependency)
# Sort the dependencies list in the order from dependents to dependencies.
# e.g. If A and B depend on C and C depends on D, sort them in A, B, C, D.
# Note: flat_list is already sorted in the order from dependencies to
# dependents.
if sort_dependencies and "dependencies" in target_dict:
target_dict["dependencies"] = [
dep
for dep in reversed(flat_list)
if dep in target_dict["dependencies"]
]
# Initialize this here to speed up MakePathRelative.
exception_re = re.compile(r"""["']?[-/$<>^]""")
def MakePathRelative(to_file, fro_file, item):
# If item is a relative path, it's relative to the build file dict that it's
# coming from. Fix it up to make it relative to the build file dict that
# it's going into.
# Exception: any |item| that begins with these special characters is
# returned without modification.
# / Used when a path is already absolute (shortcut optimization;
# such paths would be returned as absolute anyway)
# $ Used for build environment variables
# - Used for some build environment flags (such as -lapr-1 in a
# "libraries" section)
# < Used for our own variable and command expansions (see ExpandVariables)
# > Used for our own variable and command expansions (see ExpandVariables)
# ^ Used for our own variable and command expansions (see ExpandVariables)
#
# "/' Used when a value is quoted. If these are present, then we
# check the second character instead.
#
if to_file == fro_file or exception_re.match(item):
return item
else:
# TODO(dglazkov) The backslash/forward-slash replacement at the end is a
# temporary measure. This should really be addressed by keeping all paths
# in POSIX until actual project generation.
ret = os.path.normpath(
os.path.join(
gyp.common.RelativePath(
os.path.dirname(fro_file), os.path.dirname(to_file)
),
item,
)
).replace("\\", "/")
if item.endswith("/"):
ret += "/"
return ret
def MergeLists(to, fro, to_file, fro_file, is_paths=False, append=True):
# Python documentation recommends objects which do not support hash
# set this value to None. Python library objects follow this rule.
def is_hashable(val):
return val.__hash__
# If x is hashable, returns whether x is in s. Else returns whether x is in items.
def is_in_set_or_list(x, s, items):
if is_hashable(x):
return x in s
return x in items
prepend_index = 0
# Make membership testing of hashables in |to| (in particular, strings)
# faster.
hashable_to_set = {x for x in to if is_hashable(x)}
for item in fro:
singleton = False
if type(item) in (str, int):
# The cheap and easy case.
if is_paths:
to_item = MakePathRelative(to_file, fro_file, item)
else:
to_item = item
if not (type(item) is str and item.startswith("-")):
# Any string that doesn't begin with a "-" is a singleton - it can
# only appear once in a list, to be enforced by the list merge append
# or prepend.
singleton = True
elif type(item) is dict:
# Make a copy of the dictionary, continuing to look for paths to fix.
# The other intelligent aspects of merge processing won't apply because
# item is being merged into an empty dict.
to_item = {}
MergeDicts(to_item, item, to_file, fro_file)
elif type(item) is list:
# Recurse, making a copy of the list. If the list contains any
# descendant dicts, path fixing will occur. Note that here, custom
# values for is_paths and append are dropped; those are only to be
# applied to |to| and |fro|, not sublists of |fro|. append shouldn't
# matter anyway because the new |to_item| list is empty.
to_item = []
MergeLists(to_item, item, to_file, fro_file)
else:
raise TypeError(
"Attempt to merge list item of unsupported type "
+ item.__class__.__name__
)
if append:
# If appending a singleton that's already in the list, don't append.
# This ensures that the earliest occurrence of the item will stay put.
if not singleton or not is_in_set_or_list(to_item, hashable_to_set, to):
to.append(to_item)
if is_hashable(to_item):
hashable_to_set.add(to_item)
else:
# If prepending a singleton that's already in the list, remove the
# existing instance and proceed with the prepend. This ensures that the
# item appears at the earliest possible position in the list.
while singleton and to_item in to:
to.remove(to_item)
# Don't just insert everything at index 0. That would prepend the new
# items to the list in reverse order, which would be an unwelcome
# surprise.
to.insert(prepend_index, to_item)
if is_hashable(to_item):
hashable_to_set.add(to_item)
prepend_index = prepend_index + 1
def MergeDicts(to, fro, to_file, fro_file):
# I wanted to name the parameter "from" but it's a Python keyword...
for k, v in fro.items():
# It would be nice to do "if not k in to: to[k] = v" but that wouldn't give
# copy semantics. Something else may want to merge from the |fro| dict
# later, and having the same dict ref pointed to twice in the tree isn't
# what anyone wants considering that the dicts may subsequently be
# modified.
if k in to:
bad_merge = False
if type(v) in (str, int):
if type(to[k]) not in (str, int):
bad_merge = True
elif not isinstance(v, type(to[k])):
bad_merge = True
if bad_merge:
raise TypeError(
"Attempt to merge dict value of type "
+ v.__class__.__name__
+ " into incompatible type "
+ to[k].__class__.__name__
+ " for key "
+ k
)
if type(v) in (str, int):
# Overwrite the existing value, if any. Cheap and easy.
is_path = IsPathSection(k)
if is_path:
to[k] = MakePathRelative(to_file, fro_file, v)
else:
to[k] = v
elif type(v) is dict:
# Recurse, guaranteeing copies will be made of objects that require it.
if k not in to:
to[k] = {}
MergeDicts(to[k], v, to_file, fro_file)
elif type(v) is list:
# Lists in dicts can be merged with different policies, depending on
# how the key in the "from" dict (k, the from-key) is written.
#
# If the from-key has ...the to-list will have this action
# this character appended:... applied when receiving the from-list:
# = replace
# + prepend
# ? set, only if to-list does not yet exist
# (none) append
#
# This logic is list-specific, but since it relies on the associated
# dict key, it's checked in this dict-oriented function.
ext = k[-1]
append = True
if ext == "=":
list_base = k[:-1]
lists_incompatible = [list_base, list_base + "?"]
to[list_base] = []
elif ext == "+":
list_base = k[:-1]
lists_incompatible = [list_base + "=", list_base + "?"]
append = False
elif ext == "?":
list_base = k[:-1]
lists_incompatible = [list_base, list_base + "=", list_base + "+"]
else:
list_base = k
lists_incompatible = [list_base + "=", list_base + "?"]
# Some combinations of merge policies appearing together are meaningless.
# It's stupid to replace and append simultaneously, for example. Append
# and prepend are the only policies that can coexist.
for list_incompatible in lists_incompatible:
if list_incompatible in fro:
raise GypError(
"Incompatible list policies " + k + " and " + list_incompatible
)
if list_base in to:
if ext == "?":
# If the key ends in "?", the list will only be merged if it doesn't
# already exist.
continue
elif type(to[list_base]) is not list:
# This may not have been checked above if merging in a list with an
# extension character.
raise TypeError(
"Attempt to merge dict value of type "
+ v.__class__.__name__
+ " into incompatible type "
+ to[list_base].__class__.__name__
+ " for key "
+ list_base
+ "("
+ k
+ ")"
)
else:
to[list_base] = []
# Call MergeLists, which will make copies of objects that require it.
# MergeLists can recurse back into MergeDicts, although this will be
# to make copies of dicts (with paths fixed), there will be no
# subsequent dict "merging" once entering a list because lists are
# always replaced, appended to, or prepended to.
is_paths = IsPathSection(list_base)
MergeLists(to[list_base], v, to_file, fro_file, is_paths, append)
else:
raise TypeError(
"Attempt to merge dict value of unsupported type "
+ v.__class__.__name__
+ " for key "
+ k
)
def MergeConfigWithInheritance(
new_configuration_dict, build_file, target_dict, configuration, visited
):
# Skip if previously visited.
if configuration in visited:
return
# Look at this configuration.
configuration_dict = target_dict["configurations"][configuration]
# Merge in parents.
for parent in configuration_dict.get("inherit_from", []):
MergeConfigWithInheritance(
new_configuration_dict,
build_file,
target_dict,
parent,
visited + [configuration],
)
# Merge it into the new config.
MergeDicts(new_configuration_dict, configuration_dict, build_file, build_file)
# Drop abstract.
if "abstract" in new_configuration_dict:
del new_configuration_dict["abstract"]
def SetUpConfigurations(target, target_dict):
# key_suffixes is a list of key suffixes that might appear on key names.
# These suffixes are handled in conditional evaluations (for =, +, and ?)
# and rules/exclude processing (for ! and /). Keys with these suffixes
# should be treated the same as keys without.
key_suffixes = ["=", "+", "?", "!", "/"]
build_file = gyp.common.BuildFile(target)
# Provide a single configuration by default if none exists.
# TODO(mark): Signal an error if default_configurations exists but
# configurations does not.
if "configurations" not in target_dict:
target_dict["configurations"] = {"Default": {}}
if "default_configuration" not in target_dict:
concrete = [
i
for (i, config) in target_dict["configurations"].items()
if not config.get("abstract")
]
target_dict["default_configuration"] = sorted(concrete)[0]
merged_configurations = {}
configs = target_dict["configurations"]
for (configuration, old_configuration_dict) in configs.items():
# Skip abstract configurations (saves work only).
if old_configuration_dict.get("abstract"):
continue
# Configurations inherit (most) settings from the enclosing target scope.
# Get the inheritance relationship right by making a copy of the target
# dict.
new_configuration_dict = {}
for (key, target_val) in target_dict.items():
key_ext = key[-1:]
if key_ext in key_suffixes:
key_base = key[:-1]
else:
key_base = key
if key_base not in non_configuration_keys:
new_configuration_dict[key] = gyp.simple_copy.deepcopy(target_val)
# Merge in configuration (with all its parents first).
MergeConfigWithInheritance(
new_configuration_dict, build_file, target_dict, configuration, []
)
merged_configurations[configuration] = new_configuration_dict
# Put the new configurations back into the target dict as a configuration.
for configuration in merged_configurations.keys():
target_dict["configurations"][configuration] = merged_configurations[
configuration
]
# Now drop all the abstract ones.
configs = target_dict["configurations"]
target_dict["configurations"] = {
k: v for k, v in configs.items() if not v.get("abstract")
}
# Now that all of the target's configurations have been built, go through
# the target dict's keys and remove everything that's been moved into a
# "configurations" section.
delete_keys = []
for key in target_dict:
key_ext = key[-1:]
if key_ext in key_suffixes:
key_base = key[:-1]
else:
key_base = key
if key_base not in non_configuration_keys:
delete_keys.append(key)
for key in delete_keys:
del target_dict[key]
# Check the configurations to see if they contain invalid keys.
for configuration in target_dict["configurations"].keys():
configuration_dict = target_dict["configurations"][configuration]
for key in configuration_dict.keys():
if key in invalid_configuration_keys:
raise GypError(
"%s not allowed in the %s configuration, found in "
"target %s" % (key, configuration, target)
)
def ProcessListFiltersInDict(name, the_dict):
"""Process regular expression and exclusion-based filters on lists.
An exclusion list is in a dict key named with a trailing "!", like
"sources!". Every item in such a list is removed from the associated
main list, which in this example, would be "sources". Removed items are
placed into a "sources_excluded" list in the dict.
Regular expression (regex) filters are contained in dict keys named with a
trailing "/", such as "sources/" to operate on the "sources" list. Regex
filters in a dict take the form:
'sources/': [ ['exclude', '_(linux|mac|win)\\.cc$'],
['include', '_mac\\.cc$'] ],
The first filter says to exclude all files ending in _linux.cc, _mac.cc, and
_win.cc. The second filter then includes all files ending in _mac.cc that
are now or were once in the "sources" list. Items matching an "exclude"
filter are subject to the same processing as would occur if they were listed
by name in an exclusion list (ending in "!"). Items matching an "include"
filter are brought back into the main list if previously excluded by an
exclusion list or exclusion regex filter. Subsequent matching "exclude"
patterns can still cause items to be excluded after matching an "include".
"""
# Look through the dictionary for any lists whose keys end in "!" or "/".
# These are lists that will be treated as exclude lists and regular
# expression-based exclude/include lists. Collect the lists that are
# needed first, looking for the lists that they operate on, and assemble
# then into |lists|. This is done in a separate loop up front, because
# the _included and _excluded keys need to be added to the_dict, and that
# can't be done while iterating through it.
lists = []
del_lists = []
for key, value in the_dict.items():
operation = key[-1]
if operation != "!" and operation != "/":
continue
if type(value) is not list:
raise ValueError(
name + " key " + key + " must be list, not " + value.__class__.__name__
)
list_key = key[:-1]
if list_key not in the_dict:
# This happens when there's a list like "sources!" but no corresponding
# "sources" list. Since there's nothing for it to operate on, queue up
# the "sources!" list for deletion now.
del_lists.append(key)
continue
if type(the_dict[list_key]) is not list:
value = the_dict[list_key]
raise ValueError(
name
+ " key "
+ list_key
+ " must be list, not "
+ value.__class__.__name__
+ " when applying "
+ {"!": "exclusion", "/": "regex"}[operation]
)
if list_key not in lists:
lists.append(list_key)
# Delete the lists that are known to be unneeded at this point.
for del_list in del_lists:
del the_dict[del_list]
for list_key in lists:
the_list = the_dict[list_key]
# Initialize the list_actions list, which is parallel to the_list. Each
# item in list_actions identifies whether the corresponding item in
# the_list should be excluded, unconditionally preserved (included), or
# whether no exclusion or inclusion has been applied. Items for which
# no exclusion or inclusion has been applied (yet) have value -1, items
# excluded have value 0, and items included have value 1. Includes and
# excludes override previous actions. All items in list_actions are
# initialized to -1 because no excludes or includes have been processed
# yet.
list_actions = list((-1,) * len(the_list))
exclude_key = list_key + "!"
if exclude_key in the_dict:
for exclude_item in the_dict[exclude_key]:
for index, list_item in enumerate(the_list):
if exclude_item == list_item:
# This item matches the exclude_item, so set its action to 0
# (exclude).
list_actions[index] = 0
# The "whatever!" list is no longer needed, dump it.
del the_dict[exclude_key]
regex_key = list_key + "/"
if regex_key in the_dict:
for regex_item in the_dict[regex_key]:
[action, pattern] = regex_item
pattern_re = re.compile(pattern)
if action == "exclude":
# This item matches an exclude regex, set its value to 0 (exclude).
action_value = 0
elif action == "include":
# This item matches an include regex, set its value to 1 (include).
action_value = 1
else:
# This is an action that doesn't make any sense.
raise ValueError(
"Unrecognized action "
+ action
+ " in "
+ name
+ " key "
+ regex_key
)
for index, list_item in enumerate(the_list):
if list_actions[index] == action_value:
# Even if the regex matches, nothing will change so continue
# (regex searches are expensive).
continue
if pattern_re.search(list_item):
# Regular expression match.
list_actions[index] = action_value
# The "whatever/" list is no longer needed, dump it.
del the_dict[regex_key]
# Add excluded items to the excluded list.
#
# Note that exclude_key ("sources!") is different from excluded_key
# ("sources_excluded"). The exclude_key list is input and it was already
# processed and deleted; the excluded_key list is output and it's about
# to be created.
excluded_key = list_key + "_excluded"
if excluded_key in the_dict:
raise GypError(
name + " key " + excluded_key + " must not be present prior "
" to applying exclusion/regex filters for " + list_key
)
excluded_list = []
# Go backwards through the list_actions list so that as items are deleted,
# the indices of items that haven't been seen yet don't shift. That means
# that things need to be prepended to excluded_list to maintain them in the
# same order that they existed in the_list.
for index in range(len(list_actions) - 1, -1, -1):
if list_actions[index] == 0:
# Dump anything with action 0 (exclude). Keep anything with action 1
# (include) or -1 (no include or exclude seen for the item).
excluded_list.insert(0, the_list[index])
del the_list[index]
# If anything was excluded, put the excluded list into the_dict at
# excluded_key.
if len(excluded_list) > 0:
the_dict[excluded_key] = excluded_list
# Now recurse into subdicts and lists that may contain dicts.
for key, value in the_dict.items():
if type(value) is dict:
ProcessListFiltersInDict(key, value)
elif type(value) is list:
ProcessListFiltersInList(key, value)
def ProcessListFiltersInList(name, the_list):
for item in the_list:
if type(item) is dict:
ProcessListFiltersInDict(name, item)
elif type(item) is list:
ProcessListFiltersInList(name, item)
def ValidateTargetType(target, target_dict):
"""Ensures the 'type' field on the target is one of the known types.
Arguments:
target: string, name of target.
target_dict: dict, target spec.
Raises an exception on error.
"""
VALID_TARGET_TYPES = (
"executable",
"loadable_module",
"static_library",
"shared_library",
"mac_kernel_extension",
"none",
"windows_driver",
)
target_type = target_dict.get("type", None)
if target_type not in VALID_TARGET_TYPES:
raise GypError(
"Target %s has an invalid target type '%s'. "
"Must be one of %s." % (target, target_type, "/".join(VALID_TARGET_TYPES))
)
if (
target_dict.get("standalone_static_library", 0)
and not target_type == "static_library"
):
raise GypError(
"Target %s has type %s but standalone_static_library flag is"
" only valid for static_library type." % (target, target_type)
)
def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
"""Ensures that the rules sections in target_dict are valid and consistent,
and determines which sources they apply to.
Arguments:
target: string, name of target.
target_dict: dict, target spec containing "rules" and "sources" lists.
extra_sources_for_rules: a list of keys to scan for rule matches in
addition to 'sources'.
"""
# Dicts to map between values found in rules' 'rule_name' and 'extension'
# keys and the rule dicts themselves.
rule_names = {}
rule_extensions = {}
rules = target_dict.get("rules", [])
for rule in rules:
# Make sure that there's no conflict among rule names and extensions.
rule_name = rule["rule_name"]
if rule_name in rule_names:
raise GypError(
f"rule {rule_name} exists in duplicate, target {target}"
)
rule_names[rule_name] = rule
rule_extension = rule["extension"]
if rule_extension.startswith("."):
rule_extension = rule_extension[1:]
if rule_extension in rule_extensions:
raise GypError(
(
"extension %s associated with multiple rules, "
+ "target %s rules %s and %s"
)
% (
rule_extension,
target,
rule_extensions[rule_extension]["rule_name"],
rule_name,
)
)
rule_extensions[rule_extension] = rule
# Make sure rule_sources isn't already there. It's going to be
# created below if needed.
if "rule_sources" in rule:
raise GypError(
"rule_sources must not exist in input, target %s rule %s"
% (target, rule_name)
)
rule_sources = []
source_keys = ["sources"]
source_keys.extend(extra_sources_for_rules)
for source_key in source_keys:
for source in target_dict.get(source_key, []):
(source_root, source_extension) = os.path.splitext(source)
if source_extension.startswith("."):
source_extension = source_extension[1:]
if source_extension == rule_extension:
rule_sources.append(source)
if len(rule_sources) > 0:
rule["rule_sources"] = rule_sources
def ValidateRunAsInTarget(target, target_dict, build_file):
target_name = target_dict.get("target_name")
run_as = target_dict.get("run_as")
if not run_as:
return
if type(run_as) is not dict:
raise GypError(
"The 'run_as' in target %s from file %s should be a "
"dictionary." % (target_name, build_file)
)
action = run_as.get("action")
if not action:
raise GypError(
"The 'run_as' in target %s from file %s must have an "
"'action' section." % (target_name, build_file)
)
if type(action) is not list:
raise GypError(
"The 'action' for 'run_as' in target %s from file %s "
"must be a list." % (target_name, build_file)
)
working_directory = run_as.get("working_directory")
if working_directory and type(working_directory) is not str:
raise GypError(
"The 'working_directory' for 'run_as' in target %s "
"in file %s should be a string." % (target_name, build_file)
)
environment = run_as.get("environment")
if environment and type(environment) is not dict:
raise GypError(
"The 'environment' for 'run_as' in target %s "
"in file %s should be a dictionary." % (target_name, build_file)
)
def ValidateActionsInTarget(target, target_dict, build_file):
"""Validates the inputs to the actions in a target."""
target_name = target_dict.get("target_name")
actions = target_dict.get("actions", [])
for action in actions:
action_name = action.get("action_name")
if not action_name:
raise GypError(
"Anonymous action in target %s. "
"An action must have an 'action_name' field." % target_name
)
inputs = action.get("inputs", None)
if inputs is None:
raise GypError("Action in target %s has no inputs." % target_name)
action_command = action.get("action")
if action_command and not action_command[0]:
raise GypError("Empty action as command in target %s." % target_name)
def TurnIntIntoStrInDict(the_dict):
"""Given dict the_dict, recursively converts all integers into strings.
"""
# Use items instead of iteritems because there's no need to try to look at
# reinserted keys and their associated values.
for k, v in the_dict.items():
if type(v) is int:
v = str(v)
the_dict[k] = v
elif type(v) is dict:
TurnIntIntoStrInDict(v)
elif type(v) is list:
TurnIntIntoStrInList(v)
if type(k) is int:
del the_dict[k]
the_dict[str(k)] = v
def TurnIntIntoStrInList(the_list):
"""Given list the_list, recursively converts all integers into strings.
"""
for index, item in enumerate(the_list):
if type(item) is int:
the_list[index] = str(item)
elif type(item) is dict:
TurnIntIntoStrInDict(item)
elif type(item) is list:
TurnIntIntoStrInList(item)
def PruneUnwantedTargets(targets, flat_list, dependency_nodes, root_targets, data):
"""Return only the targets that are deep dependencies of |root_targets|."""
qualified_root_targets = []
for target in root_targets:
target = target.strip()
qualified_targets = gyp.common.FindQualifiedTargets(target, flat_list)
if not qualified_targets:
raise GypError("Could not find target %s" % target)
qualified_root_targets.extend(qualified_targets)
wanted_targets = {}
for target in qualified_root_targets:
wanted_targets[target] = targets[target]
for dependency in dependency_nodes[target].DeepDependencies():
wanted_targets[dependency] = targets[dependency]
wanted_flat_list = [t for t in flat_list if t in wanted_targets]
# Prune unwanted targets from each build_file's data dict.
for build_file in data["target_build_files"]:
if "targets" not in data[build_file]:
continue
new_targets = []
for target in data[build_file]["targets"]:
qualified_name = gyp.common.QualifiedTarget(
build_file, target["target_name"], target["toolset"]
)
if qualified_name in wanted_targets:
new_targets.append(target)
data[build_file]["targets"] = new_targets
return wanted_targets, wanted_flat_list
def VerifyNoCollidingTargets(targets):
"""Verify that no two targets in the same directory share the same name.
Arguments:
targets: A list of targets in the form 'path/to/file.gyp:target_name'.
"""
# Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'.
used = {}
for target in targets:
# Separate out 'path/to/file.gyp, 'target_name' from
# 'path/to/file.gyp:target_name'.
path, name = target.rsplit(":", 1)
# Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'.
subdir, gyp = os.path.split(path)
# Use '.' for the current directory '', so that the error messages make
# more sense.
if not subdir:
subdir = "."
# Prepare a key like 'path/to:target_name'.
key = subdir + ":" + name
if key in used:
# Complain if this target is already used.
raise GypError(
'Duplicate target name "%s" in directory "%s" used both '
'in "%s" and "%s".' % (name, subdir, gyp, used[key])
)
used[key] = gyp
def SetGeneratorGlobals(generator_input_info):
# Set up path_sections and non_configuration_keys with the default data plus
# the generator-specific data.
global path_sections
path_sections = set(base_path_sections)
path_sections.update(generator_input_info["path_sections"])
global non_configuration_keys
non_configuration_keys = base_non_configuration_keys[:]
non_configuration_keys.extend(generator_input_info["non_configuration_keys"])
global multiple_toolsets
multiple_toolsets = generator_input_info["generator_supports_multiple_toolsets"]
global generator_filelist_paths
generator_filelist_paths = generator_input_info["generator_filelist_paths"]
def Load(
build_files,
variables,
includes,
depth,
generator_input_info,
check,
circular_check,
parallel,
root_targets,
):
SetGeneratorGlobals(generator_input_info)
# A generator can have other lists (in addition to sources) be processed
# for rules.
extra_sources_for_rules = generator_input_info["extra_sources_for_rules"]
# Load build files. This loads every target-containing build file into
# the |data| dictionary such that the keys to |data| are build file names,
# and the values are the entire build file contents after "early" or "pre"
# processing has been done and includes have been resolved.
# NOTE: data contains both "target" files (.gyp) and "includes" (.gypi), as
# well as meta-data (e.g. 'included_files' key). 'target_build_files' keeps
# track of the keys corresponding to "target" files.
data = {"target_build_files": set()}
# Normalize paths everywhere. This is important because paths will be
# used as keys to the data dict and for references between input files.
build_files = set(map(os.path.normpath, build_files))
if parallel:
LoadTargetBuildFilesParallel(
build_files, data, variables, includes, depth, check, generator_input_info
)
else:
aux_data = {}
for build_file in build_files:
try:
LoadTargetBuildFile(
build_file, data, aux_data, variables, includes, depth, check, True
)
except Exception as e:
gyp.common.ExceptionAppend(e, "while trying to load %s" % build_file)
raise
# Build a dict to access each target's subdict by qualified name.
targets = BuildTargetsDict(data)
# Fully qualify all dependency links.
QualifyDependencies(targets)
# Remove self-dependencies from targets that have 'prune_self_dependencies'
# set to 1.
RemoveSelfDependencies(targets)
# Expand dependencies specified as build_file:*.
ExpandWildcardDependencies(targets, data)
# Remove all dependencies marked as 'link_dependency' from the targets of
# type 'none'.
RemoveLinkDependenciesFromNoneTargets(targets)
# Apply exclude (!) and regex (/) list filters only for dependency_sections.
for target_name, target_dict in targets.items():
tmp_dict = {}
for key_base in dependency_sections:
for op in ("", "!", "/"):
key = key_base + op
if key in target_dict:
tmp_dict[key] = target_dict[key]
del target_dict[key]
ProcessListFiltersInDict(target_name, tmp_dict)
# Write the results back to |target_dict|.
for key in tmp_dict:
target_dict[key] = tmp_dict[key]
# Make sure every dependency appears at most once.
RemoveDuplicateDependencies(targets)
if circular_check:
# Make sure that any targets in a.gyp don't contain dependencies in other
# .gyp files that further depend on a.gyp.
VerifyNoGYPFileCircularDependencies(targets)
[dependency_nodes, flat_list] = BuildDependencyList(targets)
if root_targets:
# Remove, from |targets| and |flat_list|, the targets that are not deep
# dependencies of the targets specified in |root_targets|.
targets, flat_list = PruneUnwantedTargets(
targets, flat_list, dependency_nodes, root_targets, data
)
# Check that no two targets in the same directory have the same name.
VerifyNoCollidingTargets(flat_list)
# Handle dependent settings of various types.
for settings_type in [
"all_dependent_settings",
"direct_dependent_settings",
"link_settings",
]:
DoDependentSettings(settings_type, flat_list, targets, dependency_nodes)
# Take out the dependent settings now that they've been published to all
# of the targets that require them.
for target in flat_list:
if settings_type in targets[target]:
del targets[target][settings_type]
# Make sure static libraries don't declare dependencies on other static
# libraries, but that linkables depend on all unlinked static libraries
# that they need so that their link steps will be correct.
gii = generator_input_info
if gii["generator_wants_static_library_dependencies_adjusted"]:
AdjustStaticLibraryDependencies(
flat_list,
targets,
dependency_nodes,
gii["generator_wants_sorted_dependencies"],
)
# Apply "post"/"late"/"target" variable expansions and condition evaluations.
for target in flat_list:
target_dict = targets[target]
build_file = gyp.common.BuildFile(target)
ProcessVariablesAndConditionsInDict(
target_dict, PHASE_LATE, variables, build_file
)
# Move everything that can go into a "configurations" section into one.
for target in flat_list:
target_dict = targets[target]
SetUpConfigurations(target, target_dict)
# Apply exclude (!) and regex (/) list filters.
for target in flat_list:
target_dict = targets[target]
ProcessListFiltersInDict(target, target_dict)
# Apply "latelate" variable expansions and condition evaluations.
for target in flat_list:
target_dict = targets[target]
build_file = gyp.common.BuildFile(target)
ProcessVariablesAndConditionsInDict(
target_dict, PHASE_LATELATE, variables, build_file
)
# Make sure that the rules make sense, and build up rule_sources lists as
# needed. Not all generators will need to use the rule_sources lists, but
# some may, and it seems best to build the list in a common spot.
# Also validate actions and run_as elements in targets.
for target in flat_list:
target_dict = targets[target]
build_file = gyp.common.BuildFile(target)
ValidateTargetType(target, target_dict)
ValidateRulesInTarget(target, target_dict, extra_sources_for_rules)
ValidateRunAsInTarget(target, target_dict, build_file)
ValidateActionsInTarget(target, target_dict, build_file)
# Generators might not expect ints. Turn them into strs.
TurnIntIntoStrInDict(data)
# TODO(mark): Return |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
# a list, and not the whole data dict.
return [flat_list, targets, data]
node-gyp-9.3.0/gyp/pylib/gyp/input_test.py 0000775 0000000 0000000 00000006541 14321173220 0020536 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for the input.py file."""
import gyp.input
import unittest
class TestFindCycles(unittest.TestCase):
def setUp(self):
self.nodes = {}
for x in ("a", "b", "c", "d", "e"):
self.nodes[x] = gyp.input.DependencyGraphNode(x)
def _create_dependency(self, dependent, dependency):
dependent.dependencies.append(dependency)
dependency.dependents.append(dependent)
def test_no_cycle_empty_graph(self):
for label, node in self.nodes.items():
self.assertEqual([], node.FindCycles())
def test_no_cycle_line(self):
self._create_dependency(self.nodes["a"], self.nodes["b"])
self._create_dependency(self.nodes["b"], self.nodes["c"])
self._create_dependency(self.nodes["c"], self.nodes["d"])
for label, node in self.nodes.items():
self.assertEqual([], node.FindCycles())
def test_no_cycle_dag(self):
self._create_dependency(self.nodes["a"], self.nodes["b"])
self._create_dependency(self.nodes["a"], self.nodes["c"])
self._create_dependency(self.nodes["b"], self.nodes["c"])
for label, node in self.nodes.items():
self.assertEqual([], node.FindCycles())
def test_cycle_self_reference(self):
self._create_dependency(self.nodes["a"], self.nodes["a"])
self.assertEqual(
[[self.nodes["a"], self.nodes["a"]]], self.nodes["a"].FindCycles()
)
def test_cycle_two_nodes(self):
self._create_dependency(self.nodes["a"], self.nodes["b"])
self._create_dependency(self.nodes["b"], self.nodes["a"])
self.assertEqual(
[[self.nodes["a"], self.nodes["b"], self.nodes["a"]]],
self.nodes["a"].FindCycles(),
)
self.assertEqual(
[[self.nodes["b"], self.nodes["a"], self.nodes["b"]]],
self.nodes["b"].FindCycles(),
)
def test_two_cycles(self):
self._create_dependency(self.nodes["a"], self.nodes["b"])
self._create_dependency(self.nodes["b"], self.nodes["a"])
self._create_dependency(self.nodes["b"], self.nodes["c"])
self._create_dependency(self.nodes["c"], self.nodes["b"])
cycles = self.nodes["a"].FindCycles()
self.assertTrue([self.nodes["a"], self.nodes["b"], self.nodes["a"]] in cycles)
self.assertTrue([self.nodes["b"], self.nodes["c"], self.nodes["b"]] in cycles)
self.assertEqual(2, len(cycles))
def test_big_cycle(self):
self._create_dependency(self.nodes["a"], self.nodes["b"])
self._create_dependency(self.nodes["b"], self.nodes["c"])
self._create_dependency(self.nodes["c"], self.nodes["d"])
self._create_dependency(self.nodes["d"], self.nodes["e"])
self._create_dependency(self.nodes["e"], self.nodes["a"])
self.assertEqual(
[
[
self.nodes["a"],
self.nodes["b"],
self.nodes["c"],
self.nodes["d"],
self.nodes["e"],
self.nodes["a"],
]
],
self.nodes["a"].FindCycles(),
)
if __name__ == "__main__":
unittest.main()
node-gyp-9.3.0/gyp/pylib/gyp/mac_tool.py 0000775 0000000 0000000 00000073064 14321173220 0020141 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utility functions to perform Xcode-style build steps.
These functions are executed via gyp-mac-tool when using the Makefile generator.
"""
import fcntl
import fnmatch
import glob
import json
import os
import plistlib
import re
import shutil
import struct
import subprocess
import sys
import tempfile
def main(args):
executor = MacTool()
exit_code = executor.Dispatch(args)
if exit_code is not None:
sys.exit(exit_code)
class MacTool:
"""This class performs all the Mac tooling steps. The methods can either be
executed directly, or dispatched from an argument list."""
def Dispatch(self, args):
"""Dispatches a string command to a method."""
if len(args) < 1:
raise Exception("Not enough arguments")
method = "Exec%s" % self._CommandifyName(args[0])
return getattr(self, method)(*args[1:])
def _CommandifyName(self, name_string):
"""Transforms a tool name like copy-info-plist to CopyInfoPlist"""
return name_string.title().replace("-", "")
def ExecCopyBundleResource(self, source, dest, convert_to_binary):
"""Copies a resource file to the bundle/Resources directory, performing any
necessary compilation on each resource."""
convert_to_binary = convert_to_binary == "True"
extension = os.path.splitext(source)[1].lower()
if os.path.isdir(source):
# Copy tree.
# TODO(thakis): This copies file attributes like mtime, while the
# single-file branch below doesn't. This should probably be changed to
# be consistent with the single-file branch.
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(source, dest)
elif extension == ".xib":
return self._CopyXIBFile(source, dest)
elif extension == ".storyboard":
return self._CopyXIBFile(source, dest)
elif extension == ".strings" and not convert_to_binary:
self._CopyStringsFile(source, dest)
else:
if os.path.exists(dest):
os.unlink(dest)
shutil.copy(source, dest)
if convert_to_binary and extension in (".plist", ".strings"):
self._ConvertToBinary(dest)
def _CopyXIBFile(self, source, dest):
"""Compiles a XIB file with ibtool into a binary plist in the bundle."""
# ibtool sometimes crashes with relative paths. See crbug.com/314728.
base = os.path.dirname(os.path.realpath(__file__))
if os.path.relpath(source):
source = os.path.join(base, source)
if os.path.relpath(dest):
dest = os.path.join(base, dest)
args = ["xcrun", "ibtool", "--errors", "--warnings", "--notices"]
if os.environ["XCODE_VERSION_ACTUAL"] > "0700":
args.extend(["--auto-activate-custom-fonts"])
if "IPHONEOS_DEPLOYMENT_TARGET" in os.environ:
args.extend(
[
"--target-device",
"iphone",
"--target-device",
"ipad",
"--minimum-deployment-target",
os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
]
)
else:
args.extend(
[
"--target-device",
"mac",
"--minimum-deployment-target",
os.environ["MACOSX_DEPLOYMENT_TARGET"],
]
)
args.extend(
["--output-format", "human-readable-text", "--compile", dest, source]
)
ibtool_section_re = re.compile(r"/\*.*\*/")
ibtool_re = re.compile(r".*note:.*is clipping its content")
try:
stdout = subprocess.check_output(args)
except subprocess.CalledProcessError as e:
print(e.output)
raise
current_section_header = None
for line in stdout.splitlines():
if ibtool_section_re.match(line):
current_section_header = line
elif not ibtool_re.match(line):
if current_section_header:
print(current_section_header)
current_section_header = None
print(line)
return 0
def _ConvertToBinary(self, dest):
subprocess.check_call(
["xcrun", "plutil", "-convert", "binary1", "-o", dest, dest]
)
def _CopyStringsFile(self, source, dest):
"""Copies a .strings file using iconv to reconvert the input into UTF-16."""
input_code = self._DetectInputEncoding(source) or "UTF-8"
# Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call
# CFPropertyListCreateFromXMLData() behind the scenes; at least it prints
# CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
# semicolon in dictionary.
# on invalid files. Do the same kind of validation.
import CoreFoundation
with open(source, "rb") as in_file:
s = in_file.read()
d = CoreFoundation.CFDataCreate(None, s, len(s))
_, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None)
if error:
return
with open(dest, "wb") as fp:
fp.write(s.decode(input_code).encode("UTF-16"))
def _DetectInputEncoding(self, file_name):
"""Reads the first few bytes from file_name and tries to guess the text
encoding. Returns None as a guess if it can't detect it."""
with open(file_name, "rb") as fp:
try:
header = fp.read(3)
except Exception:
return None
if header.startswith(b"\xFE\xFF"):
return "UTF-16"
elif header.startswith(b"\xFF\xFE"):
return "UTF-16"
elif header.startswith(b"\xEF\xBB\xBF"):
return "UTF-8"
else:
return None
def ExecCopyInfoPlist(self, source, dest, convert_to_binary, *keys):
"""Copies the |source| Info.plist to the destination directory |dest|."""
# Read the source Info.plist into memory.
with open(source) as fd:
lines = fd.read()
# Insert synthesized key/value pairs (e.g. BuildMachineOSBuild).
plist = plistlib.readPlistFromString(lines)
if keys:
plist.update(json.loads(keys[0]))
lines = plistlib.writePlistToString(plist)
# Go through all the environment variables and replace them as variables in
# the file.
IDENT_RE = re.compile(r"[_/\s]")
for key in os.environ:
if key.startswith("_"):
continue
evar = "${%s}" % key
evalue = os.environ[key]
lines = lines.replace(lines, evar, evalue)
# Xcode supports various suffices on environment variables, which are
# all undocumented. :rfc1034identifier is used in the standard project
# template these days, and :identifier was used earlier. They are used to
# convert non-url characters into things that look like valid urls --
# except that the replacement character for :identifier, '_' isn't valid
# in a URL either -- oops, hence :rfc1034identifier was born.
evar = "${%s:identifier}" % key
evalue = IDENT_RE.sub("_", os.environ[key])
lines = lines.replace(lines, evar, evalue)
evar = "${%s:rfc1034identifier}" % key
evalue = IDENT_RE.sub("-", os.environ[key])
lines = lines.replace(lines, evar, evalue)
# Remove any keys with values that haven't been replaced.
lines = lines.splitlines()
for i in range(len(lines)):
if lines[i].strip().startswith("${"):
lines[i] = None
lines[i - 1] = None
lines = "\n".join(line for line in lines if line is not None)
# Write out the file with variables replaced.
with open(dest, "w") as fd:
fd.write(lines)
# Now write out PkgInfo file now that the Info.plist file has been
# "compiled".
self._WritePkgInfo(dest)
if convert_to_binary == "True":
self._ConvertToBinary(dest)
def _WritePkgInfo(self, info_plist):
"""This writes the PkgInfo file from the data stored in Info.plist."""
plist = plistlib.readPlist(info_plist)
if not plist:
return
# Only create PkgInfo for executable types.
package_type = plist["CFBundlePackageType"]
if package_type != "APPL":
return
# The format of PkgInfo is eight characters, representing the bundle type
# and bundle signature, each four characters. If that is missing, four
# '?' characters are used instead.
signature_code = plist.get("CFBundleSignature", "????")
if len(signature_code) != 4: # Wrong length resets everything, too.
signature_code = "?" * 4
dest = os.path.join(os.path.dirname(info_plist), "PkgInfo")
with open(dest, "w") as fp:
fp.write(f"{package_type}{signature_code}")
def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
fd = os.open(lockfile, os.O_RDONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
fcntl.flock(fd, fcntl.LOCK_EX)
return subprocess.call(cmd_list)
def ExecFilterLibtool(self, *cmd_list):
"""Calls libtool and filters out '/path/to/libtool: file: foo.o has no
symbols'."""
libtool_re = re.compile(
r"^.*libtool: (?:for architecture: \S* )?" r"file: .* has no symbols$"
)
libtool_re5 = re.compile(
r"^.*libtool: warning for library: "
+ r".* the table of contents is empty "
+ r"\(no object file members in the library define global symbols\)$"
)
env = os.environ.copy()
# Ref:
# http://www.opensource.apple.com/source/cctools/cctools-809/misc/libtool.c
# The problem with this flag is that it resets the file mtime on the file to
# epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone.
env["ZERO_AR_DATE"] = "1"
libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
err = libtoolout.communicate()[1].decode("utf-8")
for line in err.splitlines():
if not libtool_re.match(line) and not libtool_re5.match(line):
print(line, file=sys.stderr)
# Unconditionally touch the output .a file on the command line if present
# and the command succeeded. A bit hacky.
if not libtoolout.returncode:
for i in range(len(cmd_list) - 1):
if cmd_list[i] == "-o" and cmd_list[i + 1].endswith(".a"):
os.utime(cmd_list[i + 1], None)
break
return libtoolout.returncode
def ExecPackageIosFramework(self, framework):
# Find the name of the binary based on the part before the ".framework".
binary = os.path.basename(framework).split(".")[0]
module_path = os.path.join(framework, "Modules")
if not os.path.exists(module_path):
os.mkdir(module_path)
module_template = (
"framework module %s {\n"
' umbrella header "%s.h"\n'
"\n"
" export *\n"
" module * { export * }\n"
"}\n" % (binary, binary)
)
with open(os.path.join(module_path, "module.modulemap"), "w") as module_file:
module_file.write(module_template)
def ExecPackageFramework(self, framework, version):
"""Takes a path to Something.framework and the Current version of that and
sets up all the symlinks."""
# Find the name of the binary based on the part before the ".framework".
binary = os.path.basename(framework).split(".")[0]
CURRENT = "Current"
RESOURCES = "Resources"
VERSIONS = "Versions"
if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)):
# Binary-less frameworks don't seem to contain symlinks (see e.g.
# chromium's out/Debug/org.chromium.Chromium.manifest/ bundle).
return
# Move into the framework directory to set the symlinks correctly.
pwd = os.getcwd()
os.chdir(framework)
# Set up the Current version.
self._Relink(version, os.path.join(VERSIONS, CURRENT))
# Set up the root symlinks.
self._Relink(os.path.join(VERSIONS, CURRENT, binary), binary)
self._Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES)
# Back to where we were before!
os.chdir(pwd)
def _Relink(self, dest, link):
"""Creates a symlink to |dest| named |link|. If |link| already exists,
it is overwritten."""
if os.path.lexists(link):
os.remove(link)
os.symlink(dest, link)
def ExecCompileIosFrameworkHeaderMap(self, out, framework, *all_headers):
framework_name = os.path.basename(framework).split(".")[0]
all_headers = [os.path.abspath(header) for header in all_headers]
filelist = {}
for header in all_headers:
filename = os.path.basename(header)
filelist[filename] = header
filelist[os.path.join(framework_name, filename)] = header
WriteHmap(out, filelist)
def ExecCopyIosFrameworkHeaders(self, framework, *copy_headers):
header_path = os.path.join(framework, "Headers")
if not os.path.exists(header_path):
os.makedirs(header_path)
for header in copy_headers:
shutil.copy(header, os.path.join(header_path, os.path.basename(header)))
def ExecCompileXcassets(self, keys, *inputs):
"""Compiles multiple .xcassets files into a single .car file.
This invokes 'actool' to compile all the inputs .xcassets files. The
|keys| arguments is a json-encoded dictionary of extra arguments to
pass to 'actool' when the asset catalogs contains an application icon
or a launch image.
Note that 'actool' does not create the Assets.car file if the asset
catalogs does not contains imageset.
"""
command_line = [
"xcrun",
"actool",
"--output-format",
"human-readable-text",
"--compress-pngs",
"--notices",
"--warnings",
"--errors",
]
is_iphone_target = "IPHONEOS_DEPLOYMENT_TARGET" in os.environ
if is_iphone_target:
platform = os.environ["CONFIGURATION"].split("-")[-1]
if platform not in ("iphoneos", "iphonesimulator"):
platform = "iphonesimulator"
command_line.extend(
[
"--platform",
platform,
"--target-device",
"iphone",
"--target-device",
"ipad",
"--minimum-deployment-target",
os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
"--compile",
os.path.abspath(os.environ["CONTENTS_FOLDER_PATH"]),
]
)
else:
command_line.extend(
[
"--platform",
"macosx",
"--target-device",
"mac",
"--minimum-deployment-target",
os.environ["MACOSX_DEPLOYMENT_TARGET"],
"--compile",
os.path.abspath(os.environ["UNLOCALIZED_RESOURCES_FOLDER_PATH"]),
]
)
if keys:
keys = json.loads(keys)
for key, value in keys.items():
arg_name = "--" + key
if isinstance(value, bool):
if value:
command_line.append(arg_name)
elif isinstance(value, list):
for v in value:
command_line.append(arg_name)
command_line.append(str(v))
else:
command_line.append(arg_name)
command_line.append(str(value))
# Note: actool crashes if inputs path are relative, so use os.path.abspath
# to get absolute path name for inputs.
command_line.extend(map(os.path.abspath, inputs))
subprocess.check_call(command_line)
def ExecMergeInfoPlist(self, output, *inputs):
"""Merge multiple .plist files into a single .plist file."""
merged_plist = {}
for path in inputs:
plist = self._LoadPlistMaybeBinary(path)
self._MergePlist(merged_plist, plist)
plistlib.writePlist(merged_plist, output)
def ExecCodeSignBundle(self, key, entitlements, provisioning, path, preserve):
"""Code sign a bundle.
This function tries to code sign an iOS bundle, following the same
algorithm as Xcode:
1. pick the provisioning profile that best match the bundle identifier,
and copy it into the bundle as embedded.mobileprovision,
2. copy Entitlements.plist from user or SDK next to the bundle,
3. code sign the bundle.
"""
substitutions, overrides = self._InstallProvisioningProfile(
provisioning, self._GetCFBundleIdentifier()
)
entitlements_path = self._InstallEntitlements(
entitlements, substitutions, overrides
)
args = ["codesign", "--force", "--sign", key]
if preserve == "True":
args.extend(["--deep", "--preserve-metadata=identifier,entitlements"])
else:
args.extend(["--entitlements", entitlements_path])
args.extend(["--timestamp=none", path])
subprocess.check_call(args)
def _InstallProvisioningProfile(self, profile, bundle_identifier):
"""Installs embedded.mobileprovision into the bundle.
Args:
profile: string, optional, short name of the .mobileprovision file
to use, if empty or the file is missing, the best file installed
will be used
bundle_identifier: string, value of CFBundleIdentifier from Info.plist
Returns:
A tuple containing two dictionary: variables substitutions and values
to overrides when generating the entitlements file.
"""
source_path, provisioning_data, team_id = self._FindProvisioningProfile(
profile, bundle_identifier
)
target_path = os.path.join(
os.environ["BUILT_PRODUCTS_DIR"],
os.environ["CONTENTS_FOLDER_PATH"],
"embedded.mobileprovision",
)
shutil.copy2(source_path, target_path)
substitutions = self._GetSubstitutions(bundle_identifier, team_id + ".")
return substitutions, provisioning_data["Entitlements"]
def _FindProvisioningProfile(self, profile, bundle_identifier):
"""Finds the .mobileprovision file to use for signing the bundle.
Checks all the installed provisioning profiles (or if the user specified
the PROVISIONING_PROFILE variable, only consult it) and select the most
specific that correspond to the bundle identifier.
Args:
profile: string, optional, short name of the .mobileprovision file
to use, if empty or the file is missing, the best file installed
will be used
bundle_identifier: string, value of CFBundleIdentifier from Info.plist
Returns:
A tuple of the path to the selected provisioning profile, the data of
the embedded plist in the provisioning profile and the team identifier
to use for code signing.
Raises:
SystemExit: if no .mobileprovision can be used to sign the bundle.
"""
profiles_dir = os.path.join(
os.environ["HOME"], "Library", "MobileDevice", "Provisioning Profiles"
)
if not os.path.isdir(profiles_dir):
print(
"cannot find mobile provisioning for %s" % (bundle_identifier),
file=sys.stderr,
)
sys.exit(1)
provisioning_profiles = None
if profile:
profile_path = os.path.join(profiles_dir, profile + ".mobileprovision")
if os.path.exists(profile_path):
provisioning_profiles = [profile_path]
if not provisioning_profiles:
provisioning_profiles = glob.glob(
os.path.join(profiles_dir, "*.mobileprovision")
)
valid_provisioning_profiles = {}
for profile_path in provisioning_profiles:
profile_data = self._LoadProvisioningProfile(profile_path)
app_id_pattern = profile_data.get("Entitlements", {}).get(
"application-identifier", ""
)
for team_identifier in profile_data.get("TeamIdentifier", []):
app_id = f"{team_identifier}.{bundle_identifier}"
if fnmatch.fnmatch(app_id, app_id_pattern):
valid_provisioning_profiles[app_id_pattern] = (
profile_path,
profile_data,
team_identifier,
)
if not valid_provisioning_profiles:
print(
"cannot find mobile provisioning for %s" % (bundle_identifier),
file=sys.stderr,
)
sys.exit(1)
# If the user has multiple provisioning profiles installed that can be
# used for ${bundle_identifier}, pick the most specific one (ie. the
# provisioning profile whose pattern is the longest).
selected_key = max(valid_provisioning_profiles, key=lambda v: len(v))
return valid_provisioning_profiles[selected_key]
def _LoadProvisioningProfile(self, profile_path):
"""Extracts the plist embedded in a provisioning profile.
Args:
profile_path: string, path to the .mobileprovision file
Returns:
Content of the plist embedded in the provisioning profile as a dictionary.
"""
with tempfile.NamedTemporaryFile() as temp:
subprocess.check_call(
["security", "cms", "-D", "-i", profile_path, "-o", temp.name]
)
return self._LoadPlistMaybeBinary(temp.name)
def _MergePlist(self, merged_plist, plist):
"""Merge |plist| into |merged_plist|."""
for key, value in plist.items():
if isinstance(value, dict):
merged_value = merged_plist.get(key, {})
if isinstance(merged_value, dict):
self._MergePlist(merged_value, value)
merged_plist[key] = merged_value
else:
merged_plist[key] = value
else:
merged_plist[key] = value
def _LoadPlistMaybeBinary(self, plist_path):
"""Loads into a memory a plist possibly encoded in binary format.
This is a wrapper around plistlib.readPlist that tries to convert the
plist to the XML format if it can't be parsed (assuming that it is in
the binary format).
Args:
plist_path: string, path to a plist file, in XML or binary format
Returns:
Content of the plist as a dictionary.
"""
try:
# First, try to read the file using plistlib that only supports XML,
# and if an exception is raised, convert a temporary copy to XML and
# load that copy.
return plistlib.readPlist(plist_path)
except Exception:
pass
with tempfile.NamedTemporaryFile() as temp:
shutil.copy2(plist_path, temp.name)
subprocess.check_call(["plutil", "-convert", "xml1", temp.name])
return plistlib.readPlist(temp.name)
def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix):
"""Constructs a dictionary of variable substitutions for Entitlements.plist.
Args:
bundle_identifier: string, value of CFBundleIdentifier from Info.plist
app_identifier_prefix: string, value for AppIdentifierPrefix
Returns:
Dictionary of substitutions to apply when generating Entitlements.plist.
"""
return {
"CFBundleIdentifier": bundle_identifier,
"AppIdentifierPrefix": app_identifier_prefix,
}
def _GetCFBundleIdentifier(self):
"""Extracts CFBundleIdentifier value from Info.plist in the bundle.
Returns:
Value of CFBundleIdentifier in the Info.plist located in the bundle.
"""
info_plist_path = os.path.join(
os.environ["TARGET_BUILD_DIR"], os.environ["INFOPLIST_PATH"]
)
info_plist_data = self._LoadPlistMaybeBinary(info_plist_path)
return info_plist_data["CFBundleIdentifier"]
def _InstallEntitlements(self, entitlements, substitutions, overrides):
"""Generates and install the ${BundleName}.xcent entitlements file.
Expands variables "$(variable)" pattern in the source entitlements file,
add extra entitlements defined in the .mobileprovision file and the copy
the generated plist to "${BundlePath}.xcent".
Args:
entitlements: string, optional, path to the Entitlements.plist template
to use, defaults to "${SDKROOT}/Entitlements.plist"
substitutions: dictionary, variable substitutions
overrides: dictionary, values to add to the entitlements
Returns:
Path to the generated entitlements file.
"""
source_path = entitlements
target_path = os.path.join(
os.environ["BUILT_PRODUCTS_DIR"], os.environ["PRODUCT_NAME"] + ".xcent"
)
if not source_path:
source_path = os.path.join(os.environ["SDKROOT"], "Entitlements.plist")
shutil.copy2(source_path, target_path)
data = self._LoadPlistMaybeBinary(target_path)
data = self._ExpandVariables(data, substitutions)
if overrides:
for key in overrides:
if key not in data:
data[key] = overrides[key]
plistlib.writePlist(data, target_path)
return target_path
def _ExpandVariables(self, data, substitutions):
"""Expands variables "$(variable)" in data.
Args:
data: object, can be either string, list or dictionary
substitutions: dictionary, variable substitutions to perform
Returns:
Copy of data where each references to "$(variable)" has been replaced
by the corresponding value found in substitutions, or left intact if
the key was not found.
"""
if isinstance(data, str):
for key, value in substitutions.items():
data = data.replace("$(%s)" % key, value)
return data
if isinstance(data, list):
return [self._ExpandVariables(v, substitutions) for v in data]
if isinstance(data, dict):
return {k: self._ExpandVariables(data[k], substitutions) for k in data}
return data
def NextGreaterPowerOf2(x):
return 2 ** (x).bit_length()
def WriteHmap(output_name, filelist):
"""Generates a header map based on |filelist|.
Per Mark Mentovai:
A header map is structured essentially as a hash table, keyed by names used
in #includes, and providing pathnames to the actual files.
The implementation below and the comment above comes from inspecting:
http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
while also looking at the implementation in clang in:
https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
"""
magic = 1751998832
version = 1
_reserved = 0
count = len(filelist)
capacity = NextGreaterPowerOf2(count)
strings_offset = 24 + (12 * capacity)
max_value_length = max(len(value) for value in filelist.values())
out = open(output_name, "wb")
out.write(
struct.pack(
"