Skip to content

Commit

Permalink
Don't throw missing entrypoint error if package type is library (#1702)
Browse files Browse the repository at this point in the history
The `packageType` property was not getting properly propagated from the
manifest all the way to the `PackageInfo`. This PR fixes that.



https://github.com/microsoft/qsharp/assets/12157751/33395cde-5d81-4ff1-8b7c-d27400ac4edd
  • Loading branch information
sezna authored Jul 8, 2024
1 parent 18d5b5f commit 4bac636
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/qsc/src/packages/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn mock_program() -> Project {
Arc::from("SomeLibraryAlias"),
Arc::from("SomeLibraryKey"),
)]),
package_type: Some(qsc_project::PackageType::Exe),
},
packages: FxHashMap::from_iter(vec![(
Arc::from("SomeLibraryKey"),
Expand All @@ -32,6 +33,7 @@ fn mock_program() -> Project {
)],
language_features: LanguageFeatures::default(),
dependencies: FxHashMap::default(),
package_type: Some(qsc_project::PackageType::Lib),
},
)]),
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc_project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use error::StdFsError;
#[cfg(feature = "fs")]
pub use fs::StdFs;
pub use js::{JSFileEntry, JSProjectHost};
pub use manifest::{Manifest, ManifestDescriptor, PackageRef, MANIFEST_FILE_NAME};
pub use manifest::{Manifest, ManifestDescriptor, PackageRef, PackageType, MANIFEST_FILE_NAME};
pub use project::FileSystemAsync;
pub use project::{
key_for_package_ref, package_ref_from_key, DirEntry, EntryType, Error, FileSystem,
Expand Down
10 changes: 10 additions & 0 deletions compiler/qsc_project/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ pub struct Manifest {
pub dependencies: FxHashMap<String, PackageRef>,
#[serde(default)]
pub files: Vec<String>,
#[serde(default)]
pub package_type: Option<PackageType>,
}

#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
pub enum PackageType {
#[serde(rename = "exe")]
Exe,
#[serde(rename = "lib")]
Lib,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand Down
11 changes: 10 additions & 1 deletion compiler/qsc_project/src/project.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use crate::{manifest::GitHubRef, Manifest, ManifestDescriptor, PackageRef};
use crate::{
manifest::{GitHubRef, PackageType},
Manifest, ManifestDescriptor, PackageRef,
};
use async_trait::async_trait;
use futures::FutureExt;
use miette::Diagnostic;
Expand Down Expand Up @@ -48,6 +51,7 @@ impl Project {
sources: vec![(name.clone(), contents)],
language_features: LanguageFeatures::default(),
dependencies: FxHashMap::default(),
package_type: None,
},
packages: FxHashMap::default(),
},
Expand Down Expand Up @@ -380,6 +384,7 @@ pub trait FileSystemAsync {
sources,
language_features: LanguageFeatures::from_iter(&manifest.manifest.language_features),
dependencies,
package_type: manifest.manifest.package_type,
})
}

Expand Down Expand Up @@ -448,6 +453,7 @@ pub trait FileSystemAsync {
.into_iter()
.map(|(k, v)| (k.into(), key_for_package_ref(&v)))
.collect(),
package_type: manifest.package_type,
})
}

Expand Down Expand Up @@ -585,6 +591,7 @@ pub struct PackageInfo {
pub sources: Sources,
pub language_features: LanguageFeatures,
pub dependencies: FxHashMap<PackageAlias, PackageKey>,
pub package_type: Option<PackageType>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -655,12 +662,14 @@ impl PackageGraphSources {
pub fn with_no_dependencies(
sources: Vec<(Arc<str>, Arc<str>)>,
language_features: LanguageFeatures,
package_type: Option<PackageType>,
) -> Self {
Self {
root: PackageInfo {
sources,
language_features,
dependencies: FxHashMap::default(),
package_type,
},
packages: FxHashMap::default(),
}
Expand Down
15 changes: 15 additions & 0 deletions compiler/qsc_project/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn basic_manifest() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -75,6 +76,7 @@ fn circular_imports() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -112,6 +114,7 @@ fn different_files_same_manifest() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -141,6 +144,7 @@ fn empty_manifest() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -182,6 +186,7 @@ fn folder_structure() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -218,6 +223,7 @@ fn hidden_files() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -258,6 +264,7 @@ fn peer_file() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -287,6 +294,7 @@ fn language_feature() {
1,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -318,6 +326,7 @@ fn with_local_dep() {
dependencies: {
"MyDep": "{\"path\":\"local_dep\"}",
},
package_type: None,
},
packages: {
"{\"path\":\"local_dep\"}": PackageInfo {
Expand All @@ -331,6 +340,7 @@ fn with_local_dep() {
0,
),
dependencies: {},
package_type: None,
},
},
},
Expand Down Expand Up @@ -362,6 +372,7 @@ fn transitive_dep() {
dependencies: {
"MyDep": "{\"path\":\"with_local_dep\"}",
},
package_type: None,
},
packages: {
"{\"path\":\"local_dep\"}": PackageInfo {
Expand All @@ -375,6 +386,7 @@ fn transitive_dep() {
0,
),
dependencies: {},
package_type: None,
},
"{\"path\":\"with_local_dep\"}": PackageInfo {
sources: [
Expand All @@ -389,6 +401,7 @@ fn transitive_dep() {
dependencies: {
"MyDep": "{\"path\":\"local_dep\"}",
},
package_type: None,
},
},
},
Expand Down Expand Up @@ -418,6 +431,7 @@ fn explicit_files_list() {
0,
),
dependencies: {},
package_type: None,
},
packages: {},
},
Expand Down Expand Up @@ -449,6 +463,7 @@ fn circular_dep() {
dependencies: {
"MyCircularDep": "{\"path\":\"circular_dep\"}",
},
package_type: None,
},
packages: {},
},
Expand Down
6 changes: 6 additions & 0 deletions language_service/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ impl<'a> CompilationStateUpdater<'a> {
loaded_project.package_graph_sources.root.language_features,
),
lints_config: loaded_project.lints,
package_type: loaded_project.package_graph_sources.root.package_type.map(
|x| match x {
qsc_project::PackageType::Exe => qsc::PackageType::Exe,
qsc_project::PackageType::Lib => qsc::PackageType::Lib,
},
),
..PartialConfiguration::default()
};

Expand Down
1 change: 1 addition & 0 deletions language_service/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn compile_project_with_fake_stdlib_and_markers_cursor_optional(
sources,
language_features: LanguageFeatures::default(),
dependencies: FxHashMap::default(),
package_type: None,
},
packages: FxHashMap::default(),
},
Expand Down
1 change: 1 addition & 0 deletions pip/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl Interpreter {
let graph = PackageGraphSources::with_no_dependencies(
Vec::default(),
LanguageFeatures::from_iter(language_features),
None,
);
BuildableProgram::new(target.into(), graph)
};
Expand Down
20 changes: 19 additions & 1 deletion wasm/src/project_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ impl From<qsc_project::PackageInfo> for PackageInfo {
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
package_type: value.package_type.map(|x| {
match x {
qsc_project::PackageType::Exe => "exe",
qsc_project::PackageType::Lib => "lib",
}
.into()
}),
}
}
}
Expand Down Expand Up @@ -266,11 +273,15 @@ serializable_type! {
pub sources: Vec<(String, String)>,
pub language_features: Vec<String>,
pub dependencies: FxHashMap<PackageAlias,PackageKey>,
pub package_type: Option<String>,
},
r#"export interface IPackageInfo {
r#"
export interface IPackageInfo {
sources: [string, string][];
languageFeatures: string[];
dependencies: Record<string,string>;
packageType?: "exe" | "lib";
}"#
}

Expand Down Expand Up @@ -351,6 +362,13 @@ impl From<PackageInfo> for qsc_project::PackageInfo {
.into_iter()
.map(|(k, v)| (Arc::from(k), Arc::from(v)))
.collect(),
package_type: value.package_type.map(|x| match x.as_str() {
"exe" => qsc_project::PackageType::Exe,
"lib" => qsc_project::PackageType::Lib,
_ => unreachable!(
"expected one of 'exe' or 'lib' -- should be guaranteed by TS types"
),
}),
}
}
}
Expand Down

0 comments on commit 4bac636

Please sign in to comment.