Skip to content

Commit

Permalink
Merge branch 'master' into additional-verification-after-attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
panliming-tuya authored Oct 14, 2022
2 parents 11b5724 + ac19e88 commit ea40f1a
Show file tree
Hide file tree
Showing 42 changed files with 1,161 additions and 441 deletions.
2 changes: 1 addition & 1 deletion .spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ matrix:
# converts markdown to HTML
- pyspelling.filters.markdown:
sources:
- '**/*.md|!third_party/**|!examples/common/**/repo/**'
- '**/*.md|!third_party/**|!examples/common/**/repo/**|!docs/ERROR_CODES.md'
aspell:
ignore-case: true
176 changes: 175 additions & 1 deletion build/chip/java/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ template("java_library") {
_data_deps = invoker.data_deps
}

# Generates a .java file containing all sources to be compiled
# Generates a .sources file containing all sources to be compiled
_java_sources_file = "$target_gen_dir/$target_name.sources"
if (defined(invoker.java_sources_file)) {
_java_sources_file = invoker.java_sources_file
Expand Down Expand Up @@ -176,6 +176,162 @@ template("java_library") {
}
}

# Declare a Java executable target
#
# Manifext.txt: contains the given class as the entrypoint about the files packaged in a Java executable target.
#
# sources: List of .java files included in this binary. Mutually exclusive with jar_path.
#
# jar_path: A path to an existing JAR. Mutually exclusive with sources.
#
# output_name: File name for the output binary under root_build_dir/bin.
#
# javac_flags: additional flags to pass to the javac compiler
#
template("java_binary") {
# Figure out the output name
_jar_name = target_name
if (defined(invoker.output_name)) {
_jar_name = invoker.output_name
} else {
_jar_name += ".jar"
}

_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}

# What files will be compiled
_java_files = []
if (defined(invoker.sources)) {
_java_files = invoker.sources
}

_is_prebuilt = defined(invoker.jar_path)

_jar_output = ""
_target_dir_name = get_label_info(":$target_name", "dir")
if (_is_prebuilt) {
assert(_java_files == [])
_jar_output = "$root_out_dir/bin/$_target_dir_name/" +
get_path_info(invoker.jar_path, "name") + ".jar"
} else {
_jar_output = "$root_out_dir/bin/$_target_dir_name/$_jar_name"
}

# Generate a list containing the expected build_config filepath of every dependency.
_deps_configs = []
foreach(_dep, _deps) {
_dep_gen_dir = get_label_info(_dep, "target_gen_dir")
_dep_name = get_label_info(_dep, "name")
_dep_config = "$_dep_gen_dir/$_dep_name.json"
_deps_configs += [ _dep_config ]
}
_rebased_deps_configs = rebase_path(_deps_configs, root_build_dir)

# Create the name for this target's build_config.
_library_target_name = target_name
_build_config = "$target_gen_dir/$_library_target_name.json"
_rebased_build_config = rebase_path(_build_config, root_build_dir)

# Write the build_config file for this target.
_config_target_name = target_name + "_config"
action(_config_target_name) {
script = write_build_config

deps = _deps

outputs = [ _build_config ]
args = [
"--jar-path",
rebase_path(_jar_output, root_build_dir),
"--build-config",
_rebased_build_config,
"--deps-configs=$_rebased_deps_configs",
]
}

# Building from sources - perform Java compilation and JAR creation.
if (!_is_prebuilt) {
# Additional flags
_javac_flags = [
"-Werror",
"-Xlint:all",
]
if (defined(invoker.javac_flags)) {
_javac_flags += invoker.javac_flags
}

# Data deps
_data_deps = []
if (defined(invoker.data_deps)) {
_data_deps = invoker.data_deps
}

# Generates a .sources file containing all sources to be compiled
_java_sources_file = "$target_gen_dir/$target_name.sources"
if (defined(invoker.java_sources_file)) {
_java_sources_file = invoker.java_sources_file
}
write_file(_java_sources_file, rebase_path(_java_files, root_build_dir))

# Compiles the given files into a directory and generates a 'class list'
_javac_target_name = target_name + "__javac"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/classes"
_class_list_file = "$target_gen_dir/$target_name.classlist"
action(_javac_target_name) {
sources = _java_files
deps = [ ":$_config_target_name" ]

outputs = [ _class_list_file ]

script = javac_runner

args = [
"--classdir",
_class_dir,
"--outfile",
rebase_path(_class_list_file, root_build_dir),
"--build-config",
_rebased_build_config,
"--",
"-d",
_class_dir,
"@" + rebase_path(_java_sources_file, root_build_dir),
] + _javac_flags
}

# Bundles all files within the 'class directory' into a jar file
action(target_name) {
deps = [ ":$_javac_target_name" ] + _deps

data_deps = _data_deps

outputs = [ _jar_output ]

script = jar_runner

args = [
"cfm",
rebase_path(_jar_output, root_build_dir),
"Manifest.txt",
"-C",
_class_dir,
".",
]
}
} else {
# Using pre-specified JAR instead of building from sources - simply copy the JAR to the output directory.
_original_jar_path = invoker.jar_path
copy(target_name) {
sources = [ _original_jar_path ]
outputs = [ _jar_output ]
deps = [ ":$_config_target_name" ] + _deps
}
}
}

template("android_library") {
java_library(target_name) {
forward_variables_from(invoker, "*")
Expand All @@ -194,6 +350,24 @@ template("android_library") {
}
}

template("android_binary") {
java_binary(target_name) {
forward_variables_from(invoker, "*")

if (!defined(javac_flags)) {
javac_flags = []
}

javac_flags += [
"-Xlint:-options",
"-source",
"8",
"-target",
"8",
]
}
}

template("java_prebuilt") {
java_library(target_name) {
forward_variables_from(invoker, "*")
Expand Down
6 changes: 4 additions & 2 deletions config/nrfconnect/chip-module/generate_factory_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ if(CONFIG_CHIP_FACTORY_DATA_USE_DEFAULT_CERTS)
# convert decimal PID to its hexadecimal representation to find out certification files in repository
math(EXPR LOCAL_PID "${CONFIG_CHIP_DEVICE_PRODUCT_ID}" OUTPUT_FORMAT HEXADECIMAL)
string(SUBSTRING ${LOCAL_PID} 2 -1 raw_pid)
string(TOUPPER ${raw_pid} raw_pid_upper)
# all certs are located in ${CHIP_ROOT}/credentials/development/attestation
# it can be used during development without need to generate new certifications
string(APPEND script_args "--dac_cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid}-Cert.der\"\n")
string(APPEND script_args "--dac_key \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid}-Key.der\"\n")
string(APPEND script_args "--dac_cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Cert.der\"\n")
string(APPEND script_args "--dac_key \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Key.der\"\n")
string(APPEND script_args "--pai_cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-PAI-noPID-Cert.der\"\n")
else()
find_program(chip_cert_exe NAMES chip-cert REQUIRED)
Expand All @@ -79,6 +80,7 @@ string(APPEND script_args "--spake2_it \"${CONFIG_CHIP_DEVICE_SPAKE2_IT}\"\n")
string(APPEND script_args "--spake2_salt \"${CONFIG_CHIP_DEVICE_SPAKE2_SALT}\"\n")
string(APPEND script_args "--discriminator ${CONFIG_CHIP_DEVICE_DISCRIMINATOR}\n")
string(APPEND script_args "--passcode ${CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE}\n")
string(APPEND script_args "--include_passcode\n")
string(APPEND script_args "--overwrite\n")

# check if spake2 verifier should be generated using script
Expand Down
Loading

0 comments on commit ea40f1a

Please sign in to comment.