Skip to content

Commit

Permalink
build,tools: simply build config as config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Jan 31, 2019
1 parent dc1d331 commit 23b0104
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
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
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',
'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
17 changes: 14 additions & 3 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 @@ -272,11 +276,18 @@ def AddModule(module, source):
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)
config_filename = str(name).replace('gypi', 'json')
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

0 comments on commit 23b0104

Please sign in to comment.