Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Factor out nmf generation into a GN template
Browse files Browse the repository at this point in the history
This change factors out the logic for generating nmf files into a GN
template so that it can be reused across different GN files.

BUG=462791
[email protected], [email protected], [email protected]

Review URL: https://codereview.chromium.org/1432313002

Cr-Commit-Position: refs/heads/master@{#359661}
  • Loading branch information
petrhosek authored and Commit bot committed Nov 13, 2015
1 parent bd12887 commit 998705e
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 79 deletions.
139 changes: 139 additions & 0 deletions build/config/nacl/rules.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Copyright 2015 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/features.gni")
import("//build/config/nacl/config.gni")

# Generate a nmf file
#
# Native Client Manifest (nmf) is a JSON file that tells the browser where to
# download and load Native Client application files and libraries.
#
# Variables:
# executables: .nexe/.pexe/.bc executables to generate nmf for
# lib_prefix: path to prepend to shared libraries in the nmf
# nmf: the name and the path of the output file
# nmfflags: additional flags for the nmf generator
# stage_dependencies: directory for staging libraries
template("generate_nmf") {
assert(defined(invoker.executables), "Must define executables")
assert(defined(invoker.nmf), "Must define nmf")

action(target_name) {
nmfflags = []

forward_variables_from(invoker,
[
"deps",
"data_deps",
"executables",
"lib_prefix",
"nmf",
"nmfflags",
"public_deps",
"stage_dependencies",
"testonly",
])

script = "//native_client_sdk/src/tools/create_nmf.py"
sources = executables
outputs = [
nmf,
]
if (is_nacl_glibc) {
if (defined(stage_dependencies)) {
nmfflags += [ "--stage-dependencies=" +
rebase_path(stage_dependencies, root_build_dir) ]
lib_path = stage_dependencies
} else {
lib_path = root_build_dir
}
if (defined(lib_prefix)) {
nmfflags += [ "--lib-prefix=" + lib_prefix ]
lib_path += "/${lib_prefix}"
}

# NOTE: There is no explicit dependency for the lib32
# and lib64 directories created in the product directory.
# They are created as a side-effect of nmf creation.
nmfflags += [ "--library-path=" + rebase_path(root_out_dir) ]
if (current_cpu == "x86") {
nmfflags += [ "--library-path=" +
rebase_path("${nacl_toolchain_tooldir}/lib32") ]
data = [
"${lib_path}/lib32/",
]
} else if (current_cpu == "x64") {
nmfflags +=
[ "--library-path=" + rebase_path("${nacl_toolchain_tooldir}/lib") ]
data = [
"${lib_path}/lib64/",
]
} else {
nmfflags +=
[ "--library-path=" + rebase_path("${nacl_toolchain_tooldir}/lib") ]
data = [
"${lib_path}/lib/",
]
}
}
args = [
"--no-default-libpath",
"--objdump=" + rebase_path("${nacl_toolprefix}objdump"),
"--output=" + rebase_path(nmf, root_build_dir),
] + nmfflags + rebase_path(sources, root_build_dir)
if (is_nacl_glibc && current_cpu == "arm") {
deps += [ "//native_client/src/untrusted/elf_loader:elf_loader" ]
}
}
}

# Generate a nmf file for Non-SFI tests
#
# Non-SFI tests use a different manifest format from regular Native Client and
# as such requires a different generator.
#
# Variables:
# executable: Non-SFI .nexe executable to generate nmf for
# nmf: the name and the path of the output file
template("generate_nonsfi_test_nmf") {
assert(defined(invoker.executable), "Must define executable")
assert(defined(invoker.nmf), "Must define nmf")

action(target_name) {
forward_variables_from(invoker,
[
"deps",
"data_deps",
"executable",
"nmf",
"testonly",
"public_deps",
])

script = "//ppapi/tests/create_nonsfi_test_nmf.py"
sources = [
executable,
]
outputs = [
nmf,
]

# NOTE: We use target_cpu rather than current_cpu on purpose because
# current_cpu is always going to be pnacl for Non-SFI, but the Non-SFI
# .nexe executable is always translated to run on the target machine.
if (target_cpu == "x86") {
arch = "x86-32"
} else if (target_cpu == "x64") {
arch = "x86-64"
} else {
arch = target_cpu
}
args = [
"--program=" + rebase_path(executable, root_build_dir),
"--arch=${arch}",
"--output=" + rebase_path(nmf, root_build_dir),
]
}
}
89 changes: 10 additions & 79 deletions ppapi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ copy("copy_test_files2") {

import("//build/config/features.gni")
import("//build/config/nacl/config.gni")
import("//build/config/nacl/rules.gni")
import("//ppapi/ppapi_sources.gni")
import("//testing/test.gni")

Expand Down Expand Up @@ -312,93 +313,23 @@ if (enable_nacl) {
}
}

action("generate_nmf") {
generate_nmf("ppapi_nacl_tests_nmf") {
if (is_nacl_glibc) {
nmf = "${root_build_dir}/ppapi_nacl_tests_glibc.nmf"
} else if (current_cpu == "pnacl") {
nmf = "${root_build_dir}/ppapi_nacl_tests_pnacl.nmf"
} else {
nmf = "${root_build_dir}/ppapi_nacl_tests_newlib.nmf"
}
nexe = "${root_out_dir}/ppapi_nacl_tests.nexe"

objdump = rebase_path("${nacl_toolprefix}objdump")

script = "//native_client_sdk/src/tools/create_nmf.py"
sources = [
nexe,
]
outputs = [
nmf,
]
data = [
nexe,
executables = get_target_outputs(":nacl_tests_copy")
deps = [
":nacl_tests_copy",
]
nmf_flags = []
if (is_nacl_glibc) {
nmf_flags += [ "--library-path=" + rebase_path(root_out_dir) ]
if (current_cpu == "x86") {
nmf_flags += [ "--library-path=" +
rebase_path("${nacl_toolchain_tooldir}/lib32") ]
data += [ "$root_build_dir/lib32/" ]
}
if (target_cpu == "x64" || (target_cpu == "x86" && is_win)) {
nmf_flags += [ "--library-path=" +
rebase_path("${nacl_toolchain_tooldir}/lib") ]
data += [ "$root_build_dir/lib64/" ]
}
if (current_cpu == "arm") {
nmf_flags += [ "--library-path=" +
rebase_path("${nacl_toolchain_tooldir}/lib") ]
data += [ "$root_build_dir/lib/" ]
}
}
args = [
"--no-default-libpath",
"--objdump=" + objdump,
"--output=" + rebase_path(nmf, root_build_dir),
"--stage-dependencies=" + rebase_path(root_build_dir),
] + nmf_flags + rebase_path(sources, root_build_dir)
if (current_cpu == "pnacl") {
deps = [
":translate_pexe_to_nexe",
]
} else {
deps = [
":ppapi_nacl_tests",
]
if (is_nacl_glibc && current_cpu == "arm") {
deps += [ "//native_client/src/untrusted/elf_loader:elf_loader" ]
}
}
}

action("generate_nonsfi_nmf") {
generate_nonsfi_test_nmf("ppapi_nacl_tests_pnacl_nonsfi_nmf") {
nmf = "${root_build_dir}/ppapi_nacl_tests_pnacl_nonsfi.nmf"
nexe = "${root_out_dir}/ppapi_nacl_tests.nexe"

script = "//ppapi/tests/create_nonsfi_test_nmf.py"
sources = [
nexe,
]
outputs = [
nmf,
]
data = [
nexe,
]
if (target_cpu == "x86") {
arch = "x86-32"
} else if (target_cpu == "x64") {
arch = "x86-64"
} else if (target_cpu == "arm") {
arch = "arm"
}
args = [
"--program=" + rebase_path(sources[0], root_build_dir),
"--arch=${arch}",
"--output=" + rebase_path(nmf, root_build_dir),
]
executable = "${root_out_dir}/ppapi_nacl_tests.nexe"
deps = [
":translate_pexe_to_nexe",
]
Expand All @@ -409,12 +340,12 @@ if (enable_nacl) {
data_deps = [
":copy_test_files",
":nacl_tests_copy(//build/toolchain/nacl:clang_newlib_${target_cpu})",
":generate_nmf(//build/toolchain/nacl:glibc_${target_cpu})",
":ppapi_nacl_tests_nmf(//build/toolchain/nacl:glibc_${target_cpu})",
]
if (enable_pnacl) {
data_deps += [
":generate_nmf(//build/toolchain/nacl:newlib_pnacl)",
":generate_nonsfi_nmf(//build/toolchain/nacl:newlib_pnacl_nonsfi)",
":ppapi_nacl_tests_nmf(//build/toolchain/nacl:newlib_pnacl)",
":ppapi_nacl_tests_pnacl_nonsfi_nmf(//build/toolchain/nacl:newlib_pnacl_nonsfi)",
]
}
}
Expand Down

0 comments on commit 998705e

Please sign in to comment.