Skip to content

Commit

Permalink
fix(flatten): update license handling logic (#184)
Browse files Browse the repository at this point in the history
Closes #183

Instead of finding line containing license in target source and adding
it to the top, we find it and extract the license identifier itself
  • Loading branch information
klkvr authored Aug 4, 2024
1 parent ec205aa commit 9af04b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions crates/compilers/src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'a> FlatteningResult<'a> {
let mut result = String::new();

if let Some(license) = &self.license {
result.push_str(&format!("{license}\n"));
result.push_str(&format!("// {license}\n"));
}
for pragma in &self.pragmas {
result.push_str(&format!("{pragma}\n"));
Expand Down Expand Up @@ -757,7 +757,9 @@ impl Flattener {

for loc in &self.collect_licenses() {
if loc.path == self.target {
target_license = Some(self.read_location(loc));
let license_line = self.read_location(loc);
let license_start = license_line.find("SPDX-License-Identifier:").unwrap();
target_license = Some(license_line[license_start..].trim());
}
updates.entry(loc.path.clone()).or_default().insert((
loc.start,
Expand Down
2 changes: 1 addition & 1 deletion test-data/hardhat-sample/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.0;

import "hardhat/console.sol";
Expand Down

0 comments on commit 9af04b2

Please sign in to comment.