Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build,tools: refactor build config into config.json #25798

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ node
node_g
*.swp
.benchmark_reports
icu_config.gypi
.eslintcache
node_trace.*.log
coverage/
!**/node_modules/**/coverage
Expand All @@ -50,11 +48,11 @@ Release/
!**/node_modules/**/release
!doc/blog/**
*.sln
!nodemsi.sln
!tools/msvs/msi/nodemsi.sln
*.suo
*.vcproj
*.vcxproj
!custom_actions.vcxproj
!tools/msvs/msi/custom_actions.vcxproj
*.vcxproj.user
*.vcxproj.filters
UpgradeLog*.XML
Expand All @@ -64,12 +62,12 @@ ipch/
*.opensdf
*.VC.db
*.VC.opendb
.vs/
.vscode/
/*.exe

/config.mk
/config.json
/config.gypi
/icu_config.gypi
/config.status
/config_fips.gypi
*-nodegyp*
Expand Down Expand Up @@ -115,7 +113,6 @@ tools/doc/node_modules
tools/clang-format/node_modules

# test artifacts
icu_config.gypi
*.tap

# Xcode workspaces and project folders
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ clean: ## Remove build artifacts.
.PHONY: distclean
distclean:
$(RM) -r out
$(RM) config.gypi icu_config.gypi config_fips.gypi
$(RM) config.gypi icu_config.gypi config_fips.gypi config.json
$(RM) config.mk
$(RM) -r $(NODE_EXE) $(NODE_G_EXE)
$(RM) -r node_modules
Expand Down
36 changes: 23 additions & 13 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,15 @@ def configure_static(o):
o['libraries'] += ['-static-libasan']


def write(filename, data):
def write(filename, data, dumpVerbose=False, isJson=False):
print_verbose('creating %s' % filename)
with open(filename, 'w+') as f:
f.write(data)
if dumpVerbose:
print_verbose(data)
with open(filename, 'w+') as fh:
if isJson:
json.dump(data, fh, indent=2, sort_keys=True)
else:
fh.write(data)

do_not_edit = '# Do not edit. Generated by the configure script.\n'

Expand Down Expand Up @@ -1639,20 +1644,25 @@ def make_bin_override():
else:
make_global_settings = False

write('config.json', variables, dumpVerbose=True, isJson=True)

output = {
'variables': variables,
'target_defaults': output,
'variables': {
'includes': [ 'config.json' ],
},
}
if make_global_settings:
output['make_global_settings'] = make_global_settings

print_verbose(output)

write('config.gypi', do_not_edit +
pprint.pformat(output, indent=2) + '\n')
config_gypi = do_not_edit + pprint.pformat(output, indent=2) + '\n'
write('config.gypi', config_gypi, dumpVerbose=True)

write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
' '.join([pipes.quote(arg) for arg in original_argv]) + '\n')
config_status = """#!/bin/sh
set -x
exec ./configure %s
""" % ' '.join([pipes.quote(arg) for arg in original_argv])
write('config.status', config_status)
os.chmod('config.status', 0o775)

config = {
Expand All @@ -1664,14 +1674,14 @@ def make_bin_override():
if options.prefix:
config['PREFIX'] = options.prefix

config = '\n'.join(['='.join(item) for item in config.items()]) + '\n'
config_mk = do_not_edit + '\n'.join(['='.join(item) for item in config.items()]) + '\n'

# On Windows there's no reason to search for a different python binary.
bin_override = None if sys.platform == 'win32' else make_bin_override()
if bin_override:
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config
config_mk = 'export PATH:=' + bin_override + ':$(PATH)\n' + config_mk

write('config.mk', do_not_edit + config)
write('config.mk', config_mk)

gyp_args = ['--no-parallel']

Expand Down
1 change: 1 addition & 0 deletions src/node_native_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class NativeModuleLoader {
// Generated by tools/js2c.py as node_javascript.cc
void LoadJavaScriptSource(); // Loads data into source_
UnionBytes GetConfig(); // Return data for config.gypi
UnionBytes GetBuildConfig(); // Return data for config.json

// Generated by tools/generate_code_cache.js as node_code_cache.cc when
// the build is configured with --code-cache-path=.... They are noops
Expand Down
16 changes: 4 additions & 12 deletions tools/install.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/usr/bin/env python

from __future__ import print_function
import ast
import errno
import json
import os
import re
import shutil
import sys
from getmoduleversion import get_version

# set at init time
node_prefix = '/usr/local' # PREFIX variable from Makefile
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
target_defaults = None
variables = None

def abspath(*args):
path = os.path.join(*args)
return os.path.abspath(path)

def load_config():
s = open('config.gypi').read()
return ast.literal_eval(s)

def try_unlink(path):
try:
os.unlink(path)
Expand Down Expand Up @@ -173,6 +166,7 @@ def ignore_inspector_headers(files, dest):
action([
'common.gypi',
'config.gypi',
'config.json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does any downstream rely on the variables being in config.gypi instead of being included? (Not sure who to ping but I guess this could make the PR semver-major?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just recreate config.gypi in this script? Or does that defeat the purpose of this PR if there is an inconsistency between what's generated in the build and what gets distributed in the tarballs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered that. Since they are both created by ./configure we could do that to solve this if we find it's a problem.
I wanted to do it like this to see if we can map the scope by looking for things that break.

(P.S. if we decide to make this semver-major, then I guess it would make sense to add the deprecation of process.config here)

'src/node.h',
'src/node_api.h',
'src/js_native_api.h',
Expand Down Expand Up @@ -205,14 +199,12 @@ def ignore_inspector_headers(files, dest):
], 'include/node/')

def run(args):
global node_prefix, install_path, target_defaults, variables
global node_prefix, install_path, variables

# chdir to the project's top-level directory
os.chdir(abspath(os.path.dirname(__file__), '..'))

conf = load_config()
variables = conf['variables']
target_defaults = conf['target_defaults']
variables = json.load('config.json')

# argv[2] is a custom install prefix for packagers (think DESTDIR)
# argv[3] is a custom install prefix (think PREFIX)
Expand Down
19 changes: 15 additions & 4 deletions tools/js2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def ReadMacros(lines):
return UnionBytes(config_raw, arraysize(config_raw)); // config.gypi
}}

UnionBytes NativeModuleLoader::GetBuildConfig() {{
return UnionBytes(build_config_raw, arraysize(build_config_raw)); // config.json
}}

}} // namespace native_module

}} // namespace node
Expand Down Expand Up @@ -271,12 +275,19 @@ def AddModule(module, source):
# later on anyway, so get it out of the way now
if name.endswith('.gypi'):
# Currently only config.gypi is allowed
assert name == 'config.gypi'
lines = re.sub(r'\'true\'', 'true', lines)
lines = re.sub(r'\'false\'', 'false', lines)
assert name.endswith('config.gypi')
config_filename = str(name).replace('gypi', 'json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass config.json to js2c in node.gyp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being I'm assuming 1:1 correspondence, and I want to keep the embedded config_raw data exactly the same using:
https://github.com/nodejs/node/blob/c663277042ed56a221bfbb25b5acf18a1ce2fdbd/tools/js2c.py#L285
So the tight coupling is there anyway...

config = ReadFile(config_filename)
config = re.sub('"true"', 'true', config)
config = re.sub('"false"', 'false', config)
print(config)
config_definition = GetDefinition('build_config_raw', config)
definitions.append(config_definition)
lines = lines.replace("{ 'includes': ['config.json']}", config)
lines = re.sub(r'#.*?\n', '', lines)
lines = re.sub(r'\'', '"', lines)
lines = re.sub("'", '"', lines)
definition = GetDefinition('config_raw', lines)
print(lines)
definitions.append(definition)
else:
AddModule(name.split('.', 1)[0], lines)
Expand Down