You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by jm...@apache.org on 2022/10/12 12:05:01 UTC

[skywalking-php] branch master updated: Fix package.xml role error (#16)

This is an automated email from the ASF dual-hosted git repository.

jmjoy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git


The following commit(s) were added to refs/heads/master by this push:
     new b3d138a  Fix package.xml role error (#16)
b3d138a is described below

commit b3d138a7737868171d1a1712090940bb3600d5bd
Author: 何延龙 <he...@gmail.com>
AuthorDate: Wed Oct 12 20:04:56 2022 +0800

    Fix package.xml role error (#16)
---
 config.m4                                 |  4 ----
 package.tpl.xml                           |  2 +-
 scripts/src/command/create_package_xml.rs | 22 +++++++++++++++++++---
 src/lib.rs                                |  4 ++--
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/config.m4 b/config.m4
index 132194f..eecf076 100644
--- a/config.m4
+++ b/config.m4
@@ -63,12 +63,8 @@ cp ./target/$CARGO_MODE_DIR/libskywalking_agent.so ./modules/skywalking_agent.so
     .rustfmt.toml:.rustfmt.toml \
     Cargo.lock:Cargo.lock \
     Cargo.toml:Cargo.toml \
-    LICENSE:LICENSE \
-    NOTICE:NOTICE \
-    README.md:README.md \
     build.rs:build.rs \
     docker-compose.yml:docker-compose.yml \
-    docs:docs \
     scripts:scripts \
     src:src \
     tests:tests \
diff --git a/package.tpl.xml b/package.tpl.xml
index e18ca58..d1f9580 100644
--- a/package.tpl.xml
+++ b/package.tpl.xml
@@ -55,7 +55,7 @@ limitations under the License.
 	</notes>
 	<contents>
 		<dir name="/">
-			{% for file in files %}<file role="src" name="{{ file.path }}" />
+			{% for file in files %}{{ file.path|file_filter }}
 			{% endfor %}
 		</dir>
 	</contents>
diff --git a/scripts/src/command/create_package_xml.rs b/scripts/src/command/create_package_xml.rs
index 8c12958..8ded8b9 100644
--- a/scripts/src/command/create_package_xml.rs
+++ b/scripts/src/command/create_package_xml.rs
@@ -16,8 +16,8 @@
 use chrono::{DateTime, Local};
 use clap::Parser;
 use serde::Serialize;
-use std::{fs, path::PathBuf, process::Command, time::SystemTime};
-use tera::{Context, Tera};
+use std::{collections::HashMap, fs, path::PathBuf, process::Command, time::SystemTime};
+use tera::{Context, Result, Tera, Value};
 use tracing::info;
 
 /// Create package.xml from template file.
@@ -53,6 +53,19 @@ struct File {
     path: String,
 }
 
+pub fn file_filter(value: &Value, _: &HashMap<String, Value>) -> Result<Value> {
+    let mut role = "src";
+    let path = value.to_string().trim_matches('"').to_string();
+    if path.ends_with(".md") || path == "LICENSE" || path == "NOTICE" {
+        role = "doc"
+    }
+
+    Ok(Value::String(format!(
+        "<file name=\"{}\" role=\"{}\"/>",
+        path, role
+    )))
+}
+
 impl CreatePackageXmlCommand {
     pub fn run(&self) -> anyhow::Result<()> {
         info!(tpl_path = ?&self.tpl_path, "read template content");
@@ -64,7 +77,10 @@ impl CreatePackageXmlCommand {
         context.insert("notes", &self.notes);
         context.insert("files", &self.get_git_files()?);
 
-        let contents = Tera::one_off(&tpl, &context, false)?;
+        let mut tera = Tera::default();
+        tera.register_filter("file_filter", file_filter);
+        let contents = tera.render_str(&tpl, &context)?;
+
         info!(target_path = ?&self.target_path, "write target content");
         fs::write(&self.target_path, contents)?;
 
diff --git a/src/lib.rs b/src/lib.rs
index b20294a..c08a17c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,9 +13,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#![warn(rust_2018_idioms, missing_docs)]
+#![allow(missing_docs)]
+#![warn(rust_2018_idioms)]
 #![warn(clippy::dbg_macro, clippy::print_stdout)]
-#![doc = include_str!("../README.md")]
 
 mod channel;
 mod component;